use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRLanguageFactory method buildLanguagesFromClassification.
/**
* Builds language objects from classification categories
*/
private void buildLanguagesFromClassification() {
this.classificationLastRead = DAO.getLastModified();
MCRCategory root = DAO.getCategory(classification, -1);
if (root == null) {
LOGGER.warn("Language classification {} not found", classification.getRootID());
return;
}
for (MCRCategory category : root.getChildren()) {
buildLanguage(category);
}
}
use of org.mycore.datamodel.classifications2.MCRCategory 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.MCRCategory in project mycore by MyCoRe-Org.
the class MCRAbstractCategoryImplTest method getCurrentLabel.
@Test
public void getCurrentLabel() {
MCRCategory cat = new MCRSimpleAbstractCategoryImpl();
MCRLabel label1 = new MCRLabel("de", "german", null);
MCRLabel label2 = new MCRLabel("fr", "french", null);
MCRLabel label3 = new MCRLabel("at", "austrian", null);
cat.getLabels().add(label1);
cat.getLabels().add(label2);
cat.getLabels().add(label3);
MCRSession session = MCRSessionMgr.getCurrentSession();
session.setCurrentLanguage("en");
assertEquals("German label expected", label3, cat.getCurrentLabel().get());
cat.getLabels().clear();
cat.getLabels().add(label2);
cat.getLabels().add(label3);
cat.getLabels().add(label1);
assertEquals("German label expected", label3, cat.getCurrentLabel().get());
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method getParents.
@Test
public void getParents() {
addWorldClassification();
MCRCategory find = category.getChildren().get(0).getChildren().get(0);
List<MCRCategory> parents = DAO.getParents(find.getId());
MCRCategory findParent = find;
for (MCRCategory parent : parents) {
findParent = findParent.getParent();
assertNotNull("Returned too much parents.", findParent);
assertEquals("Parents did not match.", findParent.getId(), parent.getId());
}
}
use of org.mycore.datamodel.classifications2.MCRCategory 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());
}
Aggregations