Search in sources :

Example 6 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRExtractRelatedItemsEventHandler method extractRelatedItems.

private void extractRelatedItems(final MCREvent evt, final MCRObject object) {
    if (!MCRMODSWrapper.isSupported(object)) {
        return;
    }
    Element mods = new MCRMODSWrapper(object).getMODS();
    MCRObjectID oid = object.getId();
    for (Element relatedItem : mods.getChildren("relatedItem", MCRConstants.MODS_NAMESPACE)) {
        String href = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
        LOGGER.info("Found related item in {}, href={}", object.getId(), href);
        // MCR-957: only create releated object if mycoreId
        MCRObjectID mcrIdCheck;
        try {
            mcrIdCheck = MCRObjectID.getInstance(href);
        } catch (Exception e) {
            // not a valid MCRObjectID -> don't create anyway
            continue;
        }
        // create if integer value == 0
        if (mcrIdCheck.getNumberAsInteger() == 0) {
            // MCR-931: check for type='host' and present parent document
            if (!isHost(relatedItem) || object.getStructure().getParentID() == null) {
                MCRObjectID relatedID;
                try {
                    relatedID = createRelatedObject(relatedItem, oid);
                } catch (MCRAccessException e) {
                    throw new MCRException(e);
                }
                href = relatedID.toString();
                LOGGER.info("Setting href of related item to {}", href);
                relatedItem.setAttribute("href", href, MCRConstants.XLINK_NAMESPACE);
                if (isHost(relatedItem)) {
                    LOGGER.info("Setting {} as parent of {}", href, oid);
                    object.getStructure().setParent(relatedID);
                }
            }
        } else if (isParentExists(relatedItem)) {
            MCRObjectID relatedID = MCRObjectID.getInstance(href);
            if (object.getStructure().getParentID() == null) {
                LOGGER.info("Setting {} as parent of {}", href, oid);
                object.getStructure().setParent(relatedID);
            } else if (!object.getStructure().getParentID().equals(relatedID)) {
                LOGGER.info("Setting {} as parent of {}", href, oid);
                object.getStructure().setParent(relatedID);
            }
        }
    }
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element) MCRAccessException(org.mycore.access.MCRAccessException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistenceException(org.mycore.common.MCRPersistenceException) MCRException(org.mycore.common.MCRException) MCRAccessException(org.mycore.access.MCRAccessException)

Example 7 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRRSSFeedImporter method buildMCRObject.

private MCRObject buildMCRObject(Element publicationXML, String projectID) {
    MCRObject obj = new MCRObject(new Document(publicationXML));
    MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
    wrapper.setServiceFlag("status", STATUS_FLAG);
    MCRObjectID oid = MCRObjectID.getNextFreeId(projectID, "mods");
    obj.setId(oid);
    return obj;
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

Example 8 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCROAIDeletedSearcher method searchDeleted.

/**
 * Returns a list with identifiers of the deleted objects within the given date boundary.
 * If the record policy indicates that there is no support for tracking deleted an empty
 * list is returned.
 *
 * @param from from date
 * @param until to date
 *
 * @return a list with identifiers of the deleted objects
 */
protected List<Header> searchDeleted(Instant from, Instant until) {
    DeletedRecordPolicy deletedRecordPolicy = this.identify.getDeletedRecordPolicy();
    if (from == null || DeletedRecordPolicy.No.equals(deletedRecordPolicy) || DeletedRecordPolicy.Transient.equals(deletedRecordPolicy)) {
        return new ArrayList<>();
    }
    LOGGER.info("Getting identifiers of deleted items");
    Map<MCRObjectID, Instant> deletedItems = MCRMetadataHistoryManager.getDeletedItems(from, Optional.ofNullable(until));
    List<String> types = getConfig().getStrings(getConfigPrefix() + "DeletedRecordTypes", null);
    if (types == null || types.isEmpty()) {
        return deletedItems.entrySet().stream().map(this::toHeader).collect(Collectors.toList());
    }
    return deletedItems.entrySet().stream().filter(e -> types.contains(e.getKey().getTypeId())).map(this::toHeader).collect(Collectors.toList());
}
Also used : DeletedRecordPolicy(org.mycore.oai.pmh.Identify.DeletedRecordPolicy) Instant(java.time.Instant) ArrayList(java.util.ArrayList) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 9 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRMODSMetadataShareAgent method receiveMetadata.

/* (non-Javadoc)
     * @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject, org.mycore.datamodel.metadata.MCRObject)
     */
@Override
public void receiveMetadata(MCRObject child) {
    MCRMODSWrapper childWrapper = new MCRMODSWrapper(child);
    MCRObjectID parentID = child.getStructure().getParentID();
    LOGGER.debug("Removing old inherited Metadata.");
    childWrapper.removeInheritedMetadata();
    if (parentID != null && MCRMODSWrapper.isSupported(parentID)) {
        MCRObject parent = MCRMetadataManager.retrieveMCRObject(parentID);
        MCRMODSWrapper parentWrapper = new MCRMODSWrapper(parent);
        inheritToChild(parentWrapper, childWrapper);
    }
    for (Element relatedItem : childWrapper.getLinkedRelatedItems()) {
        String type = relatedItem.getAttributeValue("type");
        String holderId = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
        LOGGER.info("receive metadata from {} document {}", type, holderId);
        if ((holderId == null || parentID != null && parentID.toString().equals(holderId)) && MCRMODSRelationshipType.host.name().equals(type)) {
            // already received metadata from parent;
            continue;
        }
        MCRObjectID holderObjectID = MCRObjectID.getInstance(holderId);
        if (MCRMODSWrapper.isSupported(holderObjectID)) {
            MCRObject targetObject = MCRMetadataManager.retrieveMCRObject(holderObjectID);
            MCRMODSWrapper targetWrapper = new MCRMODSWrapper(targetObject);
            relatedItem.addContent(targetWrapper.getMODS().cloneContent());
        }
    }
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 10 with MCRObjectID

use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.

the class MCRMODSWrapper method setID.

public MCRObjectID setID(String projectID, int ID) {
    MCRObjectID objID = MCRObjectID.getInstance(MCRObjectID.formatID(projectID, MODS_OBJECT_TYPE, ID));
    object.setId(objID);
    return objID;
}
Also used : MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Aggregations

MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)144 IOException (java.io.IOException)37 MCRObject (org.mycore.datamodel.metadata.MCRObject)32 MCRException (org.mycore.common.MCRException)30 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)30 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)29 MCRPath (org.mycore.datamodel.niofs.MCRPath)25 MCRAccessException (org.mycore.access.MCRAccessException)22 Document (org.jdom2.Document)20 MCRPersistenceException (org.mycore.common.MCRPersistenceException)18 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)16 JDOMException (org.jdom2.JDOMException)15 MCRBase (org.mycore.datamodel.metadata.MCRBase)15 SAXException (org.xml.sax.SAXException)15 Date (java.util.Date)14 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)13 MCRSession (org.mycore.common.MCRSession)11 MCRContent (org.mycore.common.content.MCRContent)11 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)11 URISyntaxException (java.net.URISyntaxException)10