use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRCategoryImpl method calculateLeftRightAndLevel.
/**
* calculates left and right value throug the subtree rooted at
* <code>co</code>.
*
* @param leftStart
* this.left will be set to this value
* @param levelStart
* this.getLevel() will return this value
* @return this.right
*/
public int calculateLeftRightAndLevel(int leftStart, int levelStart) {
int curValue = leftStart;
final int nextLevel = levelStart + 1;
setLeft(leftStart);
setLevel(levelStart);
for (MCRCategory child : getChildren()) {
LOGGER.debug(child.getId());
curValue = ((MCRCategoryImpl) child).calculateLeftRightAndLevel(++curValue, nextLevel);
}
setRight(++curValue);
return curValue;
}
use of org.mycore.datamodel.classifications2.MCRCategory 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.MCRCategory in project mycore by MyCoRe-Org.
the class MCRClassificationUtils method fromStream.
/**
* Imports a classification from the given input stream. If the classification
* already exists, it will be replaced.
*
* @param inputStream the classification stream
* @throws MCRException xml parsing went wrong
* @throws SAXParseException xml parsing went wrong
* @throws URISyntaxException unable to transform the xml to a {@link MCRCategory}
* @throws MCRAccessException you are not allowed to import the classification
*/
public static void fromStream(InputStream inputStream) throws MCRException, SAXParseException, URISyntaxException, MCRAccessException {
MCRCategoryDAO DAO = MCRCategoryDAOFactory.getInstance();
Document jdom = MCRXMLParserFactory.getParser().parseXML(new MCRStreamContent(inputStream));
MCRCategory classification = MCRXMLTransformer.getCategory(jdom);
if (DAO.exist(classification.getId())) {
if (!MCRAccessManager.checkPermission(classification.getId().getRootID(), PERMISSION_WRITE)) {
throw MCRAccessException.missingPermission("update classification " + classification.getId().getRootID(), classification.getId().getRootID(), PERMISSION_WRITE);
}
DAO.replaceCategory(classification);
} else {
if (!MCRAccessManager.checkPermission(CREATE_CLASS_PERMISSION)) {
throw MCRAccessException.missingPermission("create classification " + classification.getId().getRootID(), classification.getId().getRootID(), CREATE_CLASS_PERMISSION);
}
DAO.addCategory(null, classification);
}
}
use of org.mycore.datamodel.classifications2.MCRCategory in project mycore by MyCoRe-Org.
the class MCRRoleManager method loadSystemRoles.
private static void loadSystemRoles() {
if (lastLoaded == DAO.getLastModified() || !DAO.exist(MCRUser2Constants.ROLE_CLASSID)) {
return;
}
lastLoaded = DAO.getLastModified();
int onlyNonHierarchicalRoles = 1;
MCRCategory roleCategory = DAO.getCategory(MCRUser2Constants.ROLE_CLASSID, onlyNonHierarchicalRoles);
rolesByName.clear();
rolesList.clear();
if (roleCategory != null) {
for (MCRCategory child : roleCategory.getChildren()) {
String name = child.getId().getID();
MCRRole role = new MCRRole(name, child.getLabels());
rolesByName.put(name, role);
rolesList.add(role);
}
}
}
use of org.mycore.datamodel.classifications2.MCRCategory 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