19 package org.turro.cleanup;
22 import java.util.stream.Stream;
23 import org.turro.dossier.db.DossierPU;
24 import org.turro.dossier.dw.DatawarehouseUtil;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.Issue;
27 import org.turro.jpa.Dao;
28 import org.turro.sql.SqlClause;
38 public boolean isMine(Object entity) {
39 return entity instanceof
Dossier;
44 if(entity instanceof
Dossier dossier) {
47 cleanupIssues(dao, dossier, mode);
48 cleanupRequests(dao, dossier, mode);
61 try(Stream<Issue> stream = SqlClause.select(
"i").from(
"Issue i")
62 .where().equal(
"i.dossier", dossier)
64 .stream(
Issue.class)) {
65 stream.forEach(issue -> {
71 private void cleanupRequests(Dao dao, Dossier dossier, CleanupMode mode) {
72 CleanupAction.from(
"Removing requests...", () -> {
73 SqlClause.delete(
"ParticipantRequest")
74 .where().equal(
"dossier", dossier)
82 SqlClause.delete(
"Participant")
83 .where().isNull(
"dossier")
86 SqlClause.delete(
"ParticipantRequest")
87 .where().isNull(
"dossier")
90 SqlClause.delete(
"CategoryRequest")
91 .where().isNull(
"category")
94 cleanOrphansFor(
"dossier", getEntityPaths(dao, Long.class,
"Dossier",
"id",
"dossier"));
void cleanOrphansFor(String root, Set< String > entities)
ICleanupConsole getConsole()
static CleanupAction from(String message, Runnable action)
void execute(ICleanupConsole console, CleanupMode mode)
static void executeForEntity(Object entity, ICleanupConsole console, CleanupMode mode)
static void executeForCommons(String entityPath, ICleanupConsole console, CleanupMode mode, Set< IElephantCleanup.Commons > commons)
boolean isMine(Object entity)
void cleanEntity(Object entity, CleanupMode mode)
static String getObjectPath(Object object)
static void remove(Dao dao, Dossier dossier)
void deleteObject(Object obj)
void addMessage(String message)