-
Notifications
You must be signed in to change notification settings - Fork 188
/
RObjectTemplate.java
132 lines (110 loc) · 4.7 KB
/
RObjectTemplate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.repo.sql.data.common;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.enums.RObjectTemplateType;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.IdGeneratorResult;
import com.evolveum.midpoint.repo.sql.util.MidPointJoinedPersister;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Persister;
import org.hibernate.annotations.Where;
import javax.persistence.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* @author lazyman
*/
@Entity
@ForeignKey(name = "fk_object_template")
@Table(uniqueConstraints = @UniqueConstraint(name = "uc_object_template_name", columnNames = {"name_norm"}))
@Persister(impl = MidPointJoinedPersister.class)
public class RObjectTemplate extends RObject<ObjectTemplateType> {
private RPolyString name;
private RObjectTemplateType type;
private Set<RObjectReference<RObjectTemplate>> includeRef;
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 7")
@OneToMany(mappedBy = RObjectReference.F_OWNER, orphanRemoval = true)
@ForeignKey(name = "none")
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<RObjectReference<RObjectTemplate>> getIncludeRef() {
if (includeRef == null) {
includeRef = new HashSet<>();
}
return includeRef;
}
@Enumerated(EnumType.ORDINAL)
public RObjectTemplateType getType() {
return type;
}
public void setType(RObjectTemplateType type) {
this.type = type;
}
@Embedded
public RPolyString getName() {
return name;
}
public void setIncludeRef(Set<RObjectReference<RObjectTemplate>> includeRef) {
this.includeRef = includeRef;
}
public void setName(RPolyString name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
RObjectTemplate that = (RObjectTemplate) o;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (type != null ? !type.equals(that.type) : that.type != null)
return false;
if (includeRef != null ? !includeRef.equals(that.includeRef) : that.includeRef != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
}
public static void copyFromJAXB(ObjectTemplateType jaxb, RObjectTemplate repo, PrismContext prismContext,
IdGeneratorResult generatorResult) throws DtoTranslationException {
RObject.copyFromJAXB(jaxb, repo, prismContext, generatorResult);
repo.setType(RUtil.getRepoEnumValue(jaxb.asPrismObject().getElementName(), RObjectTemplateType.class));
repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
repo.getIncludeRef().addAll(RUtil.safeListReferenceToSet(
jaxb.getIncludeRef(), prismContext, repo, RReferenceOwner.INCLUDE));
}
@Override
public ObjectTemplateType toJAXB(PrismContext prismContext, Collection<SelectorOptions<GetOperationOptions>> options)
throws DtoTranslationException {
ObjectTemplateType object = new ObjectTemplateType();
RUtil.revive(object, prismContext);
RObjectTemplate.copyToJAXB(this, object, prismContext, options);
return object;
}
}