Rev 1791 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1791 | Rev 1821 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.services.users; |
1 | package pt.estgp.estgweb.services.users; |
2 | 2 | ||
3 | import org.apache.log4j.Logger; |
3 | import org.apache.log4j.Logger; |
- | 4 | import org.reflections.Reflections; |
|
4 | import pt.estgp.estgweb.domain.*; |
5 | import pt.estgp.estgweb.domain.*; |
5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
6 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
- | 7 | import pt.estgp.estgweb.domain.dao.RoleContainer; |
|
6 | import pt.estgp.estgweb.filters.exceptions.AccessDeniedException; |
8 | import pt.estgp.estgweb.filters.exceptions.AccessDeniedException; |
7 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
9 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
8 | 10 | ||
9 | import java.io.BufferedReader; |
11 | import java.io.BufferedReader; |
10 | import java.io.IOException; |
12 | import java.io.IOException; |
11 | import java.io.StringReader; |
13 | import java.io.StringReader; |
12 | import java.util.ArrayList; |
14 | import java.util.ArrayList; |
13 | import java.util.List; |
15 | import java.util.List; |
- | 16 | import java.util.Set; |
|
14 | 17 | ||
15 | /** |
18 | /** |
16 | * Created by jorgemachado on 29/01/16. |
19 | * Created by jorgemachado on 29/01/16. |
17 | */ |
20 | */ |
18 | public class UserRoleConfigService implements IService |
21 | public class UserRoleConfigService implements IService |
Line 53... | Line 56... | ||
53 | 56 | ||
54 | 57 | ||
55 | public ReplaceRoleResult updateOldRoleWithView(1.5.0/docs/api/java/lang/String.html">String oldRole,UserRoleConfigImpl newViewRoleConfig, UserSession sess) |
58 | public ReplaceRoleResult updateOldRoleWithView(1.5.0/docs/api/java/lang/String.html">String oldRole,UserRoleConfigImpl newViewRoleConfig, UserSession sess) |
56 | throws AccessDeniedException |
59 | throws AccessDeniedException |
57 | { |
60 | { |
- | 61 | return updateOldRoleWithView(oldRole, newViewRoleConfig, sess,true); |
|
- | 62 | } |
|
- | 63 | ||
- | 64 | public ReplaceRoleResult updateOldRoleWithView(1.5.0/docs/api/java/lang/String.html">String oldRole,UserRoleConfigImpl newViewRoleConfig, UserSession sess,boolean updateCourses) |
|
- | 65 | throws AccessDeniedException |
|
- | 66 | { |
|
58 | UserRoleConfig oldUserRoleConfig = DaoFactory.getUserRoleConfigDaoImpl().findByRole(oldRole); |
67 | UserRoleConfig oldUserRoleConfig = DaoFactory.getUserRoleConfigDaoImpl().findByRole(oldRole); |
- | 68 | if(oldUserRoleConfig == null) |
|
- | 69 | { |
|
- | 70 | return addUpdateRole(newViewRoleConfig,sess,updateCourses); |
|
- | 71 | } |
|
- | 72 | else |
|
- | 73 | { |
|
59 | newViewRoleConfig.setId(oldUserRoleConfig.getId()); |
74 | newViewRoleConfig.setId(oldUserRoleConfig.getId()); |
60 | return addUpdateRole(newViewRoleConfig,sess); |
75 | return addUpdateRole(newViewRoleConfig,sess,updateCourses); |
- | 76 | } |
|
61 | } |
77 | } |
62 | 78 | ||
- | 79 | public ReplaceRoleResult addUpdateRole(UserRoleConfigImpl viewRoleConfig, UserSession sess) throws AccessDeniedException { |
|
- | 80 | return addUpdateRole(viewRoleConfig, sess,true); |
|
- | 81 | } |
|
63 | public ReplaceRoleResult addUpdateRole(UserRoleConfigImpl viewRoleConfig, UserSession sess) |
82 | public ReplaceRoleResult addUpdateRole(UserRoleConfigImpl viewRoleConfig, UserSession sess, boolean updateCourseRoles) |
64 | throws AccessDeniedException |
83 | throws AccessDeniedException |
65 | { |
84 | { |
66 | 85 | ||
67 | ReplaceRoleResult replaceRoleResult; |
86 | ReplaceRoleResult replaceRoleResult; |
68 | //boolean isNew = userRoleConfig.getId() <= 0; |
87 | //boolean isNew = userRoleConfig.getId() <= 0; |
69 | UserRoleConfig persistent; |
88 | UserRoleConfig persistent; |
70 | 1.5.0/docs/api/java/lang/String.html">String newRoleStr = viewRoleConfig.getRole().trim(); |
89 | 1.5.0/docs/api/java/lang/String.html">String newRoleStr = viewRoleConfig.getRole().trim(); |
71 | if(viewRoleConfig.getId() <= 0) |
90 | if(viewRoleConfig.getId() <= 0) |
72 | { |
91 | { |
73 | replaceRoleResult = replaceOrCreateRoleKey(null, newRoleStr, sess); |
92 | replaceRoleResult = replaceOrCreateRoleKey(null, newRoleStr, sess,updateCourseRoles); |
74 | if(replaceRoleResult.roleKeyAlreadyExist) |
93 | if(replaceRoleResult.roleKeyAlreadyExist) |
75 | return replaceRoleResult; |
94 | return replaceRoleResult; |
76 | persistent = replaceRoleResult.updatedUserRoleConfig; |
95 | persistent = replaceRoleResult.updatedUserRoleConfig; |
77 | } |
96 | } |
78 | else |
97 | else |
Line 82... | Line 101... | ||
82 | boolean chaveMudou = !newRoleStr.equals(persistent.getRole()); |
101 | boolean chaveMudou = !newRoleStr.equals(persistent.getRole()); |
83 | if(chaveMudou) |
102 | if(chaveMudou) |
84 | { |
103 | { |
85 | if(sess.getUser().isSuperuserOrAdmin()) |
104 | if(sess.getUser().isSuperuserOrAdmin()) |
86 | { |
105 | { |
87 | replaceRoleResult = replaceOrCreateRoleKey(persistent.getRole(), newRoleStr, sess); |
106 | replaceRoleResult = replaceOrCreateRoleKey(persistent.getRole(), newRoleStr, sess,updateCourseRoles); |
88 | 107 | ||
89 | if(replaceRoleResult.roleKeyAlreadyExist) |
108 | if(replaceRoleResult.roleKeyAlreadyExist) |
90 | return replaceRoleResult; |
109 | return replaceRoleResult; |
91 | persistent = replaceRoleResult.updatedUserRoleConfig; |
110 | persistent = replaceRoleResult.updatedUserRoleConfig; |
92 | } |
111 | } |
Line 113... | Line 132... | ||
113 | 132 | ||
114 | return replaceRoleResult; |
133 | return replaceRoleResult; |
115 | } |
134 | } |
116 | 135 | ||
117 | 136 | ||
- | 137 | public static Set<Class<? extends RoleContainer>> roleContainerClasses = null; |
|
- | 138 | private synchronized void init() |
|
- | 139 | { |
|
- | 140 | if(roleContainerClasses == null) |
|
- | 141 | { |
|
- | 142 | Reflections reflections = new Reflections("pt.estgp.estgweb"); |
|
- | 143 | ||
- | 144 | roleContainerClasses = reflections.getSubTypesOf(RoleContainer.class); |
|
- | 145 | } |
|
- | 146 | } |
|
- | 147 | ||
- | 148 | ||
118 | /** |
149 | /** |
119 | * Serviço de nível SUPORTE |
150 | * Serviço de nível SUPORTE |
120 | * Usado pelo update de Roles e Pela normalização de Roles de Comissões de Curso |
151 | * Usado pelo update de Roles e Pela normalização de Roles de Comissões de Curso |
121 | * Substitui a presença de um ROLE por um NOVO |
152 | * Substitui a presença de um ROLE por um NOVO |
122 | * |
153 | * |
Line 125... | Line 156... | ||
125 | * @param newRole need to be filled |
156 | * @param newRole need to be filled |
126 | * @param sess |
157 | * @param sess |
127 | * @return ReplaceRoleResult if roleKeyAlreadyExist = true - nothing was done need to be a none existing new role key |
158 | * @return ReplaceRoleResult if roleKeyAlreadyExist = true - nothing was done need to be a none existing new role key |
128 | * ReplaceRoleResult.updatedUserRoleConfig tem o role antigo atualizado ou o novo criado com o newRole |
159 | * ReplaceRoleResult.updatedUserRoleConfig tem o role antigo atualizado ou o novo criado com o newRole |
129 | */ |
160 | */ |
130 | public ReplaceRoleResult replaceOrCreateRoleKey(1.5.0/docs/api/java/lang/String.html">String oldRole, 1.5.0/docs/api/java/lang/String.html">String newRole, UserSession sess) |
161 | public ReplaceRoleResult replaceOrCreateRoleKey(1.5.0/docs/api/java/lang/String.html">String oldRole, 1.5.0/docs/api/java/lang/String.html">String newRole, UserSession sess,boolean updateCourses) |
131 | { |
162 | { |
132 | ReplaceRoleResult result = new ReplaceRoleResult(newRole); |
163 | ReplaceRoleResult result = new ReplaceRoleResult(newRole); |
133 | 164 | ||
134 | UserRoleConfig roleConfig = DaoFactory.getUserRoleConfigDaoImpl().findByRole(newRole); |
165 | UserRoleConfig roleConfig = DaoFactory.getUserRoleConfigDaoImpl().findByRole(newRole); |
135 | if(roleConfig != null) |
166 | if(roleConfig != null) |
Line 150... | Line 181... | ||
150 | roleConfig.setRole(newRole); |
181 | roleConfig.setRole(newRole); |
151 | result.updatedUserRoleConfig = roleConfig; |
182 | result.updatedUserRoleConfig = roleConfig; |
152 | 183 | ||
153 | replaceUserRoles(oldRole, newRole, result); |
184 | replaceUserRoles(oldRole, newRole, result); |
154 | 185 | ||
- | 186 | if(updateCourses) |
|
155 | replaceCourseRoles(oldRole, newRole, result); |
187 | replaceCourseRoles(oldRole, newRole, result); |
156 | 188 | ||
157 | replaceSchoolAndDepartmentRoles(oldRole, newRole, result); |
189 | replaceSchoolAndDepartmentRoles(oldRole, newRole, result); |
158 | 190 | ||
159 | replaceEventClasseManagerRoles(oldRole, newRole, result); |
191 | replaceEventClasseManagerRoles(oldRole, newRole, result); |
- | 192 | init(); |
|
- | 193 | for (1.5.0/docs/api/java/lang/Class.html">Class serviceClass : roleContainerClasses) { |
|
- | 194 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Replacing Roles Notification Found: " + serviceClass.getName()); |
|
- | 195 | try { |
|
- | 196 | ((RoleContainer)serviceClass.newInstance()).replaceRoleNotification(oldRole,newRole,result); |
|
- | 197 | } catch (1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException e) { |
|
- | 198 | logger.error(e,e); |
|
- | 199 | } catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e) { |
|
- | 200 | logger.error(e, e); |
|
- | 201 | } |
|
- | 202 | } |
|
- | 203 | //DaoFactory.getBpmnRoleSelectorDaoImpl().replaceRoleNotification(oldRole, newRole, result); |
|
160 | 204 | ||
161 | replaceBpmnActorPoolInstancesRoles(oldRole, newRole, result); |
- | |
162 | - | ||
163 | replaceBpmnActorPoolRoles(oldRole, newRole, result); |
205 | //replaceBpmnActorPoolRoles(oldRole, newRole, result); |
164 | 206 | ||
165 | 207 | ||
166 | } |
208 | } |
167 | return result; |
209 | return result; |
168 | } |
210 | } |
169 | 211 | ||
170 | private void replaceBpmnActorPoolInstancesRoles(1.5.0/docs/api/java/lang/String.html">String oldRole, 1.5.0/docs/api/java/lang/String.html">String newRole, ReplaceRoleResult result) { |
- | |
171 | List<BpmnActorPoolInstanceImpl> actorPoolInstances = DaoFactory.getBpmnActorPoolInstanceDaoImpl().findByRole(oldRole); |
- | |
172 | result.afectedActorPoolRolesInstances = actorPoolInstances.size(); |
- | |
173 | for(BpmnActorPoolInstanceImpl actorPoolInstance: actorPoolInstances) |
- | |
174 | { |
- | |
175 | actorPoolInstance.replaceRole(oldRole,newRole); |
- | |
176 | } |
- | |
177 | } |
- | |
178 | - | ||
179 | private void replaceBpmnActorPoolRoles(1.5.0/docs/api/java/lang/String.html">String oldRole, 1.5.0/docs/api/java/lang/String.html">String newRole, ReplaceRoleResult result) { |
- | |
180 | List<BpmnActorPoolImpl> actorPools = DaoFactory.getBpmnActorPoolDaoImpl().findByRole(oldRole); |
- | |
181 | result.afectedActorPoolRoles = actorPools.size(); |
- | |
182 | for(BpmnActorPoolImpl actorPool: actorPools) |
- | |
183 | { |
- | |
184 | actorPool.replaceRole(oldRole,newRole); |
- | |
185 | } |
- | |
186 | } |
- | |
187 | 212 | ||
188 | private void replaceEventClasseManagerRoles(1.5.0/docs/api/java/lang/String.html">String oldRole, 1.5.0/docs/api/java/lang/String.html">String newRole, ReplaceRoleResult result) { |
213 | private void replaceEventClasseManagerRoles(1.5.0/docs/api/java/lang/String.html">String oldRole, 1.5.0/docs/api/java/lang/String.html">String newRole, ReplaceRoleResult result) { |
189 | List<EventClass> eventClasses = DaoFactory.getEventClassDaoImpl().findByManagerRole(oldRole); |
214 | List<EventClass> eventClasses = DaoFactory.getEventClassDaoImpl().findByManagerRole(oldRole); |
190 | result.afectedEventClassManagers = eventClasses.size(); |
215 | result.afectedEventClassManagers = eventClasses.size(); |
191 | for(EventClass eventClass: eventClasses) |
216 | for(EventClass eventClass: eventClasses) |