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));
}
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);
}
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 "" + oaiSet.getSpec() + "".");
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);
}
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())));
}
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");
}
Aggregations