Search in sources :

Example 41 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryDAOImpl method buildCategoryFromPrefetchedList.

private static MCRCategoryImpl buildCategoryFromPrefetchedList(List<MCRCategoryDTO> list, MCRCategoryID returnID) {
    LOGGER.debug(() -> "using prefetched list: " + list);
    MCRCategoryImpl predecessor = null;
    for (MCRCategoryDTO entry : list) {
        predecessor = entry.merge(predecessor);
    }
    return MCRStreamUtils.flatten(predecessor.getRoot(), MCRCategory::getChildren, Collection::parallelStream).filter(c -> c.getId().equals(returnID)).findFirst().map(MCRCategoryImpl.class::cast).orElseThrow(() -> new MCRException("Could not find " + returnID + " in database result."));
}
Also used : NoResultException(javax.persistence.NoResultException) HashMap(java.util.HashMap) FlushModeType(javax.persistence.FlushModeType) Function(java.util.function.Function) TypedQuery(javax.persistence.TypedQuery) MCRException(org.mycore.common.MCRException) ArrayList(java.util.ArrayList) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) URI(java.net.URI) Collector(java.util.stream.Collector) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Collection(java.util.Collection) MCRPersistenceException(org.mycore.common.MCRPersistenceException) Set(java.util.Set) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) AbstractMap(java.util.AbstractMap) List(java.util.List) Query(javax.persistence.Query) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) MCRStreamUtils(org.mycore.common.MCRStreamUtils) LogManager(org.apache.logging.log4j.LogManager) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRException(org.mycore.common.MCRException) Collection(java.util.Collection)

Example 42 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryImpl method getPositionInParentByID.

@Transient
private int getPositionInParentByID() {
    int position = 0;
    for (MCRCategory sibling : parent.getChildren()) {
        if (getId().equals(sibling.getId())) {
            return position;
        }
        position++;
    }
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("List of children of parent: ");
        sb.append(parent.getId()).append('\n');
        for (MCRCategory sibling : parent.getChildren()) {
            sb.append(sibling.getId()).append('\n');
        }
        LOGGER.debug(sb.toString());
    }
    throw new IndexOutOfBoundsException("Position -1 is not valid: " + getId() + " parent:" + parent.getId() + " children: " + parent.getChildren().stream().map(MCRCategory::getId).map(MCRCategoryID::getID).collect(Collectors.joining(", ")));
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) UniqueConstraint(javax.persistence.UniqueConstraint) Transient(javax.persistence.Transient)

Example 43 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRCategoryMapperBase method map.

public Set<MCRCategoryID> map(Collection<MCRCategoryID> input) {
    SortedSet<MCRCategoryID> output = new TreeSet<>();
    for (MCRCategoryID categoryID : input) {
        Set<MCRCategoryID> mapped = collectMappings(categoryID);
        output.addAll(mapped);
    }
    return output;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) TreeSet(java.util.TreeSet)

Example 44 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRRoleManager method storeRoleAssignments.

/**
 * Stores role membership information of the user
 *
 * @param user the user
 */
static void storeRoleAssignments(MCRUser user) {
    MCRCategLinkReference ref = getLinkID(user);
    LinkedList<MCRCategoryID> categories = new LinkedList<>();
    for (String roleID : user.getSystemRoleIDs()) {
        MCRCategoryID categID = new MCRCategoryID(MCRUser2Constants.ROLE_CLASSID.getRootID(), roleID);
        categories.add(categID);
    }
    for (String roleID : user.getExternalRoleIDs()) {
        MCRCategoryID categID = MCRCategoryID.fromString(roleID);
        categories.add(categID);
    }
    LOGGER.info("Assigning {} to these roles: {}", user.getUserID(), categories);
    CATEG_LINK_SERVICE.setLinks(ref, categories);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategLinkReference(org.mycore.datamodel.classifications2.MCRCategLinkReference) LinkedList(java.util.LinkedList)

Example 45 with MCRCategoryID

use of org.mycore.datamodel.classifications2.MCRCategoryID in project mycore by MyCoRe-Org.

the class MCRRoleManager method addRole.

/**
 * Adds <code>role</code> to the classification system.
 * If the representing {@link MCRCategory} already exists this method does nothing.
 * It will create any category if necessary.
 */
public static void addRole(MCRRole role) {
    MCRCategoryID categoryID = null;
    if (role.isSystemRole()) {
        categoryID = new MCRCategoryID(MCRUser2Constants.ROLE_CLASSID.getRootID(), role.getName());
    } else {
        categoryID = MCRCategoryID.fromString(role.getName());
    }
    if (DAO.exist(categoryID)) {
        return;
    }
    MCRCategoryID rootID = MCRCategoryID.rootID(categoryID.getRootID());
    if (!DAO.exist(rootID)) {
        MCRCategoryImpl category = new MCRCategoryImpl();
        category.setId(rootID);
        HashSet<MCRLabel> labels = new HashSet<>();
        labels.add(new MCRLabel("de", "Systemrollen", null));
        labels.add(new MCRLabel("en", "system roles", null));
        category.setLabels(labels);
        DAO.addCategory(null, category);
    }
    MCRCategoryImpl category = new MCRCategoryImpl();
    category.setId(categoryID);
    category.getLabels().addAll(role.getLabels());
    DAO.addCategory(rootID, category);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) HashSet(java.util.HashSet)

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