Rev 1306 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
850 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
852 | jmachado | 3 | import org.apache.log4j.Logger; |
853 | jmachado | 4 | import pt.estgp.estgweb.Globals; |
852 | jmachado | 5 | import pt.estgp.estgweb.utils.RoleManager; |
6 | import pt.estgp.estgweb.utils.StringsUtils; |
||
7 | |||
850 | jmachado | 8 | import java.io.Serializable; |
9 | import java.util.List; |
||
10 | |||
11 | /** |
||
12 | * Created by jorgemachado on 10/01/14. |
||
13 | */ |
||
14 | public class ProcessEventFileImpl extends ProcessEventFile |
||
15 | { |
||
852 | jmachado | 16 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(ProcessEventImpl.class); |
17 | |||
853 | jmachado | 18 | |
852 | jmachado | 19 | public static enum AccessLevel |
20 | { |
||
21 | ALL_IN_PROCESS, |
||
22 | ALL_EXCEPT_STARTER, |
||
23 | ONLY_STARTER, |
||
24 | OWNER, |
||
25 | FORWARD_EVENTS, |
||
26 | BACKWARD_EVENTS, |
||
27 | DEFINED_USERS_IDS, |
||
28 | DEFINED_ROLES_IDS |
||
29 | } |
||
30 | |||
850 | jmachado | 31 | @1.5.0/docs/api/java/lang/Override.html">Override |
32 | public List<String> getOwnerRoles() { |
||
853 | jmachado | 33 | return null; |
850 | jmachado | 34 | } |
35 | |||
36 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
37 | public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole() { |
||
853 | jmachado | 38 | return null; |
850 | jmachado | 39 | } |
40 | |||
41 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
42 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() { |
||
43 | return getId(); |
||
44 | } |
||
852 | jmachado | 45 | |
46 | public void setFileAccessLevelEnum(AccessLevel fileAccessLevel) { |
||
47 | super.setFileAccessLevel(fileAccessLevel.name()); |
||
48 | } |
||
49 | |||
50 | public AccessLevel getFileAccessLevelEnum() |
||
51 | { |
||
853 | jmachado | 52 | 1.5.0/docs/api/java/lang/System.html">System.out.println("File Level:" + getFileAccessLevel()); |
53 | if(getFileAccessLevel() == null) |
||
54 | return AccessLevel.OWNER; |
||
852 | jmachado | 55 | for(AccessLevel al : AccessLevel.values()) |
56 | { |
||
57 | if(al.name().equals(getFileAccessLevel())) |
||
58 | { |
||
59 | return al; |
||
60 | } |
||
61 | } |
||
62 | return AccessLevel.OWNER; |
||
63 | } |
||
64 | |||
65 | public boolean canSeeFile(User user) |
||
66 | { |
||
853 | jmachado | 67 | if(user.isSuperuser() || user.hasRole(Globals.ROLE_PROCESSES_ADMIN)) |
852 | jmachado | 68 | return true; |
853 | jmachado | 69 | if(isOwnedBy(user)) |
70 | return true; |
||
71 | |||
852 | jmachado | 72 | switch(getFileAccessLevelEnum()) |
73 | { |
||
74 | case ALL_IN_PROCESS: |
||
75 | return ((ProcessImpl)getProcessEvent().getProcess()).isInProcess(user); |
||
76 | case ALL_EXCEPT_STARTER: |
||
77 | return ((ProcessImpl)getProcessEvent().getProcess()).isInProcess(user) |
||
78 | && |
||
79 | !getProcessEvent().getProcess().isOwnedBy(user); |
||
80 | case ONLY_STARTER: |
||
81 | return isOwnedBy(user) || |
||
82 | getProcessEvent().getProcess().isOwnedBy(user); |
||
83 | case OWNER: |
||
84 | return isOwnedBy(user); |
||
85 | case FORWARD_EVENTS: |
||
86 | return isOwnedBy(user) || |
||
87 | ((ProcessEventImpl)getProcessEvent()).isInNextEvents(user); |
||
88 | case BACKWARD_EVENTS: |
||
89 | return isOwnedBy(user) || |
||
90 | ((ProcessEventImpl)getProcessEvent()).isInPreviousEvents(user); |
||
91 | case DEFINED_USERS_IDS: |
||
92 | if(getFileAccessIdentifiers() == null || getFileAccessIdentifiers().trim().length() == 0) |
||
93 | { |
||
94 | logger.error("Atention event: " +getId() + " has no target ids and defined access is DEFINED_USERS_IDS"); |
||
95 | return false; |
||
96 | } |
||
97 | if(isOwnedBy(user)) return true; |
||
98 | List<String> ids = StringsUtils.getStringsFromSerial(getFileAccessIdentifiers(), ";"); |
||
99 | for(1.5.0/docs/api/java/lang/String.html">String idstr: ids) |
||
100 | { |
||
101 | if(user.getId() == 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(idstr)) |
||
102 | return true; |
||
103 | } |
||
104 | return false; |
||
105 | case DEFINED_ROLES_IDS: |
||
106 | if(getFileAccessRoles() == null || getFileAccessRoles().trim().length() == 0) |
||
107 | { |
||
108 | logger.error("Atention event file: " +getId() + " has no roles and defined access is DEFINED_ROLES_IDS"); |
||
109 | return false; |
||
110 | } |
||
111 | return isOwnedBy(user) || |
||
112 | user.hasRole(RoleManager.getRolesFromSerial(getFileAccessRoles())); |
||
113 | } |
||
114 | logger.error("Access Level not found in process event file " + getId()); |
||
115 | return false; |
||
116 | } |
||
853 | jmachado | 117 | |
118 | public boolean canOpenCloseGhost(User user) |
||
119 | { |
||
120 | return (isOwnedBy(user) && getProcessEvent().getCloseDate() == null && getProcessEvent().getNextEvent() == null) |
||
121 | || user.isSuperuser() || user.hasRole(Globals.ROLE_PROCESSES_ADMIN); |
||
122 | } |
||
850 | jmachado | 123 | } |