Search in sources :

Example 16 with MCRCategLinkReference

use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.

the class MCRRoleManager method isAssignedToRole.

static boolean isAssignedToRole(MCRUser user, String roleID) {
    MCRCategoryID categoryID = MCRCategoryID.fromString(roleID);
    MCRCategLinkReference linkReference = getLinkID(user);
    return CATEG_LINK_SERVICE.isInCategory(linkReference, categoryID);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 17 with MCRCategLinkReference

use of org.mycore.datamodel.classifications2.MCRCategLinkReference 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)

Example 18 with MCRCategLinkReference

use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.

the class MCRXMLFunctions method isInCategory.

/**
 * Verifies if object is in specified category.
 * @see MCRCategLinkService#isInCategory(MCRCategLinkReference, MCRCategoryID)
 * @param objectId valid MCRObjectID as String
 * @param categoryId valid MCRCategoryID as String
 * @return true if object is in category, else false
 */
public static boolean isInCategory(String objectId, String categoryId) {
    try {
        MCRCategoryID categID = MCRCategoryID.fromString(categoryId);
        MCRObjectID mcrObjectID = MCRObjectID.getInstance(objectId);
        MCRCategLinkReference reference = new MCRCategLinkReference(mcrObjectID);
        return MCRCategLinkServiceHolder.instance.isInCategory(reference, categID);
    } catch (Throwable e) {
        LOGGER.error("Error while checking if object is in category", e);
        return false;
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 19 with MCRCategLinkReference

use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.

the class MCRCategLinkServiceImpl method setLinks.

@Override
public void setLinks(MCRCategLinkReference objectReference, Collection<MCRCategoryID> categories) {
    EntityManager entityManager = MCREntityManagerProvider.getCurrentEntityManager();
    categories.stream().distinct().forEach(categID -> {
        final MCRCategory category = getMCRCategory(entityManager, categID);
        if (category == null) {
            throw new MCRPersistenceException("Could not link to unknown category " + categID);
        }
        MCRCategoryLinkImpl link = new MCRCategoryLinkImpl(category, objectReference);
        if (LOGGER.isDebugEnabled()) {
            MCRCategory linkedCategory = link.getCategory();
            StringBuilder debugMessage = new StringBuilder("Adding Link from ").append(linkedCategory.getId());
            if (linkedCategory instanceof MCRCategoryImpl) {
                debugMessage.append("(").append(((MCRCategoryImpl) linkedCategory).getInternalID()).append(") ");
            }
            debugMessage.append("to ").append(objectReference);
            LOGGER.debug(debugMessage.toString());
        }
        entityManager.persist(link);
        LOGGER.debug("===DONE: {}", link.id);
    });
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) EntityManager(javax.persistence.EntityManager) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 20 with MCRCategLinkReference

use of org.mycore.datamodel.classifications2.MCRCategLinkReference in project mycore by MyCoRe-Org.

the class MCRSolrCategLinkService method deleteLinks.

@Override
public void deleteLinks(Collection<MCRCategLinkReference> references) {
    super.deleteLinks(references);
    // solr
    SolrClient solrClient = MCRSolrClassificationUtil.getCore().getClient();
    for (MCRCategLinkReference reference : references) {
        try {
            delete(solrClient, reference);
        } catch (Exception exc) {
            LOGGER.error("Unable to delete links of object {}", reference.getObjectID(), exc);
        }
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Aggregations

MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)19 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)5 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)5 EntityManager (javax.persistence.EntityManager)3 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)3 MCRPath (org.mycore.datamodel.niofs.MCRPath)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Element (org.jdom2.Element)2 Test (org.junit.Test)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 ProviderMismatchException (java.nio.file.ProviderMismatchException)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 BitSet (java.util.BitSet)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1