19 package org.turro.alliance.content;
22 import java.io.FileReader;
23 import java.io.IOException;
24 import java.io.Writer;
26 import java.util.TreeSet;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.impl.util.FileUtil;
31 import org.turro.file.FileWatch;
32 import org.turro.json.Jsons;
33 import org.turro.lock.Initializer;
34 import org.turro.log.WebLoggers;
35 import org.turro.phase.PhaseDefinition;
36 import org.turro.phase.PhaseType;
37 import org.turro.reflection.JSONSerializer;
38 import org.turro.security.ConceptPermission;
47 return stream().filter(pd -> pd.getIndex() == index).findFirst().orElse(
null);
51 return stream().filter(pd -> pd.getName().equals(name)).findFirst().orElse(
null);
56 if(pd ==
null)
return index;
57 return pd.
getMapping().getOrDefault(serverId, index);
62 private void setDefaults() {
64 .icon(
"lightbulb yellow")
65 .described(
"New idea")
70 .described(
"Project incubation")
74 .icon(
"user tag brown")
75 .described(
"Request for proposal")
81 .described(
"Being executed")
87 .described(
"Project archive")
95 private static final Initializer<AlliancePhaseDefinitions> INIT =
new Initializer<>();
96 private static final FileWatch watch =
new FileWatch(definitionsFile());
99 return INIT.
instance(() -> !watch.isNewer(), () ->
load());
107 try(FileReader reader =
new FileReader(definitionsFile())) {
108 return Jsons.read(reader);
109 }
catch (IOException ex) {
112 return Jsons.array();
115 private static final String PROJECT_PHASES_FILE =
"/WEB-INF/elephant/conf/alliance-phases.json";
119 if(watch.exists())
try {
121 JSONSerializer ser =
new JSONSerializer(
true);
123 }
catch (IOException ex) {
126 if(definitions ==
null) {
128 definitions.setDefaults();
136 JSONSerializer ser =
new JSONSerializer(definitions,
true);
137 writer.write(ser.toJson());
138 }
catch (IOException ex) {
139 Logger.getLogger(AlliancePhaseDefinitions.class.getName()).log(Level.SEVERE,
ElephantContext.
logMsg(
null), ex);
143 private static File definitionsFile() {
144 return new File(ElephantContext.getRealPath(PROJECT_PHASES_FILE));
static AlliancePhaseDefinitions load()
static AlliancePhaseDefinitions instance()
int getMapping(int index, String serverId)
static String logMsg(String msg)
static OutputStreamWriter getFileWriter(String folder, String file)
static String getContent(File file)
static WebLoggers severe(Object entity)
WebLoggers exception(Throwable throwable)
Map< String, Integer > getMapping()
static PhaseDefinition create(int index, String name, Set< PhaseType > types)
static ConceptPermission forbid(String name)