1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.identity.personal;
17
18 import javax.persistence.Column;
19 import javax.persistence.Entity;
20 import javax.persistence.GeneratedValue;
21 import javax.persistence.Id;
22 import javax.persistence.Table;
23 import javax.persistence.Transient;
24 import org.kuali.rice.kim.api.KimApiConstants;
25 import org.kuali.rice.kim.api.identity.personal.EntityEthnicity;
26 import org.kuali.rice.kim.api.identity.personal.EntityEthnicityContract;
27 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
28 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29 import org.kuali.rice.krad.bo.DataObjectBase;
30 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
31
32 @Entity
33 @Table(name = "KRIM_ENTITY_ETHNIC_T")
34 public class EntityEthnicityBo extends DataObjectBase implements EntityEthnicityContract {
35
36 private static final long serialVersionUID = 1L;
37
38 @PortableSequenceGenerator(name = "KRIM_ENTITY_ETHNIC_ID_S")
39 @GeneratedValue(generator = "KRIM_ENTITY_ETHNIC_ID_S")
40 @Id
41 @Column(name = "ID")
42 private String id;
43
44 @Column(name = "ENTITY_ID")
45 private String entityId;
46
47 @Column(name = "ETHNCTY_CD")
48 private String ethnicityCode;
49
50 @Column(name = "SUB_ETHNCTY_CD")
51 private String subEthnicityCode;
52
53 @Transient
54 private boolean suppressPersonal;
55
56 public static EntityEthnicity to(EntityEthnicityBo bo) {
57 if (bo == null) {
58 return null;
59 }
60 return EntityEthnicity.Builder.create(bo).build();
61 }
62
63
64
65
66
67
68
69 public static EntityEthnicityBo from(EntityEthnicity immutable) {
70 if (immutable == null) {
71 return null;
72 }
73 EntityEthnicityBo bo = new EntityEthnicityBo();
74 bo.entityId = immutable.getEntityId();
75 bo.id = immutable.getId();
76 bo.ethnicityCode = immutable.getEthnicityCodeUnmasked();
77 bo.subEthnicityCode = immutable.getSubEthnicityCodeUnmasked();
78 bo.setVersionNumber(immutable.getVersionNumber());
79 bo.setObjectId(immutable.getObjectId());
80 return bo;
81 }
82
83 @Override
84 public boolean isSuppressPersonal() {
85 try {
86 EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId());
87 if (privacy != null) {
88 this.suppressPersonal = privacy.isSuppressPersonal();
89 } else {
90 this.suppressPersonal = false;
91 }
92 } catch (NullPointerException e) {
93 return false;
94 } catch (ClassCastException c) {
95 return false;
96 }
97 return suppressPersonal;
98 }
99
100 @Override
101 public String getEthnicityCode() {
102 if (isSuppressPersonal()) {
103 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
104 }
105 return this.ethnicityCode;
106 }
107
108 @Override
109 public String getSubEthnicityCode() {
110 if (isSuppressPersonal()) {
111 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
112 }
113 return this.subEthnicityCode;
114 }
115
116 @Override
117 public String getEthnicityCodeUnmasked() {
118 return this.ethnicityCode;
119 }
120
121 @Override
122 public String getSubEthnicityCodeUnmasked() {
123 return this.subEthnicityCode;
124 }
125
126 @Override
127 public String getId() {
128 return id;
129 }
130
131 public void setId(String id) {
132 this.id = id;
133 }
134
135 @Override
136 public String getEntityId() {
137 return entityId;
138 }
139
140 public void setEntityId(String entityId) {
141 this.entityId = entityId;
142 }
143
144 public void setEthnicityCode(String ethnicityCode) {
145 this.ethnicityCode = ethnicityCode;
146 }
147
148 public void setSubEthnicityCode(String subEthnicityCode) {
149 this.subEthnicityCode = subEthnicityCode;
150 }
151
152 public boolean getSuppressPersonal() {
153 return suppressPersonal;
154 }
155
156 public void setSuppressPersonal(boolean suppressPersonal) {
157 this.suppressPersonal = suppressPersonal;
158 }
159 }