use of edu.harvard.iq.dataverse.engine.command.impl.GetHarvestingClientCommand in project dataverse by IQSS.
the class HarvestingClients method harvestingClient.
@GET
@Path("{nickName}")
public Response harvestingClient(@PathParam("nickName") String nickName, @QueryParam("key") String apiKey) throws IOException {
HarvestingClient harvestingClient = null;
try {
harvestingClient = harvestingClientService.findByNickname(nickName);
} catch (Exception ex) {
logger.warning("Exception caught looking up harvesting client " + nickName + ": " + ex.getMessage());
return error(Response.Status.BAD_REQUEST, "Internal error: failed to look up harvesting client " + nickName + ".");
}
if (harvestingClient == null) {
return error(Response.Status.NOT_FOUND, "Harvesting client " + nickName + " not found.");
}
HarvestingClient retrievedHarvestingClient = null;
try {
// findUserOrDie() and execCommand() both throw WrappedResponse
// exception, that already has a proper HTTP response in it.
retrievedHarvestingClient = execCommand(new GetHarvestingClientCommand(createDataverseRequest(findUserOrDie()), harvestingClient));
logger.info("retrieved Harvesting Client " + retrievedHarvestingClient.getName() + " with the GetHarvestingClient command.");
} catch (WrappedResponse wr) {
return wr.getResponse();
} catch (Exception ex) {
logger.warning("Unknown exception caught while executing GetHarvestingClientCommand: " + ex.getMessage());
retrievedHarvestingClient = null;
}
if (retrievedHarvestingClient == null) {
return error(Response.Status.BAD_REQUEST, "Internal error: failed to retrieve harvesting client " + nickName + ".");
}
try {
return ok(harvestingConfigAsJson(retrievedHarvestingClient));
} catch (Exception ex) {
logger.warning("Unknown exception caught while trying to format harvesting client config as json: " + ex.getMessage());
return error(Response.Status.BAD_REQUEST, "Internal error: failed to produce output for harvesting client " + nickName + ".");
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.GetHarvestingClientCommand in project dataverse by IQSS.
the class HarvestingClients method harvestingClients.
/*
* /api/harvest/clients
* and
* /api/harvest/clients/{nickname}
* will, by default, return a JSON record with the information about the
* configured remote archives.
* optionally, plain text output may be provided as well.
*/
@GET
@Path("/")
public Response harvestingClients(@QueryParam("key") String apiKey) throws IOException {
List<HarvestingClient> harvestingClients = null;
try {
harvestingClients = harvestingClientService.getAllHarvestingClients();
} catch (Exception ex) {
return error(Response.Status.INTERNAL_SERVER_ERROR, "Caught an exception looking up configured harvesting clients; " + ex.getMessage());
}
if (harvestingClients == null) {
// returning an empty list:
return ok(jsonObjectBuilder().add("harvestingClients", ""));
}
JsonArrayBuilder hcArr = Json.createArrayBuilder();
for (HarvestingClient harvestingClient : harvestingClients) {
// We already have this harvestingClient - wny do we need to
// execute this "Get HarvestingClients Client Command" in order to get it,
// again? - the purpose of the command is to run the request through
// the Authorization system, to verify that they actually have
// the permission to view this harvesting client config. -- L.A. 4.4
HarvestingClient retrievedHarvestingClient = null;
try {
DataverseRequest req = createDataverseRequest(findUserOrDie());
retrievedHarvestingClient = execCommand(new GetHarvestingClientCommand(req, harvestingClient));
} catch (Exception ex) {
// Don't do anything.
// We'll just skip this one - since this means the user isn't
// authorized to view this client configuration.
}
if (retrievedHarvestingClient != null) {
hcArr.add(harvestingConfigAsJson(retrievedHarvestingClient));
}
}
return ok(jsonObjectBuilder().add("harvestingClients", hcArr));
}
Aggregations