Search in sources :

Example 6 with OAISet

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

the class HarvestingServer method createOaiSet.

/**
 * create an OAI set from spec in path and other parameters from POST body
 * (as JSON). {"name":$set_name,
 * "description":$optional_set_description,"definition":$set_search_query_string}.
 */
@POST
@Path("{specname}")
public Response createOaiSet(String jsonBody, @PathParam("specname") String spec, @QueryParam("key") String apiKey) throws IOException, JsonParseException {
    /*
	     * authorization modeled after the UI (aka HarvestingSetsPage)
         */
    AuthenticatedUser dvUser;
    try {
        dvUser = findAuthenticatedUserOrDie();
    } catch (WrappedResponse wr) {
        return wr.getResponse();
    }
    if (!dvUser.isSuperuser()) {
        return badRequest(ResourceBundle.getBundle("Bundle").getString("harvestserver.newSetDialog.setspec.superUser.required"));
    }
    StringReader rdr = new StringReader(jsonBody);
    try (JsonReader jrdr = Json.createReader(rdr)) {
        JsonObject json = jrdr.readObject();
        OAISet set = new OAISet();
        // Validating spec
        if (!StringUtils.isEmpty(spec)) {
            if (spec.length() > 30) {
                return badRequest(ResourceBundle.getBundle("Bundle").getString("harvestserver.newSetDialog.setspec.sizelimit"));
            }
            if (!Pattern.matches("^[a-zA-Z0-9\\_\\-]+$", spec)) {
                return badRequest(ResourceBundle.getBundle("Bundle").getString("harvestserver.newSetDialog.setspec.invalid"));
            // If it passes the regex test, check
            }
            if (oaiSetService.findBySpec(spec) != null) {
                return badRequest(ResourceBundle.getBundle("Bundle").getString("harvestserver.newSetDialog.setspec.alreadyused"));
            }
        } else {
            return badRequest(ResourceBundle.getBundle("Bundle").getString("harvestserver.newSetDialog.setspec.required"));
        }
        set.setSpec(spec);
        String name, desc, defn;
        try {
            name = json.getString("name");
        } catch (NullPointerException npe_name) {
            return badRequest(ResourceBundle.getBundle("Bundle").getString("harvestserver.newSetDialog.setspec.required"));
        }
        try {
            defn = json.getString("definition");
        } catch (NullPointerException npe_defn) {
            throw new JsonParseException("definition unspecified");
        }
        try {
            desc = json.getString("description");
        } catch (NullPointerException npe_desc) {
            // treating description as optional
            desc = "";
        }
        set.setName(name);
        set.setDescription(desc);
        set.setDefinition(defn);
        oaiSetService.save(set);
        return created("/harvest/server/oaisets" + spec, oaiSetAsJson(set));
    }
}
Also used : StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 7 with OAISet

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

the class Metadata method exportOaiSet.

/**
 * initial attempt at triggering indexing/creation/population of a OAI set without going throught
 * the UI.
 */
@PUT
@Path("/exportOAI/{specname}")
public Response exportOaiSet(@PathParam("specname") String spec) {
    // assuming this belongs here (because it's a metadata export), but open to moving it elsewhere
    OAISet set = null;
    try {
        set = oaiSetService.findBySpec(spec);
    } catch (Exception ex) {
        return error(Response.Status.BAD_REQUEST, "bad request / invalid OAI set");
    }
    if (null == set) {
        return error(Response.Status.NOT_FOUND, "unable to find specified OAI set");
    }
    try {
        oaiSetService.setUpdateInProgress(set.getId());
        oaiSetService.exportOaiSetAsync(set);
        return ok("export started");
    } catch (Exception ex) {
        return error(Response.Status.BAD_REQUEST, "problem exporting OAI set");
    }
}
Also used : OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

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