use of org.mycore.datamodel.classifications2.MCRCategoryID 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.MCRCategoryID 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());
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRServiceFlagEventHandler method updateDerivateState.
protected static void updateDerivateState(MCRObject obj) {
MCRCategoryID state = obj.getService().getState();
obj.getStructure().getDerivates().stream().map(MCRMetaLinkID::getXLinkHrefID).forEach(id -> updateDerivateState(id, state));
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRServiceFlagEventHandler method setDefaultState.
protected static void setDefaultState(MCRObjectService objService) {
if (objService.getState() == null) {
MCRCategoryID defaultState = new MCRCategoryID(MCRConfiguration.instance().getString("MCR.Metadata.Service.State.Classification.ID"), MCRConfiguration.instance().getString("MCR.Metadata.Service.State.Category.Default"));
objService.setState(defaultState);
}
}
use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.
the class MCRServiceFlagEventHandler method updateDerivateState.
protected static void updateDerivateState(MCRObjectID derID, MCRCategoryID state) {
MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derID);
MCRCategoryID oldState = derivate.getService().getState();
if (!state.equals(oldState)) {
derivate.getService().setState(state);
MCRMetadataManager.updateMCRDerivateXML(derivate);
}
}
Aggregations