Search in sources :

Example 11 with MCRLabel

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

the class MCRCategoryDTO method appendLabel.

private MCRCategoryImpl appendLabel(MCRCategoryImpl cat) {
    if (lang != null) {
        MCRLabel label = new MCRLabel(lang, text, Optional.ofNullable(description).filter(s -> !s.isEmpty()).orElse(null));
        cat.getLabels().add(label);
    }
    return cat;
}
Also used : MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 12 with MCRLabel

use of org.mycore.datamodel.classifications2.MCRLabel 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)

Example 13 with MCRLabel

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

the class MCRRoleResolver method getAssignableGroupsForUser.

public static Element getAssignableGroupsForUser() throws MCRAccessException {
    LOGGER.warn("Please fix http://sourceforge.net/p/mycore/bugs/568/");
    List<MCRRole> groupIDs = null;
    // current user.
    if (MCRAccessManager.checkPermission(MCRUser2Constants.USER_ADMIN_PERMISSION)) {
        groupIDs = MCRRoleManager.listSystemRoles();
    } else if (MCRAccessManager.checkPermission(MCRUser2Constants.USER_CREATE_PERMISSION)) {
        final MCRUser currentUser = MCRUserManager.getCurrentUser();
        groupIDs = new ArrayList<>(currentUser.getSystemRoleIDs().size());
        for (final String id : currentUser.getSystemRoleIDs()) {
            groupIDs.add(MCRRoleManager.getRole(id));
        }
    } else {
        throw MCRAccessException.missingPrivilege("List asignable groups for new user.", MCRUser2Constants.USER_ADMIN_PERMISSION, MCRUser2Constants.USER_CREATE_PERMISSION);
    }
    // Loop over all assignable groups
    final Element root = new Element("items");
    for (final MCRRole group : groupIDs) {
        String label = group.getName();
        MCRLabel groupLabel = group.getLabel();
        if (groupLabel != null && groupLabel.getText() != null) {
            label = groupLabel.getText();
        }
        final Element item = new Element("item").setAttribute("value", group.getName()).setAttribute("label", label);
        root.addContent(item);
    }
    return root;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Example 14 with MCRLabel

use of org.mycore.datamodel.classifications2.MCRLabel 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 15 with MCRLabel

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

the class MCRUserCommands method listRole.

public static void listRole(MCRRole role) {
    StringBuilder sb = new StringBuilder();
    sb.append("       role=").append(role.getName());
    for (MCRLabel label : role.getLabels()) {
        sb.append("\n         ").append(label);
    }
    Collection<String> userIds = MCRRoleManager.listUserIDs(role);
    for (String userId : userIds) {
        sb.append("\n          user assigned to role=").append(userId);
    }
    LOGGER.info(sb.toString());
}
Also used : MCRLabel(org.mycore.datamodel.classifications2.MCRLabel)

Aggregations

MCRLabel (org.mycore.datamodel.classifications2.MCRLabel)30 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)14 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)11 HashSet (java.util.HashSet)8 Test (org.junit.Test)6 JsonObject (com.google.gson.JsonObject)4 Element (org.jdom2.Element)4 MCRException (org.mycore.common.MCRException)3 MCRLabelSetWrapper (org.mycore.frontend.classeditor.wrapper.MCRLabelSetWrapper)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MCRCategoryImpl (org.mycore.datamodel.classifications2.impl.MCRCategoryImpl)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonArray (com.google.gson.JsonArray)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1