use of org.mycore.datamodel.classifications2.MCRCategoryID 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.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method isCategoryID.
/**
* @param classificationId
* @param categoryId
* @return
*/
public static boolean isCategoryID(String classificationId, String categoryId) {
MCRCategory category = null;
try {
MCRCategoryID categID = MCRCategoryID.fromString(classificationId + ":" + categoryId);
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
category = dao.getCategory(categID, 0);
} catch (Throwable e) {
LOGGER.error("Could not determine state for classification id {} and category id {}", classificationId, categoryId, e);
}
return category != null;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID 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.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImpl method getMCRCategory.
private static MCRCategory getMCRCategory(EntityManager entityManager, MCRCategoryID categID) {
MCRCategory categ = categCache.getIfUpToDate(categID, DAO.getLastModified());
if (categ != null) {
return categ;
}
categ = MCRCategoryDAOImpl.getByNaturalID(entityManager, categID);
if (categ == null) {
return null;
}
categCache.put(categID, categ);
return categ;
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImpl method hasLinks.
@Override
public Map<MCRCategoryID, Boolean> hasLinks(MCRCategory category) {
if (category == null) {
return hasLinksForClassifications();
}
MCRCategoryImpl rootImpl = (MCRCategoryImpl) MCRCategoryDAOFactory.getInstance().getCategory(category.getRoot().getId(), -1);
if (rootImpl == null) {
// Category does not exist, so it has no links
return getNoLinksMap(category);
}
HashMap<MCRCategoryID, Boolean> boolMap = new HashMap<>();
final BitSet linkedInternalIds = getLinkedInternalIds();
storeHasLinkValues(boolMap, linkedInternalIds, rootImpl);
return boolMap;
}
Aggregations