Skip to content

Commit

Permalink
Merge pull request #3630 from pameyer/exp-fix_facet_api
Browse files Browse the repository at this point in the history
3591: list facet API fix
  • Loading branch information
kcondon authored Feb 22, 2017
2 parents 7162f5a + 4190f6b commit 5aeb54a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.harvard.iq.dataverse.DatasetFieldType;
import edu.harvard.iq.dataverse.DatasetVersion;
import edu.harvard.iq.dataverse.Dataverse;
import edu.harvard.iq.dataverse.DataverseFacet;
import edu.harvard.iq.dataverse.DataverseContact;
import edu.harvard.iq.dataverse.authorization.DataverseRole;
import edu.harvard.iq.dataverse.DvObject;
Expand Down Expand Up @@ -342,15 +343,37 @@ public Response setMetadataRoot( @PathParam("identifier")String dvIdtf, String b

@GET
@Path("{identifier}/facets/")
/**
* return list of facets for the dataverse with alias `dvIdtf`
*/
public Response listFacets( @PathParam("identifier") String dvIdtf ) {
return allowCors(response( req -> ok(
execCommand(new ListFacetsCommand(req, findDataverseOrDie(dvIdtf)) )
.stream().map(f->json(f)).collect(toJsonArray()))));
try
{
User u = findUserOrDie();
DataverseRequest r = createDataverseRequest( u );
Dataverse dataverse = findDataverseOrDie(dvIdtf);
JsonArrayBuilder fs = Json.createArrayBuilder();
for( DataverseFacet f : execCommand( new ListFacetsCommand( r, dataverse ) ) )
{
fs.add( f.getDatasetFieldType().getName() );
}
return allowCors( ok( fs ) );
}
catch( WrappedResponse e )
{
return e.getResponse();
}
}

@POST
@Path("{identifier}/facets")
@Produces(MediaType.APPLICATION_JSON)
/**
* (not publicly documented) API endpoint for assigning facets to a dataverse.
* `curl -X POST -H "X-Dataverse-key: $ADMIN_KEY" http://localhost:8088/api/dataverses/$dv/facets --upload-file foo.json`; where foo.json contains a list of datasetField names,
* works as expected (judging by the UI).
* This triggers a 500 when '-d @foo.json' is used.
*/
public Response setFacets( @PathParam("identifier")String dvIdtf, String facetIds ) {

List<DatasetFieldType> facets = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Set;

/**
*
* List the search facets {@link DataverseFacet} of a {@link Dataverse}.
* @author michaelsuo
*/
// no annotations here, since permissions are dynamically decided
Expand Down

0 comments on commit 5aeb54a

Please sign in to comment.