use of org.mycore.backend.hibernate.tables.MCRFSNODES_ in project mycore by MyCoRe-Org.
the class MCRIFSCommands method checkDerivatesWithProjectIDInMCRFSNODES.
@MCRCommand(syntax = "check mcrfsnodes of derivates with project id {0}", help = "check the entries of MCRFSNODES with project ID {0} that the derivate exists")
public static void checkDerivatesWithProjectIDInMCRFSNODES(String project_id) {
LOGGER.info("Start check of MCRFSNODES for derivates with project ID {}", project_id);
if (project_id == null || project_id.length() == 0) {
LOGGER.error("Project ID missed for check MCRFSNODES entries of derivates with project ID {0}");
return;
}
MCRXMLMetadataManager mgr = MCRXMLMetadataManager.instance();
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> query = cb.createQuery(String.class);
Root<MCRFSNODES> nodes = query.from(MCRFSNODES.class);
AtomicInteger counter = new AtomicInteger();
em.createQuery(query.distinct(true).select(nodes.get(MCRFSNODES_.owner)).where(cb.like(nodes.get(MCRFSNODES_.owner), project_id + "\\_%"))).getResultList().stream().peek(ignore -> counter.incrementAndGet()).map(MCRObjectID::getInstance).filter(derID -> {
try {
return !mgr.exists(derID);
} catch (IOException e) {
LOGGER.error("Error while checking existence of {}", derID, e);
return true;
}
}).forEach(missingDerivate -> LOGGER.error(" !!!! Can't find MCRFSNODES entry {} as existing derivate", missingDerivate));
LOGGER.info("Check done for {} entries", counter.get());
}
Aggregations