| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.document; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import javax.persistence.AttributeOverride; |
| 22 | |
import javax.persistence.AttributeOverrides; |
| 23 | |
import javax.persistence.CascadeType; |
| 24 | |
import javax.persistence.Column; |
| 25 | |
import javax.persistence.Entity; |
| 26 | |
import javax.persistence.FetchType; |
| 27 | |
import javax.persistence.JoinColumn; |
| 28 | |
import javax.persistence.OneToMany; |
| 29 | |
import javax.persistence.Table; |
| 30 | |
import javax.persistence.Transient; |
| 31 | |
|
| 32 | |
import org.apache.commons.lang.StringUtils; |
| 33 | |
import org.apache.log4j.Logger; |
| 34 | |
import org.hibernate.annotations.Fetch; |
| 35 | |
import org.hibernate.annotations.FetchMode; |
| 36 | |
import org.hibernate.annotations.Type; |
| 37 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
| 38 | |
import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO; |
| 39 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
| 40 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
| 41 | |
import org.kuali.rice.kim.bo.ui.GroupDocumentMember; |
| 42 | |
import org.kuali.rice.kim.bo.ui.GroupDocumentQualifier; |
| 43 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
| 44 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 45 | |
import org.kuali.rice.kim.util.KimConstants; |
| 46 | |
import org.kuali.rice.kns.service.SequenceAccessorService; |
| 47 | |
import org.springframework.util.AutoPopulatingList; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
@Entity |
| 57 | |
@AttributeOverrides({ |
| 58 | |
@AttributeOverride(name="documentNumber",column=@Column(name="FDOC_NBR")) |
| 59 | |
}) |
| 60 | |
@Table(name="KRIM_GRP_DOCUMENT_T") |
| 61 | |
public class IdentityManagementGroupDocument extends IdentityManagementTypeAttributeTransactionalDocument { |
| 62 | 0 | private static final Logger LOG = Logger.getLogger(IdentityManagementGroupDocument.class); |
| 63 | |
|
| 64 | |
private static final long serialVersionUID = 1L; |
| 65 | |
|
| 66 | |
|
| 67 | |
@Column(name="GRP_ID") |
| 68 | |
protected String groupId; |
| 69 | |
@Column(name="KIM_TYP_ID") |
| 70 | |
protected String groupTypeId; |
| 71 | |
@Transient |
| 72 | |
protected String groupTypeName; |
| 73 | |
@Column(name="GRP_NMSPC") |
| 74 | |
protected String groupNamespace; |
| 75 | |
@Column(name="GRP_NM") |
| 76 | |
protected String groupName; |
| 77 | |
@Column(name="GRP_DESC") |
| 78 | |
protected String groupDescription; |
| 79 | 0 | @Type(type="yes_no") |
| 80 | |
@Column(name="ACTV_IND") |
| 81 | |
protected boolean active = true; |
| 82 | |
|
| 83 | |
@Transient |
| 84 | |
protected boolean editing; |
| 85 | |
|
| 86 | 0 | @OneToMany(targetEntity = GroupDocumentMember.class, fetch = FetchType.EAGER, cascade=CascadeType.ALL) |
| 87 | |
@Fetch(value = FetchMode.SELECT) |
| 88 | |
@JoinColumn(name="FDOC_NBR", insertable = false, updatable = false) |
| 89 | |
private List<GroupDocumentMember> members = new AutoPopulatingList(GroupDocumentMember.class); |
| 90 | 0 | @OneToMany(targetEntity = GroupDocumentQualifier.class, fetch = FetchType.EAGER, cascade=CascadeType.ALL) |
| 91 | |
@Fetch(value = FetchMode.SELECT) |
| 92 | |
@JoinColumn(name="FDOC_NBR", insertable = false, updatable = false) |
| 93 | |
private List<GroupDocumentQualifier> qualifiers = new AutoPopulatingList(GroupDocumentQualifier.class); |
| 94 | |
|
| 95 | 0 | public IdentityManagementGroupDocument() { |
| 96 | 0 | } |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public boolean isActive() { |
| 102 | 0 | return this.active; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public void setActive(boolean active) { |
| 109 | 0 | this.active = active; |
| 110 | 0 | } |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public void setRoleId(String groupId) { |
| 116 | 0 | this.groupId = groupId; |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public void addMember(GroupDocumentMember member) { |
| 123 | 0 | getMembers().add(member); |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public KimTypeInfo getKimType() { |
| 130 | 0 | return KIMServiceLocatorWeb.getTypeInfoService().getKimType(getGroupTypeId()); |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public GroupDocumentMember getBlankMember() { |
| 137 | 0 | return new GroupDocumentMember(); |
| 138 | |
} |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
@Override |
| 144 | |
public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) { |
| 145 | 0 | super.doRouteStatusChange(statusChangeEvent); |
| 146 | 0 | if (getDocumentHeader().getWorkflowDocument().stateIsProcessed()) { |
| 147 | 0 | KIMServiceLocatorInternal.getUiDocumentService().saveGroup(this); |
| 148 | |
} |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
@Override |
| 152 | |
public void prepareForSave(){ |
| 153 | |
String groupId; |
| 154 | 0 | if(StringUtils.isBlank(getGroupId())){ |
| 155 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
| 156 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
| 157 | |
"KRIM_GRP_ID_S", this.getClass()); |
| 158 | 0 | groupId = nextSeq.toString(); |
| 159 | 0 | setGroupId(groupId); |
| 160 | 0 | } else{ |
| 161 | 0 | groupId = getGroupId(); |
| 162 | |
} |
| 163 | 0 | if(getMembers()!=null){ |
| 164 | |
String groupMemberId; |
| 165 | 0 | for(GroupDocumentMember member: getMembers()){ |
| 166 | 0 | member.setGroupId(getGroupId()); |
| 167 | 0 | if(StringUtils.isBlank(member.getGroupMemberId())){ |
| 168 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
| 169 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
| 170 | |
"KRIM_GRP_MBR_ID_S", this.getClass()); |
| 171 | 0 | groupMemberId = nextSeq.toString(); |
| 172 | 0 | member.setGroupMemberId(groupMemberId); |
| 173 | |
} |
| 174 | 0 | if (StringUtils.isBlank(member.getDocumentNumber())) { |
| 175 | 0 | member.setDocumentNumber(getDocumentNumber()); |
| 176 | |
} |
| 177 | |
} |
| 178 | |
} |
| 179 | 0 | int index = 0; |
| 180 | |
|
| 181 | 0 | if(getDefinitions()!=null){ |
| 182 | 0 | for(String key : getDefinitions().keySet()) { |
| 183 | 0 | if ( getQualifiers().size() > index ) { |
| 184 | 0 | GroupDocumentQualifier qualifier = getQualifiers().get(index); |
| 185 | 0 | qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key))); |
| 186 | 0 | qualifier.setKimTypId(getKimType().getKimTypeId()); |
| 187 | 0 | qualifier.setGroupId(groupId); |
| 188 | |
} |
| 189 | 0 | index++; |
| 190 | |
} |
| 191 | |
} |
| 192 | 0 | } |
| 193 | |
|
| 194 | |
public void initializeDocumentForNewGroup() { |
| 195 | 0 | if(StringUtils.isBlank(this.groupId)){ |
| 196 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
| 197 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
| 198 | |
KimConstants.SequenceNames.KRIM_GROUP_ID_S, this.getClass()); |
| 199 | 0 | this.groupId = nextSeq.toString(); |
| 200 | |
} |
| 201 | 0 | if(StringUtils.isBlank(this.groupTypeId)) { |
| 202 | 0 | this.groupTypeId = "1"; |
| 203 | |
} |
| 204 | 0 | } |
| 205 | |
|
| 206 | |
public String getGroupId(){ |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | 0 | return groupId; |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
public void setGroupId(String groupId) { |
| 217 | 0 | this.groupId = groupId; |
| 218 | 0 | } |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
public String getGroupName() { |
| 224 | 0 | return this.groupName; |
| 225 | |
} |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
public void setGroupName(String groupName) { |
| 231 | 0 | this.groupName = groupName; |
| 232 | 0 | } |
| 233 | |
|
| 234 | |
public String getGroupDescription() { |
| 235 | 0 | return this.groupDescription; |
| 236 | |
} |
| 237 | |
|
| 238 | |
public void setGroupDescription(String groupDescription) { |
| 239 | 0 | this.groupDescription = groupDescription; |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
public String getGroupNamespace() { |
| 246 | 0 | return this.groupNamespace; |
| 247 | |
} |
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
public void setGroupNamespace(String groupNamespace) { |
| 253 | 0 | this.groupNamespace = groupNamespace; |
| 254 | 0 | } |
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
public String getGroupTypeId() { |
| 260 | 0 | return this.groupTypeId; |
| 261 | |
} |
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
public void setGroupTypeId(String groupTypeId) { |
| 267 | 0 | this.groupTypeId = groupTypeId; |
| 268 | 0 | } |
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public String getGroupTypeName() { |
| 274 | 0 | return this.groupTypeName; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
public void setGroupTypeName(String groupTypeName) { |
| 281 | 0 | this.groupTypeName = groupTypeName; |
| 282 | 0 | } |
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
public List<GroupDocumentMember> getMembers() { |
| 288 | 0 | return this.members; |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
public void setMembers(List<GroupDocumentMember> members) { |
| 295 | 0 | this.members = members; |
| 296 | 0 | } |
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
public List<GroupDocumentQualifier> getQualifiers() { |
| 302 | 0 | return this.qualifiers; |
| 303 | |
} |
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
public void setQualifiers(List<GroupDocumentQualifier> qualifiers) { |
| 309 | 0 | this.qualifiers = qualifiers; |
| 310 | 0 | } |
| 311 | |
|
| 312 | |
public GroupDocumentQualifier getQualifier(String kimAttributeDefnId) { |
| 313 | 0 | for(GroupDocumentQualifier qualifier: qualifiers){ |
| 314 | 0 | if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) |
| 315 | 0 | return qualifier; |
| 316 | |
} |
| 317 | 0 | return null; |
| 318 | |
} |
| 319 | |
|
| 320 | |
public AttributeSet getQualifiersAsAttributeSet() { |
| 321 | 0 | AttributeSet attributes = new AttributeSet(qualifiers.size()); |
| 322 | 0 | for(GroupDocumentQualifier qualifier: qualifiers){ |
| 323 | 0 | if ( qualifier.getKimAttribute() != null ) { |
| 324 | 0 | attributes.put(qualifier.getKimAttribute().getAttributeName(), qualifier.getAttrVal()); |
| 325 | |
} else { |
| 326 | 0 | LOG.warn( "Unknown attribute ID on group: " + qualifier.getKimAttrDefnId() + " / value=" + qualifier.getAttrVal()); |
| 327 | 0 | attributes.put("Unknown Attribute ID: " + qualifier.getKimAttrDefnId(), qualifier.getAttrVal()); |
| 328 | |
} |
| 329 | |
} |
| 330 | 0 | return attributes; |
| 331 | |
} |
| 332 | |
|
| 333 | |
public void setDefinitions(AttributeDefinitionMap definitions) { |
| 334 | 0 | super.setDefinitions(definitions); |
| 335 | 0 | if(getQualifiers()==null || getQualifiers().size()<1){ |
| 336 | |
GroupDocumentQualifier qualifier; |
| 337 | 0 | setQualifiers(new ArrayList<GroupDocumentQualifier>()); |
| 338 | 0 | if(getDefinitions()!=null){ |
| 339 | 0 | for(String key : getDefinitions().keySet()) { |
| 340 | 0 | qualifier = new GroupDocumentQualifier(); |
| 341 | 0 | qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key))); |
| 342 | 0 | getQualifiers().add(qualifier); |
| 343 | |
} |
| 344 | |
} |
| 345 | |
} |
| 346 | 0 | } |
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
public boolean isEditing() { |
| 352 | 0 | return this.editing; |
| 353 | |
} |
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
public void setEditing(boolean editing) { |
| 359 | 0 | this.editing = editing; |
| 360 | 0 | } |
| 361 | |
|
| 362 | |
public void setKimType(KimTypeInfo kimType) { |
| 363 | 0 | super.setKimType(kimType); |
| 364 | 0 | if (kimType != null){ |
| 365 | 0 | setGroupTypeId(kimType.getKimTypeId()); |
| 366 | 0 | setGroupTypeName(kimType.getName()); |
| 367 | |
} |
| 368 | 0 | } |
| 369 | |
} |