use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRRoleManager method getExternalRole.
/**
* Factory for external roles
* @param name a valid {@link MCRCategoryID}
* @return MCRRole instance or null if category does not exist
*/
public static MCRRole getExternalRole(String name) {
MCRCategoryID categoryID = MCRCategoryID.fromString(name);
if (categoryID.isRootID()) {
LOGGER.debug("External role may not be a rootCategory: {}", categoryID);
return null;
}
MCRCategory category = DAO.getCategory(categoryID, 0);
if (category == null) {
LOGGER.debug("Category does not exist: {}", categoryID);
return null;
}
return new MCRRole(name, category.getLabels());
}
use of org.mycore.datamodel.classifications2.MCRCategoryID 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.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRAuthorityWithURI method lookupCategoryID.
@Override
protected MCRCategoryID lookupCategoryID() {
for (MCRCategory category : getCategoryByURI(valueURI)) {
if (authorityURI.equals(category.getRoot().getLabel(LABEL_LANG_URI).get().getText())) {
return category.getId();
}
}
// maybe valueUri is in form {authorityURI}#{categId}
if (valueURI.startsWith(authorityURI) && authorityURI.length() < valueURI.length()) {
String categId;
try {
categId = valueURI.substring(authorityURI.length() + 1);
} catch (RuntimeException e) {
LOGGER.warn("authorityURI:{}, valueURI:{}", authorityURI, valueURI);
throw e;
}
int internalStylePos = authorityURI.indexOf(CLASS_URI_PART);
if (internalStylePos > 0) {
String rootId = authorityURI.substring(internalStylePos + CLASS_URI_PART.length());
MCRCategoryID catId = new MCRCategoryID(rootId, categId);
if (DAO.exist(catId)) {
return catId;
}
}
return getCategoryByURI(authorityURI).stream().map(cat -> new MCRCategoryID(cat.getId().getRootID(), categId)).filter(DAO::exist).findFirst().orElse(null);
}
return null;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRAccessCondition method lookupCategoryID.
/* (non-Javadoc)
* @see org.mycore.mods.classification.MCRAuthorityInfo#lookupCategoryID()
*/
@Override
protected MCRCategoryID lookupCategoryID() {
Collection<MCRCategory> categoryByURI = MCRAuthorityWithURI.getCategoryByURI(href);
if (categoryByURI.size() > 1) {
throw new MCRException(href + " is ambigous: " + categoryByURI.stream().map(MCRCategory::getId).collect(Collectors.toList()));
}
if (!categoryByURI.isEmpty()) {
return categoryByURI.iterator().next().getId();
}
// maybe href is in form {authorityURI}#{categId}
String categId, authorityURI = null;
try {
authorityURI = href.substring(0, href.lastIndexOf("#"));
categId = href.substring(authorityURI.length() + 1);
} catch (RuntimeException e) {
LOGGER.warn("authorityURI:{}, valueURI:{}", authorityURI, href);
return null;
}
int internalStylePos = authorityURI.indexOf(MCRAuthorityWithURI.CLASS_URI_PART);
if (internalStylePos > 0) {
String rootId = authorityURI.substring(internalStylePos + MCRAuthorityWithURI.CLASS_URI_PART.length());
MCRCategoryID catId = new MCRCategoryID(rootId, categId);
if (DAO.exist(catId)) {
return catId;
}
}
Collection<MCRCategory> classes = MCRAuthorityWithURI.getCategoryByURI(authorityURI);
return classes.stream().map(cat -> new MCRCategoryID(cat.getId().getRootID(), categId)).filter(DAO::exist).findFirst().orElse(null);
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method getDisplayName.
/**
* @param classificationId
* @param categoryId
* @return
*/
public static String getDisplayName(String classificationId, String categoryId) {
try {
MCRCategoryID categID = new MCRCategoryID(classificationId, categoryId);
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
MCRCategory category = dao.getCategory(categID, 0);
return Optional.ofNullable(category).map(MCRCategory::getCurrentLabel).filter(Optional::isPresent).map(Optional::get).map(MCRLabel::getText).orElse("");
} catch (Throwable e) {
LOGGER.error("Could not determine display name for classification id {} and category id {}", classificationId, categoryId, e);
return "";
}
}
Aggregations