use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl 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;
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImpl method setLinks.
@Override
public void setLinks(MCRCategLinkReference objectReference, Collection<MCRCategoryID> categories) {
EntityManager entityManager = MCREntityManagerProvider.getCurrentEntityManager();
categories.stream().distinct().forEach(categID -> {
final MCRCategory category = getMCRCategory(entityManager, categID);
if (category == null) {
throw new MCRPersistenceException("Could not link to unknown category " + categID);
}
MCRCategoryLinkImpl link = new MCRCategoryLinkImpl(category, objectReference);
if (LOGGER.isDebugEnabled()) {
MCRCategory linkedCategory = link.getCategory();
StringBuilder debugMessage = new StringBuilder("Adding Link from ").append(linkedCategory.getId());
if (linkedCategory instanceof MCRCategoryImpl) {
debugMessage.append("(").append(((MCRCategoryImpl) linkedCategory).getInternalID()).append(") ");
}
debugMessage.append("to ").append(objectReference);
LOGGER.debug(debugMessage.toString());
}
entityManager.persist(link);
LOGGER.debug("===DONE: {}", link.id);
});
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategLinkServiceImpl method hasLinks.
@Override
public Map<MCRCategoryID, Boolean> hasLinks(MCRCategory category) {
if (category == null) {
return hasLinksForClassifications();
}
MCRCategoryImpl rootImpl = (MCRCategoryImpl) MCRCategoryDAOFactory.getInstance().getCategory(category.getRoot().getId(), -1);
if (rootImpl == null) {
// Category does not exist, so it has no links
return getNoLinksMap(category);
}
HashMap<MCRCategoryID, Boolean> boolMap = new HashMap<>();
final BitSet linkedInternalIds = getLinkedInternalIds();
storeHasLinkValues(boolMap, linkedInternalIds, rootImpl);
return boolMap;
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImpl method repairLeftRightValue.
public void repairLeftRightValue(String classID) {
final MCRCategoryID rootID = MCRCategoryID.rootID(classID);
withoutFlush(MCREntityManagerProvider.getCurrentEntityManager(), true, entityManager -> {
MCRCategoryImpl classification = MCRCategoryDAOImpl.getByNaturalID(entityManager, rootID);
classification.calculateLeftRightAndLevel(Integer.MAX_VALUE / 2, LEVEL_START_VALUE);
entityManager.flush();
classification.calculateLeftRightAndLevel(LEFT_START_VALUE, LEVEL_START_VALUE);
});
}
use of org.mycore.datamodel.classifications2.impl.MCRCategoryImpl in project mycore by MyCoRe-Org.
the class MCRCategoryDAOImpl method deleteCategory.
@Override
public void deleteCategory(MCRCategoryID id) {
EntityManager entityManager = MCREntityManagerProvider.getCurrentEntityManager();
LOGGER.debug("Will get: {}", id);
MCRCategoryImpl category = getByNaturalID(entityManager, id);
if (category == null) {
throw new MCRPersistenceException("Category " + id + " was not found. Delete aborted.");
}
LOGGER.debug("Will delete: {}", category.getId());
MCRCategory parent = category.parent;
category.detachFromParent();
entityManager.remove(category);
if (parent != null) {
entityManager.flush();
LOGGER.debug("Left: {} Right: {}", category.getLeft(), category.getRight());
// always add +1 for the currentNode
int nodes = 1 + (category.getRight() - category.getLeft()) / 2;
final int increment = nodes * -2;
// decrement left and right values by nodes
updateLeftRightValue(entityManager, category.getRootID(), category.getLeft(), increment);
}
updateTimeStamp();
updateLastModified(category.getRootID());
}
Aggregations