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));
}
}
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");
}
}
Aggregations