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);
}
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()));
}
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;
}
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());
}
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());
}
Aggregations