Project

General

Profile

Revision 98f59aa5

ID98f59aa5b729d4b720484f9f2565dd6ae6f72d35
Parent b53e0b8f
Child 77d3424c

Added by Andreas Kohlbecker almost 3 years ago

ref #6867 GrantedAuthorityRevokingRegistrationUpdateLister implemented

View differences:

src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java
16 16
import javax.servlet.annotation.WebServlet;
17 17

  
18 18
import org.apache.log4j.Logger;
19
import org.hibernate.SessionFactory;
20
import org.hibernate.event.service.spi.EventListenerRegistry;
21
import org.hibernate.event.spi.EventType;
22
import org.hibernate.internal.SessionFactoryImpl;
19 23
import org.springframework.beans.BeansException;
20 24
import org.springframework.beans.factory.annotation.Autowired;
21 25
import org.springframework.context.ApplicationContext;
......
41 45
import eu.etaxonomy.cdm.common.ConfigFileUtil;
42 46
import eu.etaxonomy.cdm.dataInserter.RegistrationRequiredDataInserter;
43 47
import eu.etaxonomy.cdm.opt.config.DataSourceConfigurer;
48
import eu.etaxonomy.cdm.persistence.hibernate.GrantedAuthorityRevokingRegistrationUpdateLister;
44 49
import eu.etaxonomy.cdm.vaadin.security.annotation.EnableAnnotationBasedAccessControl;
45 50
import eu.etaxonomy.cdm.vaadin.ui.ConceptRelationshipUI;
46 51
import eu.etaxonomy.cdm.vaadin.ui.DistributionStatusUI;
......
85 90
    @Autowired
86 91
    Environment env;
87 92

  
93
    @Autowired
94
    private SessionFactory sessionFactory;
95

  
96
    private boolean registrationUiHibernateEventListenersDone = false;
97

  
88 98
    /*
89 99
     * NOTE: It is necessary to map the URLs starting with /VAADIN/* since none of the
90 100
     * @WebServlets is mapped to the root path. It is sufficient to configure one of the
......
114 124
                        }
115 125

  
116 126
                    });
127
                    ).getServiceRegistry().getService
117 128

  
118 129
                }});
119 130

  
......
139 150
    @UIScope
140 151
    public RegistrationUI registrationUI() {
141 152
        if(isUIEnabled(RegistrationUI.class)){
153
            registerRegistrationUiHibernateEventListeners();
154

  
142 155
            return new RegistrationUI();
143 156
        }
144 157
        return null;
145 158
    }
146 159

  
160
    /**
161
     * this is only a quick implementation for testing,
162
     * TODO see also the NOTE on CdmListenerIntegrator class declaration for a prospective better solution
163
     */
164
    protected void registerRegistrationUiHibernateEventListeners() {
165
        if(!registrationUiHibernateEventListenersDone){
166
            EventListenerRegistry listenerRegistry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(
167
                    EventListenerRegistry.class);
168
            GrantedAuthorityRevokingRegistrationUpdateLister listener = new GrantedAuthorityRevokingRegistrationUpdateLister();
169
            listenerRegistry.appendListeners(EventType.POST_UPDATE, listener);
170
            registrationUiHibernateEventListenersDone = true;
171
        }
172
    }
173

  
147 174
    @Bean
148 175
    public AbstractDataInserter registrationRequiredDataInserter() throws BeansException{
149 176
        if(isUIEnabled(RegistrationUI.class)){
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
    }
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/PersonField.java
45 45
     * do not allow entities which are having only <code>null</code> values in all fields
46 46
     * {@link #getValue()} would return <code>null</code> in this case.
47 47
     */
48
    boolean allowNewEmptyEntity = false;
48
    boolean allowNewEmptyEntity = true;
49 49

  
50 50
    private LazyComboBox<Person> personSelect = new LazyComboBox<Person>(Person.class);
51 51

  
......
77 77
    private TextField suffixField = new TextField();
78 78
    private SwitchButton unlockSwitch = new SwitchButton();
79 79

  
80
    private boolean onCommit = false;
81

  
82

  
80 83
    /**
81 84
     * @param caption
82 85
     */
......
288 291

  
289 292
        List<Field>ignoreFields = super.nullValueCheckIgnoreFields();
290 293
        ignoreFields.add(unlockSwitch);
294

  
291 295
        if(unlockSwitch.getValue().booleanValue() == false){
292 296
            if(getValue().getId() == 0){
293 297
                // only it the entity is unsaved!
......
327 331
        if(bean == null){
328 332
            return null;
329 333
        }
330
        boolean isUnsaved = bean.getId() == 0;
331
        if(isUnsaved && hasNullContent() && !allowNewEmptyEntity) {
332
            return null;
333
        }
334
       // boolean isUnsaved = bean.getId() == 0;
335
//        if(isUnsaved && hasNullContent() && !allowNewEmptyEntity) {
336
//            return null;
337
//        }
334 338
        return bean;
335 339
    }
336 340

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
362 362
                    getView().getCitationID(),
363 363
                    typifiedNameId
364 364
                    );
365
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE));
365
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
366 366
            popup.loadInEditor(identifierSet);
367 367
            popup.withDeleteButton(true);
368 368
        } else {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)