Search in sources :

Example 1 with MCRLabelSetWrapper

use of org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper in project mycore by MyCoRe-Org.

the class MCRCategoryListTypeAdapter method createCategRefJSONObj.

private JsonElement createCategRefJSONObj(MCRCategory categ, Boolean hasLink) {
    JsonObject categRefJsonObject = new JsonObject();
    categRefJsonObject.add(ID, serializationContext.serialize(categ.getId()));
    Set<MCRLabel> labels = categ.getLabels();
    categRefJsonObject.add(LABELS, serializationContext.serialize(new MCRLabelSetWrapper(labels)));
    URI uri = categ.getURI();
    if (uri != null) {
        categRefJsonObject.addProperty(URISTR, uri.toString());
    }
    categRefJsonObject.addProperty(HASCHILDREN, categ.hasChildren());
    categRefJsonObject.addProperty(HASLINK, hasLink);
    return categRefJsonObject;
}
Also used : JsonObject(com.google.gson.JsonObject) MCRLabelSetWrapper(org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) URI(java.net.URI)

Example 2 with MCRLabelSetWrapper

use of org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper 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 3 with MCRLabelSetWrapper

use of org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper 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 4 with MCRLabelSetWrapper

use of org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper in project mycore by MyCoRe-Org.

the class MCRLabelSetTypeAdapter method deserialize.

@Override
public MCRLabelSetWrapper deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    Set<MCRLabel> labels = new HashSet<>();
    for (JsonElement jsonElement : json.getAsJsonArray()) {
        JsonObject labelJsonObject = jsonElement.getAsJsonObject();
        MCRLabel label = jsonLabelToMCRLabel(labelJsonObject);
        if (label != null) {
            labels.add(label);
        } else {
            LOGGER.warn("Unable to add label with empty lang or text: {}", labelJsonObject);
        }
    }
    return new MCRLabelSetWrapper(labels);
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) MCRLabelSetWrapper(org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

Aggregations

JsonObject (com.google.gson.JsonObject)4 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)4 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)2 HashSet (java.util.HashSet)1 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)1 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)1 MCRCategoryListWrapper (org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper)1