Search in sources :

Example 21 with MCRCategoryImpl

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

the class MCRRoleManager method addRole.

/**
 * Adds <code>role</code> to the classification system.
 * If the representing {@link MCRCategory} already exists this method does nothing.
 * It will create any category if necessary.
 */
public static void addRole(MCRRole role) {
    MCRCategoryID categoryID = null;
    if (role.isSystemRole()) {
        categoryID = new MCRCategoryID(MCRUser2Constants.ROLE_CLASSID.getRootID(), role.getName());
    } else {
        categoryID = MCRCategoryID.fromString(role.getName());
    }
    if (DAO.exist(categoryID)) {
        return;
    }
    MCRCategoryID rootID = MCRCategoryID.rootID(categoryID.getRootID());
    if (!DAO.exist(rootID)) {
        MCRCategoryImpl category = new MCRCategoryImpl();
        category.setId(rootID);
        HashSet<MCRLabel> labels = new HashSet<>();
        labels.add(new MCRLabel("de", "Systemrollen", null));
        labels.add(new MCRLabel("en", "system roles", null));
        category.setLabels(labels);
        DAO.addCategory(null, category);
    }
    MCRCategoryImpl category = new MCRCategoryImpl();
    category.setId(categoryID);
    category.getLabels().addAll(role.getLabels());
    DAO.addCategory(rootID, category);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Example 22 with MCRCategoryImpl

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

the class MCRCategLinkServiceImplTest method isInCategory.

@Test
public void isInCategory() {
    MCRCategoryImpl germany = (MCRCategoryImpl) category.getChildren().get(0).getChildren().get(0);
    MCRCategoryImpl europe = (MCRCategoryImpl) category.getChildren().get(0);
    MCRCategoryImpl asia = (MCRCategoryImpl) category.getChildren().get(1);
    MCRCategLinkReference jena = new MCRCategLinkReference("Jena", "city");
    addTestLinks();
    startNewTransaction();
    assertTrue("Jena should be in Germany", SERVICE.isInCategory(jena, germany.getId()));
    assertTrue("Jena should be in Europe", SERVICE.isInCategory(jena, europe.getId()));
    assertFalse("Jena should not be in Asia", SERVICE.isInCategory(jena, asia.getId()));
}
Also used : MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) Test(org.junit.Test)

Example 23 with MCRCategoryImpl

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

the class MCRCategoryDAOImplTest method newCategory.

private MCRCategoryImpl newCategory(MCRCategoryID id, String description) {
    MCRCategoryImpl newCateg = new MCRCategoryImpl();
    newCateg.setId(id);
    Set<MCRLabel> labels = new HashSet<>();
    labels.add(new MCRLabel("en", id.toString(), description));
    newCateg.setLabels(labels);
    return newCateg;
}
Also used : MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Example 24 with MCRCategoryImpl

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

Example 25 with MCRCategoryImpl

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

the class MCRCategoryDAOImplTest method testReplaceCategoryNewParent.

/**
 * tests top category child to new parent
 */
public void testReplaceCategoryNewParent() {
    addWorldClassification();
    MCRCategory europe = category.getChildren().get(0);
    MCRCategoryImpl test = new MCRCategoryImpl();
    test.setId(new MCRCategoryID(category.getId().getRootID(), "test"));
    test.setLabels(new HashSet<>());
    test.getLabels().add(new MCRLabel("de", "JUnit testcase", null));
    category.getChildren().add(test);
    category.getChildren().remove(0);
    test.getChildren().add(europe);
    DAO.replaceCategory(category);
    startNewTransaction();
    MCRCategory rootNode = getRootCategoryFromSession();
    assertEquals("Category count does not match.", countNodes(category), countNodes(rootNode));
    assertEquals("Label count does not match.", category.getChildren().get(0).getLabels().size(), rootNode.getChildren().get(0).getLabels().size());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)17 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)17 Test (org.junit.Test)15 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)10 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)7 EntityManager (javax.persistence.EntityManager)6 HashMap (java.util.HashMap)4 MCRException (org.mycore.common.MCRException)4 MCRPersistenceException (org.mycore.common.MCRPersistenceException)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 AbstractMap (java.util.AbstractMap)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 BiConsumer (java.util.function.BiConsumer)2 Consumer (java.util.function.Consumer)2