use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImplTest method addCategory.
@Test
public void addCategory() throws MCRException {
addWorldClassification();
assertTrue("Exist check failed for Category " + category.getId(), DAO.exist(category.getId()));
MCRCategoryImpl india = new MCRCategoryImpl();
india.setId(new MCRCategoryID(category.getId().getRootID(), "India"));
india.setLabels(new HashSet<>());
india.getLabels().add(new MCRLabel("de", "Indien", null));
india.getLabels().add(new MCRLabel("en", "India", null));
DAO.addCategory(new MCRCategoryID(category.getId().getRootID(), "Asia"), india);
startNewTransaction();
assertTrue("Exist check failed for Category " + india.getId(), DAO.exist(india.getId()));
MCRCategoryImpl rootCategory = getRootCategoryFromSession();
assertEquals("Child category count does not match.", category.getChildren().size(), rootCategory.getChildren().size());
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Number> countQuery = cb.createQuery(Number.class);
long allNodes = em.createQuery(countQuery.select(cb.count(countQuery.from(MCRCategoryImpl.class)))).getSingleResult().longValue();
// category + india
assertEquals("Complete category count does not match.", countNodes(category) + 1, allNodes);
assertTrue("No root category present", rootCategory.getRoot() != null);
}
use of org.mycore.datamodel.classifications2.MCRLabel 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()));
}
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRLabelSetTypeAdapter method jsonLabelToMCRLabel.
private MCRLabel jsonLabelToMCRLabel(JsonObject labelJsonObject) {
String lang = labelJsonObject.get(LANG).getAsString();
String text = labelJsonObject.get(TEXT).getAsString();
JsonElement jsonElement = labelJsonObject.get(DESCRIPTION);
String description = null;
if (jsonElement != null) {
description = jsonElement.getAsString();
}
if (lang == null || lang.trim().equals("") || text == null || text.trim().equals("")) {
return null;
}
return new MCRLabel(lang, text, description);
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRLabelSetTypeAdapter method deserialize.
@Override
public MCRLabelSetWrapper deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Set<MCRLabel> labels = new HashSet<>();
for (JsonElement jsonElement : json.getAsJsonArray()) {
JsonObject labelJsonObject = jsonElement.getAsJsonObject();
MCRLabel label = jsonLabelToMCRLabel(labelJsonObject);
if (label != null) {
labels.add(label);
} else {
LOGGER.warn("Unable to add label with empty lang or text: {}", labelJsonObject);
}
}
return new MCRLabelSetWrapper(labels);
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class GsonSerializationTest method createCateg.
protected MCRCategoryImpl createCateg(String rootID, String id2, String text) {
MCRCategoryImpl mcrCategoryImpl = new MCRCategoryImpl();
MCRCategoryID id = new MCRCategoryID(rootID, id2);
mcrCategoryImpl.setId(id);
Set<MCRLabel> labels = new HashSet<>();
labels.add(new MCRLabel("de", text + "_de", "desc_" + text + "_de"));
labels.add(new MCRLabel("en", text + "_en", "desc_" + text + "_en"));
mcrCategoryImpl.setLabels(labels);
return mcrCategoryImpl;
}
Aggregations