BrightSide Workbench Full Report + Source Code
StudentsParser.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.string.ObjectString;
22 import org.turro.string.Strings;
23 import org.turro.annotation.ExternalParser;
24 import org.turro.auth.Authentication;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.students.content.ChallengeContentIterator;
27 import org.turro.students.content.PracticalWorkContentIterator;
28 import org.turro.students.entities.PracticalWorkRole;
29 
34 @ExternalParser
35 public class StudentsParser extends AbstractParser {
36 
37  @Override
38  public String getParserName() {
39  return "Students";
40  }
41 
42  @Override
43  protected boolean doExecute() {
44  boolean done = false;
45  if("challenges".equals(getMacroName()) || "challenges-summary".equals(getMacroName()) ||
46  "mychallenges".equals(getMacroName()) || "mychallenges-summary".equals(getMacroName())) {
49  cci.setPage((Integer) ObjectString.parseNativeString(getToken(2), Integer.class, true));
50  cci.setAllowInterest(true);
51  cci.setAllowVotes(true);
52  cci.setAllowComments(true);
53  cci.setAllowAttachments(true);
54  cci.setAllowFiles(true);
55  cci.setAllowDescriptions(true);
57  cci.setFullTemplate(getToken(4));
58  cci.setRestricted(getMacroName().contains("mychallenges"));
59  if(getMacroName().contains("summary")) {
60  cci.setNavigatorTop(false);
61  cci.setNavigatorBottom(false);
62  }
63  cci.load();
64  cci.render();
65  done = true;
66  } else if("jobboard".equals(getMacroName()) || "jobboard-summary".equals(getMacroName()) ||
67  "myjobboard".equals(getMacroName()) || "myjobboard-summary".equals(getMacroName()) ||
68  "lastjobboard".equals(getMacroName()) || "lastjobboard-summary".equals(getMacroName()) ||
69  "mylastjobboard".equals(getMacroName()) || "mylastjobboard-summary".equals(getMacroName())) {
71  Strings.isBlank(getToken(3)) ? null : ElephantContext.getRootWebPath() + getToken(3));
72  String role = getToken(1);
73  csci.setRole("all".equals(role) ? null : PracticalWorkRole.valueOf(role));
74  String type = getToken(2);
75  csci.setType("all".equals(type) ? null : type);
76  csci.setPage((Integer) ObjectString.parseNativeString(getToken(4), Integer.class, true));
77  csci.setAllowAttachments(true);
78  csci.setAllowComments(true);
80  if(getMacroName().contains("summary")) {
81  csci.setNavigatorTop(false);
82  csci.setNavigatorBottom(false);
83  }
84  if(getMacroName().contains("my")) {
85  csci.setRestricted(true);
86  }
87  if(getMacroName().contains("last")) {
88  csci.setLastEntries(true);
89  csci.setForceSummary(true);
90  }
91  csci.load();
92  csci.render();
93  done = true;
94  }
95  return done;
96  }
97 
98  @Override
99  protected void explainMacros(ParserMacroSet macros) {
100  macros.addMacro("challenges")
101  .addParameter("context", false)
102  .addParameter("count", true, "10")
103  .addParameter("summaryTemplate", true, "summary")
104  .addParameter("fullTemplate", true, "full");
105  macros.addMacro("challenges-summary")
106  .copyParametersFrom("challenges", macros);
107  macros.addMacro("mychallenges")
108  .copyParametersFrom("challenges", macros);
109  macros.addMacro("mychallenges-summary")
110  .copyParametersFrom("challenges", macros);
111  macros.addMacro("jobboard")
112  .addParameter("role", false)
113  .addPossibleValue("SERVICE_SUPPLY")
114  .addPossibleValue("SERVICE_DEMAND")
115  .addParameter("type", false)
116  .addParameter("context", true)
117  .addParameter("count", true, "10")
118  .addParameter("template", true, "summary");
119  macros.addMacro("jobboard-summary")
120  .copyParametersFrom("jobboard", macros);
121  macros.addMacro("myjobboard")
122  .copyParametersFrom("jobboard", macros);
123  macros.addMacro("myjobboard-summary")
124  .copyParametersFrom("jobboard", macros);
125  macros.addMacro("lastjobboard")
126  .copyParametersFrom("jobboard", macros);
127  macros.addMacro("lastjobboard-summary")
128  .copyParametersFrom("jobboard", macros);
129  macros.addMacro("mylastjobboard")
130  .copyParametersFrom("jobboard", macros);
131  macros.addMacro("mylastjobboard-summary")
132  .copyParametersFrom("jobboard", macros);
133  }
134 
135 }
void setAllowAttachments(boolean allowAttachments)
void setAllowInterest(boolean allowInterest)
void setFullTemplate(String fullTemplate)
void setAllowDescriptions(boolean allowDescriptions)
void setForceSummary(boolean forceSummary)
void setAllowComments(boolean allowComments)
void setNavigatorBottom(boolean navigatorBottom)
void setSummaryTemplate(String summaryTemplate)
void setNavigatorTop(boolean navigatorTop)
ParserMacro addMacro(String macroName)
ParserMacro addPossibleValue(String value)
void copyParametersFrom(String macroName, ParserMacroSet macros)
ParserMacro addParameter(String name, boolean optional)
void explainMacros(ParserMacroSet macros)