BrightSide Workbench Full Report + Source Code
AllianceEntityInfo.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.content;
20 
21 import java.io.IOException;
22 import java.io.Writer;
23 import java.util.HashMap;
24 import org.turro.action.EntitiesInfo;
25 import org.turro.action.EntityInfoType;
26 import org.turro.action.IEntityInfo;
27 import org.turro.action.LinkType;
28 import org.turro.annotation.EntityInfo;
29 import org.turro.json.Jsons;
30 import org.turro.log.WebLoggers;
31 import org.turro.path.Path;
32 import org.turro.util.Converter;
33 import org.turro.ws.service.WsConstants;
34 import org.turro.ws.service.p2p.P2PServer;
35 import org.turro.ws.service.p2p.P2Ps;
36 
42 public class AllianceEntityInfo implements IEntityInfo {
43 
44  @Override
45  public boolean writeEntityInfo(Writer out, Path path, EntityInfoType type, LinkType link) {
46  if("axparticipation".equals(path.getRoot())) {
47  try {
48  String[] nodes = path.getNode(1).split("__");
49  Jsons ud = P2Ps.getP2PData(path.getFrom(2).substring(1), Converter.STANDARD.convert(nodes[1], Long.class),
50  P2PServer.P2P_SERVICE, WsConstants.USER_DATA, Jsons.object().add("userId", nodes[0]));
51  HashMap<String, Object> args = new HashMap<>();
52  args.put("entityPath", path.getPath());
53  args.put("resolver", this);
54  args.put("name", ud.getString("userName"));
55  args.put("email", ud.getString("userEmail"));
56  out.write(EntitiesInfo.getString(null, null, "alliance/client/participation", type, link, args));
57  return true;
58  } catch (IOException ex) {
59  WebLoggers.severe(this).exception(ex).log();
60  }
61  }
62  return false;
63  }
64 
65  @Override
66  public String resolveLink(String link) {
67  return null;
68  }
69 
70 }
static String getString(Object entity, Object wrapper, String label, EntityInfoType type, LinkType link)
boolean writeEntityInfo(Writer out, Path path, EntityInfoType type, LinkType link)
static WebLoggers severe(Object entity)
Definition: WebLoggers.java:51
WebLoggers exception(Throwable throwable)
Definition: WebLoggers.java:29