BrightSide Workbench Full Report + Source Code
ContactSummary.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.command;
20 
21 import org.turro.action.IUserSummary;
22 import org.turro.action.UserSummaries;
23 import org.turro.annotation.UserSummary;
24 import org.turro.auth.Authentication;
25 import org.turro.commentit.CommentItUtil;
26 import org.turro.contacts.profile.ProfileContext;
27 import org.turro.elephant.context.Application;
28 import org.turro.elephant.context.IConstructor;
29 import org.turro.log.SystemLogger;
30 import org.turro.marker.ElephantMarker;
31 import org.turro.parser.ContactsParser;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.util.CompareUtil;
34 
39 @UserSummary
40 public class ContactSummary implements IUserSummary, Comparable<IUserSummary> {
41 
42  @Override
43  public String render(IConstructor constructor) {
44  ElephantMarker marker = new ElephantMarker(constructor);
46  return marker.parse("contact", "userSummary");
47  }
48 
49  @Override
50  public boolean isRequired() {
51  return false;
52  }
53 
54  @Override
55  public void init(IConstructor constructor) {
56  Long commentsCount = (Long) UserSummaries.getAttribute("commentsFullCount");
57  if(commentsCount == null) {
60  UserSummaries.setAttribute("pendingCommentsCount", Long.valueOf(CommentItUtil.countPending()));
61  UserSummaries.setAttribute("commentsFullCount", Long.valueOf(CommentItUtil.count()));
62  UserSummaries.setAttribute("contactFullCount", new ContactsParser().getCount(constructor, ""));
63  if(!contact.isOutsider()) {
64  UserSummaries.setAttribute("coworkersCount", contact.getCoworkers().size());
65  UserSummaries.setAttribute("logCount", SystemLogger.getInstance().getCountOf(null, null, null));
66  UserSummaries.setAttribute("loginCount", SystemLogger.getInstance().getCountOf(null, "/log/in", null));
67  UserSummaries.setAttribute("studentCount", ProfileContext.countStudents());
68  UserSummaries.setAttribute("possibleStudentCount", ProfileContext.countPossibleStudents());
69  UserSummaries.setAttribute("workerCount", ProfileContext.countStudents());
70  UserSummaries.setAttribute("possibleWorkerCount", ProfileContext.countPossibleWorkers());
71  UserSummaries.setAttribute("companyCount", ProfileContext.countCompanies());
72  UserSummaries.setAttribute("centerCount", ProfileContext.countCenters());
73  UserSummaries.setAttribute("fullStudentCount", ((long) UserSummaries.getAttribute("studentCount")) + ((long) UserSummaries.getAttribute("possibleStudentCount")));
74  UserSummaries.setAttribute("fullWorkerCount", ((long) UserSummaries.getAttribute("workerCount")) + ((long) UserSummaries.getAttribute("possibleWorkerCount")));
75  }
76  }
77  }
78 
79  @Override
80  public int getOrder() {
81  return 4;
82  }
83 
84  @Override
85  public int compareTo(IUserSummary o) {
86  int result = CompareUtil.compare(getOrder(), o.getOrder());
87  if(result == 0) {
88  result = CompareUtil.compare(getClass().getName(), o.getClass().getName());
89  }
90  return result;
91  }
92 
93 }
static void setAttribute(String attribute, Object value)
static Map< String, Object > getAttributes()
static Object getAttribute(String attribute)
String render(IConstructor constructor)
void init(IConstructor constructor)
static ISystemLogger getInstance()
String parse(String rootTmpl, String tmpl)
Long getCount(IConstructor constructor, String syndicationId)
long getCountOf(String comment, String logPath, Date since)