Search in sources :

Example 56 with MCRCategory

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

the class MCRRoleServlet method getRoleElements.

private Collection<Element> getRoleElements() {
    ArrayList<Element> list = new ArrayList<>(roleCategories.size());
    for (MCRCategoryID categID : roleCategories) {
        Element role = new Element("role");
        role.setAttribute("categID", categID.toString());
        MCRCategory category = categoryDao.getCategory(categID, 0);
        if (category == null) {
            continue;
        }
        role.setAttribute("label", category.getCurrentLabel().map(MCRLabel::getText).orElse(categID.getID()));
        list.add(role);
    }
    return list;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 57 with MCRCategory

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

the class MCRCategLinkServiceImplTest method getAllCategIDs.

private static Collection<MCRCategoryID> getAllCategIDs(MCRCategory category) {
    HashSet<MCRCategoryID> ids = new HashSet<>();
    ids.add(category.getId());
    for (MCRCategory cat : category.getChildren()) {
        ids.addAll(getAllCategIDs(cat));
    }
    return ids;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) HashSet(java.util.HashSet)

Example 58 with MCRCategory

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

the class MCRCategoryDAOImplTest method replaceCategoryWithItself.

@Test
public void replaceCategoryWithItself() {
    addWorldClassification();
    MCRCategory europe = category.getChildren().get(0);
    MCRCategory germany = europe.getChildren().get(0);
    DAO.replaceCategory(germany);
    startNewTransaction();
    getRootCategoryFromSession();
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 59 with MCRCategory

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

the class MCRCategoryDAOImplTest method getCategoriesByLabel.

@Test
public void getCategoriesByLabel() {
    addWorldClassification();
    MCRCategory find = category.getChildren().get(0).getChildren().get(0);
    MCRCategory dontFind = category.getChildren().get(1);
    MCRLabel label = find.getLabels().iterator().next();
    List<MCRCategory> results = DAO.getCategoriesByLabel(category.getId(), label.getLang(), label.getText());
    assertFalse("No search results found", results.isEmpty());
    assertTrue("Could not find Category: " + find.getId(), results.get(0).getLabels().contains(label));
    assertTrue("No search result expected.", DAO.getCategoriesByLabel(dontFind.getId(), label.getLang(), label.getText()).isEmpty());
    results = DAO.getCategoriesByLabel(label.getLang(), label.getText());
    assertFalse("No search results found", results.isEmpty());
    assertTrue("Could not find Category: " + find.getId(), results.get(0).getLabels().contains(label));
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 60 with MCRCategory

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

the class MCRCategoryDAOImplTest method moveCategoryInParent.

@Test
public void moveCategoryInParent() throws SQLException {
    addWorldClassification();
    MCRCategory moveNode = category.getChildren().get(1);
    DAO.moveCategory(moveNode.getId(), moveNode.getParent().getId(), 0);
    startNewTransaction();
    MCRCategoryImpl rootNode = getRootCategoryFromSession();
    checkLeftRightLevelValue(rootNode, 0, 0);
    MCRCategory movedNode = rootNode.getChildren().get(0);
    assertEquals("Did not expect this category on position 0.", moveNode.getId(), movedNode.getId());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

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