Search in sources :

Example 1 with MCRLinkTableManager

use of org.mycore.datamodel.common.MCRLinkTableManager in project mycore by MyCoRe-Org.

the class MCRXMLFunctions method getLinkDestinations.

/**
 * Returns a list of link targets of a given MCR object type. The structure
 * is <em>link</em>. If no links are found an empty NodeList is returned.
 *
 * @param mcrid
 *            MCRObjectID as String as the link source
 * @param destinationType
 *            MCR object type
 * @return a NodeList with <em>link</em> elements
 */
public static NodeList getLinkDestinations(String mcrid, String destinationType) {
    DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked();
    try {
        Document document = documentBuilder.newDocument();
        Element rootElement = document.createElement("linklist");
        document.appendChild(rootElement);
        MCRLinkTableManager ltm = MCRLinkTableManager.instance();
        for (String id : ltm.getDestinationOf(mcrid, destinationType)) {
            Element link = document.createElement("link");
            link.setTextContent(id);
            rootElement.appendChild(link);
        }
        return rootElement.getChildNodes();
    } finally {
        MCRDOMUtils.releaseDocumentBuilder(documentBuilder);
    }
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) MCRLinkTableManager(org.mycore.datamodel.common.MCRLinkTableManager)

Example 2 with MCRLinkTableManager

use of org.mycore.datamodel.common.MCRLinkTableManager in project mycore by MyCoRe-Org.

the class MCRXMLFunctions method getLinkSources.

/**
 * Returns a list of link sources of a given MCR object type. The structure
 * is <em>link</em>. If no links are found an empty NodeList is returned.
 *
 * @param mcrid
 *            MCRObjectID as String as the link target
 * @param sourceType
 *            MCR object type
 * @return a NodeList with <em>link</em> elements
 */
public static NodeList getLinkSources(String mcrid, String sourceType) {
    DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked();
    try {
        Document document = documentBuilder.newDocument();
        Element rootElement = document.createElement("linklist");
        document.appendChild(rootElement);
        MCRLinkTableManager ltm = MCRLinkTableManager.instance();
        for (String id : ltm.getSourceOf(mcrid)) {
            if (sourceType == null || MCRObjectID.getIDParts(id)[1].equals(sourceType)) {
                Element link = document.createElement("link");
                link.setTextContent(id);
                rootElement.appendChild(link);
            }
        }
        return rootElement.getChildNodes();
    } finally {
        MCRDOMUtils.releaseDocumentBuilder(documentBuilder);
    }
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) MCRLinkTableManager(org.mycore.datamodel.common.MCRLinkTableManager)

Example 3 with MCRLinkTableManager

use of org.mycore.datamodel.common.MCRLinkTableManager in project mycore by MyCoRe-Org.

the class MCRObjectUtils method getDerivates.

/**
 * Returns all derivates connected with this object. This includes derivates which are defined in the
 * structure part and also derivate links.
 *
 * @param mcrObjectID object identifier to get the root node
 * @return set of derivates
 */
public static List<MCRObjectID> getDerivates(MCRObjectID mcrObjectID) {
    MCRLinkTableManager linkTableManager = MCRLinkTableManager.instance();
    Stream<String> derivateStream = linkTableManager.getDestinationOf(mcrObjectID, MCRLinkTableManager.ENTRY_TYPE_DERIVATE).stream();
    Stream<String> derivateLinkStream = linkTableManager.getDestinationOf(mcrObjectID, MCRLinkTableManager.ENTRY_TYPE_DERIVATE_LINK).stream().map(link -> link.substring(0, link.indexOf("/")));
    return Stream.concat(derivateStream, derivateLinkStream).distinct().map(MCRObjectID::getInstance).collect(Collectors.toList());
}
Also used : MCRLinkTableManager(org.mycore.datamodel.common.MCRLinkTableManager)

Example 4 with MCRLinkTableManager

use of org.mycore.datamodel.common.MCRLinkTableManager in project mycore by MyCoRe-Org.

the class MCRMODSLinksEventHandler method handleObjectCreated.

/* (non-Javadoc)
     * @see org.mycore.common.events.MCREventHandlerBase#handleObjectCreated(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject)
     */
@Override
protected void handleObjectCreated(final MCREvent evt, final MCRObject obj) {
    if (!MCRMODSWrapper.isSupported(obj)) {
        return;
    }
    MCRMODSWrapper modsWrapper = new MCRMODSWrapper(obj);
    final HashSet<MCRCategoryID> categories = new HashSet<>(modsWrapper.getMcrCategoryIDs());
    if (!categories.isEmpty()) {
        final MCRCategLinkReference objectReference = new MCRCategLinkReference(obj.getId());
        MCRCategLinkServiceFactory.getInstance().setLinks(objectReference, categories);
    }
    List<Element> linkingNodes = modsWrapper.getLinkedRelatedItems();
    if (!linkingNodes.isEmpty()) {
        MCRLinkTableManager linkTableManager = MCRLinkTableManager.instance();
        for (Element linkingNode : linkingNodes) {
            String targetID = linkingNode.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
            if (targetID == null) {
                continue;
            }
            String relationshipTypeRaw = linkingNode.getAttributeValue("type");
            MCRMODSRelationshipType relType = MCRMODSRelationshipType.valueOf(relationshipTypeRaw);
            // MCR-1328 (no reference links for 'host')
            if (relType != MCRMODSRelationshipType.host) {
                linkTableManager.addReferenceLink(obj.getId(), MCRObjectID.getInstance(targetID), MCRLinkTableManager.ENTRY_TYPE_REFERENCE, relType.toString());
            }
        }
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) MCRLinkTableManager(org.mycore.datamodel.common.MCRLinkTableManager) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) HashSet(java.util.HashSet)

Aggregations

MCRLinkTableManager (org.mycore.datamodel.common.MCRLinkTableManager)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 HashSet (java.util.HashSet)1 Element (org.jdom2.Element)1 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)1 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)1