Project

General

Profile

Download (22.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.name;
10

    
11
import java.util.Arrays;
12
import java.util.EnumSet;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.Stack;
19

    
20
import org.hibernate.criterion.Restrictions;
21
import org.springframework.beans.factory.DisposableBean;
22
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.context.annotation.Scope;
24
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
25
import org.vaadin.viritin.fields.AbstractElementCollection;
26

    
27
import com.vaadin.spring.annotation.SpringComponent;
28

    
29
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
30
import eu.etaxonomy.cdm.cache.CdmTransientEntityAndUuidCacher;
31
import eu.etaxonomy.cdm.format.reference.ReferenceEllypsisFormatter.LabelType;
32
import eu.etaxonomy.cdm.model.ICdmEntityUuidCacher;
33
import eu.etaxonomy.cdm.model.agent.AgentBase;
34
import eu.etaxonomy.cdm.model.agent.Person;
35
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
36
import eu.etaxonomy.cdm.model.common.AnnotationType;
37
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
39
import eu.etaxonomy.cdm.model.location.Country;
40
import eu.etaxonomy.cdm.model.name.Registration;
41
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
42
import eu.etaxonomy.cdm.model.occurrence.Collection;
43
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
44
import eu.etaxonomy.cdm.model.permission.CRUD;
45
import eu.etaxonomy.cdm.model.reference.Reference;
46
import eu.etaxonomy.cdm.model.reference.ReferenceType;
47
import eu.etaxonomy.cdm.model.term.TermType;
48
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
49
import eu.etaxonomy.cdm.persistence.dao.common.Restriction.Operator;
50
import eu.etaxonomy.cdm.persistence.query.MatchMode;
51
import eu.etaxonomy.cdm.service.CdmBeanItemContainerFactory;
52
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
53
import eu.etaxonomy.cdm.service.CdmFilterablePagingProviderFactory;
54
import eu.etaxonomy.cdm.service.ISpecimenTypeDesignationWorkingSetService;
55
import eu.etaxonomy.cdm.service.UserHelperAccess;
56
import eu.etaxonomy.cdm.service.initstrategies.AgentBaseInit;
57
import eu.etaxonomy.cdm.vaadin.component.CollectionRowItemCollection;
58
import eu.etaxonomy.cdm.vaadin.event.EditorActionContext;
59
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
60
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEventFilter;
61
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
62
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationTermLists;
63
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
64
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
65
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
66
import eu.etaxonomy.cdm.vaadin.util.CollectionCaptionGenerator;
67
import eu.etaxonomy.cdm.vaadin.util.ReferenceEllypsisCaptionGenerator;
68
import eu.etaxonomy.cdm.vaadin.view.occurrence.CollectionPopupEditor;
69
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
70
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
71
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
72
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
73
import eu.etaxonomy.vaadin.mvp.AbstractView;
74
/**
75
 * SpecimenTypeDesignationWorkingsetPopupEditorView implementation must override the showInEditor() method,
76
 * see {@link #prepareAsFieldGroupDataSource()} for details.
77
 *
78
 * @author a.kohlbecker
79
 * @since Jun 13, 2017
80
 */
81
@SpringComponent
82
@Scope("prototype")
83
public class SpecimenTypeDesignationWorkingsetEditorPresenter
84
    extends AbstractEditorPresenter<SpecimenTypeDesignationWorkingSetDTO , SpecimenTypeDesignationWorkingsetPopupEditorView>
85
    implements CachingPresenter, DisposableBean {
86

    
87
    private static final long serialVersionUID = 4255636253714476918L;
88

    
89
    private static final EnumSet<CRUD> COLLECTION_EDITOR_CRUD = EnumSet.of(CRUD.UPDATE, CRUD.DELETE);
90

    
91

    
92
    /**
93
     * This object for this field will either be injected by the {@link PopupEditorFactory} or by a Spring
94
     * {@link BeanFactory}
95
     */
96
    @Autowired
97
    private ISpecimenTypeDesignationWorkingSetService specimenTypeDesignationWorkingSetService;
98

    
99
    @Autowired
100
    protected CdmFilterablePagingProviderFactory pagingProviderFactory;
101

    
102
    @Autowired
103
    protected CdmBeanItemContainerFactory cdmBeanItemContainerFactory;
104

    
105
    /**
106
     * if not null, this CRUD set is to be used to create a CdmAuthoritiy for the base entitiy which will be
107
     * granted to the current use as long this grant is not assigned yet.
108
     */
109
    private EnumSet<CRUD> crud = null;
110

    
111
    private ICdmEntityUuidCacher cache;
112

    
113
    SpecimenTypeDesignationWorkingSetDTO<Registration> workingSetDto;
114

    
115
    CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider;
116

    
117
    /**
118
     * The unit of publication in which the type designation has been published.
119
     * This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
120
     * but never a {@link ReferenceType#Section}
121
     */
122
    private DescriptionElementSource publishedUnit;
123

    
124
    private Map<CollectionPopupEditor, SpecimenTypeDesignationDTORow> collectionPopupEditorsRowMap = new HashMap<>();
125

    
126
    private Map<ReferencePopupEditor, ToOneRelatedEntityCombobox<Reference>> referencePopupEditorsCombobox = new HashMap<>();
127

    
128
    private Set<CollectionRowItemCollection> popuEditorTypeDesignationSourceRows = new HashSet<>();
129

    
130
    private java.util.Collection<CdmBase> rootEntities = new HashSet<>();
131

    
132

    
133
    /**
134
     * Loads an existing working set from the database. This process actually involves
135
     * loading the Registration specified by the <code>RegistrationAndWorkingsetId.registrationId</code> and in
136
     * a second step to find the workingset by the <code>registrationAndWorkingsetId.workingsetId</code>.
137
     * <p>
138
     * The <code>identifier</code> must be of the type {@link TypeDesignationWorkingsetIds} whereas the
139
     * field <code>registrationId</code> must be present.
140
     * The field <code>workingsetId</code> however can be null.
141
     * I this case a new workingset with a new {@link FieldUnit} as
142
     * base entity is being created.
143
     *
144
     * @param identifier a {@link TypeDesignationWorkingsetIds}
145
     */
146
    @Override
147
    protected SpecimenTypeDesignationWorkingSetDTO<Registration> loadBeanById(Object identifier) {
148

    
149
        cache = new CdmTransientEntityAndUuidCacher(this);
150
        if(identifier != null){
151

    
152
            SpecimenTypeDesignationWorkingsetIds idset = (SpecimenTypeDesignationWorkingsetIds)identifier;
153

    
154
            if(idset.baseEntityRef != null){
155
                // load existing workingset
156
                workingSetDto = specimenTypeDesignationWorkingSetService.load(idset.registrationUuid, idset.baseEntityRef);
157
                if(workingSetDto.getFieldUnit() == null){
158
                    workingSetDto = specimenTypeDesignationWorkingSetService.fixMissingFieldUnit(workingSetDto);
159
                        // FIXME open Dialog to warn user about adding an empty fieldUnit to the typeDesignations
160
                        //       This method must go again into the presenter !!!!
161
                        logger.info("Basing all typeDesignations on a new fieldUnit");
162
                }
163
            } else {
164
                // create a new workingset, for a new fieldunit which is the base for the workingset
165
                workingSetDto = specimenTypeDesignationWorkingSetService.create(idset.getRegistrationUUID(), idset.getTypifiedNameUuid());
166
                cache.load(workingSetDto.getTypifiedName());
167
                rootEntities.add(workingSetDto.getTypifiedName());
168
            }
169
            Registration registration = workingSetDto.getOwner();
170
            // need to use load() but put() see #7214
171
            cache.load(registration);
172
            rootEntities.add(registration);
173
            try {
174
                setPublishedUnit(RegistrationDTO.findPublishedUnit(registration));
175
            } catch (Exception e) {
176
                // FIXME report error state instead
177
                logger.error("Error on finding published unit in " + registration.toString(), e);
178
            }
179
        } else {
180
            workingSetDto = null;
181
        }
182

    
183
        if (getPublishedUnit() != null) {
184
            // reduce available references to those which are sections of
185
            // the publicationUnit and the publishedUnit itself
186
            referencePagingProvider.getCriteria()
187
                    .add(Restrictions.or(
188
                            Restrictions.and(
189
                                    Restrictions.eq("inReference", publishedUnit.getCitation()),
190
                                    Restrictions.eq("type", ReferenceType.Section)),
191
                            Restrictions.idEq(publishedUnit.getCitation().getId()))
192
                         );
193
        }
194

    
195
        return workingSetDto;
196
    }
197

    
198

    
199
    /**
200
     * {@inheritDoc}
201
     */
202
    @SuppressWarnings("serial")
203
    @Override
204
    public void handleViewEntered() {
205

    
206
        getView().getCountrySelectField().setContainerDataSource(cdmBeanItemContainerFactory.buildVocabularyTermsItemContainer(Country.uuidCountryVocabulary));
207

    
208
        CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> termOrPersonPagingProvider = pagingProviderFactory.teamOrPersonPagingProvider();
209
        CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider = pagingProviderFactory.personPagingProvider();
210
        termOrPersonPagingProvider.setInitStrategy(AgentBaseInit.TEAM_OR_PERSON_INIT_STRATEGY);
211
        // the ToOneRelatedEntityReloader is added internally in the TeamOrPersonField:
212
        getView().getCollectorField().setFilterablePersonPagingProvider(personPagingProvider, this);
213
        getView().getCollectorField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
214

    
215
        getView().getExactLocationField().getReferenceSystemSelect().setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(TermType.ReferenceSystem));
216
        getView().getExactLocationField().getReferenceSystemSelect().setItemCaptionPropertyId("label");
217

    
218
        getView().getTypeDesignationsCollectionField().addElementRemovedListener(e -> deleteTypeDesignation(e.getElement()));
219
        getView().getTypeDesignationsCollectionField().addElementAddedListener(e -> addTypeDesignation(e.getElement()));
220

    
221
        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildVocabularyTermsItemContainer(
222
                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
223

    
224
        popuEditorTypeDesignationSourceRows.clear();
225
        CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
226
        collectionPagingProvider.getRestrictions().add(new Restriction<>("institute.titleCache", Operator.OR, MatchMode.ANYWHERE, CdmFilterablePagingProvider.QUERY_STRING_PLACEHOLDER));
227

    
228
        referencePagingProvider = pagingProviderFactory.referencePagingProvider();
229

    
230
        getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
231

    
232
            @Override
233
            public SpecimenTypeDesignationDTORow create() {
234

    
235
                SpecimenTypeDesignationDTORow row = new SpecimenTypeDesignationDTORow();
236

    
237
                row.kindOfUnit.setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(
238
                        RegistrationTermLists.KIND_OF_UNIT_TERM_UUIDS())
239
                        );
240
                row.kindOfUnit.setNullSelectionAllowed(false);
241

    
242
                row.typeStatus.setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(
243
                        RegistrationTermLists.SPECIMEN_TYPE_DESIGNATION_STATUS_UUIDS())
244
                        );
245
                row.typeStatus.setNullSelectionAllowed(false);
246

    
247

    
248
                row.collection.loadFrom(
249
                        collectionPagingProvider,
250
                        collectionPagingProvider,
251
                        collectionPagingProvider.getPageSize()
252
                        );
253
                row.collection.getSelect().setCaptionGenerator(new CollectionCaptionGenerator());
254
                row.collection.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Collection>(row.collection.getSelect(),
255
                        SpecimenTypeDesignationWorkingsetEditorPresenter.this));
256
                row.collection.addClickListenerAddEntity(e -> doCollectionEditorAdd(row));
257
                row.collection.addClickListenerEditEntity(e -> {
258
                        if(row.collection.getValue() != null){
259
                            doCollectionEditorEdit(row);
260
                        }
261
                    });
262

    
263
                row.designationReference.loadFrom(
264
                        referencePagingProvider,
265
                        referencePagingProvider,
266
                        referencePagingProvider.getPageSize()
267
                        );
268
                row.designationReference.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC, row.designationReference.getSelect()));
269
                row.designationReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.designationReference.getSelect(),
270
                        SpecimenTypeDesignationWorkingsetEditorPresenter.this));
271
                row.designationReference.addClickListenerAddEntity(e -> doReferenceEditorAdd(row.designationReference));
272
                row.designationReference.addClickListenerEditEntity(e -> {
273
                    if(row.designationReference.getValue() != null){
274
                        doReferenceEditorEdit(row.designationReference);
275
                    }
276
                });
277

    
278
                row.mediaSpecimenReference.loadFrom(
279
                        referencePagingProvider,
280
                        referencePagingProvider,
281
                        referencePagingProvider.getPageSize()
282
                        );
283
                row.mediaSpecimenReference.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC, row.mediaSpecimenReference.getSelect()));
284
                row.mediaSpecimenReference.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(row.mediaSpecimenReference.getSelect(),
285
                        SpecimenTypeDesignationWorkingsetEditorPresenter.this));
286
                row.mediaSpecimenReference.addClickListenerAddEntity(e -> doReferenceEditorAdd(row.mediaSpecimenReference));
287
                row.mediaSpecimenReference.addClickListenerEditEntity(e -> {
288
                    if(row.mediaSpecimenReference.getValue() != null){
289
                        doReferenceEditorEdit(row.mediaSpecimenReference);
290
                    }
291
                });
292

    
293
                getView().applyDefaultComponentStyle(row.components());
294

    
295
                popuEditorTypeDesignationSourceRows.add(row);
296

    
297
                return row;
298
            }
299

    
300
        });
301

    
302
    }
303

    
304

    
305
    /**
306
     * {@inheritDoc}
307
     */
308
    @Override
309
    protected void saveBean(SpecimenTypeDesignationWorkingSetDTO dto) {
310

    
311
        if(crud != null){
312
            UserHelperAccess.userHelper().createAuthorityForCurrentUser(dto.getFieldUnit(), crud, null);
313
        }
314

    
315
        List<SpecimenTypeDesignationDTO> stdDTOs = dto.getSpecimenTypeDesignationDTOs();
316
        for(SpecimenTypeDesignationDTO stddto : stdDTOs) {
317
            // clean up
318
            if(!stddto.getTypeStatus().hasDesignationSource()) {
319
                stddto.setDesignationReference(null);
320
                stddto.setDesignationReferenceDetail(null);
321
            }
322
        }
323

    
324
        specimenTypeDesignationWorkingSetService.save(dto);
325
    }
326

    
327
    /**
328
     * {@inheritDoc}
329
     */
330
    @Override
331
    protected void deleteBean(SpecimenTypeDesignationWorkingSetDTO bean) {
332
        specimenTypeDesignationWorkingSetService.delete(bean, true);
333
    }
334

    
335
    /**
336
     * @param element
337
     * @return
338
     */
339
    private void addTypeDesignation(SpecimenTypeDesignationDTO element) {
340
        getView().updateAllowDeleteTypeDesignation();
341
    }
342

    
343

    
344
    /**
345
     * In this method the SpecimenTypeDesignation is dissociated from the Registration.
346
     * The actual deletion of the SpecimenTypeDesignation and DerivedUnit will take place in {@link #saveBean(SpecimenTypeDesignationWorkingSetDTO)}
347
     *
348
     * TODO once https://dev.e-taxonomy.eu/redmine/issues/7077 is fixed dissociating from the Registration could be removed here
349
     *
350
     * @param e
351
     * @return
352
     */
353
    private void deleteTypeDesignation(SpecimenTypeDesignationDTO element) {
354

    
355
        Registration reg = workingSetDto.getOwner();
356
        SpecimenTypeDesignation std = element.asSpecimenTypeDesignation();
357

    
358
        reg.getTypeDesignations().remove(std);
359

    
360
        getView().updateAllowDeleteTypeDesignation();
361
    }
362

    
363
    /**
364
     * @param crud
365
     */
366
    public void setGrantsForCurrentUser(EnumSet<CRUD> crud) {
367
        this.crud = crud;
368
    }
369

    
370
    /**
371
     * {@inheritDoc}
372
     */
373
    @Override
374
    public ICdmEntityUuidCacher getCache() {
375
        return cache;
376
    }
377

    
378
    @Override
379
    public void disposeCache() {
380
        cache.dispose();
381
    }
382

    
383
    public void doCollectionEditorAdd(SpecimenTypeDesignationDTORow row) {
384

    
385
        CollectionPopupEditor collectionPopupEditor = openPopupEditor(CollectionPopupEditor.class, null);
386

    
387
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
388
        collectionPopupEditor.withDeleteButton(true);
389
        collectionPopupEditor.loadInEditor(null);
390

    
391
        collectionPopupEditorsRowMap.put(collectionPopupEditor, row);
392
    }
393

    
394
    public void doCollectionEditorEdit(SpecimenTypeDesignationDTORow row) {
395

    
396
        CollectionPopupEditor collectionPopupEditor = openPopupEditor(CollectionPopupEditor.class, null);
397

    
398
        collectionPopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
399
        collectionPopupEditor.withDeleteButton(true);
400
        collectionPopupEditor.loadInEditor(row.collection.getValue().getUuid());
401

    
402
        collectionPopupEditorsRowMap.put(collectionPopupEditor, row);
403
    }
404

    
405

    
406
    @EventBusListenerMethod(filter = EntityChangeEventFilter.OccurrenceCollectionFilter.class)
407
    public void onCollectionEvent(EntityChangeEvent event){
408

    
409
        if(event.getSourceView() instanceof AbstractPopupEditor) {
410

    
411
            Stack<EditorActionContext> context = ((AbstractPopupEditor) event.getSourceView()).getEditorActionContext();
412
            if(context.size() > 1){
413
               AbstractView<?> parentView = context.get(context.size() - 2).getParentView();
414
               if(getView().equals(parentView)){
415
                   Collection newCollection = getRepo().getCollectionService().load(
416
                           event.getEntityUuid(), Arrays.asList(new String[]{"$.institute"})
417
                           );
418
                   cache.load(newCollection);
419

    
420
                   if(event.isCreatedType()){
421
                       SpecimenTypeDesignationDTORow row = collectionPopupEditorsRowMap.get(event.getSourceView());
422
                       ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, 3);
423
                       combobox.setValue((Collection) event.getEntity());
424
                   } else {
425
                       for( CollectionRowItemCollection row : popuEditorTypeDesignationSourceRows) {
426
                           ToOneRelatedEntityCombobox<Collection> combobox = row.getComponent(ToOneRelatedEntityCombobox.class, 3);
427
                           combobox.reload();
428
                       }
429
                   }
430
               }
431
            }
432
        }
433
    }
434

    
435
    public void doReferenceEditorAdd(ToOneRelatedEntityCombobox<Reference> referenceComobox) {
436

    
437
        ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
438

    
439
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
440
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
441
        referencePopupEditor.withDeleteButton(true);
442
        referencePopupEditor.loadInEditor(null);
443

    
444
        referencePopupEditorsCombobox.put(referencePopupEditor, referenceComobox);
445
    }
446

    
447
    public void doReferenceEditorEdit(ToOneRelatedEntityCombobox<Reference> referenceComobox) {
448

    
449
        ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
450
        referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
451
        referencePopupEditor.grantToCurrentUser(COLLECTION_EDITOR_CRUD);
452
        referencePopupEditor.withDeleteButton(true);
453
        referencePopupEditor.loadInEditor(referenceComobox.getValue().getUuid());
454

    
455
        referencePopupEditorsCombobox.put(referencePopupEditor, referenceComobox);
456
    }
457

    
458
    @EventBusListenerMethod(filter = EntityChangeEventFilter.ReferenceFilter.class)
459
    public void onReferenceEvent(EntityChangeEvent event){
460

    
461
        Reference newRef = getRepo().getReferenceService().load(event.getEntityUuid(), Arrays.asList(new String[]{"$"}));
462
        cache.load(newRef);
463

    
464
        ToOneRelatedEntityCombobox<Reference> combobox = referencePopupEditorsCombobox.get(event.getSourceView());
465
        if(event.isCreatedType()){
466
            combobox.setValue((Reference) event.getEntity());
467
        } else {
468
            for( CollectionRowItemCollection row : popuEditorTypeDesignationSourceRows) {
469
                combobox.reload();
470
            }
471
        }
472
    }
473

    
474
    /**
475
     * {@inheritDoc}
476
     */
477
    @Override
478
    public void addRootEntity(CdmBase entity) {
479
        rootEntities.add(entity);
480
    }
481

    
482
    /**
483
     * {@inheritDoc}
484
     */
485
    @Override
486
    public java.util.Collection<CdmBase> getRootEntities() {
487
        return rootEntities ;
488
    }
489

    
490
    /**
491
     * {@inheritDoc}
492
     */
493
    @Override
494
    public void destroy() throws Exception {
495
        super.destroy();
496
        cache.dispose();
497
    }
498

    
499
    /**
500
     * @return
501
     *  the {@link #publishedUnit}
502
     */
503
    public DescriptionElementSource getPublishedUnit() {
504
        return publishedUnit;
505
    }
506

    
507
    /**
508
     * @param publishedUnit
509
     *  The unit of publication in which the type designation has been published.
510
     *  This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
511
     */
512
    protected void setPublishedUnit(DescriptionElementSource publishedUnit) throws Exception {
513
        if(publishedUnit == null) {
514
            throw new NullPointerException();
515
        }
516
        if(publishedUnit.getCitation() == null) {
517
            throw new NullPointerException("The citation of the published unit must not be null.");
518
        }
519
        if(!RegistrationUIDefaults.NOMECLATURAL_PUBLICATION_UNIT_TYPES.contains(publishedUnit.getCitation().getType())) {
520
            throw new Exception("The referrence type '"  + publishedUnit.getType() + "'is not allowed for publishedUnit.");
521
        }
522
        this.publishedUnit = publishedUnit;
523
    }
524

    
525
}
(9-9/17)