-
Notifications
You must be signed in to change notification settings - Fork 188
/
RLookupTable.java
103 lines (82 loc) · 3.53 KB
/
RLookupTable.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
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.other.RLookupTableRow;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.IdGeneratorResult;
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.LookupTableRowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;
import javax.persistence.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* @author Viliam Repan (lazyman)
*/
@Entity
@ForeignKey(name = "fk_lookup_table")
@Table(uniqueConstraints = @UniqueConstraint(name = "uc_lookup_name", columnNames = {"name_norm"}))
public class RLookupTable extends RObject<LookupTableType> {
private RPolyString name;
private Set<RLookupTableRow> rows;
@OneToMany(mappedBy = "owner", orphanRemoval = true)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<RLookupTableRow> getRows() {
if (rows == null) {
rows = new HashSet<>();
}
return rows;
}
public void setRows(Set<RLookupTableRow> rows) {
this.rows = rows;
}
@Override
@Embedded
public RPolyString getName() {
return name;
}
@Override
public void setName(RPolyString name) {
this.name = name;
}
public static void copyFromJAXB(LookupTableType jaxb, RLookupTable repo, PrismContext prismContext,
IdGeneratorResult generatorResult) throws DtoTranslationException {
RObject.copyFromJAXB(jaxb, repo, prismContext, generatorResult);
repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
LookupTableTableType table = jaxb.getTable();
if (table == null) {
return;
}
for (LookupTableRowType row : table.getRow()) {
RLookupTableRow rRow = new RLookupTableRow();
rRow.setOwner(repo);
rRow.setKey(row.getKey());
rRow.setLabel(RPolyString.copyFromJAXB(row.getLabel()));
rRow.setLastChangeTimestamp(row.getLastChangeTimestamp());
rRow.setValue(row.getValue());
repo.getRows().add(rRow);
}
}
protected static <T extends ObjectType> void copyToJAXB(RLookupTable repo, LookupTableType jaxb, PrismContext prismContext,
Collection<SelectorOptions<GetOperationOptions>> options)
throws DtoTranslationException {
//todo wtf with this
RObject.copyToJAXB(repo, jaxb, prismContext, options);
if (repo.getRows() != null && !repo.getRows().isEmpty()) {
}
}
@Override
public LookupTableType toJAXB(PrismContext prismContext, Collection<SelectorOptions<GetOperationOptions>> options) throws DtoTranslationException {
LookupTableType object = new LookupTableType();
RUtil.revive(object, prismContext);
RLookupTable.copyToJAXB(this, object, prismContext, options);
return object;
}
}