Search in sources :

Example 91 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID 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)

Example 92 with MCRCategoryID

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

the class MCRCategoryMapper method getMappingRule.

protected String getMappingRule(MCRCategoryID categoryID) {
    MCRCategory category = DAO.getCategory(categoryID, 0);
    // "x-mapper" was used in previous versions of mycore
    MCRLabel label = category.getLabel("x-mapping").orElse(category.getLabel("x-mapper").orElseThrow(() -> new MCRException("Category " + category + " does not hav a label for 'x-mapping'.")));
    return label.getText();
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRException(org.mycore.common.MCRException) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 93 with MCRCategoryID

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

the class MCRClassificationUtils method asDocument.

/**
 * Returns the classification as a jdom document. Returns null if the
 * classification does not exists.
 *
 * @param classId the classification root id
 * @return the classification as jdom document
 */
public static Document asDocument(String classId) {
    MCRCategoryID categoryId = MCRCategoryID.rootID(classId);
    MCRCategory classification = MCRCategoryDAOFactory.getInstance().getRootCategory(categoryId, -1);
    if (classification == null) {
        return null;
    }
    return MCRCategoryTransformer.getMetaDataDocument(classification, true);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 94 with MCRCategoryID

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

the class MCRSolrCategoryDAO method setLabels.

@Override
public MCRCategory setLabels(MCRCategoryID id, Set<MCRLabel> labels) {
    MCRCategory category = super.setLabels(id, labels);
    MCRSolrClassificationUtil.reindex(category);
    return category;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Example 95 with MCRCategoryID

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

the class MCRSolrCategoryDAO method setLabel.

@Override
public MCRCategory setLabel(MCRCategoryID id, MCRLabel label) {
    MCRCategory category = super.setLabel(id, label);
    MCRSolrClassificationUtil.reindex(category);
    return category;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Aggregations

MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)82 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)42 Test (org.junit.Test)14 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)13 Element (org.jdom2.Element)12 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)11 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)7 HashMap (java.util.HashMap)6 MCRException (org.mycore.common.MCRException)6 EntityManager (javax.persistence.EntityManager)5 Document (org.jdom2.Document)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Collection (java.util.Collection)4 LinkedList (java.util.LinkedList)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)4 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)4