BrightSide Workbench Full Report + Source Code
AllianceHelper.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.iterator;
20 
21 import java.util.List;
22 import org.turro.alliance.client.Projects;
23 import org.turro.alliance.service.AxServer;
24 import org.turro.alliance.service.AxClient;
25 import org.turro.annotation.ElephantHelper;
26 import org.turro.elephant.db.ElephantPU;
27 import org.turro.json.JsonSearch;
28 import org.turro.json.Jsons;
29 import org.turro.marker.IElephantHelper;
30 import org.turro.sql.SqlClause;
31 import org.turro.ws.WsMember;
32 import org.turro.ws.WsServer;
33 import org.turro.ws.service.WsConstants;
34 import org.turro.ws.service.member.Servers;
35 
41 public class AllianceHelper implements IElephantHelper {
42 
43  @Override
44  public String getName() {
45  return "alliance";
46  }
47 
48  public List<WsServer> getServers() {
49  return SqlClause.select("s").from("WsServer s")
50  .where().equal("s.service", AxServer.SERVER_SERVICE)
51  .dao(new ElephantPU())
52  .resultList(WsServer.class);
53  }
54 
55  public Jsons getJsonServers() {
56  Jsons servers = Jsons.array();
57  getServers().forEach(server -> servers.addValue(Jsons.read(server.toJson())));
58  return servers;
59  }
60 
61  public List<WsMember> getMembers() {
62  return SqlClause.select("m").from("WsMember m")
63  .where().equal("m.service", AxClient.CLIENT_SERVICE)
64  .dao(new ElephantPU())
65  .resultList(WsMember.class);
66  }
67 
68  public Jsons getJsonMembers() {
69  Jsons members = Jsons.array();
70  getMembers().forEach(member -> members.addValue(Jsons.read(member.toJson())));
71  return members;
72  }
73 
74  public String getMemberFace(String serverDomain, Long memberId) {
75  return Servers.getElephantString(serverDomain, WsConstants.MEMBER_FACE,
76  Jsons.object().add("memberId", memberId));
77  }
78 
79  public String getMemberName(String serverDomain, Long memberId) {
80  return Servers.getElephantString(serverDomain, WsConstants.MEMBER_NAME,
81  Jsons.object().add("memberId", memberId));
82  }
83 
84  public <T> T getAxParticipations(WsServer server, String axId) {
85  return JsonSearch.of(Projects.from(server).axParticipations(axId)).silent().root();
86  }
87 
88  public <T> T getAxParticipations(WsServer server, String axId, String as) {
89  return JsonSearch.of(Projects.from(server).axParticipations(axId, as)).silent().root();
90  }
91 
92 }
static Projects from(WsServer server)
String getMemberName(String serverDomain, Long memberId)
String getMemberFace(String serverDomain, Long memberId)
static final String CLIENT_SERVICE
Definition: AxClient.java:58
static final String SERVER_SERVICE
Definition: AxServer.java:51