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