Search in sources :

Example 16 with MCRCategoryID

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

the class MCRCategoryTypeAdapter method deserialize.

@Override
public MCRJSONCategory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject categJsonObject = json.getAsJsonObject();
    MCRJSONCategory deserializedCateg = new MCRJSONCategory();
    JsonElement idJsonElement = categJsonObject.get(ID);
    if (idJsonElement != null) {
        MCRCategoryID id = context.deserialize(idJsonElement, MCRCategoryID.class);
        deserializedCateg.setId(id);
    }
    JsonElement parentIdJsonElement = categJsonObject.get(PARENTID);
    if (parentIdJsonElement != null) {
        MCRCategoryID parentId = context.deserialize(parentIdJsonElement, MCRCategoryID.class);
        deserializedCateg.setParentID(parentId);
    }
    JsonElement positionJsonElem = categJsonObject.get(POSITION);
    if (positionJsonElem != null) {
        deserializedCateg.setPositionInParent(positionJsonElem.getAsInt());
    }
    JsonElement labelSetWrapperElem = categJsonObject.get(LABELS);
    if (labelSetWrapperElem != null) {
        MCRLabelSetWrapper labelSetWrapper = context.deserialize(labelSetWrapperElem, MCRLabelSetWrapper.class);
        deserializedCateg.setLabels(labelSetWrapper.getSet());
    }
    JsonElement uriJsonElement = categJsonObject.get(URISTR);
    if (uriJsonElement != null) {
        String uriStr = uriJsonElement.getAsString();
        deserializedCateg.setURI(URI.create(uriStr));
    }
    return deserializedCateg;
}
Also used : MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) MCRLabelSetWrapper(org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)

Example 17 with MCRCategoryID

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

the class MCRCategoryTypeAdapter method serialize.

@Override
public JsonElement serialize(MCRJSONCategory category, Type arg1, JsonSerializationContext contextSerialization) {
    JsonObject rubricJsonObject = new JsonObject();
    MCRCategoryID id = category.getId();
    if (id != null) {
        rubricJsonObject.add(ID, contextSerialization.serialize(id));
    }
    Set<MCRLabel> labels = category.getLabels();
    rubricJsonObject.add(LABELS, contextSerialization.serialize(new MCRLabelSetWrapper(labels)));
    URI uri = category.getURI();
    if (uri != null) {
        rubricJsonObject.addProperty(URISTR, uri.toString());
    }
    if (category.hasChildren()) {
        List<MCRCategory> children = category.getChildren();
        Map<MCRCategoryID, Boolean> linkMap = getLinkService().hasLinks(category);
        if (linkMap.values().contains(true)) {
            rubricJsonObject.addProperty(HASLINK, true);
        }
        rubricJsonObject.add(CHILDREN, contextSerialization.serialize(new MCRCategoryListWrapper(children, linkMap)));
    }
    return rubricJsonObject;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) JsonObject(com.google.gson.JsonObject) MCRLabelSetWrapper(org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) URI(java.net.URI)

Example 18 with MCRCategoryID

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

the class MCRMODSWrapper method getMcrCategoryIDs.

public List<MCRCategoryID> getMcrCategoryIDs() {
    final List<Element> categoryNodes = getCategoryNodes();
    final List<MCRCategoryID> categories = new ArrayList<>(categoryNodes.size());
    for (Element node : categoryNodes) {
        final MCRCategoryID categoryID = MCRClassMapper.getCategoryID(node);
        if (categoryID != null) {
            categories.add(categoryID);
        }
    }
    return categories;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRMetaElement(org.mycore.datamodel.metadata.MCRMetaElement) Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 19 with MCRCategoryID

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

the class MCRMODSClassificationSupport method getMCRClassNodes.

public static NodeList getMCRClassNodes(final NodeList sources) {
    if (sources.getLength() == 0) {
        LOGGER.warn("Cannot get first element of node list 'sources'.");
        return null;
    }
    DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked();
    try {
        final Document document = documentBuilder.newDocument();
        final Element source = (Element) sources.item(0);
        MCRCategoryID category = MCRClassMapper.getCategoryID(source);
        if (category == null) {
            return null;
        }
        final Element returns = document.createElement("returns");
        returns.setAttributeNS(MCRConstants.MCR_NAMESPACE.getURI(), "mcr:categId", category.toString());
        return returns.getChildNodes();
    } catch (Throwable e) {
        LOGGER.warn("Error in Xalan Extension", e);
        return null;
    } finally {
        MCRDOMUtils.releaseDocumentBuilder(documentBuilder);
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 20 with MCRCategoryID

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

the class MCRMODSClassificationSupport method getClassNodes.

/**
 * For a category ID, looks up the authority information for that category and returns the attributes in the given
 * MODS element so that it represents that category. This is used as a Xalan extension.
 */
public static NodeList getClassNodes(final NodeList sources) {
    if (sources.getLength() == 0) {
        LOGGER.warn("Cannot get first element of node list 'sources'.");
        return null;
    }
    DocumentBuilder documentBuilder = MCRDOMUtils.getDocumentBuilderUnchecked();
    try {
        Document document = documentBuilder.newDocument();
        final Element source = (Element) sources.item(0);
        final String categId = source.getAttributeNS(MCRConstants.MCR_NAMESPACE.getURI(), "categId");
        final MCRCategoryID categoryID = MCRCategoryID.fromString(categId);
        final Element returns = document.createElementNS(source.getNamespaceURI(), source.getLocalName());
        MCRClassMapper.assignCategory(returns, categoryID);
        return returns.getChildNodes();
    } catch (Throwable e) {
        LOGGER.warn("Error in Xalan Extension", e);
        return null;
    } finally {
        MCRDOMUtils.releaseDocumentBuilder(documentBuilder);
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

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