use of edu.harvard.iq.dataverse.engine.command.impl.GetUserTracesCommand in project dataverse by IQSS.
the class Users method getTraces.
@GET
@Path("{identifier}/traces")
public Response getTraces(@PathParam("identifier") String identifier) {
try {
AuthenticatedUser userToQuery = authSvc.getAuthenticatedUser(identifier);
JsonObjectBuilder jsonObj = execCommand(new GetUserTracesCommand(createDataverseRequest(findUserOrDie()), userToQuery, null));
return ok(jsonObj);
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.GetUserTracesCommand in project dataverse by IQSS.
the class Users method getTraces.
@GET
@Path("{identifier}/traces/{element}")
@Produces("text/csv, application/json")
public Response getTraces(@Context Request req, @PathParam("identifier") String identifier, @PathParam("element") String element) {
try {
AuthenticatedUser userToQuery = authSvc.getAuthenticatedUser(identifier);
if (!elements.contains(element)) {
throw new BadRequestException("Not a valid element");
}
JsonObjectBuilder jsonObj = execCommand(new GetUserTracesCommand(createDataverseRequest(findUserOrDie()), userToQuery, element));
List<Variant> vars = Variant.mediaTypes(MediaType.valueOf(FileUtil.MIME_TYPE_CSV), MediaType.APPLICATION_JSON_TYPE).add().build();
MediaType requestedType = req.selectVariant(vars).getMediaType();
if ((requestedType != null) && (requestedType.equals(MediaType.APPLICATION_JSON_TYPE))) {
return ok(jsonObj);
}
JsonArray items = null;
try {
items = jsonObj.build().getJsonObject("traces").getJsonObject(element).getJsonArray("items");
} catch (Exception e) {
return ok(jsonObj);
}
return ok(FileUtil.jsonArrayOfObjectsToCSV(items, items.getJsonObject(0).keySet().toArray(new String[0])), MediaType.valueOf(FileUtil.MIME_TYPE_CSV), element + ".csv");
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
Aggregations