Search in sources :

Example 1 with MCRCStoreIFS2

use of org.mycore.datamodel.ifs2.MCRCStoreIFS2 in project mycore by MyCoRe-Org.

the class MCRIFS2Commands method repairMcrdataXmlForDerivate.

@MCRCommand(syntax = "repair mcrdata.xml for derivate {0} in content store {1}", help = "repair the entries in mcrdata.xml with data from content store {1} for MCRDerivate {0}")
public static void repairMcrdataXmlForDerivate(String derivate_id, String content_store) {
    LOGGER.info("Start repair of mcrdata.xml for derivate {} in store {}", derivate_id, content_store);
    // check input;
    MCRObjectID mcr_derivate_id;
    try {
        mcr_derivate_id = MCRObjectID.getInstance(derivate_id);
    } catch (MCRException e) {
        LOGGER.error("Wrong derivate parameter, it is not a MCRObjectID");
        return;
    }
    if (content_store == null || content_store.length() == 0) {
        LOGGER.error("Empty content store parameter");
        return;
    }
    MCRContentStore store = MCRContentStoreFactory.getStore(content_store);
    if (!(store instanceof MCRCStoreIFS2)) {
        LOGGER.error("The content store is not a IFS2 type");
        return;
    }
    // repair
    try {
        MCRFileCollection file_collection = ((MCRCStoreIFS2) store).getIFS2FileCollection(mcr_derivate_id);
        file_collection.repairMetadata();
    } catch (IOException e) {
        LOGGER.error("Erroe while repair derivate with ID {}", mcr_derivate_id);
    }
}
Also used : MCRCStoreIFS2(org.mycore.datamodel.ifs2.MCRCStoreIFS2) MCRException(org.mycore.common.MCRException) MCRFileCollection(org.mycore.datamodel.ifs2.MCRFileCollection) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) MCRContentStore(org.mycore.datamodel.ifs.MCRContentStore) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 2 with MCRCStoreIFS2

use of org.mycore.datamodel.ifs2.MCRCStoreIFS2 in project mycore by MyCoRe-Org.

the class MCRIFS2Commands method fixMCRFSNODESForDerivate.

private static void fixMCRFSNODESForDerivate(String content_store, String derivate_id, boolean check_only) {
    // check input
    MCRObjectID mcr_derivate_id;
    try {
        mcr_derivate_id = MCRObjectID.getInstance(derivate_id);
    } catch (MCRException e) {
        LOGGER.error("Wrong derivate parameter, it is not a MCRObjectID");
        return;
    }
    if (content_store == null || content_store.length() == 0) {
        LOGGER.error("Empty content store parameter");
        return;
    }
    MCRContentStore store = MCRContentStoreFactory.getStore(content_store);
    if (!(store instanceof MCRCStoreIFS2)) {
        LOGGER.error("The content store is not a IFS2 type");
        return;
    }
    // list all files
    try {
        MCRFileCollection file_collection = ((MCRCStoreIFS2) store).getIFS2FileCollection(mcr_derivate_id);
        File root_node = file_collection.getLocalFile();
        String storage_base = root_node.getAbsolutePath();
        storage_base = storage_base.substring(0, storage_base.length() - derivate_id.length());
        fixMCRFSNODESForNode(root_node, content_store, derivate_id, storage_base, check_only);
    } catch (IOException e) {
        LOGGER.error("Error while list all files of derivate with ID {}", mcr_derivate_id);
        e.printStackTrace();
    }
    Session session = MCRHIBConnection.instance().getSession();
    Transaction tx = session.getTransaction();
    if (tx.getStatus().isOneOf(TransactionStatus.ACTIVE)) {
        tx.commit();
    }
}
Also used : MCRCStoreIFS2(org.mycore.datamodel.ifs2.MCRCStoreIFS2) MCRException(org.mycore.common.MCRException) Transaction(org.hibernate.Transaction) MCRFileCollection(org.mycore.datamodel.ifs2.MCRFileCollection) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) MCRContentStore(org.mycore.datamodel.ifs.MCRContentStore) File(java.io.File) Session(org.hibernate.Session) MCRSession(org.mycore.common.MCRSession)

Aggregations

IOException (java.io.IOException)2 MCRException (org.mycore.common.MCRException)2 MCRContentStore (org.mycore.datamodel.ifs.MCRContentStore)2 MCRCStoreIFS2 (org.mycore.datamodel.ifs2.MCRCStoreIFS2)2 MCRFileCollection (org.mycore.datamodel.ifs2.MCRFileCollection)2 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)2 File (java.io.File)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 MCRSession (org.mycore.common.MCRSession)1 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)1