use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method testClassEditorBatch.
@Test
public void testClassEditorBatch() throws Exception {
EntityManager entityManager = MCREntityManagerProvider.getCurrentEntityManager();
Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL("http://mycore.de/classifications/nameIdentifier.xml")));
MCRCategory nameIdentifier = MCRXMLTransformer.getCategory(xml);
MCRCategory secondCateg = nameIdentifier.getChildren().get(1);
DAO.addCategory(null, nameIdentifier);
startNewTransaction();
MCRCategLinkServiceFactory.getInstance().getLinksFromCategory(secondCateg.getId());
assertTrue(secondCateg.getId() + " should exist.", DAO.exist(secondCateg.getId()));
// re-set labels
DAO.setLabels(secondCateg.getId(), secondCateg.getLabels().stream().collect(Collectors.toSet()));
// re-set URI
entityManager.detach(DAO.setURI(secondCateg.getId(), secondCateg.getURI()));
// move to new index
DAO.moveCategory(secondCateg.getId(), secondCateg.getParent().getId(), 0);
startNewTransaction();
MCRCategoryImpl copyOfDB = MCRCategoryDAOImpl.getByNaturalID(entityManager, secondCateg.getId());
assertNotNull(secondCateg.getId() + " must hav a parent.", copyOfDB.getParent());
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method addCategoryToPosition.
/**
* Test case for https://sourceforge.net/p/mycore/bugs/664/
*/
@Test
public void addCategoryToPosition() {
addWorldClassification();
MCRCategoryImpl america = new MCRCategoryImpl();
MCRCategoryID categoryID = new MCRCategoryID(category.getId().getRootID(), "America");
america.setId(categoryID);
america.setLabels(new HashSet<>());
america.getLabels().add(new MCRLabel("de", "Amerika", null));
america.getLabels().add(new MCRLabel("en", "America", null));
DAO.addCategory(category.getId(), america, 1);
startNewTransaction();
america = MCRCategoryDAOImpl.getByNaturalID(getEntityManager().get(), america.getId());
assertNotNull(categoryID + " was not added to database.", america);
assertEquals("invalid position in parent", 1, america.getPositionInParent());
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method addCategory.
@Test
public void addCategory() throws MCRException {
addWorldClassification();
assertTrue("Exist check failed for Category " + category.getId(), DAO.exist(category.getId()));
MCRCategoryImpl india = new MCRCategoryImpl();
india.setId(new MCRCategoryID(category.getId().getRootID(), "India"));
india.setLabels(new HashSet<>());
india.getLabels().add(new MCRLabel("de", "Indien", null));
india.getLabels().add(new MCRLabel("en", "India", null));
DAO.addCategory(new MCRCategoryID(category.getId().getRootID(), "Asia"), india);
startNewTransaction();
assertTrue("Exist check failed for Category " + india.getId(), DAO.exist(india.getId()));
MCRCategoryImpl rootCategory = getRootCategoryFromSession();
assertEquals("Child category count does not match.", category.getChildren().size(), rootCategory.getChildren().size());
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Number> countQuery = cb.createQuery(Number.class);
long allNodes = em.createQuery(countQuery.select(cb.count(countQuery.from(MCRCategoryImpl.class)))).getSingleResult().longValue();
// category + india
assertEquals("Complete category count does not match.", countNodes(category) + 1, allNodes);
assertTrue("No root category present", rootCategory.getRoot() != null);
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method moveCategoryDeep.
@Test
public void moveCategoryDeep() {
String rootIDStr = "rootID";
MCRCategoryID rootID = MCRCategoryID.rootID(rootIDStr);
MCRCategoryID child1ID = new MCRCategoryID(rootIDStr, "child1");
MCRCategoryID child2ID = new MCRCategoryID(rootIDStr, "child2");
MCRCategoryID child3ID = new MCRCategoryID(rootIDStr, "child3");
MCRCategoryID child4ID = new MCRCategoryID(rootIDStr, "child4");
MCRCategoryImpl root = newCategory(rootID, "root node");
MCRCategoryImpl a = newCategory(child1ID, "child node 1");
MCRCategoryImpl aa = newCategory(child2ID, "child node 2");
MCRCategoryImpl aaa = newCategory(child3ID, "child node 3");
MCRCategoryImpl aab = newCategory(child4ID, "child node 4");
addChild(root, a);
addChild(a, aa);
addChild(aa, aaa);
addChild(aa, aab);
startNewTransaction();
DAO.addCategory(null, root);
endTransaction();
startNewTransaction();
DAO.moveCategory(child4ID, child3ID);
endTransaction();
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method moveCategoryWithoutIndex.
@Test
public void moveCategoryWithoutIndex() throws SQLException {
addWorldClassification();
checkLeftRightLevelValue(getRootCategoryFromSession(), 0, 0);
startNewTransaction();
MCRCategory moveNode = category.getChildren().get(1);
// Europe conquer Asia
DAO.moveCategory(moveNode.getId(), category.getChildren().get(0).getId());
startNewTransaction();
MCRCategoryImpl rootNode = getRootCategoryFromSession();
checkLeftRightLevelValue(rootNode, 0, 0);
}
Aggregations