use of org.mycore.datamodel.classifications2.MCRCategLinkService in project mycore by MyCoRe-Org.
the class MCRSolrClassificationUtil method rebuildIndex.
/**
* Reindex the whole classification system.
*/
public static void rebuildIndex() {
LOGGER.info("rebuild classification index...");
// categories
MCRCategoryDAO categoryDAO = MCRCategoryDAOFactory.getInstance();
List<MCRCategoryID> rootCategoryIDs = categoryDAO.getRootCategoryIDs();
for (MCRCategoryID rootID : rootCategoryIDs) {
LOGGER.info("rebuild classification '{}'...", rootID);
MCRCategory rootCategory = categoryDAO.getCategory(rootID, -1);
List<MCRCategory> categoryList = getDescendants(rootCategory);
categoryList.add(rootCategory);
List<SolrInputDocument> solrDocumentList = toSolrDocument(categoryList);
bulkIndex(solrDocumentList);
}
// links
MCRCategLinkService linkService = MCRCategLinkServiceFactory.getInstance();
Collection<String> linkTypes = linkService.getTypes();
for (String linkType : linkTypes) {
LOGGER.info("rebuild '{}' links...", linkType);
bulkIndex(linkService.getLinks(linkType).stream().map(link -> new MCRSolrCategoryLink(link.getCategory().getId(), link.getObjectReference())).map(MCRSolrCategoryLink::toSolrDocument).collect(Collectors.toList()));
}
}
use of org.mycore.datamodel.classifications2.MCRCategLinkService 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;
}
}
Aggregations