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