Search in sources :

Example 1 with MCRCategLinkService

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()));
    }
}
Also used : Collection(java.util.Collection) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) IOException(java.io.IOException) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) List(java.util.List) Logger(org.apache.logging.log4j.Logger) MCRCategLinkService(org.mycore.datamodel.classifications2.MCRCategLinkService) MCRCategLinkServiceFactory(org.mycore.datamodel.classifications2.MCRCategLinkServiceFactory) MCRSolrClientFactory(org.mycore.solr.MCRSolrClientFactory) Lists(com.google.common.collect.Lists) MCRSolrConstants(org.mycore.solr.MCRSolrConstants) MCRCategoryDAOFactory(org.mycore.datamodel.classifications2.MCRCategoryDAOFactory) MCRSolrCore(org.mycore.solr.MCRSolrCore) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) LinkedList(java.util.LinkedList) LogManager(org.apache.logging.log4j.LogManager) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) SolrInputDocument(org.apache.solr.common.SolrInputDocument) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) SolrInputDocument(org.apache.solr.common.SolrInputDocument) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategLinkService(org.mycore.datamodel.classifications2.MCRCategLinkService)

Example 2 with MCRCategLinkService

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;
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Aggregations

MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)2 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1 MCRCategLinkService (org.mycore.datamodel.classifications2.MCRCategLinkService)1 MCRCategLinkServiceFactory (org.mycore.datamodel.classifications2.MCRCategLinkServiceFactory)1 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)1 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)1 MCRCategoryDAOFactory (org.mycore.datamodel.classifications2.MCRCategoryDAOFactory)1