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;
}
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);
}
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;
}
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;
}
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());
}
Aggregations