use of org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper 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.MCRCategoryListWrapper in project mycore by MyCoRe-Org.
the class MCRClassificationEditorResource method getClassification.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClassification() {
Gson gson = MCRJSONManager.instance().createGson();
List<MCRCategory> rootCategories = new LinkedList<>(CATEGORY_DAO.getRootCategories());
rootCategories.removeIf(category -> !MCRAccessManager.checkPermission(category.getId().getRootID(), PERMISSION_WRITE));
if (rootCategories.isEmpty() && !MCRAccessManager.checkPermission(MCRClassificationUtils.CREATE_CLASS_PERMISSION)) {
return Response.status(Status.UNAUTHORIZED).build();
}
Map<MCRCategoryID, Boolean> linkMap = CATEG_LINK_SERVICE.hasLinks(null);
String json = gson.toJson(new MCRCategoryListWrapper(rootCategories, linkMap));
return Response.ok(json).build();
}
use of org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper in project mycore by MyCoRe-Org.
the class MCRCategoryListTypeAdapter method deserialize.
@Override
public MCRCategoryListWrapper deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
List<MCRCategory> categList = new ArrayList<>();
for (JsonElement categRef : json.getAsJsonArray()) {
JsonObject categRefJsonObject = categRef.getAsJsonObject();
MCRCategory categ = context.deserialize(categRefJsonObject, MCRJSONCategory.class);
categList.add(categ);
}
return new MCRCategoryListWrapper(categList);
}
use of org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper in project mycore by MyCoRe-Org.
the class MCRClassificationEditorResourceTest method getRootCategories.
@Test
public void getRootCategories() throws Exception {
final String categoryJsonStr = target("classifications").request().get(String.class);
MCRCategoryListWrapper categListWrapper = MCRJSONManager.instance().createGson().fromJson(categoryJsonStr, MCRCategoryListWrapper.class);
List<MCRCategory> categList = categListWrapper.getList();
assertEquals("Wrong number of root categories.", 2, categList.size());
}
Aggregations