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);
}
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());
}
}
}
}
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;
}
}
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);
});
}
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);
}
}
}
Aggregations