| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.impl.responsibility; |
| 17 | |
|
| 18 | |
|
| 19 | |
import javax.persistence.CascadeType |
| 20 | |
import javax.persistence.Column |
| 21 | |
import javax.persistence.Entity |
| 22 | |
import javax.persistence.FetchType |
| 23 | |
import javax.persistence.Id |
| 24 | |
import javax.persistence.JoinColumn |
| 25 | |
import javax.persistence.OneToMany |
| 26 | |
import javax.persistence.OneToOne |
| 27 | |
import javax.persistence.Table |
| 28 | |
import org.hibernate.annotations.Fetch |
| 29 | |
import org.hibernate.annotations.FetchMode |
| 30 | |
import org.hibernate.annotations.Type |
| 31 | |
import org.kuali.rice.kim.api.responsibility.Responsibility |
| 32 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityContract |
| 33 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
| 34 | |
import org.kuali.rice.kim.api.type.KimType |
| 35 | |
import org.kuali.rice.kim.api.type.KimTypeAttribute |
| 36 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService |
| 37 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo |
| 38 | |
import org.kuali.rice.kim.impl.role.RoleResponsibilityBo |
| 39 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
| 40 | |
import org.kuali.rice.krad.service.DataDictionaryService |
| 41 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb |
| 42 | |
|
| 43 | |
@Entity |
| 44 | |
@Table(name = "KRIM_RSP_T") |
| 45 | |
public class ResponsibilityBo extends PersistableBusinessObjectBase implements ResponsibilityContract { |
| 46 | |
|
| 47 | |
private static final long serialVersionUID = 1L; |
| 48 | |
|
| 49 | |
@Id |
| 50 | |
@Column(name = "RSP_ID") |
| 51 | |
String id |
| 52 | |
|
| 53 | |
@Column(name="NMSPC_CD") |
| 54 | |
String namespaceCode |
| 55 | |
|
| 56 | |
@Column(name="NM") |
| 57 | |
String name |
| 58 | |
|
| 59 | |
@Column(name="DESC_TXT", length=400) |
| 60 | |
String description; |
| 61 | |
|
| 62 | |
@Column(name="PERM_TMPL_ID") |
| 63 | |
String templateId |
| 64 | |
|
| 65 | |
@Column(name="ACTV_IND") |
| 66 | |
@Type(type="yes_no") |
| 67 | |
boolean active |
| 68 | |
|
| 69 | |
@OneToOne(targetEntity=ResponsibilityTemplateBo.class,cascade=[],fetch=FetchType.EAGER) |
| 70 | |
@JoinColumn(name="PERM_TMPL_ID", insertable=false, updatable=false) |
| 71 | |
ResponsibilityTemplateBo template; |
| 72 | |
|
| 73 | |
@OneToMany(targetEntity=ResponsibilityAttributeBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id") |
| 74 | |
@Fetch(value = FetchMode.SELECT) |
| 75 | |
List<ResponsibilityAttributeBo> attributeDetails |
| 76 | |
|
| 77 | |
@OneToMany(targetEntity=RoleResponsibilityBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id") |
| 78 | |
@Fetch(value = FetchMode.SELECT) |
| 79 | |
List<RoleResponsibilityBo> roleResponsibilities |
| 80 | |
|
| 81 | |
Map<String,String> attributes |
| 82 | |
|
| 83 | |
Map<String,String> getAttributes() { |
| 84 | 0 | return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
static Responsibility to(ResponsibilityBo bo) { |
| 93 | 0 | if (bo == null) { |
| 94 | 0 | return null |
| 95 | |
} |
| 96 | |
|
| 97 | 0 | return Responsibility.Builder.create(bo).build(); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
static ResponsibilityBo from(Responsibility im) { |
| 106 | 0 | if (im == null) { |
| 107 | 0 | return null |
| 108 | |
} |
| 109 | |
|
| 110 | 0 | ResponsibilityBo bo = new ResponsibilityBo() |
| 111 | 0 | bo.id = im.id |
| 112 | 0 | bo.namespaceCode = im.namespaceCode |
| 113 | 0 | bo.name = im.name |
| 114 | 0 | bo.description = im.description |
| 115 | 0 | bo.active = im.active |
| 116 | 0 | bo.templateId = im.template.getId() |
| 117 | 0 | bo.template = ResponsibilityTemplateBo.from(im.template) |
| 118 | 0 | bo.attributes = im.attributes |
| 119 | 0 | bo.versionNumber = im.versionNumber |
| 120 | 0 | bo.objectId = im.objectId; |
| 121 | |
|
| 122 | 0 | return bo |
| 123 | |
} |
| 124 | |
|
| 125 | |
ResponsibilityTemplateBo getTemplate() { |
| 126 | 0 | return template; |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
String getDetailObjectsValues(){ |
| 131 | 0 | return attributeDetails.collect {it.attributeValue}.join(",") |
| 132 | |
} |
| 133 | |
|
| 134 | |
String getDetailObjectsToDisplay() { |
| 135 | 0 | final KimType kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
| 136 | |
|
| 137 | 0 | return attributeDetails.collect { |
| 138 | 0 | getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(it.kimAttributeId)) + ":" + it.attributeValue |
| 139 | |
}.join(",") |
| 140 | |
} |
| 141 | |
|
| 142 | |
private String getKimAttributeLabelFromDD( KimTypeAttribute attribute ){ |
| 143 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName() ); |
| 144 | |
} |
| 145 | |
|
| 146 | |
private DataDictionaryService dataDictionaryService; |
| 147 | |
private DataDictionaryService getDataDictionaryService() { |
| 148 | 0 | if(dataDictionaryService == null){ |
| 149 | 0 | dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService(); |
| 150 | |
} |
| 151 | 0 | return dataDictionaryService; |
| 152 | |
} |
| 153 | |
|
| 154 | |
private KimTypeInfoService kimTypeInfoService; |
| 155 | |
private KimTypeInfoService getTypeInfoService() { |
| 156 | 0 | if(kimTypeInfoService == null){ |
| 157 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
| 158 | |
} |
| 159 | 0 | return kimTypeInfoService; |
| 160 | |
} |
| 161 | |
} |