BrightSide Workbench Full Report + Source Code
ConvocationCheck.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.www.convocation;
20 
21 import org.turro.string.Strings;
22 import org.turro.action.Contacts;
23 import org.turro.collections.KeyValueMap;
24 import org.turro.contacts.Convocation;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.marker.ElephantMarker;
28 import org.turro.marker.MarkerHelper;
29 import org.turro.plugin.contacts.IContact;
30 
35 public class ConvocationCheck {
36 
37  private final IConstructor constructor;
38  private String template;
39  private Convocation convocation;
40  private IContact contact;
41 
42  public ConvocationCheck(IConstructor constructor) {
43  this.constructor = constructor;
44  }
45 
46  public void setTemplate(String template) {
47  this.template = template;
48  }
49 
50  public String check() {
51  KeyValueMap kvm = MarkerHelper.getObfuscatedParameters();
52  if(kvm != null) {
53  convocation = new ContactsPU().find(Convocation.class, kvm.get("item"));
54  contact = Contacts.getContactById(kvm.get("contact"));
55  }
56  if(convocation != null && contact != null && contact.isValid()) {
57  return getMarker().parse("convocation", Strings.isBlank(template) ? "check" : template);
58  }
59  return "";
60  }
61 
62  private ElephantMarker getMarker() {
63  ElephantMarker marker = new ElephantMarker(constructor);
64  marker.put("actions", this);
65  marker.put("contact", contact);
66  marker.put("convocation", convocation);
67  return marker;
68  }
69 
70 }
static IContact getContactById(String id)
Definition: Contacts.java:72
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static KeyValueMap getObfuscatedParameters()