BrightSide Workbench Full Report + Source Code
RequestsVM.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.model;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.turro.alliance.service.AxConstants;
24 import org.turro.alliance.service.AxServer;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.json.Jsons;
27 import org.turro.ws.service.member.Servers;
28 import org.zkoss.bind.annotation.BindingParam;
29 import org.zkoss.bind.annotation.Command;
30 import org.zkoss.bind.annotation.ExecutionArgParam;
31 import org.zkoss.bind.annotation.Init;
32 import org.zkoss.bind.annotation.NotifyChange;
33 import org.zkoss.zk.ui.Executions;
34 
39 public class RequestsVM {
40 
41  private Dossier dossier;
42 
43  @Init
44  public void init(@ExecutionArgParam("dossier") Dossier dossier) {
45  if(dossier != null) this.dossier = dossier;
46  if(this.dossier == null) {
47  this.dossier = (Dossier) Executions.getCurrent().getAttribute("dossier");
48  }
49  }
50 
51  @NotifyChange("model")
52  @Command("validate")
53  public void validate(@BindingParam("request") RequestAdapter request) {
54  Servers.getData(request.getServer(), AxConstants.AXPENDING_VALIDATE,
55  Jsons.object().add("item", request.getAxPending().asJsonValue()));
56  model = null;
57  }
58 
59  @NotifyChange("model")
60  @Command("delete")
61  public void delete(@BindingParam("request") RequestAdapter request) {
62  Servers.getData(request.getServer(), AxConstants.AXPENDING_DELETE,
63  Jsons.object().add("item", request.getAxPending().asJsonValue()));
64  model = null;
65  }
66 
67  @NotifyChange("model")
68  @Command("save")
69  public void save(@BindingParam("request") RequestAdapter request) {
70  Servers.getData(request.getServer(), AxConstants.AXPARTICIPATION_SAVE,
71  Jsons.object().add("item", request.getAxPending().asJsonValue()));
72  model = null;
73  }
74 
75  /* Model */
76 
77  private List<RequestAdapter> model;
78 
79  public List<RequestAdapter> getModel() {
80  if(model == null) {
81  model = new ArrayList<>();
82  Servers.getServers(AxServer.SERVER_SERVICE).forEach(server -> {
83  Jsons request = Jsons.object();
84  if(dossier != null) {
85  request.add("id", String.valueOf(dossier.getId()));
86  }
87  Jsons requests = Servers.getData(server, AxConstants.AXPENDING_REQUESTS, request);
88  if(!Jsons.isEmpty(requests)) requests.getStructure().asArray().forEach(axr -> {
89  model.add(new RequestAdapter(server, Jsons.read(axr.toString())));
90  });
91  });
92  }
93  return model;
94  }
95 
96 }
void save(@BindingParam("request") RequestAdapter request)
Definition: RequestsVM.java:69
void validate(@BindingParam("request") RequestAdapter request)
Definition: RequestsVM.java:53
void init(@ExecutionArgParam("dossier") Dossier dossier)
Definition: RequestsVM.java:44
void delete(@BindingParam("request") RequestAdapter request)
Definition: RequestsVM.java:61
static final String SERVER_SERVICE
Definition: AxServer.java:51