use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method countChildren.
/**
* Counts the classification categories on top level
*
* @param classID classification ID
*/
@MCRCommand(syntax = "count classification children of {0}", help = "The command count the categoies of the classification with MCRObjectID {0} in the system.", order = 80)
public static void countChildren(String classID) {
MCRCategory category = DAO.getCategory(MCRCategoryID.rootID(classID), 1);
System.out.printf(Locale.ROOT, "%s has %d children", category.getId(), category.getChildren().size());
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRDerivateCommands method exportAllDerivates.
/**
* The command look for all derivates in the application and build export
* commands.
*
* @param dirname
* the filename to store the object
* @param style
* the type of the stylesheet
* @return a list of export commands for each derivate
*/
@MCRCommand(syntax = "export all derivates to directory {0} with {1}", help = "Stores all derivates to the directory {0} with the stylesheet mcr_{1}-derivate.xsl. For {1} save is the default.", order = 100)
public static List<String> exportAllDerivates(String dirname, String style) {
// check dirname
File dir = new File(dirname);
if (dir.isFile()) {
throw new MCRException(dirname + " is not a dirctory.");
}
List<String> ids = MCRXMLMetadataManager.instance().listIDsOfType("derivate");
List<String> cmds = new ArrayList<>(ids.size());
for (String id : ids) {
cmds.add("export derivate " + id + " to directory " + dirname + " with " + style);
}
return cmds;
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method permissionUpdateForID.
/**
* updates the permission for a given id and a given permission type with a
* given rule
*
* @param permission
* String type of permission like read, writedb, etc.
* @param id
* String the id of the object the rule is assigned to
* @param strFileRule
* String the path to the xml file, that contains the rule
* @param description
* String give a special description, if the semantics of your
* rule is multiple used
*/
@MCRCommand(syntax = "update permission {0} for id {1} with rulefile {2} described by {3}", help = "The command updates access rule for a given id of a given permission with a given special rule", order = 60)
public static void permissionUpdateForID(String permission, String id, String strFileRule, String description) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Element rule = getRuleFromFile(strFileRule);
if (rule == null) {
return;
}
AI.addRule(id, permission, rule, description);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method deletePermission.
/**
* delete the permission {0}
*
* @param permission
* the name of the permission
*/
@MCRCommand(syntax = "delete permission {0}", help = "Remove a named permission entriy from the Access Control System.", order = 30)
public static void deletePermission(String permission) throws Exception {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
AI.removeRule(permission);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRAccessCommands method listAllPermissions.
/**
* This method invokes MCRUserMgr.getAllPrivileges() and retrieves a
* ArrayList of all privileges stored in the persistent datastore.
*/
@MCRCommand(syntax = "list all permissions", help = "List all permission entries.", order = 20)
public static void listAllPermissions() throws MCRException {
MCRAccessInterface AI = MCRAccessManager.getAccessImpl();
Collection<String> permissions = AI.getPermissions();
boolean noPermissionsDefined = true;
for (String permission : permissions) {
noPermissionsDefined = false;
String description = AI.getRuleDescription(permission);
if (description.equals("")) {
description = "No description";
}
org.jdom2.Element rule = AI.getRule(permission);
LOGGER.info(" {}", permission);
LOGGER.info(" {}", description);
if (rule != null) {
org.jdom2.output.XMLOutputter o = new org.jdom2.output.XMLOutputter();
LOGGER.info(" {}", o.outputString(rule));
}
}
if (noPermissionsDefined) {
LOGGER.warn("No permissions defined");
}
LOGGER.info("");
}
Aggregations