BrightSide Workbench Full Report + Source Code
ParticipationAdapter.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 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.client.model;
20 
21 import java.util.Date;
22 import java.util.Objects;
23 import org.turro.alliance.client.Projects;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.json.JsonSearch;
27 import org.turro.json.Jsons;
28 import org.turro.ws.WsServer;
29 import org.turro.ws.service.WsConstants;
30 import org.turro.ws.service.member.Servers;
31 
36 public class ParticipationAdapter {
37 
38  private final WsServer server;
39  private final Long callingMember;
40  private final Jsons axParticipation;
41 
42  public ParticipationAdapter(WsServer server, Long callingMember, Jsons axParticipation) {
43  this.server = server;
44  this.callingMember = callingMember;
45  this.axParticipation = axParticipation;
46  }
47 
48  public WsServer getServer() {
49  return server;
50  }
51 
52  public Jsons getAxParticipation() {
53  return axParticipation;
54  }
55 
56  public boolean getBeneficiary() {
57  return axParticipation.getBoolean("beneficiary");
58  }
59 
60  public boolean getOfferer() {
61  return axParticipation.getBoolean("offerer");
62  }
63 
64  public boolean getConsortium() {
65  return axParticipation.getBoolean("consortium");
66  }
67 
68  public Date getCreation() {
69  return axParticipation.getDate("creation");
70  }
71 
72  public String getRequesterName() {
73  return axParticipation.getString("memberName");
74  }
75 
76  public String getReceiverName() {
77  return Servers.getElephantString(server.getServerDomain(), WsConstants.MEMBER_TRADENAME,
78  Jsons.object().add("memberId", JsonSearch.of(axParticipation).read("$.relation.mainMemberId", Long.class)));
79  }
80 
81  public String getProjectDescription() {
82  JsonSearch axp = JsonSearch.of(axParticipation);
83  if(Objects.equals(callingMember, axp.read("$.relation.mainMemberId", Long.class))) {
84  return new DossierPU().find(Dossier.class, axp.read("$.relation.mainEntityId", Long.class)).getDescription();
85  } else {
86  return Projects.from(server).project(projectId(axp)).getString("name");
87  }
88  }
89 
90  public <T> T getRequest() {
91  return JsonSearch.of(axParticipation).silent().root();
92  }
93 
94  private String projectId(JsonSearch axp) {
95  return axp.read("$.relation.mainEntityId") +
96  "##" +
97  axp.read("$.relation.mainMemberId", Integer.class);
98  }
99 
100 }
static Projects from(WsServer server)
ParticipationAdapter(WsServer server, Long callingMember, Jsons axParticipation)
String getServerDomain()
Definition: WsServer.java:52