Search in sources :

Example 66 with MCRCategory

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

the class MCRCategoryDAOImplTest method replaceMarcRelator.

@Test
public void replaceMarcRelator() throws Exception {
    MCRCategory marcrelator = loadClassificationResource("/marcrelator-test.xml");
    DAO.addCategory(null, marcrelator);
    startNewTransaction();
    marcrelator = loadClassificationResource("/marcrelator-test2.xml");
    DAO.replaceCategory(marcrelator);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Test(org.junit.Test)

Example 67 with MCRCategory

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

the class MCRCategoryDAOImplTest method getRootCategories.

@Test
public void getRootCategories() {
    addWorldClassification();
    MCRCategoryID find = category.getId();
    List<MCRCategory> classes = DAO.getRootCategories();
    assertEquals("Result size does not match.", 1, classes.size());
    assertEquals("Returned MCRCategoryID does not match.", find, classes.get(0).getId());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Test(org.junit.Test)

Example 68 with MCRCategory

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

the class MCRClassificationBrowser2 method addLabel.

/**
 * Add label in current lang, otherwise default lang, optional with
 * description
 */
private void addLabel(HttpServletRequest req, MCRCategory child, Element category) {
    MCRLabel label = child.getCurrentLabel().orElseThrow(() -> new MCRException("Category " + child.getId() + " has no labels."));
    category.addContent(new Element("label").setText(label.getText()));
    // if true, add description
    boolean descr = Boolean.valueOf(req.getParameter("adddescription"));
    if (descr && (label.getDescription() != null)) {
        category.addContent(new Element("description").setText(label.getDescription()));
    }
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 69 with MCRCategory

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

the class MCRCategoryListTypeAdapter method deserialize.

@Override
public MCRCategoryListWrapper deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    List<MCRCategory> categList = new ArrayList<>();
    for (JsonElement categRef : json.getAsJsonArray()) {
        JsonObject categRefJsonObject = categRef.getAsJsonObject();
        MCRCategory categ = context.deserialize(categRefJsonObject, MCRJSONCategory.class);
        categList.add(categ);
    }
    return new MCRCategoryListWrapper(categList);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 70 with MCRCategory

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

the class MCRCategoryListTypeAdapter method categListToJsonArray.

private JsonElement categListToJsonArray(List<MCRCategory> categList, Map<MCRCategoryID, Boolean> linkMap) {
    JsonArray categJsonArray = new JsonArray();
    for (MCRCategory categ : categList) {
        Boolean hasLink = linkMap.get(categ.getId());
        JsonElement element = createCategRefJSONObj(categ, hasLink);
        categJsonArray.add(element);
    }
    return categJsonArray;
}
Also used : JsonArray(com.google.gson.JsonArray) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) JsonElement(com.google.gson.JsonElement)

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