BrightSide Workbench Full Report + Source Code
ElephantParser.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.parser;
20 
21 import org.turro.activity.ActivitySummary;
22 import org.turro.string.ObjectString;
23 import org.turro.string.Strings;
24 import org.turro.activity.LastActivities;
25 import org.turro.annotation.ExternalParser;
26 import org.turro.anonymous.AnonymousCtrl;
27 import org.turro.auth.Authentication;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.entities.graph.EntityGraph;
30 import org.turro.jpa.content.LastActivityIterator;
31 import org.turro.plugin.contacts.IContact;
32 import org.turro.polls.PollIterator;
33 import org.turro.timetracker.TimeTrackerCtrl;
34 
39 @ExternalParser
40 public class ElephantParser extends AbstractParser {
41 
42  @Override
43  public String getParserName() {
44  return "Elephant";
45  }
46 
47  @Override
48  protected boolean doExecute() {
49  boolean done = false;
50  if("polls".equals(getMacroName()) || "poll-list".equals(getMacroName())) {
51  boolean grouped = "polls".equals(getMacroName());
53  pi.setNavigatorTop(grouped);
54  pi.setNavigatorBottom(grouped);
55  pi.setPublicOnly("true".equals(getToken(2)));
56  pi.setRestricted(true);
57  pi.setPage((Integer) ObjectString.parseNativeString(getToken(1), Integer.class, true));
58  pi.load();
59  pi.render();
60  done = true;
61  } else if("time-tracker".equals(getMacroName())) {
62  TimeTrackerCtrl ttc = new TimeTrackerCtrl();
63  if(getTokenSize() == 2) {
64  out.write(ttc.createRightNowURL("redir=/user/timetracker;type=entity;entityPath=" + getToken(1)));
65  } else {
66  ttc.render(constructor);
67  }
68  done = true;
69  } else if("anonymous".equals(getMacroName())) {
70  AnonymousCtrl anonymous = new AnonymousCtrl();
71  anonymous.renderAnswerForm(constructor);
72  done = true;
73  } else if("last-activity".equals(getMacroName()) || "last-activity-summary".equals(getMacroName())) {
77  false, Strings.isBlank(getToken(1)) ? null : ElephantContext.getRootWebPath() + getToken(2));
78  dci.setPage((Integer) ObjectString.parseNativeString(getToken(2), Integer.class, true));
79  if(getMacroName().contains("summary")) {
80  dci.setNavigatorTop(false);
81  dci.setNavigatorBottom(false);
82  }
83  dci.setSummaryTemplate(getToken(3));
84  dci.render();
85  done = true;
86  } else if("entity-graph".equals(getMacroName())) {
88  done = true;
89  } else if("activity-summary".equals(getMacroName())) {
91  done = true;
92  }
93  return done;
94  }
95 
96  @Override
97  protected void explainMacros(ParserMacroSet macros) {
98  macros.addMacro("polls")
99  .addParameter("count", true, "10")
100  .addParameter("public", true, "true");
101  macros.addMacro("poll-list")
102  .copyParametersFrom("polls", macros);
103  macros.addMacro("time-tracker")
104  .addParameter("entityPath", true);
105  macros.addMacro("anonymous");
106  macros.addMacro("last-activity")
107  .addParameter("context", true)
108  .addParameter("count", true, "10")
109  .addParameter("template", true, "summary");
110  macros.addMacro("last-activity-summary")
111  .copyParametersFrom("last-activity", macros);
112  }
113 
114 }
static void render(IConstructor constructor)
static EntityActivitySet getLastActivity(IContact contact)
void renderAnswerForm(IConstructor constructor)
static void DOT(Writer writer)
void explainMacros(ParserMacroSet macros)
ParserMacro addMacro(String macroName)
void copyParametersFrom(String macroName, ParserMacroSet macros)
ParserMacro addParameter(String name, boolean optional)
void setPublicOnly(boolean publicOnly)
void setRestricted(boolean restricted)
void render(IConstructor constructor)