| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.bo.role.impl; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.hibernate.annotations.Fetch; |
| 20 | |
import org.hibernate.annotations.FetchMode; |
| 21 | |
import org.hibernate.annotations.Type; |
| 22 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
| 23 | |
import org.kuali.rice.kim.bo.role.KimResponsibility; |
| 24 | |
import org.kuali.rice.kim.bo.role.dto.KimResponsibilityInfo; |
| 25 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo; |
| 26 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
| 27 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 28 | |
import org.kuali.rice.kim.service.KimTypeInfoService; |
| 29 | |
import org.kuali.rice.kim.util.KimConstants; |
| 30 | |
import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; |
| 31 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
| 32 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 33 | |
import org.springframework.util.AutoPopulatingList; |
| 34 | |
|
| 35 | |
import javax.persistence.*; |
| 36 | |
import java.util.Iterator; |
| 37 | |
import java.util.List; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
@Entity |
| 43 | |
@Table(name="KRIM_RSP_T") |
| 44 | 0 | public class KimResponsibilityImpl extends PersistableBusinessObjectBase implements KimResponsibility { |
| 45 | |
|
| 46 | |
private static final long serialVersionUID = 1L; |
| 47 | |
|
| 48 | |
@Id |
| 49 | |
@Column(name="RSP_ID") |
| 50 | |
protected String responsibilityId; |
| 51 | |
@Column(name="NMSPC_CD") |
| 52 | |
protected String namespaceCode; |
| 53 | |
@Column(name="NM") |
| 54 | |
protected String name; |
| 55 | |
@Column(name="DESC_TXT", length=400) |
| 56 | |
protected String description; |
| 57 | |
@Type(type="yes_no") |
| 58 | |
@Column(name="ACTV_IND") |
| 59 | |
protected boolean active; |
| 60 | |
|
| 61 | 0 | @OneToMany(targetEntity=ResponsibilityAttributeDataImpl.class,cascade={CascadeType.ALL},fetch=FetchType.EAGER,mappedBy="responsibilityId") |
| 62 | |
@Fetch(value = FetchMode.SELECT) |
| 63 | |
|
| 64 | |
protected List<ResponsibilityAttributeDataImpl> detailObjects = new AutoPopulatingList(ResponsibilityAttributeDataImpl.class); |
| 65 | |
|
| 66 | |
@Column(name="RSP_TMPL_ID") |
| 67 | |
protected String templateId; |
| 68 | 0 | @OneToOne(cascade={},fetch=FetchType.EAGER) |
| 69 | |
@JoinColumn(name="RSP_TMPL_ID", insertable=false, updatable=false) |
| 70 | |
protected KimResponsibilityTemplateImpl template = new KimResponsibilityTemplateImpl(); |
| 71 | |
|
| 72 | 0 | @OneToMany(targetEntity=RoleResponsibilityImpl.class,cascade={CascadeType.ALL},fetch=FetchType.EAGER,mappedBy="responsibilityId") |
| 73 | |
@Fetch(value = FetchMode.SELECT) |
| 74 | |
|
| 75 | |
protected List<RoleResponsibilityImpl> roleResponsibilities = new AutoPopulatingList(RoleResponsibilityImpl.class); |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public boolean isActive() { |
| 81 | 0 | return active; |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public void setActive(boolean active) { |
| 88 | 0 | this.active = active; |
| 89 | 0 | } |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
public String getDescription() { |
| 95 | 0 | return description; |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public String getResponsibilityId() { |
| 102 | 0 | return responsibilityId; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public String getName() { |
| 109 | 0 | return name; |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public String getNameToDisplay() { |
| 116 | 0 | if(template!=null && StringUtils.equals(template.getName(), name)){ |
| 117 | 0 | return name; |
| 118 | |
} else{ |
| 119 | 0 | return template.getName()+" "+name; |
| 120 | |
} |
| 121 | |
} |
| 122 | |
|
| 123 | |
public void setDescription(String responsibilityDescription) { |
| 124 | 0 | this.description = responsibilityDescription; |
| 125 | 0 | } |
| 126 | |
|
| 127 | |
public void setName(String responsibilityName) { |
| 128 | 0 | this.name = responsibilityName; |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
public KimResponsibilityInfo toSimpleInfo() { |
| 132 | 0 | KimResponsibilityInfo dto = new KimResponsibilityInfo(); |
| 133 | |
|
| 134 | 0 | dto.setResponsibilityId( getResponsibilityId() ); |
| 135 | 0 | dto.setNamespaceCode( getNamespaceCode() ); |
| 136 | 0 | dto.setName( getName() ); |
| 137 | 0 | dto.setDescription( getDescription() ); |
| 138 | 0 | dto.setActive( isActive() ); |
| 139 | 0 | dto.setDetails( getDetails() ); |
| 140 | |
|
| 141 | 0 | return dto; |
| 142 | |
} |
| 143 | |
|
| 144 | |
public List<ResponsibilityAttributeDataImpl> getDetailObjects() { |
| 145 | 0 | return this.detailObjects; |
| 146 | |
} |
| 147 | |
|
| 148 | |
public void setDetailObjects(List<ResponsibilityAttributeDataImpl> detailObjects) { |
| 149 | 0 | this.detailObjects = detailObjects; |
| 150 | 0 | detailsAsAttributeSet = null; |
| 151 | 0 | } |
| 152 | |
|
| 153 | |
public boolean hasDetails() { |
| 154 | 0 | return !detailObjects.isEmpty(); |
| 155 | |
} |
| 156 | |
|
| 157 | 0 | protected transient AttributeSet detailsAsAttributeSet = null; |
| 158 | |
|
| 159 | |
public AttributeSet getDetails() { |
| 160 | 0 | if ( detailsAsAttributeSet == null ) { |
| 161 | 0 | KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
| 162 | 0 | AttributeSet m = new AttributeSet(); |
| 163 | 0 | for ( ResponsibilityAttributeDataImpl data : getDetailObjects() ) { |
| 164 | 0 | KimTypeAttributeInfo attribute = null; |
| 165 | 0 | if ( kimType != null ) { |
| 166 | 0 | attribute = kimType.getAttributeDefinition( data.getKimAttributeId() ); |
| 167 | |
} |
| 168 | 0 | if ( attribute != null ) { |
| 169 | 0 | m.put( attribute.getAttributeName(), data.getAttributeValue() ); |
| 170 | |
} else { |
| 171 | 0 | m.put( data.getKimAttribute().getAttributeName(), data.getAttributeValue() ); |
| 172 | |
} |
| 173 | 0 | } |
| 174 | 0 | detailsAsAttributeSet = m; |
| 175 | |
} |
| 176 | 0 | return detailsAsAttributeSet; |
| 177 | |
} |
| 178 | |
|
| 179 | |
public KimResponsibilityTemplateImpl getTemplate() { |
| 180 | 0 | return this.template; |
| 181 | |
} |
| 182 | |
|
| 183 | |
public void setTemplate(KimResponsibilityTemplateImpl template) { |
| 184 | 0 | this.template = template; |
| 185 | 0 | } |
| 186 | |
|
| 187 | |
public String getNamespaceCode() { |
| 188 | 0 | return this.namespaceCode; |
| 189 | |
} |
| 190 | |
|
| 191 | |
public void setNamespaceCode(String namespaceCode) { |
| 192 | 0 | this.namespaceCode = namespaceCode; |
| 193 | 0 | } |
| 194 | |
|
| 195 | |
public String getTemplateId() { |
| 196 | 0 | return this.templateId; |
| 197 | |
} |
| 198 | |
|
| 199 | |
public void setTemplateId(String templateId) { |
| 200 | 0 | this.templateId = templateId; |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
public void setResponsibilityId(String responsibilityId) { |
| 204 | 0 | this.responsibilityId = responsibilityId; |
| 205 | 0 | } |
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public List<RoleResponsibilityImpl> getRoleResponsibilities() { |
| 211 | 0 | return this.roleResponsibilities; |
| 212 | |
} |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
public void setRoleResponsibilities( |
| 218 | |
List<RoleResponsibilityImpl> roleResponsibilities) { |
| 219 | 0 | this.roleResponsibilities = roleResponsibilities; |
| 220 | 0 | } |
| 221 | |
|
| 222 | |
|
| 223 | |
public String getDetailObjectsValues(){ |
| 224 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
| 225 | 0 | Iterator<ResponsibilityAttributeDataImpl> respIter = getDetailObjects().iterator(); |
| 226 | 0 | while ( respIter.hasNext() ) { |
| 227 | 0 | ResponsibilityAttributeDataImpl responsibilityAttributeData = respIter.next(); |
| 228 | 0 | detailObjectsToDisplay.append( responsibilityAttributeData.getAttributeValue() ); |
| 229 | 0 | if ( respIter.hasNext() ) { |
| 230 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR ); |
| 231 | |
} |
| 232 | 0 | } |
| 233 | 0 | return detailObjectsToDisplay.toString(); |
| 234 | |
} |
| 235 | |
|
| 236 | |
public String getDetailObjectsToDisplay() { |
| 237 | 0 | KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
| 238 | 0 | StringBuffer detailObjectsToDisplay = new StringBuffer(); |
| 239 | 0 | Iterator<ResponsibilityAttributeDataImpl> respIter = getDetailObjects().iterator(); |
| 240 | 0 | while ( respIter.hasNext() ) { |
| 241 | 0 | ResponsibilityAttributeDataImpl responsibilityAttributeData = respIter.next(); |
| 242 | 0 | detailObjectsToDisplay.append( getKimAttributeLabelFromDD(kimType.getAttributeDefinition(responsibilityAttributeData.getKimAttributeId()))); |
| 243 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR ); |
| 244 | 0 | detailObjectsToDisplay.append( responsibilityAttributeData.getAttributeValue() ); |
| 245 | 0 | if ( respIter.hasNext() ) { |
| 246 | 0 | detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR ); |
| 247 | |
} |
| 248 | 0 | } |
| 249 | 0 | return detailObjectsToDisplay.toString(); |
| 250 | |
} |
| 251 | |
|
| 252 | |
protected String getKimAttributeLabelFromDD( KimTypeAttributeInfo attribute ){ |
| 253 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getComponentName(), attribute.getAttributeName() ); |
| 254 | |
} |
| 255 | |
|
| 256 | |
transient private DataDictionaryService dataDictionaryService; |
| 257 | |
public DataDictionaryService getDataDictionaryService() { |
| 258 | 0 | if(dataDictionaryService == null){ |
| 259 | 0 | dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
| 260 | |
} |
| 261 | 0 | return dataDictionaryService; |
| 262 | |
} |
| 263 | |
|
| 264 | |
private transient static KimTypeInfoService kimTypeInfoService; |
| 265 | |
protected KimTypeInfoService getTypeInfoService() { |
| 266 | 0 | if(kimTypeInfoService == null){ |
| 267 | 0 | kimTypeInfoService = KIMServiceLocatorWeb.getTypeInfoService(); |
| 268 | |
} |
| 269 | 0 | return kimTypeInfoService; |
| 270 | |
} |
| 271 | |
} |