19 package org.turro.alliance.provider;
21 import java.util.List;
23 import org.turro.alliance.db.AlliancePU;
24 import org.turro.alliance.db.entities.AxProject;
25 import org.turro.jpa.Dao;
26 import org.turro.json.Jsons;
27 import org.turro.sql.SqlClause;
28 import org.turro.string.Strings;
29 import org.turro.util.Cached;
30 import org.turro.ws.WsMember;
31 import org.turro.ws.content.JsonServerProvider;
39 private final List<String> banned;
42 super(member, reason, criteria);
48 Jsons projects = Jsons.array();
49 List<Long> ids = criteria.getArrayValues(
"categoryIds", Long.class);
50 String search = criteria.getString(
"search",
"");
51 int phase = criteria.getInt(
"phase", -1);
52 boolean withBanned = criteria.getBoolean(
"withBanned",
false);
53 SqlClause.select(
"p").from(
"AxProject p")
54 .startIf(ids !=
null && !ids.isEmpty())
55 .where().in(
"categoryId", ids)
57 .startIf(!Strings.isBlank(search))
58 .whereOrAnd().partial(search,
"p.code",
"p.name",
"p.summary")
61 .whereOrAnd().equal(
"p.phaseIndex", phase)
64 .whereOrAnd().notIn(
"id", banned)
66 .orderBy(
"p.creation desc")
67 .start(criteria.getInt(
"curr", -1)).max(criteria.getInt(
"page", -1))
69 .resultList(
AxProject.class).forEach(project -> {
70 projects.addValue(Jsons.read(project.toJson(Map.of(
"banned", withBanned && banned.contains(project.getId())))));
77 List<Long> ids = criteria.getArrayValues(
"categoryIds", Long.class);
78 String search = criteria.getString(
"search",
"");
79 int phase = criteria.getInt(
"phase", -1);
80 boolean withBanned = criteria.getBoolean(
"withBanned",
false);
81 return SqlClause.select(
"count(p)").from(
"AxProject p")
82 .startIf(ids !=
null && !ids.isEmpty())
83 .where().in(
"categoryId", ids)
85 .startIf(!Strings.isBlank(search))
86 .whereOrAnd().partial(search,
"p.code",
"p.name",
"p.summary")
89 .whereOrAnd().equal(
"p.phaseIndex", phase)
92 .whereOrAnd().notIn(
"id", banned)
95 .singleResult(Long.class, 0L);
98 private final Cached<Dao> dao = Cached.instance(() ->
new AlliancePU());
List< String > getBannedIds()
static Banned of(WsMember member)
Jsons loadData(WsMember member, String reason, Jsons criteria)
ProjectProvider(WsMember member, String reason, Jsons criteria)
long count(WsMember member, String reason, Jsons criteria)