19 package org.turro.actor;
21 import java.io.FileInputStream;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.util.List;
25 import java.util.Properties;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.stream.Collectors;
30 import org.turro.elephant.context.Application;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.entities.Entities;
33 import org.turro.entities.IElephantEntity;
34 import org.turro.file.FileWatch;
35 import org.turro.plugin.contacts.IContact;
36 import org.turro.reflection.Instances;
37 import org.turro.script.Scripting;
43 public class Actors extends Properties {
45 public static boolean isActor(String actor) {
53 public static boolean isActorFor(Object entity, String actor) {
72 return load().stringPropertyNames();
76 return getActors().stream().sorted().collect(Collectors.toList());
81 private static String getFormula(String actor) {
82 return load().getProperty(actor);
87 private static final String ACTORS_FILE =
"/WEB-INF/elephant/conf/actor-context.properties";
89 private static Actors _actors;
90 private static long _lastLoad;
92 private static Actors load() {
93 boolean exists = FileWatch.exists(ElephantContext.getRealPath(ACTORS_FILE));
94 if(_actors ==
null || FileWatch.isNewer(ElephantContext.getRealPath(ACTORS_FILE), _lastLoad) || !exists) {
96 try(FileInputStream fis =
new FileInputStream(ElephantContext.getRealPath(ACTORS_FILE))) {
97 _actors =
new Actors();
100 }
catch (IOException ex) {
101 Logger.getLogger(Actors.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
104 _actors =
new Actors();
107 _lastLoad = FileWatch.getTime(ElephantContext.getRealPath(ACTORS_FILE));
112 private static void store() {
113 try(FileOutputStream fos =
new FileOutputStream(ElephantContext.getRealPath(ACTORS_FILE))) {
114 _actors.store(fos,
null);
115 }
catch (IOException ex) {
116 Logger.getLogger(Actors.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
120 private static void addStandards() {
121 _actors.put(
"SysAdmin",
"pfunc.anyOfSyndications(user, \"brightside_admin\")");
122 _actors.put(
"PartnerNetwork",
"pfunc.anyOfSyndications(user, \"partner,patron,contacts_admin\")");
123 _actors.put(
"OnlyStudent",
"user.student && !pfunc.anyOfSyndications(user, \"partner,patron\")");
124 Instances.cached().byAnnotation(ElephantActor.class, IElephantActor.class).forEach((iActor) -> {
125 iActor.addStandards(_actors);
static boolean isActorFor(IElephantEntity iee, String actor)
static boolean isActor(IContact contact, String actor)
static boolean isActorFor(Object entity, String actor)
static boolean isActorFor(IContact contact, Object entity, String actor)
static Set< String > getActors()
static boolean isActor(String actor)
static boolean isActorFor(IContact contact, IElephantEntity iee, String actor)
static List< String > getSortedActors()
static IContact getUser()
static IElephantEntity getController(String path)
static boolean evalFor(Object entity, String value)