use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl 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.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRXMLTransformer method buildCategory.
public static MCRCategory buildCategory(String classID, Element e, MCRCategory parent) throws URISyntaxException {
MCRCategoryImpl category = new MCRCategoryImpl();
// setId must be called before setParent (info important)
category.setId(new MCRCategoryID(classID, e.getAttributeValue("ID")));
category.setRoot(parent.getRoot());
category.setChildren(new ArrayList<>());
category.setParent(parent);
try {
category.setLabels(getLabels(e.getChildren("label")));
} catch (NullPointerException | IllegalArgumentException ex) {
throw new MCRException("Error while adding labels to category: " + category.getId(), ex);
}
category.setLevel(parent.getLevel() + 1);
setURL(e, category);
buildChildCategories(classID, e.getChildren("category"), category);
return category;
}
Aggregations