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