Project

General

Profile

« Previous | Next » 

Revision 1d9ed98e

Added by Andreas Kohlbecker over 3 years ago

ref #9238 extending SpecimenTypeDesignationDTO with more fields and associated DTOs, introducing ReferenceDTO, supressing unwanted and dangerous fields of RegistrationDTO

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/ref/TypedEntityReference.java
12 12

  
13 13
import org.apache.commons.lang3.builder.HashCodeBuilder;
14 14

  
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
17

  
15 18
/**
16 19
 * @author a.kohlbecker
17 20
 * @since Jun 12, 2017
......
37 40
        this.type = type;
38 41
    }
39 42

  
43
    public static <T> TypedEntityReference<T> fromCdmBase(CdmBase entity) {
44
        if(entity == null) {
45
            return null;
46
        }
47
        return new TypedEntityReference<T>((Class<T>)entity.getClass(), entity.getUuid());
48
    }
49

  
50
    public static <T> TypedEntityReference<T> fromIdentifiableEntity(IdentifiableEntity<?> entity) {
51
        if(entity == null) {
52
            return null;
53
        }
54
        return new TypedEntityReference<T>((Class<T>)entity.getClass(), entity.getUuid());
55
    }
56

  
40 57
    public Class<T> getType() {
41 58
        return type;
42 59
    }
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/RegistrationDtoBeanProcessor.java
1
/**
2
* Copyright (C) 2020 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.remote.json.processor.bean;
10

  
11
import java.util.Arrays;
12
import java.util.List;
13

  
14
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
15
import net.sf.json.JSONObject;
16
import net.sf.json.JsonConfig;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since Oct 8, 2020
21
 */
22
public class RegistrationDtoBeanProcessor extends AbstractBeanProcessor<RegistrationDTO> {
23

  
24
    @Override
25
    public List<String> getIgnorePropNames() {
26
        return Arrays.asList(
27
                "blockedBy",
28
                "blocked",
29
                "orderdTypeDesignationWorkingSets",
30
                "submitterUserName",
31
                "specificIdentifier",
32
                "typifiedName"
33
                );
34
    }
35

  
36

  
37

  
38
    @Override
39
    public JSONObject processBeanSecondStep(RegistrationDTO bean, JSONObject json, JsonConfig jsonConfig) {
40
        // nothing to do here
41
        return json;
42
    }
43

  
44
}
cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml
185 185
         <entry key="org.apache.lucene.document.Document">
186 186
              <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.LuceneDocumentBeanProcessor" />
187 187
         </entry>
188
         <entry key="eu.etaxonomy.cdm.api.service.dto.RegistrationDTO">
189
            <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.RegistrationDtoBeanProcessor" />
190
        </entry>
188 191
      </map>
189 192
    </property>
190 193
    <property name="jsonPropertyFilter">
......
480 483
        <entry key="eu.etaxonomy.cdm.model.description.KeyStatement">
481 484
            <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.KeyStatementBeanProcessor" />
482 485
        </entry>
486
        <entry key="eu.etaxonomy.cdm.api.service.dto.RegistrationDTO">
487
            <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.RegistrationDtoBeanProcessor" />
488
        </entry>
483 489
      </map>
484 490
    </property>
485 491
        <property name="jsonPropertyFilter">
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/CdmEntityIdentifier.java
11 11
import java.io.Serializable;
12 12

  
13 13
import eu.etaxonomy.cdm.model.common.CdmBase;
14
import eu.etaxonomy.cdm.ref.TypedEntityReference;
14 15

  
15 16
/**
17
 * TODO replace by {@link TypedEntityReference} ?
16 18
 * @author cmathew
17 19
 * @since 24 Jun 2015
18 20
 */
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/DerivateDTO.java
78 78
     * @return
79 79
     */
80 80
    public static DerivateDTO newInstance(SpecimenOrObservationBase sob){
81
        if(sob == null) {
82
            return null;
83
        }
81 84
        DerivateDTO derivateDto;
82 85
        if (sob.isInstanceOf(FieldUnit.class)){
83 86
            derivateDto = new FieldUnitDTO(HibernateProxyHelper.deproxy(sob, FieldUnit.class));
......
161 164
        this.specimenTypeDesignations = new HashSet<>();
162 165
        for (SpecimenTypeDesignation typeDes: specimenTypeDesignations){
163 166
            if (typeDes != null){
164
                this.specimenTypeDesignations.add(new SpecimenTypeDesignationDTO(typeDes, null));
167
                this.specimenTypeDesignations.add(new SpecimenTypeDesignationDTO(typeDes));
165 168
            }
166 169
        }
167 170

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/ReferenceDTO.java
1
/**
2
* Copyright (C) 2020 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.api.service.dto;
10

  
11
import java.net.URI;
12
import java.util.UUID;
13

  
14
import eu.etaxonomy.cdm.common.DOI;
15
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
16
import eu.etaxonomy.cdm.model.reference.Reference;
17
import eu.etaxonomy.cdm.ref.TypedEntityReference;
18

  
19
/**
20
 * @author a.kohlbecker
21
 * @since Oct 8, 2020
22
 */
23
public class ReferenceDTO extends TypedEntityReference<Reference> {
24

  
25
    private static final long serialVersionUID = -2619569446682158500L;
26

  
27
    private String titleCache;
28
    private String abbrevTitleCache;
29
    private URI uri;
30
    private DOI doi;
31
    private VerbatimTimePeriod datePublished;
32

  
33
    public static ReferenceDTO fromReference(Reference entity) {
34
        if(entity == null) {
35
            return null;
36
        }
37
        ReferenceDTO dto = new ReferenceDTO(entity.getUuid());
38
        dto.titleCache = entity.getTitleCache();
39
        dto.abbrevTitleCache = entity.getAbbrevTitleCache();
40
        dto.uri = entity.getUri();
41
        dto.doi = entity.getDoi();
42
        dto.datePublished = entity.getDatePublished();
43

  
44
        return dto;
45
    }
46

  
47
    private ReferenceDTO(UUID uuid) {
48
        super(Reference.class, uuid);
49
    }
50

  
51
    public String getTitleCache() {
52
        return titleCache;
53
    }
54

  
55
    public void setTitleCache(String titleCache) {
56
        this.titleCache = titleCache;
57
    }
58

  
59
    public String getAbbrevTitleCache() {
60
        return abbrevTitleCache;
61
    }
62

  
63
    public void setAbbrevTitleCache(String abbrevTitleCache) {
64
        this.abbrevTitleCache = abbrevTitleCache;
65
    }
66

  
67
    public URI getUri() {
68
        return uri;
69
    }
70

  
71
    public void setUri(URI uri) {
72
        this.uri = uri;
73
    }
74

  
75
    public DOI getDoi() {
76
        return doi;
77
    }
78

  
79
    public void setDoi(DOI doi) {
80
        this.doi = doi;
81
    }
82

  
83
    public VerbatimTimePeriod getDatePublished() {
84
        return datePublished;
85
    }
86

  
87
    public void setDatePublished(VerbatimTimePeriod datePublished) {
88
        this.datePublished = datePublished;
89
    }
90

  
91
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/SourceDTO.java
10 10

  
11 11
import java.util.UUID;
12 12

  
13
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
14

  
13 15
/**
14 16
 * @author a.kohlbecker
15 17
 * @since Aug 31, 2018
......
18 20
public class SourceDTO {
19 21

  
20 22
    private UUID uuid;
21
    String citation;
22 23
    String citationDetail;
24
    ReferenceDTO citation;
25

  
26
    public static SourceDTO fromDescriptionElementSource(DescriptionElementSource entity) {
27
        if(entity == null) {
28
            return null;
29
        }
30
        SourceDTO dto = new SourceDTO();
31
        dto.uuid = entity.getUuid();
32
        dto.citation = ReferenceDTO.fromReference(entity.getCitation());
33
        dto.citationDetail = entity.getCitationMicroReference();
34
        return dto;
35
    }
36

  
37
    public UUID getUuid() {
38
        return uuid;
39
    }
40

  
41

  
42
    public void setUuid(UUID uuid) {
43
        this.uuid = uuid;
44
    }
45

  
46
    public ReferenceDTO getCitation() {
47
        return citation;
48
    }
49

  
50

  
51
    public void setCitation(ReferenceDTO citation) {
52
        this.citation = citation;
53
    }
54

  
55

  
56
    public String getCitationDetail() {
57
        return citationDetail;
58
    }
59

  
60

  
61
    public void setCitationDetail(String citationDetail) {
62
        this.citationDetail = citationDetail;
63
    }
23 64

  
24 65
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/SpecimenTypeDesignationDTO.java
11 11
import java.io.Serializable;
12 12
import java.util.ArrayList;
13 13
import java.util.List;
14
import java.util.stream.Collectors;
14 15

  
15 16
import eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n;
16 17
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
17 18
import eu.etaxonomy.cdm.model.name.TaxonName;
19
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
18 20
import eu.etaxonomy.cdm.ref.EntityReference;
19 21
import eu.etaxonomy.cdm.ref.TypedEntityReference;
20 22

  
......
27 29
    private static final long serialVersionUID = -2397286652498492934L;
28 30

  
29 31
    private List<EntityReference> names;
30
    private DerivateDTO typeSpecimen;
32
    private TypedEntityReference<DerivedUnit> typeSpecimen;
31 33
    private String typeStatus;
32 34
    private String typeStatus_L10n;
35
    private SourceDTO source;
36
    private List<RegistrationDTO> registrations;
33 37

  
34 38
    /**
35 39
     *
......
37 41
     * @param typeSpecimenDTO
38 42
     *      Can be null
39 43
     */
40
    public SpecimenTypeDesignationDTO(SpecimenTypeDesignation typeDesignation, DerivateDTO typeSpecimenDTO)  {
44
    public SpecimenTypeDesignationDTO(SpecimenTypeDesignation typeDesignation)  {
41 45

  
42 46
        super(SpecimenTypeDesignation.class, typeDesignation.getUuid());
43 47

  
......
51 55
        for (TaxonName name:typeDesignation.getTypifiedNames()){
52 56
            names.add(new EntityReference(name.getUuid(), name.getTitleCache()));
53 57
        }
54
        this.typeSpecimen = typeSpecimenDTO;
58
        this.setSource(SourceDTO.fromDescriptionElementSource(typeDesignation.getSource()));
59
        this.typeSpecimen = TypedEntityReference.fromIdentifiableEntity(typeDesignation.getTypeSpecimen());
60
        setRegistrations(typeDesignation.getRegistrations().stream().map(reg -> new RegistrationDTO(reg)).collect(Collectors.toList()));
55 61

  
56 62
    }
57 63

  
......
63 69
        this.names = names;
64 70
    }
65 71

  
66
    public DerivateDTO getTypeSpecimen() {
72
    public TypedEntityReference<DerivedUnit> getTypeSpecimen() {
67 73
        return typeSpecimen;
68 74
    }
69 75

  
70
    public void setTypeSpecimen(DerivateDTO typeSpecimen) {
76
    public void setTypeSpecimen(TypedEntityReference<DerivedUnit> typeSpecimen) {
71 77
        this.typeSpecimen = typeSpecimen;
72 78
    }
73 79

  
......
96 102
        return typeStatus_L10n;
97 103
    }
98 104

  
105
    public SourceDTO getSource() {
106
        return source;
107
    }
108

  
109
    public void setSource(SourceDTO source) {
110
        this.source = source;
111
    }
112

  
113
    public List<RegistrationDTO> getRegistrations() {
114
        return registrations;
115
    }
116

  
117
    public void setRegistrations(List<RegistrationDTO> registrations) {
118
        this.registrations = registrations;
119
    }
120

  
99 121

  
100 122

  
101 123
}

Also available in: Unified diff