/** * Adds passed value to the set of values for the field in passed item. * * @param context The relevant DSpace Context. * @param item - the item to update * @param value - the value to add in this field * @throws SQLException An exception that provides information on a database access error or other errors. */ public void addItemValue(Context context, Item item, String value) throws SQLException { itemService.addMetadata(context, item, params[0], params[1], params[2], params[3], value); }
private static void applyDimField(Context context, Element field, Item item, boolean createMissingMetadataFields) throws CrosswalkException, SQLException, AuthorizeException { String schema = field.getAttributeValue("mdschema"); String element = field.getAttributeValue("element"); String qualifier = field.getAttributeValue("qualifier"); String lang = field.getAttributeValue("lang"); String authority = field.getAttributeValue("authority"); String sconf = field.getAttributeValue("confidence"); CrosswalkMetadataValidator metadataValidator = new CrosswalkMetadataValidator(); MetadataField metadataField = metadataValidator .checkMetadata(context, schema, element, qualifier, createMissingMetadataFields); // sanity check: some XSL puts an empty string in qualifier, // change it to null so we match the unqualified DC field: if (qualifier != null && qualifier.equals("")) { qualifier = null; } if ((authority != null && authority.length() > 0) || (sconf != null && sconf.length() > 0)) { int confidence = (sconf != null && sconf.length() > 0) ? Choices.getConfidenceValue(sconf) : Choices.CF_UNSET; itemService.addMetadata(context, item, metadataField, lang, field.getText(), authority, confidence); } else { itemService.addMetadata(context, item, metadataField, lang, field.getText()); } }
private void addUniqueMetadata(Context context, MetadataValueInfo info, Item item) throws SQLException { String qual = info.qualifier; if (info.qualifier == null) { qual = Item.ANY; } String lang = info.language; if (info.language == null) { lang = Item.ANY; } List<MetadataValue> existing = itemService.getMetadata( item, info.schema, info.element, qual, lang); for (MetadataValue dcValue : existing) { // FIXME: probably we want to be slightly more careful about qualifiers and languages // // if the submitted value is already attached to the item, just skip it if (dcValue.getValue().equals(info.value)) { return; } } // if we get to here, go on and add the metadata itemService.addMetadata(context, item, info.schema, info.element, info.qualifier, info.language, info.value); }
@Override public void ingest(Context context, DSpaceObject dso, Element root, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException { if (dso.getType() != Constants.ITEM) { throw new CrosswalkObjectNotSupported("DIMIngestionCrosswalk can only crosswalk an Item."); } Item item = (Item) dso; if (root == null) { System.err.println("The element received by ingest was null"); return; } List<Element> metadata = root.getChildren("field", DIM_NS); for (Element field : metadata) { String schema = field.getAttributeValue("mdschema"); String element = field.getAttributeValue("element"); String qualifier = field.getAttributeValue("qualifier"); MetadataField metadataField = metadataValidator .checkMetadata(context, schema, element, qualifier, createMissingMetadataFields); itemService.addMetadata(context, item, metadataField, field.getAttributeValue("lang"), field.getText()); } }
@Override public void ingest(Context context, DSpaceObject dso, Element root, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException { if (dso.getType() != Constants.ITEM) { throw new CrosswalkObjectNotSupported("DIMIngestionCrosswalk can only crosswalk an Item."); } Item item = (Item) dso; if (root == null) { System.err.println("The element received by ingest was null"); return; } List<Element> metadata = root.getChildren(); for (Element element : metadata) { // get language - prefer xml:lang, accept lang. String lang = element.getAttributeValue("lang", Namespace.XML_NAMESPACE); if (lang == null) { lang = element.getAttributeValue("lang"); } MetadataField metadataField = metadataValidator .checkMetadata(context, MetadataSchema.DC_SCHEMA, element.getName(), null, createMissingMetadataFields); itemService.addMetadata(context, item, metadataField, lang, element.getText()); } }
protected void populateHandleMetadata(Context context, Item item, String handle) throws SQLException, IOException, AuthorizeException { String handleref = handleService.getCanonicalForm(handle); // Add handle as identifier.uri DC value. // First check that identifier doesn't already exist. boolean identifierExists = false; List<MetadataValue> identifiers = itemService .getMetadata(item, MetadataSchema.DC_SCHEMA, "identifier", "uri", Item.ANY); for (MetadataValue identifier : identifiers) { if (handleref.equals(identifier.getValue())) { identifierExists = true; } } if (!identifierExists) { itemService.addMetadata(context, item, MetadataSchema.DC_SCHEMA, "identifier", "uri", null, handleref); } } }
/** * Removes the passed value from the set of values for the field in passed item. * * @param context The relevant DSpace Context. * @param item - the item to update * @param value - the value to remove * @throws IOException A general class of exceptions produced by failed or interrupted I/O operations. * @throws SQLException An exception that provides information on a database access error or other errors. * @throws AuthorizeException Exception indicating the current user of the context does not have permission * to perform a particular action. */ public void removeItemValue(Context context, Item item, String value) throws AuthorizeException, IOException, SQLException { if (value != null) { List<MetadataValue> dcvalues = itemService.getMetadata(item, params[0], params[1], params[2], params[3]); ArrayList<String> arrayList = new ArrayList<String>(); for (MetadataValue dcvalue : dcvalues) { if (!dcvalue.getValue().equals(value)) { arrayList.add(dcvalue.getValue()); } } itemService.clearMetadata(context, item, params[0], params[1], params[2], params[3]); itemService.addMetadata(context, item, params[0], params[1], params[2], params[3], arrayList); } }
@Override public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request) throws SQLException, AuthorizeException, IOException, WorkflowException { if (request.getParameter("submit_score") != null) { int score = Util.getIntParameter(request, "score"); //Add our score to the metadata itemService.addMetadata(c, wfi.getItem(), WorkflowRequirementsService.WORKFLOW_SCHEMA, "score", null, null, String.valueOf(score)); itemService.update(c, wfi.getItem()); return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE); } else { //We have pressed the leave button so return to our submission page return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE); } } }
@Override public void liftEmbargo(Context context, Item item) throws SQLException, AuthorizeException, IOException { // Since 3.0 the lift process for all embargoes is performed through the dates // on the authorization process (see DS-2588) // lifter.liftEmbargo(context, item); itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY); // set the dc.date.available value to right now itemService.clearMetadata(context, item, MetadataSchema.DC_SCHEMA, "date", "available", Item.ANY); itemService.addMetadata(context, item, MetadataSchema.DC_SCHEMA, "date", "available", null, DCDate.getCurrent().toString()); log.info("Lifting embargo on Item " + item.getHandle()); itemService.update(context, item); }
itemService.addMetadata(context, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null, remainder); itemService.update(context, item);
protected void recordApproval(Context context, BasicWorkflowItem workflowItem, EPerson e) throws SQLException, IOException, AuthorizeException { Item item = workflowItem.getItem(); // Get user's name + email address String usersName = getEPersonName(e); // Get current date String now = DCDate.getCurrent().toString(); // Here's what happened String provDescription = "Approved for entry into archive by " + usersName + " on " + now + " (GMT) "; // add bitstream descriptions (name, size, checksums) provDescription += installItemService.getBitstreamProvenanceMessage(context, item); // Add to item as a DC field itemService .addMetadata(context, item, MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provDescription); itemService.update(context, item); }
protected void copyMetadata(Context context, Item itemNew, Item nativeItem) throws SQLException { List<MetadataValue> md = itemService.getMetadata(nativeItem, Item.ANY, Item.ANY, Item.ANY, Item.ANY); for (MetadataValue aMd : md) { MetadataField metadataField = aMd.getMetadataField(); MetadataSchema metadataSchema = metadataField.getMetadataSchema(); String unqualifiedMetadataField = metadataSchema.getName() + "." + metadataField.getElement(); if (getIgnoredMetadataFields().contains(metadataField.toString('.')) || getIgnoredMetadataFields().contains(unqualifiedMetadataField + "." + Item.ANY)) { //Skip this metadata field continue; } itemService .addMetadata(context, itemNew, metadataField, aMd.getLanguage(), aMd.getValue(), aMd.getAuthority(), aMd.getConfidence()); } }
@Override public void setEmbargo(Context context, Item item) throws SQLException, AuthorizeException { // if lift is null, we might be restoring an item from an AIP DCDate myLift = getEmbargoTermsAsDate(context, item); if (myLift == null) { if ((myLift = recoverEmbargoDate(item)) == null) { return; } } String slift = myLift.toString(); try { context.turnOffAuthorisationSystem(); itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY); itemService.addMetadata(context, item, lift_schema, lift_element, lift_qualifier, null, slift); log.info("Set embargo on Item " + item.getHandle() + ", expires on: " + slift); setter.setEmbargo(context, item); itemService.update(context, item); } finally { context.restoreAuthSystemState(); } }
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException { //Add the provenance for the accept String now = DCDate.getCurrent().toString(); // Get user's name + email address String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService() .getEPersonName(c.getCurrentUser()); String provDescription = getProvenanceStartId() + " Approved for entry into archive by " + usersName + " on " + now + " (GMT) "; // Add to item as a DC field itemService.addMetadata(c, wfi.getItem(), MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provDescription); itemService.update(c, wfi.getItem()); }
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException { //Add the provenance for the accept String now = DCDate.getCurrent().toString(); // Get user's name + email address String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService() .getEPersonName(c.getCurrentUser()); String provDescription = getProvenanceStartId() + " Approved for entry into archive by " + usersName + " on " + now + " (GMT) "; // Add to item as a DC field itemService.addMetadata(c, wfi.getItem(), MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provDescription); itemService.update(c, wfi.getItem()); }
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException { //Add the provenance for the accept String now = DCDate.getCurrent().toString(); // Get user's name + email address String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService() .getEPersonName(c.getCurrentUser()); String provDescription = getProvenanceStartId() + " Approved for entry into archive by " + usersName + " on " + now + " (GMT) "; // Add to item as a DC field itemService.addMetadata(c, wfi.getItem(), MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provDescription); itemService.update(c, wfi.getItem()); } }
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException { //Add the provenance for the accept String now = DCDate.getCurrent().toString(); // Get user's name + email address String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService() .getEPersonName(c.getCurrentUser()); String provDescription = getProvenanceStartId() + " Approved for entry into archive by " + usersName + " on " + now + " (GMT) "; // Add to item as a DC field itemService.addMetadata(c, wfi.getItem(), MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provDescription); itemService.update(c, wfi.getItem()); }
protected void recordStart(Context context, Item myitem) throws SQLException, IOException, AuthorizeException { // get date DCDate now = DCDate.getCurrent(); // Create provenance description String provmessage; if (myitem.getSubmitter() != null) { provmessage = "Submitted by " + myitem.getSubmitter().getFullName() + " (" + myitem.getSubmitter().getEmail() + ") on " + now.toString() + "\n"; } else { // else, null submitter provmessage = "Submitted by unknown (probably automated) on" + now.toString() + "\n"; } // add sizes and checksums of bitstreams provmessage += installItemService.getBitstreamProvenanceMessage(context, myitem); // Add message to the DC itemService .addMetadata(context, myitem, MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provmessage); itemService.update(context, myitem); }
/** * Add the bitstream metadata to the item * * @param item The item * @param bitstream The bitstream * @param type The type of bitstream * @throws SQLException An exception that provides information on a database access error or other errors. */ protected void addMetadata(Item item, Bitstream bitstream, String type) throws SQLException { String value = bitstream.getFormat(Curator.curationContext()).getMIMEType() + "##"; value += bitstream.getName() + "##"; value += bitstream.getSizeBytes() + "##"; value += item.getHandle() + "##"; value += bitstream.getSequenceID() + "##"; value += bitstream.getChecksum() + "##"; if (bitstream.getDescription() != null) { value += bitstream.getDescription(); } itemService.addMetadata(Curator.curationContext(), item, "dc", "format", type, "en", value); } }
protected void recordStart(Context context, Item myitem, Action action) throws SQLException, IOException, AuthorizeException { // get date DCDate now = DCDate.getCurrent(); // Create provenance description String provmessage = ""; if (myitem.getSubmitter() != null) { provmessage = "Submitted by " + myitem.getSubmitter().getFullName() + " (" + myitem.getSubmitter().getEmail() + ") on " + now.toString() + " workflow start=" + action.getProvenanceStartId() + "\n"; } else { // else, null submitter provmessage = "Submitted by unknown (probably automated) on" + now.toString() + " workflow start=" + action.getProvenanceStartId() + "\n"; } // add sizes and checksums of bitstreams provmessage += installItemService.getBitstreamProvenanceMessage(context, myitem); // Add message to the DC itemService .addMetadata(context, myitem, MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provmessage); itemService.update(context, myitem); }