Search in sources :

Example 1 with UpdateHarvestingClientCommand

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);
}
Also used : UpdateHarvestingClientCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateHarvestingClientCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 2 with UpdateHarvestingClientCommand

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();
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) UpdateHarvestingClientCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateHarvestingClientCommand) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) IOException(java.io.IOException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

UpdateHarvestingClientCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateHarvestingClientCommand)2 HarvestingClient (edu.harvard.iq.dataverse.harvest.client.HarvestingClient)2 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 JsonObject (javax.json.JsonObject)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1