use of org.dspace.content.MetadataValue in project DSpace by DSpace.
the class MetadataValueReplacePatchOperation method setDeclaredField.
protected void setDeclaredField(Context context, DSO source, Object value, String metadata, String namedField, List<MetadataValue> metadataByMetadataString, int index) throws IllegalAccessException, SQLException {
// check field
String raw = (String) value;
for (Field field : MetadataValueRest.class.getDeclaredFields()) {
JsonProperty jsonP = field.getDeclaredAnnotation(JsonProperty.class);
if (jsonP != null && jsonP.access().equals(Access.READ_ONLY)) {
continue;
} else {
if (field.getName().equals(namedField)) {
int idx = 0;
MetadataValueRest obj = new MetadataValueRest();
for (MetadataValue mv : metadataByMetadataString) {
if (idx == index) {
obj.setAuthority(mv.getAuthority());
obj.setConfidence(mv.getConfidence());
obj.setLanguage(mv.getLanguage());
obj.setValue(mv.getValue());
if (field.getType().isAssignableFrom(Integer.class)) {
obj.setConfidence(Integer.parseInt(raw));
} else {
boolean accessible = field.isAccessible();
field.setAccessible(true);
field.set(obj, raw);
field.setAccessible(accessible);
}
break;
}
idx++;
}
replaceValue(context, source, metadata, metadataByMetadataString, obj, index);
}
}
}
}
use of org.dspace.content.MetadataValue in project DSpace by DSpace.
the class StructBuilder method exportACollection.
/**
* Add a single Collection to the Document.
*
* @param collection
* @return a fragment representing this Collection.
*/
private static Element exportACollection(Collection collection) {
// Export this Collection.
Element element = new Element("collection");
element.setAttribute("identifier", collection.getHandle());
element.addContent(new Element("name").setText(collection.getName()));
element.addContent(new Element("description").setText(collectionService.getMetadataFirstValue(collection, MetadataSchemaEnum.DC.getName(), "description", "abstract", Item.ANY)));
element.addContent(new Element("intro").setText(collectionService.getMetadataFirstValue(collection, MetadataSchemaEnum.DC.getName(), "description", null, Item.ANY)));
element.addContent(new Element("copyright").setText(collectionService.getMetadataFirstValue(collection, MetadataSchemaEnum.DC.getName(), "rights", null, Item.ANY)));
element.addContent(new Element("sidebar").setText(collectionService.getMetadataFirstValue(collection, MetadataSchemaEnum.DC.getName(), "description", "tableofcontents", Item.ANY)));
element.addContent(new Element("license").setText(collectionService.getMetadataFirstValue(collection, MetadataSchemaEnum.DC.getName(), "rights", "license", Item.ANY)));
// Provenance is special: multivalued
for (MetadataValue value : collectionService.getMetadata(collection, MetadataSchemaEnum.DC.getName(), "provenance", null, Item.ANY)) {
element.addContent(new Element("provenance").setText(value.getValue()));
}
return element;
}
use of org.dspace.content.MetadataValue in project DSpace by DSpace.
the class DOIIdentifierProvider method removeDOIFromObject.
/**
* Removes a DOI out of the metadata of a DSpaceObject.
*
* @param context The relevant DSpace Context.
* @param dso The DSpaceObject the DOI should be removed from.
* @param doi The DOI to remove out of the metadata.
* @throws AuthorizeException if authorization error
* @throws SQLException if database error
* @throws IdentifierException if identifier error
*/
protected void removeDOIFromObject(Context context, DSpaceObject dso, String doi) throws AuthorizeException, SQLException, IdentifierException {
// FIXME
if (!(dso instanceof Item)) {
throw new IllegalArgumentException("We currently support DOIs for Items only, not for " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + ".");
}
Item item = (Item) dso;
List<MetadataValue> metadata = itemService.getMetadata(item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null);
List<String> remainder = new ArrayList<>();
for (MetadataValue id : metadata) {
if (!id.getValue().equals(doiService.DOIToExternalForm(doi))) {
remainder.add(id.getValue());
}
}
itemService.clearMetadata(context, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null);
itemService.addMetadata(context, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null, remainder);
itemService.update(context, item);
}
use of org.dspace.content.MetadataValue in project DSpace by DSpace.
the class UpdateHandlePrefix method main.
/**
* When invoked as a command-line tool, updates handle prefix
*
* @param args the command-line arguments, none used
* @throws Exception on generic exception
*/
public static void main(String[] args) throws Exception {
// There should be two parameters
if (args.length < 2) {
System.out.println("\nUsage: update-handle-prefix <old handle> <new handle>\n");
System.exit(1);
} else {
HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
String oldH = args[0];
String newH = args[1];
// Get info about changes
System.out.println("\nGetting information about handles from database...");
Context context = new Context();
long count = handleService.countHandlesByPrefix(context, oldH);
if (count > 0) {
// Print info text about changes
System.out.println("In your repository will be updated " + count + " handle" + ((count > 1) ? "s" : "") + " to new prefix " + newH + " from original " + oldH + "!\n");
// Confirm with the user that this is what they want to do
System.out.print("Servlet container (e.g. Apache Tomcat, Jetty, Caucho Resin) must be running.\n" + "If it is necessary, please make a backup of the database.\n" + "Are you ready to continue? [y/n]: ");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String choiceString = input.readLine();
if (choiceString.equalsIgnoreCase("y")) {
context.turnOffAuthorisationSystem();
try {
log.info("Updating handle prefix from " + oldH + " to " + newH);
// Make the changes
System.out.print("\nUpdating handle table... ");
int updHdl = handleService.updateHandlesWithNewPrefix(context, newH, oldH);
System.out.println(updHdl + " item" + ((updHdl > 1) ? "s" : "") + " updated");
System.out.print("Updating metadatavalues table... ");
MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
String handlePrefix = handleService.getCanonicalPrefix();
Iterator<MetadataValue> metadataValues = metadataValueService.findByValueLike(context, handlePrefix + oldH);
int updMeta = 0;
while (metadataValues.hasNext()) {
MetadataValue metadataValue = metadataValues.next();
metadataValue.setValue(metadataValue.getValue().replace(handlePrefix + oldH, handlePrefix + newH));
metadataValueService.update(context, metadataValue, true);
context.uncacheEntity(metadataValue);
updMeta++;
}
System.out.println(updMeta + " metadata value" + ((updMeta > 1) ? "s" : "") + " updated");
// Commit the changes
context.complete();
log.info("Done with updating handle prefix. " + "It was changed " + updHdl + " handle" + ((updHdl > 1) ? "s" : "") + " and " + updMeta + " metadata record" + ((updMeta > 1) ? "s" : ""));
} catch (SQLException sqle) {
if ((context != null) && (context.isValid())) {
context.abort();
context = null;
}
System.out.println("\nError during SQL operations.");
throw sqle;
}
System.out.println("Handles successfully updated in database.\n");
System.out.println("Re-creating browse and search indexes...");
try {
// Reinitialise the search and browse system
ScriptLauncher.main(new String[] { "index-discovery", "-b" });
System.out.println("Browse and search indexes are ready now.");
// All done
System.out.println("\nAll done successfully. Please check the DSpace logs!\n");
} catch (Exception e) {
// Not a lot we can do
System.out.println("Error during re-indexing.");
System.out.println("\n\nAutomatic re-indexing failed. Please perform it manually.\n\n" + " [dspace]/bin/dspace index-discovery -b\n\n" + "When launching this command, your servlet container must be running.\n");
throw e;
}
context.restoreAuthSystemState();
} else {
System.out.println("No changes have been made to your data.\n");
}
} else {
System.out.println("Nothing to do! All handles are up-to-date.\n");
}
}
}
use of org.dspace.content.MetadataValue in project DSpace by DSpace.
the class XmlWorkflowServiceImpl method notifyOfArchive.
/**
* notify the submitter that the item is archived
*
* @param context The relevant DSpace Context.
* @param item which item was archived
* @param coll collection name to display in template
* @throws SQLException An exception that provides information on a database access error or other errors.
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
*/
protected void notifyOfArchive(Context context, Item item, Collection coll) throws SQLException, IOException {
try {
// Get submitter
EPerson ep = item.getSubmitter();
// send the notification to the submitter unless the submitter eperson has been deleted
if (null != ep) {
// Get the Locale
Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));
// Get the item handle to email to user
String handle = handleService.findHandle(context, item);
// Get title
List<MetadataValue> titles = itemService.getMetadata(item, MetadataSchemaEnum.DC.getName(), "title", null, Item.ANY);
String title = "";
try {
title = I18nUtil.getMessage("org.dspace.xmlworkflow.XMLWorkflowService.untitled");
} catch (MissingResourceException e) {
title = "Untitled";
}
if (titles.size() > 0) {
title = titles.iterator().next().getValue();
}
email.addRecipient(ep.getEmail());
email.addArgument(title);
email.addArgument(coll.getName());
email.addArgument(handleService.getCanonicalForm(handle));
email.send();
}
} catch (MessagingException e) {
log.warn(LogHelper.getHeader(context, "notifyOfArchive", "cannot email user" + " item_id=" + item.getID()), e);
}
}
Aggregations