Search in sources :

Example 1 with OAISet

use of edu.harvard.iq.dataverse.harvest.server.OAISet in project dataverse by IQSS.

the class HarvestingServer method oaiSets.

// TODO: this should be available to admin only.
@GET
@Path("/")
public Response oaiSets(@QueryParam("key") String apiKey) throws IOException {
    List<OAISet> oaiSets = null;
    try {
        oaiSets = oaiSetService.findAll();
    } catch (Exception ex) {
        return error(Response.Status.INTERNAL_SERVER_ERROR, "Caught an exception looking up available OAI sets; " + ex.getMessage());
    }
    if (oaiSets == null) {
        // returning an empty list:
        return ok(jsonObjectBuilder().add("oaisets", ""));
    }
    JsonArrayBuilder hcArr = Json.createArrayBuilder();
    for (OAISet set : oaiSets) {
        hcArr.add(oaiSetAsJson(set));
    }
    return ok(jsonObjectBuilder().add("oaisets", hcArr));
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with OAISet

use of edu.harvard.iq.dataverse.harvest.server.OAISet in project dataverse by IQSS.

the class HarvestingSetsPage method createSet.

public void createSet(ActionEvent ae) {
    OAISet newOaiSet = new OAISet();
    newOaiSet.setSpec(getNewSetSpec());
    newOaiSet.setName(getNewSetSpec());
    newOaiSet.setDescription(getNewSetDescription());
    newOaiSet.setDefinition(getNewSetQuery());
    boolean success = false;
    try {
        oaiSetService.save(newOaiSet);
        configuredHarvestingSets = oaiSetService.findAll();
        String successMessage = JH.localize("harvestserver.newSetDialog.success");
        successMessage = successMessage.replace("{0}", newOaiSet.getSpec());
        JsfHelper.addSuccessMessage(successMessage);
        success = true;
    } catch (Exception ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Failed to create OAI set");
        logger.log(Level.SEVERE, "Failed to create OAI set" + ex.getMessage(), ex);
    }
    if (success) {
        OAISet savedSet = oaiSetService.findBySpec(getNewSetSpec());
        if (savedSet != null) {
            runSetExport(savedSet);
            configuredHarvestingSets = oaiSetService.findAll();
        }
    }
    setPageMode(HarvestingSetsPage.PageMode.VIEW);
}
Also used : OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) OaiSetException(edu.harvard.iq.dataverse.harvest.server.OaiSetException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 3 with OAISet

use of edu.harvard.iq.dataverse.harvest.server.OAISet in project dataverse by IQSS.

the class HarvestingSetsPage method saveSet.

// this saves an existing set that the user has edited:
public void saveSet(ActionEvent ae) {
    OAISet oaiSet = getSelectedSet();
    if (oaiSet == null) {
    // TODO:
    // tell the user somehow that the set cannot be saved, and advise
    // them to save the settings they have entered.
    }
    // Note that the nickname is not editable:
    oaiSet.setDefinition(getNewSetQuery());
    oaiSet.setDescription(getNewSetDescription());
    // will try to save it now:
    boolean success = false;
    try {
        oaiSetService.save(oaiSet);
        configuredHarvestingSets = oaiSetService.findAll();
        JsfHelper.addSuccessMessage("Succesfully updated OAI set &#34;" + oaiSet.getSpec() + "&#34;.");
        success = true;
    } catch (Exception ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "Failed to update OAI set.");
        logger.log(Level.SEVERE, "Failed to update OAI set." + ex.getMessage(), ex);
    }
    if (success) {
        OAISet createdSet = oaiSetService.findBySpec(getNewSetSpec());
        if (createdSet != null) {
            runSetExport(createdSet);
            configuredHarvestingSets = oaiSetService.findAll();
        }
    }
    setPageMode(HarvestingSetsPage.PageMode.VIEW);
}
Also used : OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) OaiSetException(edu.harvard.iq.dataverse.harvest.server.OaiSetException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 4 with OAISet

use of edu.harvard.iq.dataverse.harvest.server.OAISet in project dataverse by IQSS.

the class XsetRepository method retrieveSets.

@Override
public ListSetsResult retrieveSets(int offset, int length) {
    logger.fine("calling retrieveSets()");
    List<OAISet> dataverseOAISets = setService.findAll();
    List<Set> XOAISets = new ArrayList<Set>();
    if (dataverseOAISets != null) {
        for (int i = 0; i < dataverseOAISets.size(); i++) {
            OAISet dataverseSet = dataverseOAISets.get(i);
            Set xoaiSet = new Set(dataverseSet.getSpec());
            xoaiSet.withName(dataverseSet.getName());
            XOAIMetadata xMetadata = new XOAIMetadata();
            Element element = new Element("description");
            element.withField("description", dataverseSet.getDescription());
            xMetadata.getElements().add(element);
            xoaiSet.withDescription(xMetadata);
            XOAISets.add(xoaiSet);
        }
    }
    return new ListSetsResult(offset + length < XOAISets.size(), XOAISets.subList(offset, Math.min(offset + length, XOAISets.size())));
}
Also used : Set(com.lyncode.xoai.dataprovider.model.Set) OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) ListSetsResult(com.lyncode.xoai.dataprovider.handlers.results.ListSetsResult) Element(com.lyncode.xoai.model.xoai.Element) ArrayList(java.util.ArrayList) XOAIMetadata(com.lyncode.xoai.model.xoai.XOAIMetadata) OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet)

Example 5 with OAISet

use of edu.harvard.iq.dataverse.harvest.server.OAISet in project dataverse by IQSS.

the class HarvestingServer method deleteOaiSet.

@DELETE
@Path("{specname}")
public Response deleteOaiSet(@PathParam("specname") String spec, @QueryParam("key") String apiKey) {
    OAISet set = null;
    try {
        set = oaiSetService.findBySpec(spec);
    } catch (Exception ex) {
        logger.warning("Exception caught looking up OAI set " + spec + ": " + ex.getMessage());
        return error(Response.Status.BAD_REQUEST, "Internal error: failed to look up OAI set " + spec + ".");
    }
    if (set == null) {
        return error(Response.Status.NOT_FOUND, "OAI set " + spec + " not found.");
    }
    try {
        oaiSetService.setDeleteInProgress(set.getId());
        oaiSetService.remove(set.getId());
    } catch (Exception ex) {
        return error(Response.Status.BAD_REQUEST, "Internal error: failed to delete OAI set " + spec + "; " + ex.getMessage());
    }
    return ok("OAI Set " + spec + " deleted");
}
Also used : OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

OAISet (edu.harvard.iq.dataverse.harvest.server.OAISet)7 Path (javax.ws.rs.Path)4 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)3 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 OaiSetException (edu.harvard.iq.dataverse.harvest.server.OaiSetException)2 IOException (java.io.IOException)2 ListSetsResult (com.lyncode.xoai.dataprovider.handlers.results.ListSetsResult)1 Set (com.lyncode.xoai.dataprovider.model.Set)1 Element (com.lyncode.xoai.model.xoai.Element)1 XOAIMetadata (com.lyncode.xoai.model.xoai.XOAIMetadata)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1