Search in sources :

Example 1 with MCRCategory

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);
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Example 2 with MCRCategory

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;
}
Also used : MCRException(org.mycore.common.MCRException) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)

Example 3 with MCRCategory

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRSession(org.mycore.common.MCRSession) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 4 with MCRCategory

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());
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 5 with MCRCategory

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Test(org.junit.Test)

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)87 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)36 Test (org.junit.Test)24 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)17 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)10 ArrayList (java.util.ArrayList)9 Document (org.jdom2.Document)9 Element (org.jdom2.Element)8 MCRException (org.mycore.common.MCRException)8 IOException (java.io.IOException)6 EntityManager (javax.persistence.EntityManager)6 URI (java.net.URI)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4