19 package org.turro.alliance.content.control;
21 import java.util.Collections;
22 import org.turro.action.Contacts;
23 import org.turro.action.MailSenders;
24 import org.turro.alliance.client.Projects;
25 import static org.turro.alliance.content.control.ProjectAction.TOGGLE_BAN;
26 import org.turro.alliance.service.AxConstants;
27 import org.turro.auth.Authentication;
28 import org.turro.collections.KeyValueMap;
29 import org.turro.elephant.context.IConstructor;
30 import org.turro.elephant.direct.AbstractDirectContentCtrl;
31 import org.turro.elephant.direct.DirectContent;
32 import org.turro.i18n.I_;
33 import org.turro.json.Jsons;
34 import org.turro.mail.json.JsonMailStructure;
35 import org.turro.marker.ElephantMarker;
36 import org.turro.plugin.contacts.CompoundId;
37 import org.turro.plugin.contacts.IContact;
38 import org.turro.ws.WsServer;
39 import org.turro.ws.WsServerPK;
40 import org.turro.ws.service.WsConstants;
41 import org.turro.ws.service.member.Servers;
42 import org.turro.ws.service.p2p.P2PServer;
43 import org.turro.ws.service.p2p.P2Ps;
49 @DirectContent(identifier=
"axproject-action")
54 private String axId, particiationLabel;
57 super(
"widgets/alliance/project");
67 setTemplate(action.toString().replaceAll(
"_",
"-").toLowerCase());
75 this.particiationLabel = particiationLabel;
81 marker.
put(
"checkLink", getAjaxUrl((String) marker.
get(
"domid"), map));
88 addContainerId(marker,
true);
91 KeyValueMap kvm =
new KeyValueMap(Collections.EMPTY_MAP);
92 kvm.put(
"type",
"click");
95 kvm.put(
"action", action.name());
96 kvm.put(
"axId", axId);
99 marker.
put(
"banned", Boolean.toString(isBanned()));
101 case PARTICIPATE -> {
102 marker.
put(
"participationLabel", particiationLabel);
103 marker.
put(
"participant", isParticipant(contact.
getId()));
104 marker.
put(
"requested", Boolean.toString(hasRequested(contact.
getId())));
105 kvm.put(
"contactId", contact.
getId());
106 kvm.put(
"as", particiationLabel);
109 marker.
put(
"checkLink", getAjaxUrl((String) marker.
get(
"containerId"), kvm));
113 private boolean isBanned() {
114 Jsons response = Servers.getData(server,
AxConstants.BAN_STATUS, Jsons.object().add(
"axId", axId));
115 if(!Jsons.isEmpty(response)) {
116 return response.getBoolean(
"banned");
122 private boolean hasRequested(String contactId) {
123 return Projects.from(server).hasRequested(axId, contactId, particiationLabel).getBoolean(
"requested");
126 private boolean isParticipant(String contactId) {
127 return Projects.from(server).status(axId, contactId, particiationLabel).getBoolean(
"participant");
139 String type = map.get(
"type");
140 if(
"click".equals(type)) {
141 processClick(constructor, map);
145 private void processClick(
IConstructor constructor, KeyValueMap map) {
149 map.put(
"banned", Boolean.toString(toggleBanned(map)));
151 case PARTICIPATE -> {
152 map.put(
"requested", Boolean.toString(askParticipate(map)));
155 writeMarkerToResponse(constructor, map);
160 Jsons response = Servers.getData(server,
AxConstants.BAN_TOGGLE, Jsons.object().add(
"axId", map.get(
"axId")));
161 if(!Jsons.isEmpty(response)) {
162 return response.getBoolean(
"banned");
174 Jsons response = Servers.getData(server,
AxConstants.AXPARTICIPATION_ASK, Jsons.object()
175 .add(
"as", map.get(
"as"))
176 .add(
"axId", map.get(
"axId"))
177 .add(
"contactId", contact.
getId())
178 .add(
"contactName", contact.
getName())
180 .add(
"companyId", business.
getId())
181 .add(
"companyName", business.
getName())
184 if(!Jsons.isEmpty(response) && response.getBoolean(
"requested")) {
186 P2PServer.P2P_SERVICE, WsConstants.SEND_EMAIL, Jsons.object(Jsons.read(
188 .message(
I_.
format(
"%s has requested to participate as %s in a project", contact.
getName(), map.get(
"as")))
194 I_.
format(
"%s has requested to participate as %s in an outside project", contact.
getName(), map.get(
"as")));
static IMailSender getPool()
boolean askParticipate(KeyValueMap map)
boolean toggleBanned(KeyValueMap map)
void setServer(WsServer server)
void prepareMarker(ElephantMarker marker)
void prepareCleanMarker(ElephantMarker marker, KeyValueMap map)
void setAxId(String axId)
void setAction(ProjectAction action)
void setParticiationLabel(String particiationLabel)
void doExecute(IConstructor constructor, KeyValueMap map)
static IContact getIContact()
static String format(String msg, Object... arguments)
Object put(Object key, Object value)
static WsServerPK from(String serverDomain, String service)