BrightSide Workbench Full Report + Source Code
AxP2PServer.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.service;
20 
21 import org.turro.attach.search.Attachments;
22 import org.turro.attach.zul.AttachmentUtil;
23 import org.turro.collections.KeyValueMap;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.elephant.context.Application;
27 import org.turro.json.Jsons;
28 import org.turro.reflection.stub.Stubs;
29 import org.turro.security.SecurityGroup;
30 import org.turro.sql.SqlClause;
31 import org.turro.util.Converter;
32 import org.turro.visual.DossierJsonVisualFilter;
33 import org.turro.ws.service.IWsService;
34 import org.turro.ws.service.WsService;
35 import org.turro.ws.service.p2p.SecuredP2PService;
36 
41 @WsService(path = AxP2PServer.AX_P2P_SERVICE, name = "Alliance P2P Server")
42 public class AxP2PServer extends SecuredP2PService implements IWsService {
43 
44  public static final String AX_P2P_SERVICE = "/axp2pserver";
45 
46  @Override
47  protected void doProcess(Application application, KeyValueMap map, Jsons json, String reason) {
48  if(AxConstants.PROJECT.equals(reason)) {
49  Dossier project = SqlClause.select("d").from("Dossier d")
50  .where().equal("id", Converter.STANDARD.convert(json.getString("projectId"), Long.class))
51  .dao(new DossierPU())
52  .singleResult(Dossier.class);
53  if(project != null) {
54  writeJsonResponse(application,
56  .filter(Stubs.jsonverb(project)));
57  }
58  } else if(AxConstants.ATTACHMENTS.equals(reason)) {
59  writeJsonResponse(application, Attachments.from("/dossier/" + json.getString("projectId"))
60  .onlyPublic().banRestricted().getTree().toJson());
61  } else if(AxConstants.ATTACHMENT.equals(reason)) {
62  AttachmentUtil.respond(respond(application), json.getLong("attachId"));
63  }
64  }
65 
66 }
void doProcess(Application application, KeyValueMap map, Jsons json, String reason)
static Attachments from(String path)
static boolean respond(Respond respond, Long id)
static JsonVisualFilter from(String securityGroup)