Search in sources :

Example 21 with MCRCommand

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());
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 22 with MCRCommand

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;
}
Also used : MCRException(org.mycore.common.MCRException) ArrayList(java.util.ArrayList) File(java.io.File) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 23 with MCRCommand

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);
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface) Element(org.jdom2.Element) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 24 with MCRCommand

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);
}
Also used : MCRAccessInterface(org.mycore.access.MCRAccessInterface) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 25 with MCRCommand

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("");
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRAccessInterface(org.mycore.access.MCRAccessInterface) Element(org.jdom2.Element) XMLOutputter(org.jdom2.output.XMLOutputter) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)106 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)37 MCRException (org.mycore.common.MCRException)34 IOException (java.io.IOException)30 File (java.io.File)22 ArrayList (java.util.ArrayList)18 Document (org.jdom2.Document)17 JDOMException (org.jdom2.JDOMException)17 MCRObject (org.mycore.datamodel.metadata.MCRObject)17 Path (java.nio.file.Path)16 SAXException (org.xml.sax.SAXException)16 EntityManager (javax.persistence.EntityManager)15 MCRAccessException (org.mycore.access.MCRAccessException)15 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)15 MCRPath (org.mycore.datamodel.niofs.MCRPath)15 FileNotFoundException (java.io.FileNotFoundException)13 SAXParseException (org.xml.sax.SAXParseException)12 List (java.util.List)11 Element (org.jdom2.Element)11 MCRPersistenceException (org.mycore.common.MCRPersistenceException)11