Revision 98f59aa5
Added by Andreas Kohlbecker over 6 years ago
src/main/java/eu/etaxonomy/cdm/persistence/hibernate/GrantedAuthorityRevokingRegistrationUpdateLister.java | ||
---|---|---|
15 | 15 |
import java.util.List; |
16 | 16 |
import java.util.Set; |
17 | 17 |
|
18 |
import org.hibernate.FlushMode; |
|
18 | 19 |
import org.hibernate.Query; |
19 | 20 |
import org.hibernate.event.spi.EventSource; |
20 | 21 |
import org.hibernate.event.spi.PostUpdateEvent; |
21 | 22 |
import org.hibernate.event.spi.PostUpdateEventListener; |
22 | 23 |
import org.hibernate.persister.entity.EntityPersister; |
23 | 24 |
|
25 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
|
24 | 26 |
import eu.etaxonomy.cdm.model.agent.Person; |
25 | 27 |
import eu.etaxonomy.cdm.model.agent.Team; |
28 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
26 | 29 |
import eu.etaxonomy.cdm.model.name.Registration; |
27 | 30 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
31 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
28 | 32 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
29 | 33 |
import eu.etaxonomy.cdm.model.name.TypeDesignationBase; |
34 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
35 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
36 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
30 | 37 |
import eu.etaxonomy.cdm.model.reference.Reference; |
31 | 38 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
32 | 39 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority; |
... | ... | |
53 | 60 |
|
54 | 61 |
private static final EnumSet<CRUD> UPDATE_DELETE = EnumSet.of(CRUD.UPDATE, CRUD.DELETE); |
55 | 62 |
|
63 |
private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE); |
|
64 |
|
|
56 | 65 |
/** |
57 | 66 |
* {@inheritDoc} |
58 | 67 |
*/ |
... | ... | |
69 | 78 |
|
70 | 79 |
/** |
71 | 80 |
* Walks the entity graph of the Registration instance and collects all authorities which |
72 |
* could have been granted to users. Code parts in which this could have happend can be |
|
81 |
* could have been granted to users. Code parts in which this could have happened can be
|
|
73 | 82 |
* found by searching for usage of the methods {@link eu.etaxonomy.cdm.vaadin.security.UserHelper#createAuthorityForCurrentUser(eu.etaxonomy.cdm.model.common.CdmBase, EnumSet, String) |
74 | 83 |
* UserHelper.createAuthorityForCurrentUser(eu.etaxonomy.cdm.model.common.CdmBase, EnumSet, String)} and {@link eu.etaxonomy.cdm.vaadin.security.UserHelper#createAuthorityForCurrentUser(Class, Integer, EnumSet, String) |
75 | 84 |
* UserHelper.createAuthorityForCurrentUser(Class, Integer, EnumSet, String)} |
... | ... | |
92 | 101 |
private Set<CdmAuthority> collectDeleteCandidates(Registration reg){ |
93 | 102 |
Set<CdmAuthority> deleteCandidates = new HashSet<CdmAuthority>(); |
94 | 103 |
// add authority for Registration |
95 |
deleteCandidates.add(new CdmAuthority(reg, UPDATE_DELETE));
|
|
104 |
deleteCandidates.add(new CdmAuthority(reg, RegistrationStatus.PREPARATION.name(), UPDATE));
|
|
96 | 105 |
if(reg.getName() != null){ |
97 | 106 |
addDeleteCandidates(deleteCandidates, reg.getName()); |
98 | 107 |
} |
... | ... | |
109 | 118 |
* @param name |
110 | 119 |
*/ |
111 | 120 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, TaxonName name) { |
112 |
deleteCandidates.add(new CdmAuthority(name, UPDATE_DELETE)); |
|
113 |
if(name.getNomenclaturalReference() != null){ |
|
114 |
addDeleteCandidates(deleteCandidates, (Reference)name.getNomenclaturalReference()); |
|
121 |
if(name == null){ |
|
122 |
return; |
|
115 | 123 |
} |
124 |
deleteCandidates.add(new CdmAuthority(name, UPDATE_DELETE)); |
|
125 |
addDeleteCandidates(deleteCandidates, (Reference)name.getNomenclaturalReference()); |
|
126 |
addDeleteCandidates(deleteCandidates, name.getCombinationAuthorship()); |
|
127 |
addDeleteCandidates(deleteCandidates, name.getExCombinationAuthorship()); |
|
128 |
addDeleteCandidates(deleteCandidates, name.getBasionymAuthorship()); |
|
129 |
addDeleteCandidates(deleteCandidates, name.getExBasionymAuthorship()); |
|
116 | 130 |
} |
117 | 131 |
|
118 | 132 |
|
... | ... | |
121 | 135 |
* @param td |
122 | 136 |
*/ |
123 | 137 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, TypeDesignationBase td) { |
138 |
if(td == null){ |
|
139 |
return; |
|
140 |
} |
|
124 | 141 |
deleteCandidates.add(new CdmAuthority(td, UPDATE_DELETE)); |
125 |
if(td.getCitation() != null){ |
|
126 |
addDeleteCandidates(deleteCandidates, td.getCitation()); |
|
142 |
addDeleteCandidates(deleteCandidates, td.getCitation()); |
|
143 |
if(td instanceof SpecimenTypeDesignation){ |
|
144 |
SpecimenTypeDesignation std = (SpecimenTypeDesignation)td; |
|
145 |
addDeleteCandidates(deleteCandidates, std.getTypeSpecimen()); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* @param deleteCandidates |
|
151 |
* @param typeSpecimen |
|
152 |
*/ |
|
153 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, DerivedUnit deriveUnit) { |
|
154 |
if(deriveUnit == null){ |
|
155 |
return; |
|
156 |
} |
|
157 |
if(deriveUnit.getCollection() != null){ |
|
158 |
deleteCandidates.add(new CdmAuthority(deriveUnit.getCollection(), UPDATE_DELETE)); |
|
159 |
} |
|
160 |
for(SpecimenOrObservationBase sob : deriveUnit.getOriginals()){ |
|
161 |
if(sob == null){ |
|
162 |
continue; |
|
163 |
} |
|
164 |
deleteCandidates.add(new CdmAuthority(sob, UPDATE_DELETE)); |
|
165 |
if(sob instanceof FieldUnit){ |
|
166 |
addDeleteCandidates(deleteCandidates, (FieldUnit)sob); |
|
167 |
} else { |
|
168 |
addDeleteCandidates(deleteCandidates, (DerivedUnit)sob); |
|
169 |
} |
|
127 | 170 |
} |
171 |
} |
|
128 | 172 |
|
173 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, FieldUnit fieldUnit) { |
|
174 |
if(fieldUnit == null){ |
|
175 |
return; |
|
176 |
} |
|
177 |
if(fieldUnit.getGatheringEvent() != null){ |
|
178 |
addDeleteCandidates(deleteCandidates, fieldUnit.getGatheringEvent().getActor()); |
|
179 |
} |
|
129 | 180 |
} |
130 | 181 |
|
131 | 182 |
/** |
132 | 183 |
* @param deleteCandidates |
133 | 184 |
* @param nomenclaturalReference |
134 | 185 |
*/ |
135 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, |
|
136 |
Reference reference) { |
|
186 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, Reference reference) { |
|
187 |
if(reference == null){ |
|
188 |
return; |
|
189 |
} |
|
137 | 190 |
deleteCandidates.add(new CdmAuthority(reference, UPDATE_DELETE)); |
138 |
if(reference.getAuthorship() != null){ |
|
139 |
deleteCandidates.add(new CdmAuthority(reference.getAuthorship(), UPDATE_DELETE)); |
|
140 |
if(reference.getAuthorship() instanceof Team){ |
|
141 |
List<Person> members = ((Team)reference.getAuthorship()).getTeamMembers(); |
|
191 |
addDeleteCandidates(deleteCandidates, reference.getAuthorship()); |
|
192 |
addDeleteCandidates(deleteCandidates, reference.getInReference()); |
|
193 |
} |
|
194 |
|
|
195 |
private void addDeleteCandidates(Set<CdmAuthority> deleteCandidates, AgentBase<?> agent) { |
|
196 |
if(agent == null){ |
|
197 |
return; |
|
198 |
} |
|
199 |
deleteCandidates.add(new CdmAuthority(agent, UPDATE_DELETE)); |
|
200 |
if(agent instanceof TeamOrPersonBase){ |
|
201 |
if(agent instanceof Team){ |
|
202 |
List<Person> members = ((Team)agent).getTeamMembers(); |
|
142 | 203 |
if(members != null){ |
143 | 204 |
for(Person p : members){ |
144 |
deleteCandidates.add(new CdmAuthority(p, UPDATE_DELETE)); |
|
205 |
if(p != null){ |
|
206 |
deleteCandidates.add(new CdmAuthority(p, UPDATE_DELETE)); |
|
207 |
} |
|
145 | 208 |
} |
146 | 209 |
} |
147 | 210 |
} |
148 | 211 |
} |
212 |
|
|
149 | 213 |
} |
150 | 214 |
|
151 | 215 |
|
216 |
|
|
217 |
|
|
152 | 218 |
/** |
153 | 219 |
* @param deleteCandidates |
154 | 220 |
*/ |
... | ... | |
160 | 226 |
String hql = "delete from GrantedAuthorityImpl as ga where ga.authority in (:authorities)"; |
161 | 227 |
Query query = session.createQuery(hql); |
162 | 228 |
query.setParameterList("authorities", authorityStrings); |
229 |
query.setFlushMode(FlushMode.MANUAL); // workaround for HHH-11822 (https://hibernate.atlassian.net/browse/HHH-11822) |
|
163 | 230 |
query.executeUpdate(); |
164 | 231 |
|
165 | 232 |
} |
Also available in: Unified diff
ref #6867 GrantedAuthorityRevokingRegistrationUpdateLister implemented