BrightSide Workbench Full Report + Source Code
LastActivityIterator.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.jpa.content;
20 
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26 import org.turro.string.Strings;
27 import org.turro.activity.ContactActivityMap;
28 import org.turro.activity.EntityActivitySet;
29 import org.turro.activity.IEntityLastActivity;
30 import org.turro.elephant.context.IConstructor;
31 import org.turro.entities.Entities;
32 import org.turro.entities.IElephantEntity;
33 import org.turro.marker.ElephantMarker;
34 import org.turro.plugin.contacts.IContact;
35 
40 public class LastActivityIterator extends EntityItemContentIterator<IEntityLastActivity, Object> {
41 
42  private String lastReason, lastEntity;
43  private IElephantEntity lastIee, lastMain;
44 
45  public LastActivityIterator(IConstructor constructor, Writer writer, IContact contact, EntityActivitySet activity, boolean mail, String pubPath) {
46  super(new ArrayList(activity), constructor, writer, contact, mail, pubPath);
47  }
48 
49  public LastActivityIterator(IConstructor constructor, Writer writer, IContact contact, ContactActivityMap cam, boolean mail, String pubPath) {
50  super(getLastActivity(contact, cam), constructor, writer, contact, mail, pubPath);
51  }
52 
53  @Override
54  protected void renderSummary(ElephantMarker marker, IEntityLastActivity e, int page) {
55  if(e != null) {
56  String current = e.getEntityPath();
57  IElephantEntity iee = e.getEntity();
58  IElephantEntity iMain = e.getMainEntity();
59  boolean newMain = !iee.getStringId().equals(iMain.getStringId()) &&
60  !(lastIee != null && iMain.getStringId().equals(lastIee.getStringId())) &&
61  (lastMain == null || !iMain.getStringId().equals(lastMain.getStringId()));
62  if(newMain) {
63  lastEntity = null;
64  }
65  boolean newEntity = !current.equals(lastEntity);
66  if(newEntity) {
67  lastReason = null;
68  }
69  String reason = e.getReason();
70  boolean newReason = reason != null && !reason.equals(lastReason);
71  if(iee.canPublish(getContact()) && iee.canShowInContext(getContact(), e.getActivity())) {
72  marker.put("last", e);
73  marker.put("iee", iee);
74  marker.put("main", iMain.getStringId().equals(IElephantEntity.EMPTY_ID) ? null : iMain);
75  marker.put("previous", lastIee);
76  marker.put("newMain", newMain);
77  marker.put("newEntity", newEntity);
78  marker.put("newReason", newReason);
79  marker.put("reason", reason);
80  lastMain = iMain;
81  lastEntity = current;
82  lastReason = reason;
83  lastIee = iee;
84  prepareValues(e, page);
85  marker.process(getTemplateRoot(), getSummaryTemplate(), getWriter());
86  }
87  }
88  }
89 
90  @Override
91  protected void renderItem(ElephantMarker marker, IEntityLastActivity e, int page) {
92  marker.put("activity", e);
93  prepareValues(e, page);
94  marker.process(getTemplateRoot(), getFullTemplate(), getWriter());
95  }
96 
97  @Override
98  protected IEntityLastActivity entity(Object value) {
99  return null;
100  }
101 
102  private void prepareValues(IEntityLastActivity activity, int page) {
103  prepareControls(activity, page);
104  }
105 
106  @Override
107  protected String title(IEntityLastActivity e) {
109  }
110 
111  @Override
112  protected Collection<String> metas(IEntityLastActivity e) {
113  return Collections.EMPTY_LIST;
114  }
115 
116  @Override
117  protected String getTemplateRoot() {
118  return isMail() ? "content/newsletter/sections/lastactivity" : "activity";
119  }
120 
121  @Override
122  protected Object doVotesCtrl(IEntityLastActivity e) {
123  return null;
124  }
125 
126  @Override
127  protected Object doInterestCtrl(IEntityLastActivity e) {
128  return null;
129  }
130 
131  @Override
132  protected Object doCommentsCtrl(IEntityLastActivity e) {
133  return null;
134  }
135 
136  @Override
138  return null;
139  }
140 
141  @Override
142  protected Object doFilesCtrl(IEntityLastActivity e) {
143  return null;
144  }
145 
146  @Override
148  return null;
149  }
150 
151  @Override
152  protected Object doPollsCtrl(IEntityLastActivity e) {
153  return null;
154  }
155 
156  @Override
157  protected String getItemLink(IEntityLastActivity e) {
158  return getReadAllLink();
159  }
160 
161  @Override
162  protected String getReadAllLink() {
163  if(Strings.isBlank(getContextPath())) {
164  return getRestrictedLink();
165  }
166  return getContextPath();
167  }
168 
169  @Override
170  protected String getRestrictedLink() {
171  return "/user/lastactivities";
172  }
173 
174  private static List getLastActivity(IContact contact, ContactActivityMap cam) {
175  EntityActivitySet eas = cam.get(contact.getId());
176  return eas != null ? new ArrayList(eas) : Collections.EMPTY_LIST;
177  }
178 
179 }
180 
static IElephantEntity getController(String path)
Definition: Entities.java:78
Object doDescriptionsCtrl(IEntityLastActivity e)
void renderItem(ElephantMarker marker, IEntityLastActivity e, int page)
IEntityLastActivity entity(Object value)
void renderSummary(ElephantMarker marker, IEntityLastActivity e, int page)
Collection< String > metas(IEntityLastActivity e)
LastActivityIterator(IConstructor constructor, Writer writer, IContact contact, EntityActivitySet activity, boolean mail, String pubPath)
LastActivityIterator(IConstructor constructor, Writer writer, IContact contact, ContactActivityMap cam, boolean mail, String pubPath)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
boolean canShowInContext(IContact contact, Object relatedEntity)
boolean canPublish(IContact contact)