Search in sources :

Example 46 with MCRCategoryID

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

the class MCRRoleServlet method getRoleElements.

private Collection<Element> getRoleElements() {
    ArrayList<Element> list = new ArrayList<>(roleCategories.size());
    for (MCRCategoryID categID : roleCategories) {
        Element role = new Element("role");
        role.setAttribute("categID", categID.toString());
        MCRCategory category = categoryDao.getCategory(categID, 0);
        if (category == null) {
            continue;
        }
        role.setAttribute("label", category.getCurrentLabel().map(MCRLabel::getText).orElse(categID.getID()));
        list.add(role);
    }
    return list;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 47 with MCRCategoryID

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

the class MCRUserManager method setRoles.

private static MCRUser setRoles(MCRUser mcrUser) {
    Collection<MCRCategoryID> roleIDs = MCRRoleManager.getRoleIDs(mcrUser);
    mcrUser.getSystemRoleIDs().clear();
    mcrUser.getExternalRoleIDs().clear();
    for (MCRCategoryID roleID : roleIDs) {
        if (roleID.getRootID().equals(MCRUser2Constants.ROLE_CLASSID.getRootID())) {
            mcrUser.getSystemRoleIDs().add(roleID.getID());
        } else {
            mcrUser.getExternalRoleIDs().add(roleID.toString());
        }
    }
    return mcrUser;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 48 with MCRCategoryID

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

the class MCRRoleManager method deleteRole.

/**
 * Deletes a role from the system.
 * If the role is currently not stored in the classification system this method does nothing.
 * This method will fail if any objects (e.g. users) are linked to it.
 */
public static void deleteRole(String roleID) {
    MCRRole role = MCRRoleManager.getRole(roleID);
    if (role == null) {
        // unknown role
        return;
    }
    MCRCategoryID categoryID = null;
    if (role.isSystemRole()) {
        categoryID = new MCRCategoryID(MCRUser2Constants.ROLE_CLASSID.getRootID(), role.getName());
    } else {
        categoryID = MCRCategoryID.fromString(role.getName());
    }
    DAO.deleteCategory(categoryID);
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID)

Example 49 with MCRCategoryID

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

the class MCRCategLinkServiceImplTest method getAllCategIDs.

private static Collection<MCRCategoryID> getAllCategIDs(MCRCategory category) {
    HashSet<MCRCategoryID> ids = new HashSet<>();
    ids.add(category.getId());
    for (MCRCategory cat : category.getChildren()) {
        ids.addAll(getAllCategIDs(cat));
    }
    return ids;
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) HashSet(java.util.HashSet)

Example 50 with MCRCategoryID

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

the class MCRCategoryDAOImplTest method newCategory.

private MCRCategoryImpl newCategory(MCRCategoryID id, String description) {
    MCRCategoryImpl newCateg = new MCRCategoryImpl();
    newCateg.setId(id);
    Set<MCRLabel> labels = new HashSet<>();
    labels.add(new MCRLabel("en", id.toString(), description));
    newCateg.setLabels(labels);
    return newCateg;
}
Also used : 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