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