Search in sources :

Example 71 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory 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)

Example 72 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory 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)

Example 73 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.

the class MCRClassificationEditorResource method getCategory.

private String getCategory(MCRCategoryID id) {
    if (!CATEGORY_DAO.exist(id)) {
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    MCRCategory category = CATEGORY_DAO.getCategory(id, 1);
    if (!(category instanceof MCRJSONCategory)) {
        category = new MCRJSONCategory(category);
    }
    Gson gson = MCRJSONManager.instance().createGson();
    return gson.toJson(category);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) WebApplicationException(javax.ws.rs.WebApplicationException) Gson(com.google.gson.Gson)

Example 74 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method checkMissingParent.

private static void checkMissingParent(String classID, List<String> log) {
    Session session = MCRHIBConnection.instance().getSession();
    String sqlQuery = "select cat.categid from {h-schema}MCRCategory cat WHERE cat.classid='" + classID + "' and cat.level > 0 and cat.parentID is NULL";
    @SuppressWarnings("unchecked") List<String> list = session.createNativeQuery(sqlQuery).getResultList();
    for (String categIDString : list) {
        log.add("parentID is null for category " + new MCRCategoryID(classID, categIDString));
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Session(org.hibernate.Session)

Example 75 with MCRCategory

use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method listCategory.

private static void listCategory(MCRCategory categ) {
    int level = categ.getLevel();
    StringBuilder sb = new StringBuilder(128);
    for (int i = 0; i < level * 2; i++) {
        sb.append(' ');
    }
    String space = sb.toString();
    if (categ.isCategory()) {
        LOGGER.info("{}  ID    : {}", space, categ.getId().getID());
    }
    for (MCRLabel label : categ.getLabels()) {
        LOGGER.info("{}  Label : ({}) {}", space, label.getLang(), label.getText());
    }
    List<MCRCategory> children = categ.getChildren();
    for (MCRCategory child : children) {
        listCategory(child);
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

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