@Override public boolean shareableMetadataChanged(MCRObject oldVersion, MCRObject newVersion) { final MCRObjectMetadata md = newVersion.getMetadata(); final MCRObjectMetadata mdold = oldVersion.getMetadata(); //if any metadata changed we need to update children boolean metadataChanged = !MCRXMLHelper.deepEqual(md.createXML(), mdold.createXML()); if (!metadataChanged) { LOGGER.info("Metadata did not change on update of {}", newVersion.getId()); } return metadataChanged; }
public void setMODS(Element mods) { MCRObjectMetadata om = object.getMetadata(); if (om.getMetadataElement(DEF_MODS_CONTAINER) != null) { om.removeMetadataElement(DEF_MODS_CONTAINER); } MCRMetaXML modsContainer = new MCRMetaXML(MODS_CONTAINER, null, 0); List<MCRMetaXML> list = Collections.nCopies(1, modsContainer); MCRMetaElement defModsContainer = new MCRMetaElement(MCRMetaXML.class, DEF_MODS_CONTAINER, false, true, list); om.setMetadataElement(defModsContainer); modsContainer.addContent(mods); }
private void undo(MCRObject obj) { if (oldMappings == null) { obj.getMetadata().removeMetadataElement("mappings"); } else { MCRMetaElement mmap = obj.getMetadata().getMetadataElement("mappings"); for (int i = 0; i < oldMappings.size(); i++) { mmap.addMetaObject(oldMappings.getElement(i)); } } } }
private void createMapping(MCRObject obj) { MCRMetaElement mappings = obj.getMetadata().getMetadataElement("mappings"); if (mappings != null) { oldMappings = mappings.clone(); obj.getMetadata().removeMetadataElement("mappings"); Document doc = new Document(obj.getMetadata().createXML().detach()); XPathExpression<Element> classElementPath = XPathFactory.instance().compile("//*[@categid]", Filters.element()); mappings.setHeritable(false); mappings.setNotInherit(true); obj.getMetadata().setMetadataElement(mappings); obj.getMetadata().removeMetadataElement("mappings");
/** * returns true if the given MCRObject can handle MODS metadata * @param obj - the MCRObject * @return true, if mods is supported */ public static boolean isSupported(MCRObject obj) { if (isSupported(obj.getId())) { return true; } return obj.getMetadata() != null && obj.getMetadata().getMetadataElement(DEF_MODS_CONTAINER) != null && obj.getMetadata().getMetadataElement(DEF_MODS_CONTAINER).getElementByName(MODS_CONTAINER) != null; }
@Override public void insertIdentifier(MCRPersistentIdentifier identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException { String xpath = getProperties().get("Xpath"); Document xml = obj.createXML(); MCRNodeBuilder nb = new MCRNodeBuilder(); try { nb.buildElement(xpath, identifier.asString(), xml); if (obj instanceof MCRObject) { final Element metadata = xml.getRootElement().getChild("metadata"); ((MCRObject) obj).getMetadata().setFromDOM(metadata); } else { throw new MCRPersistentIdentifierException(obj.getId() + " is no MCRObject!", new OperationNotSupportedException(getClass().getName() + " only supports " + MCRObject.class.getName() + "!")); } } catch (Exception e) { throw new MCRException("Error while inscribing PI to " + obj.getId(), e); } }
/** * @return the mods:mods Element at /metadata/def.modsContainer/modsContainer */ public Element getMODS() { try { MCRMetaXML mx = (MCRMetaXML) (object.getMetadata().getMetadataElement(DEF_MODS_CONTAINER).getElement(0)); for (Content content : mx.getContent()) { if (content instanceof Element) { return (Element) content; } } } catch (NullPointerException | IndexOutOfBoundsException e) { //do nothing } return null; }
@Override public void updateMetadata(MCRObject object, Deposit entry, boolean replace) throws SwordServerException, SwordError { if (!replace) { throw new SwordServerException("Operation is not supported!", new OperationNotSupportedException()); } final Document document = buildDCDocument(entry.getSwordEntry().getDublinCore()); final Document newMetadata = convertDCToMods(document); object.getMetadata().setFromDOM(newMetadata.detachRootElement()); try { MCRMetadataManager.update(object); } catch (MCRAccessException e) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); } }