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;
}
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;
}
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;
}
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);
}
Aggregations