use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method checkLeftRightAndLevel.
private static int checkLeftRightAndLevel(MCRCategoryImpl category, int leftStart, int levelStart, List<String> log) {
int curValue = leftStart;
final int nextLevel = levelStart + 1;
if (leftStart != category.getLeft())
log.add("LEFT of " + category.getId() + " is " + category.getLeft() + " should be " + leftStart);
if (levelStart != category.getLevel())
log.add("LEVEL of " + category.getId() + " is " + category.getLevel() + " should be " + levelStart);
int position = 0;
for (MCRCategory child : category.getChildren()) {
if (child == null) {
log.add("NULL child of parent " + category.getId() + " on position " + position);
continue;
}
LOGGER.debug(child.getId());
curValue = checkLeftRightAndLevel((MCRCategoryImpl) child, ++curValue, nextLevel, log);
position++;
}
++curValue;
if (curValue != category.getRight())
log.add("RIGHT of " + category.getId() + " is " + category.getRight() + " should be " + curValue);
return curValue;
}
use of org.mycore.datamodel.classifications2.MCRCategory 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.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class CategoryDAOMock method deleteCategory.
@Override
public void deleteCategory(MCRCategoryID id) {
MCRCategory mcrCategory = categMap.get(id);
for (MCRCategory child : mcrCategory.getChildren()) {
categMap.remove(child.getId());
}
categMap.remove(id);
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class CategoryLinkServiceMock method hasLinks.
@Override
public Map<MCRCategoryID, Boolean> hasLinks(MCRCategory category) {
List<MCRCategory> categories;
if (category == null) {
categories = MCRCategoryDAOFactory.getInstance().getRootCategories();
} else {
categories = category.getChildren();
}
Map<MCRCategoryID, Boolean> linkMap = new HashMap<>();
int i = 0;
for (MCRCategory mcrCategory : categories) {
boolean haslink = false;
if (i++ % 2 == 0) {
haslink = true;
}
linkMap.put(mcrCategory.getId(), haslink);
}
return linkMap;
}
use of org.mycore.datamodel.classifications2.MCRCategory 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()));
}
}
Aggregations