Search in sources :

Example 61 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRBasicCommands method createConfigurationDirectory.

@MCRCommand(syntax = "create configuration directory", help = "Creates the MCRConfiguration directory if it does not exist.", order = 130)
public static void createConfigurationDirectory() throws IOException {
    File configurationDirectory = MCRConfigurationDir.getConfigurationDirectory();
    ArrayList<File> directories = new ArrayList<>(3);
    directories.add(configurationDirectory);
    for (String dir : MCRConfiguration.instance().getString("MCR.ConfigurationDirectory.template.directories", "").split(",")) {
        if (!dir.trim().isEmpty()) {
            directories.add(new File(configurationDirectory, dir.trim()));
        }
    }
    for (File directory : directories) {
        if (!createDirectory(directory)) {
            break;
        }
    }
    for (String f : MCRConfiguration.instance().getString("MCR.ConfigurationDirectory.template.files", "").split(",")) {
        if (!f.trim().isEmpty()) {
            createSampleConfigFile(f.trim());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 62 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method exportAll.

/**
 * Save all MCRClassifications.
 *
 * @param dirname
 *            the directory name to store all classifications
 * @param style
 *            the name part of the stylesheet like <em>style</em>
 *            -classification.xsl
 * @return false if an error was occured, else true
 */
@MCRCommand(syntax = "export all classifications to directory {0} with {1}", help = "The command store all classifications to the directory with name {0} with the stylesheet {1}-object.xsl. For {1} save is the default.", order = 70)
public static boolean exportAll(String dirname, String style) throws Exception {
    List<MCRCategoryID> allClassIds = DAO.getRootCategoryIDs();
    boolean ret = false;
    for (MCRCategoryID id : allClassIds) {
        ret = ret & export(id.getRootID(), dirname, style);
    }
    return ret;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 63 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method checkAllClassifications.

@MCRCommand(syntax = "check all classifications", help = "checks if all redundant information are stored without conflicts", order = 140)
public static List<String> checkAllClassifications() {
    List<MCRCategoryID> classifications = MCRCategoryDAOFactory.getInstance().getRootCategoryIDs();
    List<String> commands = new ArrayList<>(classifications.size());
    for (MCRCategoryID id : classifications) {
        commands.add("check classification " + id.getRootID());
    }
    return commands;
}
Also used : MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) ArrayList(java.util.ArrayList) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 64 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method loadFromURL.

@MCRCommand(syntax = "load classification from url {0}", help = "The command adds a new classification from URL {0} to the system.", order = 15)
public static void loadFromURL(String fileURL) throws SAXParseException, MalformedURLException, URISyntaxException {
    Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL(fileURL)));
    MCRCategory category = MCRXMLTransformer.getCategory(xml);
    DAO.addCategory(null, category);
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 65 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRClassification2Commands method repairPositionInParent.

@MCRCommand(syntax = "repair position in parent", help = "fixes all categories gaps in position in parent", order = 120)
@SuppressWarnings("unchecked")
public static void repairPositionInParent() {
    Session session = MCRHIBConnection.instance().getSession();
    // this SQL-query find missing numbers in positioninparent
    String sqlQuery = "select parentid, min(cat1.positioninparent+1) from {h-schema}MCRCategory cat1 " + "where cat1.parentid is not null and not exists" + "(select 1 from {h-schema}MCRCategory cat2 " + "where cat2.parentid=cat1.parentid and cat2.positioninparent=(cat1.positioninparent+1))" + "and cat1.positioninparent not in " + "(select max(cat3.positioninparent) from {h-schema}MCRCategory cat3 " + "where cat3.parentid=cat1.parentid) group by cat1.parentid";
    for (List<Object[]> parentWithErrorsList = session.createNativeQuery(sqlQuery).getResultList(); !parentWithErrorsList.isEmpty(); parentWithErrorsList = session.createNativeQuery(sqlQuery).getResultList()) {
        for (Object[] parentWithErrors : parentWithErrorsList) {
            Number parentID = (Number) parentWithErrors[0];
            Number firstErrorPositionInParent = (Number) parentWithErrors[1];
            LOGGER.info("Category {} has the missing position {} ...", parentID, firstErrorPositionInParent);
            repairCategoryWithGapInPos(parentID, firstErrorPositionInParent);
            LOGGER.info("Fixed position {} for category {}.", firstErrorPositionInParent, parentID);
        }
    }
    sqlQuery = "select parentid, min(cat1.positioninparent-1) from {h-schema}MCRCategory cat1 " + "where cat1.parentid is not null and not exists" + "(select 1 from {h-schema}MCRCategory cat2 " + "where cat2.parentid=cat1.parentid and cat2.positioninparent=(cat1.positioninparent-1))" + "and cat1.positioninparent not in " + "(select max(cat3.positioninparent) from {h-schema}MCRCategory cat3 " + "where cat3.parentid=cat1.parentid) and cat1.positioninparent > 0 group by cat1.parentid";
    while (true) {
        List<Object[]> parentWithErrorsList = session.createNativeQuery(sqlQuery).getResultList();
        if (parentWithErrorsList.isEmpty()) {
            break;
        }
        for (Object[] parentWithErrors : parentWithErrorsList) {
            Number parentID = (Number) parentWithErrors[0];
            Number wrongStartPositionInParent = (Number) parentWithErrors[1];
            LOGGER.info("Category {} has the the starting position {} ...", parentID, wrongStartPositionInParent);
            repairCategoryWithWrongStartPos(parentID, wrongStartPositionInParent);
            LOGGER.info("Fixed position {} for category {}.", wrongStartPositionInParent, parentID);
        }
    }
    LOGGER.info("Repair position in parent finished!");
}
Also used : Session(org.hibernate.Session) 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