Search in sources :

Example 86 with MCRCategoryID

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);
    });
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 87 with MCRCategoryID

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) EntityManager(javax.persistence.EntityManager) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 88 with MCRCategoryID

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));
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 89 with MCRCategoryID

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);
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 90 with MCRCategoryID

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);
    }
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate)

Aggregations

MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)82 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)42 Test (org.junit.Test)14 MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)13 Element (org.jdom2.Element)12 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)11 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 MCRCategoryDAO (org.mycore.datamodel.classifications2.MCRCategoryDAO)7 HashMap (java.util.HashMap)6 MCRException (org.mycore.common.MCRException)6 EntityManager (javax.persistence.EntityManager)5 Document (org.jdom2.Document)5 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)5 JsonElement (com.google.gson.JsonElement)4 JsonObject (com.google.gson.JsonObject)4 Collection (java.util.Collection)4 LinkedList (java.util.LinkedList)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)4 MCRJSONCategory (org.mycore.frontend.classeditor.json.MCRJSONCategory)4