Project

General

Profile

Download (3.73 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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.model.common;
10

    
11
import java.io.Serializable;
12

    
13
import javax.persistence.Basic;
14
import javax.persistence.Column;
15
import javax.persistence.Embeddable;
16
import javax.persistence.FetchType;
17
import javax.validation.constraints.NotNull;
18
import javax.xml.bind.annotation.XmlAccessType;
19
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlAttribute;
21
import javax.xml.bind.annotation.XmlElement;
22
import javax.xml.bind.annotation.XmlRootElement;
23
import javax.xml.bind.annotation.XmlType;
24
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
25

    
26
import org.apache.commons.lang3.StringUtils;
27
import org.hibernate.annotations.Type;
28
import org.hibernate.search.annotations.Analyze;
29
import org.hibernate.search.annotations.Field;
30
import org.hibernate.search.annotations.FieldBridge;
31
import org.joda.time.DateTime;
32

    
33
import eu.etaxonomy.cdm.common.URI;
34
import eu.etaxonomy.cdm.hibernate.search.UriBridge;
35
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
36
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
37

    
38
/**
39
 * Embedabble class to embed attributes to use externally managed data
40
 * @author a.mueller
41
 * @since 12.08.2019
42
 */
43
@XmlAccessorType(XmlAccessType.FIELD)
44
@XmlType(name = "ExternallyManaged", propOrder = {
45
    "lastRetrieved",
46
    "externalId",
47
    "externalLink",
48
    "authorityType",
49
    "importMethod"
50
})
51
@XmlRootElement(name = "ExternallyManaged")
52
@Embeddable
53
public class ExternallyManaged implements Cloneable, Serializable, ICheckEmpty{
54

    
55
    private static final long serialVersionUID = -2254347420863435872L;
56

    
57

    
58
    //attributes for externally managed
59

    
60
//  @XmlElement (name = "LastRetrieved", type= String.class)
61
    @XmlJavaTypeAdapter(DateTimeAdapter.class)
62
    @Type(type="dateTimeUserType")
63
    //TODO needed??
64
    @Basic(fetch = FetchType.LAZY)
65
    @Column(name="lastRetrieved")
66
    private DateTime lastRetrieved;
67

    
68
    @XmlElement(name ="ExternalId" )
69
//  @Field
70
//  @Match(MatchMode.EQUAL)  //TODO check if this is correct
71
    @NullOrNotEmpty
72
    @Column(name="externalId", length=255)
73
    private String externalId;
74

    
75
    //Actionable link on e.g. on a webservice
76
    @XmlElement(name = "ExternalLink")
77
    @Field(analyze = Analyze.NO)
78
    @FieldBridge(impl = UriBridge.class)
79
    @Type(type="uriUserType")
80
    @Column(name="externalLink")
81
    private URI externalLink;
82

    
83
    @XmlAttribute(name ="authority")
84
    @Column(name="authorityType", length=10)
85
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
86
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.common.AuthorityType")}
87
    )
88
    @NotNull
89
    private AuthorityType authorityType;
90

    
91
    @XmlAttribute(name ="importMethod")
92
    @Column(name="importMethod", length=30)
93
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
94
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.common.ExternallyManagedImport")}
95
    )
96
    @NotNull
97
    private ExternallyManagedImport importMethod;
98

    
99
//************************* **********************/
100

    
101
    @Override
102
    public boolean checkEmpty() {
103
        return authorityType == null && StringUtils.isBlank(externalId)
104
                && externalLink == null && importMethod == null && lastRetrieved == null;
105
    }
106

    
107
// ************************ CLONE ***********************/
108

    
109
    @Override
110
    protected Object clone() throws CloneNotSupportedException {
111
        ExternallyManaged result = (ExternallyManaged)super.clone();
112

    
113
        return result;
114
    }
115

    
116
}
(13-13/56)