Search in sources :

Example 71 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method checkEmptyLabels.

private static void checkEmptyLabels(String classID, List<String> log) {
    Session session = MCRHIBConnection.instance().getSession();
    String sqlQuery = "select cat.categid from {h-schema}MCRCategory cat left outer join {h-schema}MCRCategoryLabels label on cat.internalid = label.category where cat.classid='" + classID + "' and (label.text is null or trim(label.text) = '')";
    @SuppressWarnings("unchecked") List<String> list = session.createNativeQuery(sqlQuery).getResultList();
    for (String categIDString : list) {
        log.add("EMPTY lables for category " + new MCRCategoryID(classID, categIDString));
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Session(org.hibernate.Session)

Example 72 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRFileMetaEventHandler method handleDerivateCreated.

@Override
protected void handleDerivateCreated(MCREvent evt, MCRDerivate der) {
    MCRObjectID derivateID = der.getId();
    MCRObjectDerivate objectDerivate = der.getDerivate();
    List<MCRFileMetadata> fileMetadata = objectDerivate.getFileMetadata();
    for (MCRFileMetadata metadata : fileMetadata) {
        Collection<MCRCategoryID> categories = metadata.getCategories();
        if (!categories.isEmpty()) {
            MCRPath path = MCRPath.getPath(derivateID.toString(), metadata.getName());
            MCRCategLinkReference linkReference = new MCRCategLinkReference(path);
            CATEGLINK_SERVICE.setLinks(linkReference, categories);
        }
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference)

Example 73 with MCRCategoryID

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

Example 74 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRRoleServlet method chooseCategory.

private static void chooseCategory(HttpServletRequest request) {
    MCRCategoryID categoryID;
    String categID = getProperty(request, "categID");
    if (categID != null) {
        categoryID = MCRCategoryID.fromString(categID);
    } else {
        String rootID = getProperty(request, "classID");
        categoryID = (rootID == null) ? MCRUser2Constants.ROLE_CLASSID : MCRCategoryID.rootID(rootID);
    }
    Element rootElement = getRootElement(request);
    rootElement.setAttribute("classID", categoryID.getRootID());
    if (!categoryID.isRootID()) {
        rootElement.setAttribute("categID", categoryID.getID());
    }
    request.setAttribute(LAYOUT_ELEMENT_KEY, new Document(rootElement));
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 75 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID 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)

Aggregations

MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)82 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)42 Test (org.junit.Test)14 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)13 Element (org.jdom2.Element)12 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)11 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)7 HashMap (java.util.HashMap)6 MCRException (org.mycore.common.MCRException)6 EntityManager (javax.persistence.EntityManager)5 Document (org.jdom2.Document)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Collection (java.util.Collection)4 LinkedList (java.util.LinkedList)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)4 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)4