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 eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
12
|
import eu.etaxonomy.cdm.model.molecular.DnaSample;
|
13
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
14
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
15
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
16
|
|
17
|
/**
|
18
|
* Factory for all SpecimenOrObservationBase related DTOs.
|
19
|
* <p>
|
20
|
* Internally this class delegates to the factory methods of the specific DTO implementations.
|
21
|
*
|
22
|
* @author a.kohlbecker
|
23
|
* @since Oct 14, 2020
|
24
|
*/
|
25
|
public class SpecimenOrObservationDTOFactory {
|
26
|
|
27
|
public static SpecimenOrObservationBaseDTO fromEntity(SpecimenOrObservationBase<?> entity) {
|
28
|
return fromEntity(entity, null);
|
29
|
}
|
30
|
|
31
|
public static SpecimenOrObservationBaseDTO fromEntity(SpecimenOrObservationBase<?> entity, Integer maxDepth) {
|
32
|
if(entity == null) {
|
33
|
return null;
|
34
|
}
|
35
|
if (entity.isInstanceOf(FieldUnit.class)) {
|
36
|
return FieldUnitDTO.fromEntity(HibernateProxyHelper.deproxy(entity, FieldUnit.class), maxDepth, null);
|
37
|
} else {
|
38
|
if (entity.isInstanceOf(DnaSample.class)){
|
39
|
return new DNASampleDTO(HibernateProxyHelper.deproxy(entity, DnaSample.class)); // FIXME use factory method
|
40
|
} else {
|
41
|
return DerivedUnitDTO.fromEntity(HibernateProxyHelper.deproxy(entity, DerivedUnit.class), maxDepth, null);
|
42
|
}
|
43
|
}
|
44
|
}
|
45
|
|
46
|
public static FieldUnitDTO fromFieldUnit(FieldUnit entity){
|
47
|
if(entity == null) {
|
48
|
return null;
|
49
|
}
|
50
|
return FieldUnitDTO.fromEntity(entity);
|
51
|
}
|
52
|
|
53
|
public static SpecimenOrObservationBaseDTO fromDerivedUnit(DerivedUnit entity){
|
54
|
if(entity == null) {
|
55
|
return null;
|
56
|
}
|
57
|
return DerivedUnitDTO.fromEntity(entity);
|
58
|
}
|
59
|
|
60
|
}
|