use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method export.
/**
* Save any MCRObject's to files named <em>MCRObjectID</em> .xml in a directory. The saving starts with fromID and
* runs to toID. ID's they was not found will skiped. The method use the converter stylesheet mcr_<em>style</em>
* _object.xsl.
*
* @param fromID
* the ID of the MCRObject from be save.
* @param toID
* the ID of the MCRObject to be save.
* @param dirname
* the filename to store the object
* @param style
* the type of the stylesheet
*/
@MCRCommand(syntax = "export object from {0} to {1} to directory {2} with {3}", help = "Stores all MCRObjects with MCRObjectID's between {0} and {1} to the directory {2} with the stylesheet {3}-object.xsl. For {3} save is the default.", order = 100)
public static void export(String fromID, String toID, String dirname, String style) {
MCRObjectID fid, tid;
// check fromID and toID
try {
fid = MCRObjectID.getInstance(fromID);
tid = MCRObjectID.getInstance(toID);
} catch (Exception ex) {
LOGGER.error("FromID : {}", ex.getMessage());
return;
}
// check dirname
File dir = new File(dirname);
if (!dir.isDirectory()) {
LOGGER.error("{} is not a dirctory.", dirname);
return;
}
int k = 0;
try {
Transformer trans = getTransformer(style);
for (int i = fid.getNumberAsInteger(); i < tid.getNumberAsInteger() + 1; i++) {
String id = MCRObjectID.formatID(fid.getProjectId(), fid.getTypeId(), i);
if (!MCRMetadataManager.exists(MCRObjectID.getInstance(id))) {
continue;
}
if (!exportMCRObject(dir, trans, id)) {
continue;
}
k++;
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
LOGGER.error("Exception while store file to {}", dir.getAbsolutePath());
return;
}
LOGGER.info("{} Object's stored under {}.", k, dir.getAbsolutePath());
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method checkDerivatesInObjects.
/**
* Check the derivate links in objects of MCR base ID for existing. It looks to the XML store on the disk to get all
* object IDs.
*
* @param base_id
* the base part of a MCRObjectID e.g. DocPortal_document
*/
@MCRCommand(syntax = "check derivate entries in objects for base {0}", help = "check in all objects with MCR base ID {0} for existing linked derivates", order = 400)
public static void checkDerivatesInObjects(String base_id) throws IOException {
if (base_id == null || base_id.length() == 0) {
LOGGER.error("Base ID missed for check derivate entries in objects for base {0}");
return;
}
MCRXMLMetadataManager mgr = MCRXMLMetadataManager.instance();
List<String> id_list = mgr.listIDsForBase(base_id);
int counter = 0;
int maxresults = id_list.size();
for (String objid : id_list) {
counter++;
LOGGER.info("Processing dataset {} from {} with ID: {}", counter, maxresults, objid);
// get from data
MCRObjectID mcrobjid = MCRObjectID.getInstance(objid);
MCRObject obj = MCRMetadataManager.retrieveMCRObject(mcrobjid);
List<MCRMetaLinkID> derivate_entries = obj.getStructure().getDerivates();
for (MCRMetaLinkID derivate_entry : derivate_entries) {
String derid = derivate_entry.getXLinkHref();
if (!mgr.exists(MCRObjectID.getInstance(derid))) {
LOGGER.error(" !!! Missing derivate {} in database for base ID {}", derid, base_id);
}
}
}
LOGGER.info("Check done for {} entries", Integer.toString(counter));
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRObjectCommands method delete.
/**
* Delete a MCRObject from the datastore.
*
* @param ID
* the ID of the MCRObject that should be deleted
* @throws MCRPersistenceException if a persistence problem is occurred
* @throws MCRAccessException see {@link MCRMetadataManager#deleteMCRObject(MCRObjectID)}
* @throws MCRActiveLinkException if object is referenced by other objects
*/
@MCRCommand(syntax = "delete object {0}", help = "Removes a MCRObject with the MCRObjectID {0}", order = 40)
public static void delete(String ID) throws MCRPersistenceException, MCRActiveLinkException, MCRAccessException {
MCRObjectID mcrId = MCRObjectID.getInstance(ID);
MCRMetadataManager.deleteMCRObject(mcrId);
LOGGER.info("{} deleted.", mcrId);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRBasicCommands method checkXMLFile.
/**
* The method parse and check an XML file.
*
* @param fileName
* the location of the xml file
*/
@MCRCommand(syntax = "check file {0}", help = "Checks the data file {0} against the XML Schema.", order = 160)
public static boolean checkXMLFile(String fileName) throws MCRException, SAXParseException, IOException {
if (!fileName.endsWith(".xml")) {
LOGGER.warn("{} ignored, does not end with *.xml", fileName);
return false;
}
File file = new File(fileName);
if (!file.isFile()) {
LOGGER.warn("{} ignored, is not a file.", fileName);
return false;
}
LOGGER.info("Reading file {} ...", file);
MCRContent content = new MCRFileContent(file);
MCRXMLParserFactory.getParser().parseXML(content);
LOGGER.info("The file has no XML errors.");
return true;
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method checkClassification.
@MCRCommand(syntax = "check classification {0}", help = "checks if all redundant information are stored without conflicts", order = 150)
public static void checkClassification(String id) {
LOGGER.info("Checking classifcation {}", id);
ArrayList<String> log = new ArrayList<>();
LOGGER.info("{}: checking for missing parentID", id);
checkMissingParent(id, log);
LOGGER.info("{}: checking for empty labels", id);
checkEmptyLabels(id, log);
if (log.isEmpty()) {
MCRCategoryImpl category = (MCRCategoryImpl) MCRCategoryDAOFactory.getInstance().getCategory(MCRCategoryID.rootID(id), -1);
LOGGER.info("{}: checking left, right and level values and for non-null children", id);
checkLeftRightAndLevel(category, 0, 0, log);
}
if (log.size() > 0) {
LOGGER.error("Some errors occured on last test, report will follow");
StringBuilder sb = new StringBuilder();
for (String msg : log) {
sb.append(msg).append('\n');
}
LOGGER.error("Error report for classification {}\n{}", id, sb);
} else {
LOGGER.info("Classifcation {} has no errors.", id);
}
}
Aggregations