BrightSide Workbench Full Report + Source Code
MyContactsDashboard.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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.contacts.www;
20 
21 import java.io.IOException;
22 import javax.servlet.ServletException;
23 import org.turro.string.Strings;
24 import org.turro.action.Contacts;
25 import org.turro.action.MyContacts;
26 import org.turro.contacts.db.ContactsPU;
27 import org.turro.elephant.context.IElement;
28 import org.turro.elephant.impl.abstracts.AbstractElement;
29 import org.turro.elephant.impl.context.AttributeItem;
30 import org.turro.elephant.layout.IManageable;
31 import org.turro.elephant.layout.IRenderable;
32 import org.turro.elephant.security.IDefendable;
33 import org.turro.file.util.FileAttach;
34 import org.turro.marker.ElephantMarker;
35 import org.turro.plugin.contacts.ContactSortedSet;
36 import org.turro.plugin.contacts.IContact;
37 
43 
44  protected String sclass, fullTemplate, summaryTemplate;
45  protected int count;
46  protected IContact contact;
47  protected String item;
48  protected String searchValue;
49  protected ContactSortedSet set;
50 
51  @Override
52  public void loadData() throws ServletException, IOException {
53  sclass = getAttributes().getAttributeValue("attrib:sclass", "");
54  fullTemplate = getAttributes().getAttributeValue("attrib:fullTemplate", "");
55  summaryTemplate = getAttributes().getAttributeValue("attrib:summaryTemplate", "");
56 
58 
59  item = getConstructor().getParameter("item");
60 
61  if(!Strings.isBlank(item)) {
63  }
64 
65  if(contact != null) {
67  set = null;
68  } else {
69  item = null;
71  }
72  }
73 
74  @Override
75  public void startConstruction() throws ServletException, IOException {
76 
78  marker.put("searchValue", searchValue);
79  if(!Strings.isBlank(item)) {
80  prepareValues(marker, contact, 0);
81  marker.put("contact", contact.getContact());
82  marker.process("contact", getFullTemplate());
83  } else if(set.isEmpty()) {
84  marker.put("divider", false);
85  marker.put("header", true);
86  marker.put("footer", true);
87  marker.put("empty", true);
88  marker.process("contact", getSummaryTemplate());
89  } else {
90  int index = 0;
91  marker.put("empty", false);
92  for(IContact c : set) {
93  marker.put("divider", index > 0);
94  marker.put("header", index == 0);
95  marker.put("footer", index == set.size() - 1);
96  prepareValues(marker, c, 0);
97  marker.put("contact", c.getContact());
98  marker.process("contact", getSummaryTemplate());
99  index++;
100  }
101  }
102 
103  }
104 
105  @Override
106  public String getStart() {
107  return "<div class='" + sclass + "dossier-web'>";
108  }
109 
110  @Override
111  public String getEnd() {
112  return "</div>";
113  }
114 
115  private void prepareValues(ElephantMarker marker, IContact c, int page) {
116 
117  String link = getItemLink(c, page);
118  if(link != null) {
119  marker.put("path", link);
120  marker.put("all", getPageLink(page));
121  }
122  marker.put("readall", getItemLink(c, page));
123 
124  marker.put("files", new FileAttach(ContactsPU.getObjectPath(c.getContact())));
125 
126  }
127 
128  private String getItemLink(IContact c, int page) {
129  return getContext().getFullPath() + "?item=" + c.getId() + "&page=" + page;
130  }
131 
132  private String getPageLink(int page) {
133  return getContext().getFullPath() + "?page=" + page;
134  }
135 
136 
137  private String getSummaryTemplate() {
138  return Strings.isBlank(summaryTemplate) ? "mySummary" : summaryTemplate;
139  }
140 
141  private String getFullTemplate() {
142  return Strings.isBlank(fullTemplate) ? "myFull" : fullTemplate;
143  }
144 
145 }
static IContact getContactById(String id)
Definition: Contacts.java:72
static ContactSortedSet myContacts(IConstructor constructor, String search)
Definition: MyContacts.java:34
static String getObjectPath(Object object)
Definition: ContactsPU.java:68
static AttributeItem getFromParameter(IConstructor constructor, String name, String defaultValue)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)