use of org.mycore.datamodel.ifs.MCRContentStore in project mycore by MyCoRe-Org.
the class MCRIFSCommands method moveContentToNewStore.
private static List<String> moveContentToNewStore(String source_store, String target_store, String select_key, String select_value) {
// check stores
MCRContentStore from_store = MCRContentStoreFactory.getStore(source_store);
@SuppressWarnings("unused") MCRContentStore to_store = MCRContentStoreFactory.getStore(target_store);
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
MCRStreamQuery<MCRFSNODES> streamQuery = MCRStreamQuery.getInstance(em, "from MCRFSNODES where storeid=:storeid and " + select_key + "=:selectValue order by owner", MCRFSNODES.class).setParameter("storeid", from_store.getID()).setParameter("selectValue", select_value);
try (Stream<MCRFSNODES> resultStream = streamQuery.getResultStream()) {
return resultStream.peek(em::detach).map(MCRFSNODES::getId).map(ifsId -> String.format(Locale.ROOT, "move ifs node %s to store %s", ifsId, target_store)).collect(Collectors.toList());
}
}
use of org.mycore.datamodel.ifs.MCRContentStore 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);
}
}
use of org.mycore.datamodel.ifs.MCRContentStore 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();
}
}
Aggregations