use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRLoggingCommands method changeLogLevel.
/**
* @param name
* the name of the java class or java package to set the log
* level for
* @param logLevelToSet
* the log level to set e.g. TRACE, DEBUG, INFO, WARN, ERROR and
* FATAL, providing any other value will lead to DEBUG as new log
* level
*/
@MCRCommand(syntax = "change log level of {0} to {1}", help = "{0} the package or class name for which to change the log level, {1} the log level to set.", order = 10)
public static synchronized void changeLogLevel(String name, String logLevelToSet) {
LOGGER.info("Setting log level for \"{}\" to \"{}\"", name, logLevelToSet);
Level newLevel = Level.getLevel(logLevelToSet);
if (newLevel == null) {
LOGGER.error("Unknown log level \"{}\"", logLevelToSet);
return;
}
Logger log = "ROOT".equals(name) ? LogManager.getRootLogger() : LogManager.getLogger(name);
if (log == null) {
LOGGER.error("Could not get logger for \"{}\"", name);
return;
}
LOGGER.info("Change log level from {} to {}", log.getLevel(), newLevel);
Configurator.setLevel(log.getName(), newLevel);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method repairMCRLinkHrefTable.
@MCRCommand(syntax = "repair mcrlinkhref table", help = "Runs through the whole table and checks for already deleted mcr objects and deletes them.", order = 185)
public static void repairMCRLinkHrefTable() {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
MCRStreamQuery<String> fromQuery = MCRStreamQuery.getInstance(em, "SELECT DISTINCT m.key.mcrfrom FROM MCRLINKHREF m", String.class);
MCRStreamQuery<String> toQuery = MCRStreamQuery.getInstance(em, "SELECT DISTINCT m.key.mcrto FROM MCRLINKHREF m", String.class);
String query = "DELETE FROM MCRLINKHREF m WHERE m.key.mcrfrom IN (:invalidIds) or m.key.mcrto IN (:invalidIds)";
// open streams
try (Stream<String> fromStream = fromQuery.getResultStream()) {
try (Stream<String> toStream = toQuery.getResultStream()) {
List<String> invalidIds = Stream.concat(fromStream, toStream).distinct().filter(MCRObjectID::isValid).map(MCRObjectID::getInstance).filter(MCRStreamUtils.not(MCRMetadataManager::exists)).map(MCRObjectID::toString).collect(Collectors.toList());
// delete
em.createQuery(query).setParameter("invalidIds", invalidIds).executeUpdate();
}
}
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method deleteTopologicalAllObjects.
/**
* Delete all MCRObjects from the datastore in topological order
*/
@MCRCommand(syntax = "delete all objects in topological order", help = "Removes all MCRObjects in topological order.", order = 25)
public static List<String> deleteTopologicalAllObjects() {
final List<String> objectIds = MCRXMLMetadataManager.instance().listIDs();
String[] objects = objectIds.stream().filter(id -> !id.contains("_derivate_")).toArray(String[]::new);
MCRTopologicalSort ts = new MCRTopologicalSort();
ts.prepareMCRObjects(objects);
int[] order = ts.doTopoSort();
List<String> cmds = new ArrayList<>(objectIds.size());
if (order != null) {
// delete in reverse order
for (int o = order.length - 1; o >= 0; o--) {
cmds.add("delete object " + ts.getNodeName(order[o]));
}
}
return cmds;
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method listRevisions.
/**
* List revisions of an MyCoRe Object.
*
* @param id
* id of MyCoRe Object
*/
@MCRCommand(syntax = "list revisions of {0}", help = "List revisions of MCRObject.", order = 260)
public static void listRevisions(String id) {
MCRObjectID mcrId = MCRObjectID.getInstance(id);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
try {
StringBuilder log = new StringBuilder("Revisions:\n");
List<MCRMetadataVersion> revisions = MCRXMLMetadataManager.instance().listRevisions(mcrId);
for (MCRMetadataVersion revision : revisions) {
log.append(revision.getRevision()).append(" ");
log.append(revision.getType()).append(" ");
log.append(sdf.format(revision.getDate())).append(" ");
log.append(revision.getUser());
log.append("\n");
}
LOGGER.info(log.toString());
} catch (Exception exc) {
LOGGER.error("While print revisions.", exc);
}
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method repairMetadataSearchForID.
/**
* The method start the repair of the metadata search for a given MCRObjectID as String.
*
* @param id
* the MCRObjectID as String
*/
@MCRCommand(syntax = "repair metadata search of ID {0}", help = "Retrieves the MCRObject with the MCRObjectID {0} and restores it in the search store.", order = 180)
public static void repairMetadataSearchForID(String id) {
LOGGER.info("Start the repair for the ID {}", id);
if (!MCRObjectID.isValid(id)) {
LOGGER.error("The String {} is not a MCRObjectID.", id);
return;
}
MCRObjectID mid = MCRObjectID.getInstance(id);
MCRBase obj = MCRMetadataManager.retrieve(mid);
MCRMetadataManager.fireRepairEvent(obj);
LOGGER.info("Repaired {}", mid);
}
Aggregations