BrightSide Workbench Full Report + Source Code
AxServer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.alliance.service;
20 
21 import org.turro.alliance.provider.Projects;
22 import org.turro.alliance.db.AlliancePU;
23 import org.turro.alliance.db.entities.AxCategory;
24 import org.turro.alliance.db.entities.AxTalentCategory;
25 import org.turro.alliance.provider.Banned;
26 import org.turro.alliance.provider.CategoryProvider;
27 import org.turro.alliance.provider.PhaseProvider;
28 import org.turro.alliance.provider.PreferencesProvider;
29 import org.turro.alliance.provider.ProjectGrantProvider;
30 import org.turro.alliance.provider.ProjectProvider;
31 import org.turro.alliance.provider.TagProvider;
32 import org.turro.collections.KeyValueMap;
33 import org.turro.elephant.context.Application;
34 import org.turro.importer.ImportFromMembers;
35 import org.turro.json.Jsons;
36 import org.turro.server.db.entities.AxMemberPreferences;
37 import org.turro.sql.SqlClause;
38 import org.turro.string.Strings;
39 import org.turro.ws.WsMember;
40 import org.turro.ws.service.IWsService;
41 import org.turro.ws.service.server.SecuredServerService;
42 import org.turro.ws.service.WsService;
43 
48 @WsService(path = AxServer.SERVER_SERVICE, name = "Alliance Server")
49 public class AxServer extends SecuredServerService implements IWsService {
50 
51  public static final String SERVER_SERVICE = "/axserver";
52 
53  @Override
54  protected void doProcess(Application application, KeyValueMap map, WsMember member, Jsons json, String reason) {
55  if(AxConstants.CATEGORY.equals(reason)) {
56  AxCategory cat = SqlClause.select("c").from("AxCategory c")
57  .where().equal("c.categoryId", json.getLong("id"))
58  .dao(new AlliancePU())
59  .singleResult(AxCategory.class);
60  if(cat != null) {
61  writeResponse(application, cat.toJson());
62  }
63  } else if(AxConstants.CATEGORIES.equals(reason)) {
64  Jsons categories = Jsons.array();
65  SqlClause.select("c").from("AxCategory c")
66  .orderBy("c.uniquePath")
67  .dao(new AlliancePU())
68  .resultList(AxCategory.class).forEach(category -> {
69  categories.addValue(Jsons.read(category.toJson()));
70  });
71  writeResponse(application, categories.build());
72  } else if(AxConstants.PROJECT.equals(reason)) {
73  writeResponse(application, Projects.from(member)
74  .project(json.getString("id")).toString());
75  } else if(AxConstants.PARTICIPATIONS.equals(reason)) {
76  writeResponse(application, Projects.from(member)
77  .participations(json.getString("id")).build());
78  } else if(AxConstants.AXPARTICIPATIONS.equals(reason)) {
79  writeResponse(application, Projects.from(member)
80  .axParticipations(json.getString("id"), json.getString("as", null)).build());
81  } else if(AxConstants.AXFULL_PARTICIPATIONS.equals(reason)) {
82  writeResponse(application, Projects.from(member)
83  .axFullParticipations().build());
84  } else if(AxConstants.AXPENDING_REQUESTS.equals(reason)) {
85  if(!Strings.isBlank(json.getString("id", null))) {
86  writeResponse(application, Projects.from(member)
87  .axAllParticipations(json.getString("id", null)).build());
88  } else {
89  writeResponse(application, Projects.from(member)
90  .axPendingParticipations().build());
91  }
92  } else if(AxConstants.AXPENDING_VALIDATE.equals(reason)) {
93  Projects.from(member).axValidatePending(Jsons.read(json.getObject("item").toString()));
94  } else if(AxConstants.AXPENDING_DELETE.equals(reason)) {
95  Projects.from(member).axDeleteParticipation(Jsons.read(json.getObject("item").toString()));
96  } else if(AxConstants.UPDATE_SERVER.equals(reason)) {
97  ImportFromMembers.connect(member);
98  writeResponse(application, Jsons.object().add("imported", true).build());
99  } else if(AxConstants.PROJECT_ITERATOR.equals(reason)) {
100  writeResponse(application, new ProjectProvider(member, reason, json)
101  .getData().build());
102  } else if(AxConstants.PROJECT_GRANT_ITERATOR.equals(reason)) {
103  writeResponse(application, new ProjectGrantProvider(member, reason, json)
104  .getData().build());
105  } else if(AxConstants.CATEGORY_ITERATOR.equals(reason)) {
106  writeResponse(application, new CategoryProvider(member, reason, json)
107  .getData().build());
108  } else if(AxConstants.PHASE_ITERATOR.equals(reason)) {
109  writeResponse(application, new PhaseProvider(member, reason, json)
110  .getData().build());
111  } else if(AxConstants.TAGS.equals(reason)) {
112  writeResponse(application, new TagProvider(member, reason, json)
113  .getData().build());
114  } else if(AxConstants.MEMBER_PREFERENCES.equals(reason)) {
115  writeResponse(application, new PreferencesProvider(member, reason, json)
116  .getData().build());
117  } else if(AxConstants.SAVE_PREFERENCES.equals(reason)) {
118  new AlliancePU().saveObject(AxMemberPreferences.fromJson(json.asJsonValue()));
119  } else if(AxConstants.BAN_STATUS.equals(reason)) {
120  writeResponse(application, Jsons.object()
121  .add("banned", Banned.of(member).status(json.getString("axId")))
122  .build());
123  } else if(AxConstants.BAN_TOGGLE.equals(reason)) {
124  writeResponse(application, Jsons.object()
125  .add("banned", Banned.of(member).toggle(json.getString("axId")))
126  .build());
127  } else if(AxConstants.AXPARTICIPATION_REQUESTED.equals(reason)) {
128  writeResponse(application, Jsons.object()
129  .add("requested", Projects.from(member).hasRequested(json))
130  .build());
131  } else if(AxConstants.AXPARTICIPATION_STATUS.equals(reason)) {
132  writeResponse(application, Jsons.object()
133  .add("participant", Projects.from(member).isParticipant(json))
134  .build());
135  } else if(AxConstants.AXPARTICIPATION_SAVE.equals(reason)) {
136  writeResponse(application, Jsons.object()
137  .add("participant", Projects.from(member).save(Jsons.read(json.getObject("item").toString())))
138  .build());
139  } else if(AxConstants.AXPARTICIPATION_ASK.equals(reason)) {
140  Projects.from(member).axAskParticipate(json);
141  writeResponse(application, Jsons.object()
142  .add("requested", true)
143  .build());
144  } else if(AxConstants.TALENT_CATEGORY.equals(reason)) {
145  AxTalentCategory cat = SqlClause.select("c").from("AxTalentCategory c")
146  .where().equal("c.categoryId", json.getLong("id"))
147  .dao(new AlliancePU())
148  .singleResult(AxTalentCategory.class);
149  if(cat != null) {
150  writeResponse(application, cat.toJson());
151  }
152  } else if(AxConstants.TALENT_CATEGORIES.equals(reason)) {
153  Jsons categories = Jsons.array();
154  SqlClause.select("c").from("AxTalentCategory c")
155  .orderBy("c.name")
156  .dao(new AlliancePU())
157  .resultList(AxTalentCategory.class).forEach(category -> {
158  categories.addValue(Jsons.read(category.toJson()));
159  });
160  writeResponse(application, categories.build());
161  } else {
162  writeResponse(application, "none");
163  }
164  }
165 
166 }
boolean toggle(String axId)
Definition: Banned.java:55
boolean status(String axId)
Definition: Banned.java:46
static Banned of(WsMember member)
Definition: Banned.java:81
Jsons axParticipations(String projectId, String as)
static Projects from(WsMember member)
Jsons axAllParticipations(String projectId)
void doProcess(Application application, KeyValueMap map, WsMember member, Jsons json, String reason)
Definition: AxServer.java:54
static AxMemberPreferences fromJson(JsonValue value)