19 package org.turro.alliance.service;
21 import java.util.HashSet;
23 import org.turro.action.Contacts;
24 import org.turro.alliance.db.AlliancePU;
25 import org.turro.alliance.db.entities.AxCenter;
26 import org.turro.alliance.db.entities.AxChallenge;
27 import org.turro.alliance.db.entities.AxContact;
28 import org.turro.alliance.db.entities.AxProject;
29 import org.turro.alliance.db.entities.AxProjectGrant;
30 import org.turro.alliance.db.entities.AxStudent;
31 import org.turro.alliance.db.entities.AxTag;
32 import org.turro.collections.KeyValueMap;
33 import org.turro.dossier.db.DossierPU;
34 import org.turro.dossier.entity.Dossier;
35 import org.turro.dossier.entity.ParticipantRole;
36 import org.turro.dossier.entity.ProjectGrant;
37 import org.turro.elephant.context.Application;
38 import org.turro.jpa.Dao;
39 import org.turro.json.Jsons;
40 import org.turro.member.db.entities.AxChallengeCategory;
41 import org.turro.member.db.entities.AxProjectCategory;
42 import org.turro.member.db.entities.AxProjectGrantPublic;
43 import org.turro.sql.SqlClause;
44 import org.turro.students.db.StudentsPU;
45 import org.turro.students.entities.Challenge;
46 import org.turro.ws.WsServer;
47 import org.turro.ws.service.IWsService;
48 import org.turro.ws.service.member.SecuredClientService;
49 import org.turro.ws.service.WsService;
56 public class
AxClient extends SecuredClientService implements IWsService {
58 public static final String CLIENT_SERVICE =
"/axclient";
63 long memberId = json.getInt(
"memberId");
64 Jsons users = Jsons.array();
65 getParticipantsIds().forEach(
id -> {
68 writeResponse(application, users.build());
70 long memberId = json.getInt(
"memberId");
71 Jsons projects = Jsons.array();
73 SqlClause.select(
"pc").from(
"AxProjectCategory pc")
77 Dossier dossier = dao.find(
Dossier.class, Long.valueOf(pc.getProjectId()));
78 if(dossier !=
null && dossier.
getProject() !=
null) {
79 projects.addValue(Jsons.read(AxProject.from(memberId, server, dossier, pc).toJson()));
82 writeResponse(application, projects.build());
83 }
else if(
AxConstants.PROJECT_GRANTS.equals(reason)) {
84 long memberId = json.getInt(
"memberId");
85 Jsons projectGrants = Jsons.array();
87 SqlClause.select(
"pc").from(
"AxProjectGrantPublic pc")
92 if(projectGrant !=
null) {
93 projectGrants.addValue(Jsons.read(AxProjectGrant.from(memberId, projectGrant).toJson()));
96 writeResponse(application, projectGrants.build());
98 long memberId = json.getInt(
"memberId");
99 Jsons centers = Jsons.array();
103 writeResponse(application, centers.build());
105 long memberId = json.getInt(
"memberId");
106 Jsons students = Jsons.array();
108 if(student.isStudent() && !student.isWorker()) {
109 students.addValue(Jsons.read(AxStudent.from(memberId, student).toJson()));
112 writeResponse(application, students.build());
114 long memberId = json.getInt(
"memberId");
115 Jsons challenges = Jsons.array();
117 SqlClause.select(
"pc").from(
"AxChallengeCategory pc")
122 if(challenge !=
null) {
123 challenges.addValue(Jsons.read(AxChallenge.from(memberId, server, challenge, pc).toJson()));
126 writeResponse(application, challenges.build());
128 long memberId = json.getInt(
"memberId");
129 Jsons tags = Jsons.array();
131 SqlClause.select(
"pc").from(
"AxProjectCategory pc")
135 Dossier dossier = dao.find(
Dossier.class, Long.valueOf(pc.getProjectId()));
136 if(dossier !=
null && dossier.
getProject() !=
null) {
137 AxTag.from(memberId, dossier).forEach(tag -> {
138 tags.addValue(Jsons.read(tag.toJson()));
142 SqlClause.select(
"pc").from(
"AxProjectGrantPublic pc")
147 if(projectGrant !=
null) {
148 AxTag.
from(memberId, projectGrant).forEach(tag -> {
149 tags.addValue(Jsons.read(tag.toJson()));
153 writeResponse(application, tags.build());
157 private Set<String> getParticipantsIds() {
158 Set<String> ids =
new HashSet<>();
159 ids.addAll(SqlClause.select(
"distinct p.idContact").from(
"Participant p")
160 .where().notEqual(
"role", ParticipantRole.PARTICIPANT_SUBJECT)
161 .dao(
new DossierPU())
162 .resultList(String.class));
163 ids.addAll(SqlClause.select(
"distinct p.idContact").from(
"CategoryParticipant p")
164 .where().notEqual(
"role", ParticipantRole.PARTICIPANT_SUBJECT)
165 .dao(
new DossierPU())
166 .resultList(String.class));
static AxCenter from(long memberId, String contactId)
static Set< AxTag > from(long memberId, Dossier dossier)
static final String CLIENT_SERVICE
void doProcess(Application application, KeyValueMap map, WsServer server, Jsons json, String reason)