BrightSide Workbench Full Report + Source Code
LastActivityContentProvider.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.StringWriter;
22 import java.io.Writer;
23 import org.amic.util.date.CheckDate;
24 import org.turro.action.content.AbstractContentProvider;
25 import org.turro.action.content.ContentContext;
26 import org.turro.action.content.ContentRenderer;
27 import org.turro.action.content.IContentIterator;
28 import org.turro.activity.ContactActivityMap;
29 import org.turro.activity.LastActivities;
30 import org.turro.annotation.ContentProvider;
31 import org.turro.command.MacroCommand;
32 import org.turro.elephant.context.HeadlessApplication;
33 import org.turro.plugin.contacts.IContact;
34 
39 @ContentProvider
41 
43  addCommands();
44  }
45 
46  private void addCommands() {
47  MacroCommand mc = new MacroCommand("last-activity");
48  mc.addParameter("context", "", true);
49  mc.addParameter("count", Integer.valueOf(50), true);
50  mc.addParameter("days", Integer.valueOf(7), true);
51  mc.addParameter("path", "", true);
52  mc.addParameter("template", "summary", true);
53  commands.add(mc);
54  }
55 
56  @Override
57  public ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext) {
58  if(macroCommand.itsMe("last-activity(")) {
61  new CheckDate().addDays(
62  -(macroCommand.getParameterValue(Integer.class, "days"))
63  ).getDate(),
64  macroCommand.getParameterValue(String.class, "path"), null);
65  });
66  StringWriter sw = new StringWriter();
67  //TODO: Call to LastActivities needs to be cached
70  sw, contact, cam,
71  true, macroCommand.getParameterValue(String.class, "context"));
72  di.setPage(macroCommand.getParameterValue(Integer.class, "count"));
73  di.setAllowAttachments(true);
74  di.setAllowDescriptions(true);
75  di.setAllowInterest(true);
76  di.setAllowVotes(true);
77  di.setAllowComments(true);
78  di.setAllowPolls(true);
79  di.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
80  di.setNavigatorTop(false);
81  di.setNavigatorBottom(false);
82  di.load();
83  return new ContentRenderer(macroCommand, di, sw, (IContentIterator iterator, Writer writer) -> {
84  iterator.render();
85  return writer.toString();
86  });
87  }
88  return null;
89  }
90 
91 }
static Object getContent(String context, Supplier onDefault)
static ContactActivityMap getLastActivitySession(Date from, String entityPath, String type)
ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext)