19 package org.turro.phase;
22 import java.io.IOException;
23 import java.io.Writer;
25 import java.util.TreeSet;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.impl.util.FileUtil;
30 import org.turro.file.FileWatch;
31 import org.turro.lock.Initializer;
32 import org.turro.reflection.JSONSerializer;
33 import org.turro.security.ConceptPermission;
42 return stream().filter(pd -> pd.getIndex() == index).findFirst().orElse(
null);
46 return stream().filter(pd -> pd.getName().equals(name)).findFirst().orElse(
null);
51 if(pd ==
null)
return index;
52 return pd.
getMapping().getOrDefault(serverId, index);
57 private void setDefaults() {
59 .icon(
"lightbulb yellow")
60 .described(
"New idea")
67 .described(
"Project incubation")
73 .icon(
"vote yea violet")
74 .described(
"Internally voted")
75 .addMapping(
"domain/axserver", 2)
84 .described(
"Next step based on votes")
85 .addMapping(
"domain/axserver", 2)
93 .icon(
"user tag brown")
94 .described(
"Request for proposal")
95 .addMapping(
"domain/axserver", 2)
103 .described(
"Being executed")
104 .addMapping(
"domain/axserver", 3)
108 .showRole(
"@partner:on|@admin:is")
109 .actionScript(
"user.admin || dpl.isDriver(user)"))
115 .described(
"Project archive")
116 .addMapping(
"domain/axserver", 4)
120 .showRole(
"@partner:on|@admin:is")
121 .actionScript(
"user.admin || dpl.isDriver(user)"))
129 private static final Initializer<PhaseDefinitions> INIT =
new Initializer<>();
130 private static final FileWatch watch =
new FileWatch(definitionsFile());
133 return INIT.
instance(() -> !watch.isNewer(), () ->
load());
140 private static final String PROJECT_PHASES_FILE =
"/WEB-INF/elephant/conf/project-phases.json";
144 if(watch.exists())
try {
146 JSONSerializer ser =
new JSONSerializer(
true);
148 }
catch (IOException ex) {
151 if(definitions ==
null) {
153 definitions.setDefaults();
161 JSONSerializer ser =
new JSONSerializer(definitions,
true);
162 writer.write(ser.toJson());
163 }
catch (IOException ex) {
164 Logger.getLogger(PhaseDefinitions.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
168 private static File definitionsFile() {
169 return new File(ElephantContext.getRealPath(PROJECT_PHASES_FILE));
static String logMsg(String msg)
static OutputStreamWriter getFileWriter(String folder, String file)
static String getContent(File file)
Map< String, Integer > getMapping()
static PhaseDefinition create(int index, String name, Set< PhaseType > types)
static PhaseDefinitions load()
int getMapping(int index, String serverId)
static PhaseDefinitions instance()
static ConceptPermission forbid(String name)