BrightSide Workbench Full Report + Source Code
ProjectsVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.List;
22 import org.turro.alliance.db.AlliancePU;
23 import org.turro.alliance.service.AxConstants;
24 import org.turro.alliance.service.AxServer;
25 import org.turro.jpa.Dao;
26 import org.turro.json.Jsons;
27 import org.turro.member.db.entities.AxProjectCategory;
28 import org.turro.sql.SqlClause;
29 import org.turro.ws.WsServer;
30 import org.turro.ws.service.member.Servers;
31 import org.zkoss.bind.annotation.Command;
32 import org.zkoss.bind.annotation.NotifyChange;
33 
38 public class ProjectsVM {
39 
40  public boolean isNeedsSave() {
41  return needsSave;
42  }
43 
44  public void setNeedsSave(boolean needsSave) {
45  this.needsSave = needsSave;
46  }
47 
48  @NotifyChange("model")
49  @Command("add")
50  public void add() {
51  if(server != null) {
53  pc.setServerDomain(server.getServerDomain());
54  model.add(pc);
55  needsSave = true;
56  }
57  }
58 
59  @NotifyChange("model")
60  @Command("save")
61  public void save() {
62  Dao dao = new AlliancePU();
63  model.stream().filter(pc -> pc.isEmpty())
64  .forEach(pc -> dao.deleteEntity(pc));
65  model.removeIf(pc -> pc.isEmpty());
66  dao.saveEntities(model);
67  needsSave = false;
68  }
69 
70  /* Model */
71 
72  private boolean needsSave;
73 
74  private List<AxProjectCategory> model;
75 
76  public List<AxProjectCategory> getModel() {
77  if(model == null) {
78  model = SqlClause.select("pc").from("AxProjectCategory pc")
79  .dao(new AlliancePU())
80  .resultList(AxProjectCategory.class);
81  }
82  return model;
83  }
84 
85  /* Server */
86 
87  private WsServer server;
88 
89  public WsServer getServer() {
90  return server;
91  }
92 
93  public void setServer(WsServer server) {
94  this.server = server;
95  }
96 
97  public Jsons getCategories(AxProjectCategory pc) {
98  return Servers.getData(WsServer.from(pc.getServerDomain(), AxServer.SERVER_SERVICE), AxConstants.CATEGORIES);
99  }
100 
101 }
102 
Jsons getCategories(AxProjectCategory pc)
Definition: ProjectsVM.java:97
List< AxProjectCategory > getModel()
Definition: ProjectsVM.java:76
static final String SERVER_SERVICE
Definition: AxServer.java:51
void deleteEntity(IDaoEntity entity)
Definition: Dao.java:168
void saveEntities(Collection<? extends IDaoEntity > entities)
Definition: Dao.java:133
static WsServer from(String serverDomain, String service)
Definition: WsServer.java:149
String getServerDomain()
Definition: WsServer.java:52