Search in sources :

Example 76 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory 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 77 with MCRCategory

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

the class MCRClassification2Commands method loadFromURL.

@MCRCommand(syntax = "load classification from url {0}", help = "The command adds a new classification from URL {0} to the system.", order = 15)
public static void loadFromURL(String fileURL) throws SAXParseException, MalformedURLException, URISyntaxException {
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL(fileURL)));
    MCRCategory category = MCRXMLTransformer.getCategory(xml);
    DAO.addCategory(null, category);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 78 with MCRCategory

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

the class MCRUserTestCase method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    MCRCategory groupsCategory = MCRCategoryDAOImplTest.loadClassificationResource("/mcr-roles.xml");
    MCRCategoryDAO DAO = MCRCategoryDAOFactory.getInstance();
    DAO.addCategory(null, groupsCategory);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) Before(org.junit.Before)

Example 79 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory 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 80 with MCRCategory

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

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)87 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)36 Test (org.junit.Test)24 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)17 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)10 ArrayList (java.util.ArrayList)9 Document (org.jdom2.Document)9 Element (org.jdom2.Element)8 MCRException (org.mycore.common.MCRException)8 IOException (java.io.IOException)6 EntityManager (javax.persistence.EntityManager)6 URI (java.net.URI)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4