Search in sources :

Example 26 with MCRLabel

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

the class CategoryDAOMock method createCategory.

private MCRJSONCategory createCategory(String rootID, String categID, MCRCategoryID parentID) {
    MCRCategoryID id = new MCRCategoryID(rootID, categID);
    Set<MCRLabel> labels = new HashSet<>();
    labels.add(new MCRLabel("de", id + "_text", id + "_descr"));
    labels.add(new MCRLabel("en", id + "_text", id + "_descr"));
    MCRJSONCategory newCategory = new MCRJSONCategory();
    newCategory.setId(id);
    newCategory.setLabels(labels);
    newCategory.setParentID(parentID);
    return newCategory;
}
Also used : MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Example 27 with MCRLabel

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

the class MCRClassification2Commands method listCategory.

private static void listCategory(MCRCategory categ) {
    int level = categ.getLevel();
    StringBuilder sb = new StringBuilder(128);
    for (int i = 0; i < level * 2; i++) {
        sb.append(' ');
    }
    String space = sb.toString();
    if (categ.isCategory()) {
        LOGGER.info("{}  ID    : {}", space, categ.getId().getID());
    }
    for (MCRLabel label : categ.getLabels()) {
        LOGGER.info("{}  Label : ({}) {}", space, label.getLang(), label.getText());
    }
    List<MCRCategory> children = categ.getChildren();
    for (MCRCategory child : children) {
        listCategory(child);
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 28 with MCRLabel

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

the class MCRXMLFunctions method getDisplayName.

/**
 * @param classificationId
 * @param categoryId
 * @return
 */
public static String getDisplayName(String classificationId, String categoryId) {
    try {
        MCRCategoryID categID = new MCRCategoryID(classificationId, categoryId);
        MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
        MCRCategory category = dao.getCategory(categID, 0);
        return Optional.ofNullable(category).map(MCRCategory::getCurrentLabel).filter(Optional::isPresent).map(Optional::get).map(MCRLabel::getText).orElse("");
    } catch (Throwable e) {
        LOGGER.error("Could not determine display name for classification id {} and category id {}", classificationId, categoryId, e);
        return "";
    }
}
Also used : MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Optional(java.util.Optional)

Example 29 with MCRLabel

use of org.mycore.datamodel.classifications2.MCRLabel 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 30 with MCRLabel

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

the class MCRXMLTransformer method getLabels.

public static Set<MCRLabel> getLabels(List<Element> elements) throws NullPointerException, IllegalArgumentException {
    Set<MCRLabel> labels = new HashSet<>(elements.size(), 1L);
    for (Element labelElement : elements) {
        MCRLabel label = getLabel(labelElement);
        labels.add(label);
    }
    return labels;
}
Also used : Element(org.jdom2.Element) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Aggregations

MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)30 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)14 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)8 Test (org.junit.Test)6 JsonObject (com.google.gson.JsonObject)4 Element (org.jdom2.Element)4 MCRException (org.mycore.common.MCRException)3 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonArray (com.google.gson.JsonArray)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1