BrightSide Workbench Full Report + Source Code
CategoryJsonTree.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.client;
20 
21 import java.io.Writer;
22 import java.util.List;
23 import java.util.Objects;
24 import java.util.Optional;
25 import org.turro.alliance.service.AxConstants;
26 import org.turro.collections.Item;
27 import org.turro.elephant.context.IConstructor;
28 import org.turro.json.Jsons;
29 import org.turro.marker.ElephantMarker;
30 import org.turro.ws.WsServer;
31 import org.turro.ws.content.tree.JsonHtmlClientTree;
32 import org.turro.ws.service.WsConstants;
33 
38 public class CategoryJsonTree extends JsonHtmlClientTree<Long> {
39 
40  public CategoryJsonTree(WsServer server, IConstructor constructor, Writer writer) {
41  super(server, constructor, writer);
42  }
43 
44  @Override
45  protected void renderTree(ElephantMarker marker, List<Item<Jsons, Long>> items) {
46  marker.put("server", getServer());
47  marker.put("items", items);
48  marker.process(getTemplateRoot(), getTreeTemplate(), getWriter());
49  }
50 
51  @Override
52  protected void renderItem(ElephantMarker marker, Jsons item) {
53  //
54  }
55 
56  @Override
57  protected String reason() {
58  return AxConstants.CATEGORY_ITERATOR;
59  }
60 
61  @Override
62  protected Jsons criteria() {
63  return Jsons.object();
64  }
65 
66  @Override
67  protected Long getId(Jsons entity) {
68  return entity.getLong("categoryId");
69  }
70 
71  @Override
72  protected Long getParentId(Jsons entity) {
73  return Optional.ofNullable(entity.getObject("parent"))
74  .filter(parent -> !Jsons.isNull(parent))
75  .map(parent -> parent.getLong("categoryId"))
76  .orElse(null);
77  }
78 
79  @Override
80  protected Jsons getEntity(Long id) {
81  return flat().stream()
82  .filter(i -> Objects.equals(id, i.getId()))
83  .map(i -> i.getValue())
84  .findFirst().orElse(null);
85  }
86 
87  protected String getTemplateRoot() {
88  return "alliance/client/category";
89  }
90 }
void renderItem(ElephantMarker marker, Jsons item)
void renderTree(ElephantMarker marker, List< Item< Jsons, Long >> items)
CategoryJsonTree(WsServer server, IConstructor constructor, Writer writer)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)