use of edu.harvard.iq.dataverse.engine.command.impl.UpdateHarvestingClientCommand in project dataverse by IQSS.
the class HarvestingClientsPage method saveClient.
// this saves an existing client that the user has edited:
public void saveClient(ActionEvent ae) {
HarvestingClient harvestingClient = getSelectedClient();
if (harvestingClient == null) {
// TODO:
// tell the user somehow that the client cannot be saved, and advise
// them to save the settings they have entered.
// as of now - we will show an error message, but only after the
// edit form has been closed.
}
// nickname is not editable for existing clients:
// harvestingClient.setName(newNickname);
harvestingClient.setHarvestingUrl(newHarvestingUrl);
harvestingClient.setHarvestingSet(newOaiSet);
harvestingClient.setMetadataPrefix(newMetadataFormat);
harvestingClient.setHarvestStyle(newHarvestingStyle);
if (isNewHarvestingScheduled()) {
harvestingClient.setScheduled(true);
if (isNewHarvestingScheduledWeekly()) {
harvestingClient.setSchedulePeriod(HarvestingClient.SCHEDULE_PERIOD_WEEKLY);
if (getWeekDayNumber() == null) {
// create a "week day is required..." error message, etc.
// but we may be better off not even giving them an opportunity
// to leave the field blank - ?
}
harvestingClient.setScheduleDayOfWeek(getWeekDayNumber());
} else {
harvestingClient.setSchedulePeriod(HarvestingClient.SCHEDULE_PERIOD_DAILY);
}
if (getHourOfDay() == null) {
// see the comment above, about the day of week. same here.
}
harvestingClient.setScheduleHourOfDay(getHourOfDay());
} else {
harvestingClient.setScheduled(false);
}
try {
harvestingClient = engineService.submit(new UpdateHarvestingClientCommand(dvRequestService.getDataverseRequest(), harvestingClient));
configuredHarvestingClients = harvestingClientService.getAllHarvestingClients();
if (!harvestingClient.isScheduled()) {
dataverseTimerService.removeHarvestTimer(harvestingClient);
}
JsfHelper.addSuccessMessage("Succesfully updated harvesting client " + harvestingClient.getName());
} catch (CommandException ex) {
logger.log(Level.WARNING, "Failed to save harvesting client", ex);
JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to save harvesting client", ex.getMessage());
} catch (Exception ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "Failed to save harvesting client (reason unknown).");
logger.log(Level.SEVERE, "Failed to save harvesting client (reason unknown)." + ex.getMessage(), ex);
}
setPageMode(PageMode.VIEW);
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateHarvestingClientCommand in project dataverse by IQSS.
the class HarvestingClients method modifyHarvestingClient.
@PUT
@Path("{nickName}")
public Response modifyHarvestingClient(String jsonBody, @PathParam("nickName") String nickName, @QueryParam("key") String apiKey) throws IOException, JsonParseException {
HarvestingClient harvestingClient = null;
try {
harvestingClient = harvestingClientService.findByNickname(nickName);
} catch (Exception ex) {
// We don't care what happened; we'll just assume we couldn't find it.
harvestingClient = null;
}
if (harvestingClient == null) {
return error(Response.Status.NOT_FOUND, "Harvesting client " + nickName + " not found.");
}
String ownerDataverseAlias = harvestingClient.getDataverse().getAlias();
try (StringReader rdr = new StringReader(jsonBody)) {
DataverseRequest req = createDataverseRequest(findUserOrDie());
JsonObject json = Json.createReader(rdr).readObject();
String newDataverseAlias = jsonParser().parseHarvestingClient(json, harvestingClient);
if (newDataverseAlias != null && !newDataverseAlias.equals("") && !newDataverseAlias.equals(ownerDataverseAlias)) {
return error(Response.Status.BAD_REQUEST, "Bad \"dataverseAlias\" supplied. Harvesting client " + nickName + " belongs to the dataverse " + ownerDataverseAlias);
}
HarvestingClient managedHarvestingClient = execCommand(new UpdateHarvestingClientCommand(req, harvestingClient));
return created("/datasets/" + nickName, harvestingConfigAsJson(managedHarvestingClient));
} catch (JsonParseException ex) {
return error(Response.Status.BAD_REQUEST, "Error parsing harvesting client: " + ex.getMessage());
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
Aggregations