use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class CategoryDAOMock method createCategory.
private MCRJSONCategory createCategory(String rootID, String categID, MCRCategoryID parentID) {
MCRCategoryID id = new MCRCategoryID(rootID, categID);
Set<MCRLabel> labels = new HashSet<>();
labels.add(new MCRLabel("de", id + "_text", id + "_descr"));
labels.add(new MCRLabel("en", id + "_text", id + "_descr"));
MCRJSONCategory newCategory = new MCRJSONCategory();
newCategory.setId(id);
newCategory.setLabels(labels);
newCategory.setParentID(parentID);
return newCategory;
}
use of org.mycore.datamodel.classifications2.MCRLabel 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);
}
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRXMLFunctions method getDisplayName.
/**
* @param classificationId
* @param categoryId
* @return
*/
public static String getDisplayName(String classificationId, String categoryId) {
try {
MCRCategoryID categID = new MCRCategoryID(classificationId, categoryId);
MCRCategoryDAO dao = MCRCategoryDAOFactory.getInstance();
MCRCategory category = dao.getCategory(categID, 0);
return Optional.ofNullable(category).map(MCRCategory::getCurrentLabel).filter(Optional::isPresent).map(Optional::get).map(MCRLabel::getText).orElse("");
} catch (Throwable e) {
LOGGER.error("Could not determine display name for classification id {} and category id {}", classificationId, categoryId, e);
return "";
}
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImpl method syncLabels.
private static void syncLabels(MCRCategoryImpl source, MCRCategoryImpl target) {
for (MCRLabel newLabel : source.getLabels()) {
Optional<MCRLabel> label = target.getLabel(newLabel.getLang());
if (!label.isPresent()) {
// copy new label
target.getLabels().add(newLabel);
}
label.ifPresent(oldLabel -> {
if (!oldLabel.getText().equals(newLabel.getText())) {
oldLabel.setText(newLabel.getText());
}
if (!oldLabel.getDescription().equals(newLabel.getDescription())) {
oldLabel.setDescription(newLabel.getDescription());
}
});
}
// remove labels that are not present in new version
target.getLabels().removeIf(mcrLabel -> !source.getLabel(mcrLabel.getLang()).isPresent());
}
use of org.mycore.datamodel.classifications2.MCRLabel in project mycore by MyCoRe-Org.
the class MCRXMLTransformer method getLabels.
public static Set<MCRLabel> getLabels(List<Element> elements) throws NullPointerException, IllegalArgumentException {
Set<MCRLabel> labels = new HashSet<>(elements.size(), 1L);
for (Element labelElement : elements) {
MCRLabel label = getLabel(labelElement);
labels.add(label);
}
return labels;
}
Aggregations