Search in sources :

Example 1 with MCRCategoryListWrapper

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;
}
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 2 with MCRCategoryListWrapper

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();
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with MCRCategoryListWrapper

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);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 4 with MCRCategoryListWrapper

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());
}
Also used : MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRJerseyTest(org.mycore.frontend.jersey.resources.MCRJerseyTest) Test(org.junit.Test)

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)4 MCRCategoryListWrapper (org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper)4 JsonObject (com.google.gson.JsonObject)2 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Test (org.junit.Test)1 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)1 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)1 MCRJerseyTest (org.mycore.frontend.jersey.resources.MCRJerseyTest)1