Search in sources :

Example 1 with MCRLabel

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

the class MCRStringTransformer method printLabels.

private static void printLabels(Collection<MCRLabel> labels, StringBuilder sb) {
    for (MCRLabel label : labels) {
        sb.append(label);
        sb.append(',');
    }
    if (labels.size() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
}
Also used : MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 2 with MCRLabel

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

the class MCRAbstractCategoryImplTest method getCurrentLabel.

@Test
public void getCurrentLabel() {
    MCRCategory cat = new MCRSimpleAbstractCategoryImpl();
    MCRLabel label1 = new MCRLabel("de", "german", null);
    MCRLabel label2 = new MCRLabel("fr", "french", null);
    MCRLabel label3 = new MCRLabel("at", "austrian", null);
    cat.getLabels().add(label1);
    cat.getLabels().add(label2);
    cat.getLabels().add(label3);
    MCRSession session = MCRSessionMgr.getCurrentSession();
    session.setCurrentLanguage("en");
    assertEquals("German label expected", label3, cat.getCurrentLabel().get());
    cat.getLabels().clear();
    cat.getLabels().add(label2);
    cat.getLabels().add(label3);
    cat.getLabels().add(label1);
    assertEquals("German label expected", label3, cat.getCurrentLabel().get());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRSession(org.mycore.common.MCRSession) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 3 with MCRLabel

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

the class MCRCategoryDAOImplTest method setLabel.

@Test
public void setLabel() {
    addWorldClassification();
    startNewTransaction();
    // test add
    int count = category.getLabels().size();
    final String lang = "ju";
    final String text = "JUnit-Test";
    DAO.setLabel(category.getId(), new MCRLabel(lang, text, "Added by JUnit"));
    startNewTransaction();
    MCRCategory rootNode = getRootCategoryFromSession();
    assertEquals("Label count does not match.", count + 1, rootNode.getLabels().size());
    // test modify
    String description = "Modified by JUnit";
    DAO.setLabel(category.getId(), new MCRLabel(lang, text, description));
    startNewTransaction();
    rootNode = getRootCategoryFromSession();
    assertEquals("Label count does not match.", count + 1, rootNode.getLabels().size());
    assertEquals("Label does not match.", description, rootNode.getLabel(lang).get().getDescription());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Test(org.junit.Test)

Example 4 with MCRLabel

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

the class MCRCategoryDAOImplTest method setLabels.

@Test
public void setLabels() {
    addWorldClassification();
    startNewTransaction();
    MCRCategory germany = DAO.getCategory(MCRCategoryID.fromString("World:Germany"), 0);
    MCRCategory france = DAO.getCategory(MCRCategoryID.fromString("World:France"), 0);
    Set<MCRLabel> labels1 = new HashSet<>();
    labels1.add(new MCRLabel("de", "deutschland", null));
    DAO.setLabels(germany.getId(), labels1);
    startNewTransaction();
    Set<MCRLabel> labels2 = new HashSet<>();
    labels2.add(new MCRLabel("de", "frankreich", null));
    DAO.setLabels(france.getId(), labels2);
    startNewTransaction();
    germany = DAO.getCategory(MCRCategoryID.fromString("World:Germany"), 0);
    france = DAO.getCategory(MCRCategoryID.fromString("World:France"), 0);
    assertEquals(1, germany.getLabels().size());
    assertEquals(1, france.getLabels().size());
    assertEquals("deutschland", germany.getLabel("de").get().getText());
    assertEquals("frankreich", france.getLabel("de").get().getText());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with MCRLabel

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

the class MCRCategoryListTypeAdapter method createCategRefJSONObj.

private JsonElement createCategRefJSONObj(MCRCategory categ, Boolean hasLink) {
    JsonObject categRefJsonObject = new JsonObject();
    categRefJsonObject.add(ID, serializationContext.serialize(categ.getId()));
    Set<MCRLabel> labels = categ.getLabels();
    categRefJsonObject.add(LABELS, serializationContext.serialize(new MCRLabelSetWrapper(labels)));
    URI uri = categ.getURI();
    if (uri != null) {
        categRefJsonObject.addProperty(URISTR, uri.toString());
    }
    categRefJsonObject.addProperty(HASCHILDREN, categ.hasChildren());
    categRefJsonObject.addProperty(HASLINK, hasLink);
    return categRefJsonObject;
}
Also used : JsonObject(com.google.gson.JsonObject) MCRLabelSetWrapper(org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) URI(java.net.URI)

Aggregations

MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)30 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)14 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)8 Test (org.junit.Test)6 JsonObject (com.google.gson.JsonObject)4 Element (org.jdom2.Element)4 MCRException (org.mycore.common.MCRException)3 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonArray (com.google.gson.JsonArray)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1