Search in sources :

Example 36 with MCRCategory

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;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)

Example 37 with MCRCategory

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();
}
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 38 with MCRCategory

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);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory)

Example 39 with MCRCategory

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;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) HashMap(java.util.HashMap)

Example 40 with MCRCategory

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

Aggregations

MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)87 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)36 Test (org.junit.Test)24 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)17 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)10 ArrayList (java.util.ArrayList)9 Document (org.jdom2.Document)9 Element (org.jdom2.Element)8 MCRException (org.mycore.common.MCRException)8 IOException (java.io.IOException)6 EntityManager (javax.persistence.EntityManager)6 URI (java.net.URI)5 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4