Search in sources :

Example 36 with MCRCategoryImpl

use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImpl method syncLabels.

private static void syncLabels(MCRCategoryImpl source, MCRCategoryImpl target) {
    for (MCRLabel newLabel : source.getLabels()) {
        Optional<MCRLabel> label = target.getLabel(newLabel.getLang());
        if (!label.isPresent()) {
            // copy new label
            target.getLabels().add(newLabel);
        }
        label.ifPresent(oldLabel -> {
            if (!oldLabel.getText().equals(newLabel.getText())) {
                oldLabel.setText(newLabel.getText());
            }
            if (!oldLabel.getDescription().equals(newLabel.getDescription())) {
                oldLabel.setDescription(newLabel.getDescription());
            }
        });
    }
    // remove labels that are not present in new version
    target.getLabels().removeIf(mcrLabel -> !source.getLabel(mcrLabel.getLang()).isPresent());
}
Also used : MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 37 with MCRCategoryImpl

use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.

the class MCRXMLTransformer method buildCategory.

public static MCRCategory buildCategory(String classID, Element e, MCRCategory parent) throws URISyntaxException {
    MCRCategoryImpl category = new MCRCategoryImpl();
    // setId must be called before setParent (info important)
    category.setId(new MCRCategoryID(classID, e.getAttributeValue("ID")));
    category.setRoot(parent.getRoot());
    category.setChildren(new ArrayList<>());
    category.setParent(parent);
    try {
        category.setLabels(getLabels(e.getChildren("label")));
    } catch (NullPointerException | IllegalArgumentException ex) {
        throw new MCRException("Error while adding labels to category: " + category.getId(), ex);
    }
    category.setLevel(parent.getLevel() + 1);
    setURL(e, category);
    buildChildCategories(classID, e.getChildren("category"), category);
    return category;
}
Also used : MCRException(org.mycore.common.MCRException) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)17 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)17 Test (org.junit.Test)15 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)10 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)7 EntityManager (javax.persistence.EntityManager)6 HashMap (java.util.HashMap)4 MCRException (org.mycore.common.MCRException)4 MCRPersistenceException (org.mycore.common.MCRPersistenceException)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 AbstractMap (java.util.AbstractMap)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 BiConsumer (java.util.function.BiConsumer)2 Consumer (java.util.function.Consumer)2