Search in sources :

Example 1 with MCRJSONCategory

use of org.mycore.frontend.classeditor.json.MCRJSONCategory 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 2 with MCRJSONCategory

use of org.mycore.frontend.classeditor.json.MCRJSONCategory in project mycore by MyCoRe-Org.

the class MCRClassificationEditorResource method save.

@POST
@Path("save")
@MCRRestrictedAccess(MCRClassificationWritePermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response save(String json) {
    JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
    if (jsonStreamParser.hasNext()) {
        JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
        List<JsonObject> saveList = new ArrayList<>();
        for (JsonElement jsonElement : saveObjArray) {
            saveList.add(jsonElement.getAsJsonObject());
        }
        saveList.sort(new IndexComperator());
        for (JsonObject jsonObject : saveList) {
            String status = getStatus(jsonObject);
            SaveElement categ = getCateg(jsonObject);
            MCRJSONCategory parsedCateg = parseJson(categ.getJson());
            if ("update".equals(status)) {
                new UpdateOp(parsedCateg, jsonObject).run();
            } else if ("delete".equals(status)) {
                deleteCateg(categ.getJson());
            } else {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
        // Status.CONFLICT
        return Response.status(Status.OK).build();
    } else {
        return Response.status(Status.BAD_REQUEST).build();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonStreamParser(com.google.gson.JsonStreamParser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)

Example 3 with MCRJSONCategory

use of org.mycore.frontend.classeditor.json.MCRJSONCategory in project mycore by MyCoRe-Org.

the class MCRClassificationEditorResource method deleteCateg.

@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteCateg(String json) {
    MCRJSONCategory category = parseJson(json);
    DeleteOp deleteOp = new DeleteOp(category);
    deleteOp.run();
    return deleteOp.getResponse();
}
Also used : MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) DELETE(javax.ws.rs.DELETE) PERMISSION_DELETE(org.mycore.access.MCRAccessManager.PERMISSION_DELETE) Consumes(javax.ws.rs.Consumes)

Example 4 with MCRJSONCategory

use of org.mycore.frontend.classeditor.json.MCRJSONCategory in project mycore by MyCoRe-Org.

the class MCRClassificationEditorResourceTest method getSingleCategory.

@Test
public void getSingleCategory() throws Exception {
    Collection<MCRCategory> categs = categDAO.getCategs();
    for (MCRCategory mcrCategory : categs) {
        MCRCategoryID id = mcrCategory.getId();
        String path = id.getRootID();
        String categID = id.getID();
        if (categID != null && !"".equals(categID)) {
            path = path + "/" + categID;
        }
        String categoryJsonStr = target("/classifications/" + path).request().get(String.class);
        MCRJSONCategory retrievedCateg = MCRJSONManager.instance().createGson().fromJson(categoryJsonStr, MCRJSONCategory.class);
        String errorMsg = MessageFormat.format("We want to retrieve the category {0} but it was {1}", id, retrievedCateg.getId());
        assertTrue(errorMsg, id.equals(retrievedCateg.getId()));
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRJerseyTest(org.mycore.frontend.jersey.resources.MCRJerseyTest) Test(org.junit.Test)

Example 5 with MCRJSONCategory

use of org.mycore.frontend.classeditor.json.MCRJSONCategory in project mycore by MyCoRe-Org.

the class CategoryDAOMock method buildTestCategs.

private void buildTestCategs() {
    MCRJSONCategory root_01 = createCategory("rootID_01", "", null);
    MCRJSONCategory root_02 = createCategory("rootID_02", "", null);
    MCRJSONCategory categ_01 = createCategory("rootID_01", "categ_01", null);
    MCRJSONCategory categ_02 = createCategory("rootID_01", "categ_02", null);
    List<MCRCategory> children = new ArrayList<>();
    children.add(categ_01);
    children.add(categ_02);
    root_01.setChildren(children);
    rootCategMap.put(root_01.getId(), root_01);
    rootCategMap.put(root_02.getId(), root_02);
    categMap.put(root_01.getId(), root_01);
    categMap.put(root_02.getId(), root_02);
    categMap.put(categ_01.getId(), categ_01);
    categMap.put(categ_02.getId(), categ_02);
}
Also used : MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) ArrayList(java.util.ArrayList)

Aggregations

MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)8 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)3 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonStreamParser (com.google.gson.JsonStreamParser)1 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.Test)1 PERMISSION_DELETE (org.mycore.access.MCRAccessManager.PERMISSION_DELETE)1 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)1 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)1 MCRRestrictedAccess (org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess)1