18 package org.turro.dossier.search;
20 import java.util.stream.Stream;
21 import org.turro.dossier.db.DossierPU;
22 import org.turro.dossier.entity.Category;
23 import org.turro.dossier.entity.Dossier;
24 import org.turro.dossier.entity.ParticipantRole;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.jpa.Dao;
27 import org.turro.jpa.query.JpaCriteria;
28 import org.turro.jpa.query.JpaCriteriaUpdate;
29 import org.turro.jpa.query.JpaQuery;
30 import org.turro.util.Chars;
44 wc.
addClause(
"from Category as category");
45 wc.
addClause(
"order by category.fullDescription");
52 wc.
addClause(
"from Category as category");
54 wc.
addClause(
"order by category.fullDescription");
61 dao.saveObject(category);
70 dao.getResultList(jqc.
select()).forEach((category) -> {
71 String uniquePath =
"/c" + category.getId();
72 String fullDescription = category.getDescription();
75 uniquePath =
"/c" + c.
getId() + uniquePath;
76 fullDescription = c.
getDescription() + Chars.backward().spaced() + fullDescription;
81 .set(
"fullDescription", fullDescription)
82 .where(criteria.
equal(juc.
field(
"id"), category.getId())));
85 try(Stream<Dossier> dossiers = dao.stream(
Dossier.class, jqd.
select())) {
86 dossiers.forEach((dossier) -> {
88 execute.
executeUpdate(jud.set(
"uniquePath", dossier.getCategory().getUniquePath() +
"/d" + dossier.getId())
89 .where(criteria.
equal(jud.
field(
"id"), dossier.getId())));
103 wc.
addClause(
"and exists (select c from Category as c");
104 wc.
addClause(
"where " + dossierField +
".uniquePath like concat(c.uniquePath, '/%')");
105 wc.
addClause(
"and c.id in (" + categoryIds +
"))");
110 wc.
addClause(
"select cp from CategoryParticipant as cp");
111 wc.
addClause(
"where cp.idContact = :idContact");
113 wc.
addClause(
"and (cp.role = :cprole1 or cp.role = :cprole2)");
117 wc.
addClause(
"cp.category.uniquePath = " + dossierField +
".category.uniquePath");
118 wc.
addClause(
"or " + dossierField +
".category.uniquePath like concat(cp.category.uniquePath, '/%')");
124 wc.
addClause(
"select cp from CategoryParticipant as cp");
125 wc.
addClause(
"where cp.idContact = :idContact");
127 wc.
addClause(
"and (cp.role = :cprole1 or cp.role = :cprole2)");
131 wc.
addClause(
"cp.category.uniquePath = " + categoryField +
".uniquePath");
132 wc.
addClause(
"or cp.category.uniquePath like concat(" + categoryField +
".uniquePath, '/%')");
133 wc.
addClause(
"or " + categoryField +
".uniquePath like concat(cp.category.uniquePath, '/%')");
135 wc.
addClause(
"select dp from Participant as dp");
137 wc.
addClause(
"dp.dossier.category.uniquePath = " + categoryField +
".uniquePath");
138 wc.
addClause(
"or dp.dossier.category.uniquePath like concat(" + categoryField +
".uniquePath, '/%')");
140 wc.
addClause(
"and dp.idContact = :idContact");
142 wc.
addClause(
"and (dp.role = :dpdrole1 or dp.role = :dpdrole2)");
java.util.List getCategoryList()
static void normalizeUniquePaths(Dossier dossier)
static void normalizeUniquePaths()
java.util.List getCategoryRootList()
static void addParticipantCategoryAffiliance(WhereClause wc, String sep, String idContact, String categoryField)
static void saveCategory(Category category)
static void addParticipantAffiliance(WhereClause wc, String sep, String idContact, String dossierField)
static void addExistsCategoryAffiliance(WhereClause wc, String categoryIds, String dossierField)
void addClause(String clause)
void addNamedValue(String name, Object value)
int executeUpdate(String query)
Path field(String fieldName)
Predicate equal(Expression<?> x, Expression<?> y)