use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRXMLTransformer method getCategory.
public static MCRCategory getCategory(Document xml) throws URISyntaxException {
MCRCategoryImpl category = new MCRCategoryImpl();
category.setRoot(category);
final String classID = xml.getRootElement().getAttributeValue("ID");
category.setLevel(0);
category.setId(MCRCategoryID.rootID(classID));
setURL(xml.getRootElement(), category);
// setChildren has to be called before setParent (below) can be called without
// database access see: org.mycore.datamodel.classifications2.impl.MCRAbstractCategoryImpl.getChildren()
category.setChildren(new ArrayList<>());
buildChildCategories(classID, xml.getRootElement().getChild("categories").getChildren("category"), category);
try {
category.setLabels(getLabels(xml.getRootElement().getChildren("label")));
} catch (NullPointerException | IllegalArgumentException ex) {
throw new MCRException("Error while adding labels to classification: " + classID, ex);
}
return category;
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImplTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
if (SERVICE == null) {
SERVICE = new MCRCategLinkServiceImpl();
}
loadWorldClassification();
MCRCategoryImpl germany = (MCRCategoryImpl) category.getChildren().get(0).getChildren().get(0);
MCRCategoryImpl uk = (MCRCategoryImpl) category.getChildren().get(0).getChildren().get(1);
DAO.addCategory(null, category);
testLinks = new ArrayList<>();
testLinks.add(new MCRCategoryLinkImpl(germany, new MCRCategLinkReference("Jena", "city")));
testLinks.add(new MCRCategoryLinkImpl(germany, new MCRCategLinkReference("Thüringen", "state")));
testLinks.add(new MCRCategoryLinkImpl(germany, new MCRCategLinkReference("Hessen", "state")));
testLinks.add(new MCRCategoryLinkImpl(germany, new MCRCategLinkReference("Saale", "river")));
final MCRCategLinkReference northSeaReference = new MCRCategLinkReference("North Sea", "sea");
testLinks.add(new MCRCategoryLinkImpl(germany, northSeaReference));
testLinks.add(new MCRCategoryLinkImpl(uk, LONDON_REFERENCE));
testLinks.add(new MCRCategoryLinkImpl(uk, ENGLAND_REFERENCE));
testLinks.add(new MCRCategoryLinkImpl(uk, new MCRCategLinkReference("Thames", "river")));
testLinks.add(new MCRCategoryLinkImpl(uk, northSeaReference));
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method addCategorySingleSteps.
/**
* Test case for https://sourceforge.net/p/mycore/bugs/612/
*/
@Test
public void addCategorySingleSteps() {
MCRCategory root = new MCRCategoryImpl();
MCRCategoryID rootID = MCRCategoryID.rootID("junit");
root.setId(rootID);
DAO.addCategory(null, root);
startNewTransaction();
MCRCategory a = new MCRCategoryImpl();
MCRCategoryID aId = new MCRCategoryID(rootID.getRootID(), "a");
a.setId(aId);
MCRCategory b = new MCRCategoryImpl();
MCRCategoryID bId = new MCRCategoryID(rootID.getRootID(), "b");
b.setId(bId);
MCRCategory c = new MCRCategoryImpl();
MCRCategoryID cId = new MCRCategoryID(rootID.getRootID(), "c");
c.setId(cId);
DAO.addCategory(rootID, a);
DAO.addCategory(rootID, c);
DAO.addCategory(aId, b);
startNewTransaction();
assertTrue("Category c should not contain child categories.", DAO.getChildren(cId).isEmpty());
assertFalse("Category a should contain child categories.", DAO.getChildren(aId).isEmpty());
root = DAO.getCategory(rootID, -1);
checkLeftRightLevelValue((MCRCategoryImpl) root, 0, 0);
assertEquals("Did not get all categories", 4, countNodes(root));
List<MCRCategory> children = root.getChildren();
assertEquals("Children count mismatch", 2, children.size());
a = children.get(0);
c = children.get(1);
assertEquals("Wrong order of children", aId, a.getId());
assertEquals("Wrong order of children", cId, c.getId());
assertTrue("Category c should not contain child categories.", c.getChildren().isEmpty());
assertFalse("Category a should contain child categories.", a.getChildren().isEmpty());
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method replaceCategory.
@Test
public void replaceCategory() throws URISyntaxException, MCRException, SAXParseException, IOException {
loadWorldClassification2();
addWorldClassification();
DAO.replaceCategory(category2);
startNewTransaction();
MCRCategoryImpl rootNode = getRootCategoryFromSession();
assertEquals("Category count does not match.", countNodes(category2), countNodes(rootNode));
assertEquals("Label count does not match.", category2.getChildren().get(0).getLabels().size(), rootNode.getChildren().get(0).getLabels().size());
checkLeftRightLevelValue(rootNode, 0, 0);
final URI germanURI = new URI("http://www.deutschland.de");
final MCRCategory germany = rootNode.getChildren().get(0).getChildren().get(0);
assertEquals("URI was not updated", germanURI, germany.getURI());
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method checkLeftRightLevelValue.
private int checkLeftRightLevelValue(MCRCategoryImpl node, int leftStart, int levelStart) {
int curValue = leftStart;
final int nextLevel = levelStart + 1;
assertEquals("Left value did not match on ID: " + node.getId(), leftStart, node.getLeft());
assertEquals("Level value did not match on ID: " + node.getId(), levelStart, node.getLevel());
for (MCRCategory child : node.getChildren()) {
curValue = checkLeftRightLevelValue((MCRCategoryImpl) child, ++curValue, nextLevel);
}
assertEquals("Right value did not match on ID: " + node.getId(), ++curValue, node.getRight());
return curValue;
}
Aggregations