Project

General

Profile

« Previous | Next » 

Revision 303a8ebc

Added by Andreas Kohlbecker about 3 years ago

ref #9290 limiting designation sources to the publication unit and sub sections in NameTypeDesignationEditor

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
15 15
import java.util.List;
16 16
import java.util.UUID;
17 17

  
18
import org.apache.log4j.Logger;
19
import org.hibernate.criterion.Restrictions;
18 20
import org.springframework.beans.factory.annotation.Autowired;
19 21
import org.springframework.context.annotation.Scope;
20 22
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
......
30 32
import eu.etaxonomy.cdm.format.reference.ReferenceEllypsisFormatter.LabelType;
31 33
import eu.etaxonomy.cdm.model.common.Annotation;
32 34
import eu.etaxonomy.cdm.model.common.AnnotationType;
35
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
33 36
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
34 37
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
35 38
import eu.etaxonomy.cdm.model.name.TaxonName;
36 39
import eu.etaxonomy.cdm.model.permission.CRUD;
37 40
import eu.etaxonomy.cdm.model.reference.Reference;
41
import eu.etaxonomy.cdm.model.reference.ReferenceType;
38 42
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
39 43
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
40 44
import eu.etaxonomy.cdm.service.CdmStore;
......
45 49
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
46 50
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
47 51
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
52
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
48 53
import eu.etaxonomy.cdm.vaadin.ui.config.TaxonNamePopupEditorConfig;
49 54
import eu.etaxonomy.cdm.vaadin.util.ReferenceEllypsisCaptionGenerator;
50 55
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
......
65 70

  
66 71
    private static final long serialVersionUID = 896305051895903033L;
67 72

  
73
    public static final Logger logger = Logger.getLogger(SpecimenTypeDesignationWorkingsetEditorPresenter.class);
74

  
68 75
    @Autowired
69 76
    private IRegistrationWorkingSetService registrationWorkingSetService;
70 77

  
......
72 79

  
73 80
    private TaxonName typifiedNameInContext;
74 81

  
82
    /**
83
     * The unit of publication in which the type designation has been published.
84
     * This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
85
     * but never a {@link ReferenceType#Section}
86
     */
87
    private DescriptionElementSource publishedUnit;
88

  
75 89
    protected static BeanInstantiator<NameTypeDesignation> defaultBeanInstantiator = new BeanInstantiator<NameTypeDesignation>() {
76 90

  
77 91
        @Override
......
93 107
     */
94 108
    @Override
95 109
    protected NameTypeDesignation loadBeanById(Object identifier) {
110
        NameTypeDesignation bean;
96 111
        if(identifier instanceof Integer || identifier == null){
97
            return super.loadBeanById(identifier);
112
            bean = super.loadBeanById(identifier);
98 113
        } else {
99 114
            TypeDesignationWorkingsetIds idset = (TypeDesignationWorkingsetIds)identifier;
100 115
            RegistrationDTO regDTO = registrationWorkingSetService.loadDtoByUuid(idset.registrationUuid);
......
106 121
            } else {
107 122
                // TypeDesignationWorkingSet for NameTyped only contain one item!!!
108 123
                UUID nameTypeDesignationUuid = typeDesignationWorkingSet.getTypeDesignations().get(0).getUuid();
109
                return super.loadBeanById(nameTypeDesignationUuid);
124
                bean = super.loadBeanById(nameTypeDesignationUuid);
110 125
            }
111 126
        }
127

  
128
        try {
129
            setPublishedUnit(bean.getTypifiedNames().iterator().next().getNomenclaturalSource());
130
        } catch (Exception e) {
131
            // FIXME report error state instead
132
            logger.error("Error on finding published unit in " + bean, e);
133
        }
134

  
135
        if (getPublishedUnit() != null) {
136
            // reduce available references to those which are sections of
137
            // the publicationUnit and the publishedUnit itself
138
            referencePagingProvider.getCriteria()
139
                    .add(Restrictions.or(
140
                            Restrictions.and(
141
                                    Restrictions.eq("inReference", publishedUnit.getCitation()),
142
                                    Restrictions.eq("type", ReferenceType.Section)),
143
                            Restrictions.idEq(publishedUnit.getCitation().getId()))
144
                         );
145
        }
146

  
147
        return bean;
112 148
    }
113 149

  
114 150

  
......
121 157
                "$",
122 158
                "annotations.*", // * is needed as log as we are using a table in FilterableAnnotationsField
123 159
                "typifiedNames.typeDesignations", // important !!
160
                "typifiedNames.nomenclaturalSource.citation",
124 161
                "typeName.$",
125 162
                "source.citation",
126 163
                "source.annotations",
......
315 352
        }
316 353
    }
317 354

  
355
    /**
356
     * @return
357
     *  the {@link #publishedUnit}
358
     */
359
    public DescriptionElementSource getPublishedUnit() {
360
        return publishedUnit;
361
    }
362

  
363
    /**
364
     * @param publishedUnit
365
     *  The unit of publication in which the type designation has been published.
366
     *  This may be any type listed in {@link RegistrationUIDefaults#NOMECLATURAL_PUBLICATION_UNIT_TYPES}
367
     */
368
    protected void setPublishedUnit(DescriptionElementSource publishedUnit) throws Exception {
369
        if(publishedUnit == null) {
370
            throw new NullPointerException();
371
        }
372
        if(publishedUnit.getCitation() == null) {
373
            throw new NullPointerException("The citation of the published unit must not be null.");
374
        }
375
        if(!RegistrationUIDefaults.NOMECLATURAL_PUBLICATION_UNIT_TYPES.contains(publishedUnit.getCitation().getType())) {
376
            throw new Exception("The referrence type '"  + publishedUnit.getType() + "'is not allowed for publishedUnit.");
377
        }
378
        this.publishedUnit = publishedUnit;
379
    }
380

  
318 381
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
17 17
import java.util.Set;
18 18
import java.util.Stack;
19 19

  
20
import org.apache.log4j.Logger;
20 21
import org.hibernate.criterion.Restrictions;
21 22
import org.springframework.beans.factory.DisposableBean;
22 23
import org.springframework.beans.factory.annotation.Autowired;
......
86 87

  
87 88
    private static final long serialVersionUID = 4255636253714476918L;
88 89

  
90
    public static final Logger logger = Logger.getLogger(SpecimenTypeDesignationWorkingsetEditorPresenter.class);
91

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

  
91 94

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
626 626
                @Override
627 627
                public NameTypeDesignation createNewBean() {
628 628

  
629
                    TaxonName typifiedName = getRepo().getNameService().load(event.getTypifiedNameUuid(), Arrays.asList(new String[]{"typeDesignations", "homotypicalGroup"}));
629
                    TaxonName typifiedName = getRepo().getNameService().load(event.getTypifiedNameUuid(), Arrays.asList(new String[]{
630
                            "typeDesignations",
631
                            "homotypicalGroup",
632
                            "nomenclaturalSource.citation"
633
                            }));
630 634
                    NameTypeDesignation nameTypeDesignation  = NameTypeDesignation.NewInstance();
631 635
                    nameTypeDesignation.getTypifiedNames().add(typifiedName);
632 636
                    return nameTypeDesignation;

Also available in: Unified diff