| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.rice.kim.impl.type; | 
  | 17 |  |   | 
  | 18 |  |  import org.apache.commons.lang.StringUtils; | 
  | 19 |  |  import org.kuali.rice.kim.api.KimConstants; | 
  | 20 |  |  import org.kuali.rice.kim.api.type.KimAttributeField; | 
  | 21 |  |  import org.kuali.rice.kim.api.type.KimType; | 
  | 22 |  |  import org.kuali.rice.kim.bo.impl.KimAttributes; | 
  | 23 |  |  import org.kuali.rice.kim.document.IdentityManagementKimDocument; | 
  | 24 |  |  import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator; | 
  | 25 |  |  import org.kuali.rice.kim.framework.type.KimTypeService; | 
  | 26 |  |  import org.kuali.rice.kim.service.KIMServiceLocatorInternal; | 
  | 27 |  |   | 
  | 28 |  |  import javax.persistence.Transient; | 
  | 29 |  |  import java.util.HashMap; | 
  | 30 |  |  import java.util.List; | 
  | 31 |  |  import java.util.Map; | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 |  |   | 
  | 37 |  |   | 
  | 38 |  |   | 
  | 39 |  |   | 
  | 40 | 0 |  public class IdentityManagementTypeAttributeTransactionalDocument extends IdentityManagementKimDocument { | 
  | 41 |  |   | 
  | 42 |  |          protected static final long serialVersionUID = -9064436454008712125L; | 
  | 43 |  |          @Transient | 
  | 44 |  |          protected transient KimTypeService kimTypeService; | 
  | 45 |  |          @Transient | 
  | 46 |  |          protected KimType kimType; | 
  | 47 |  |          @Transient | 
  | 48 |  |          protected List<? extends KimAttributes> attributes; | 
  | 49 |  |          @Transient | 
  | 50 |  |          protected transient List<KimAttributeField> definitions; | 
  | 51 |  |          @Transient | 
  | 52 |  |          protected transient Map<String,Object> attributeEntry; | 
  | 53 |  |           | 
  | 54 |  |           | 
  | 55 |  |   | 
  | 56 |  |   | 
  | 57 |  |          public List<? extends KimAttributes> getAttributes() { | 
  | 58 | 0 |                  return this.attributes; | 
  | 59 |  |          } | 
  | 60 |  |           | 
  | 61 |  |   | 
  | 62 |  |   | 
  | 63 |  |          public void setAttributes(List<? extends KimAttributes> attributes) { | 
  | 64 | 0 |                  this.attributes = attributes; | 
  | 65 | 0 |          } | 
  | 66 |  |           | 
  | 67 |  |   | 
  | 68 |  |   | 
  | 69 |  |          public KimType getKimType() { | 
  | 70 | 0 |                  return this.kimType; | 
  | 71 |  |          } | 
  | 72 |  |           | 
  | 73 |  |   | 
  | 74 |  |   | 
  | 75 |  |          public void setKimType(KimType kimType) { | 
  | 76 | 0 |                  this.kimType = kimType; | 
  | 77 | 0 |          } | 
  | 78 |  |   | 
  | 79 |  |          public Map<String,Object> getAttributeEntry() { | 
  | 80 | 0 |                  if(attributeEntry==null || attributeEntry.isEmpty()) | 
  | 81 | 0 |                          attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions()); | 
  | 82 | 0 |                  return attributeEntry; | 
  | 83 |  |          } | 
  | 84 |  |   | 
  | 85 |  |          public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){ | 
  | 86 | 0 |                  String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR); | 
  | 87 | 0 |                  StringBuffer commaDelimitedAttributesLabels = new StringBuffer(); | 
  | 88 | 0 |                  for(String name: names){ | 
  | 89 | 0 |                          commaDelimitedAttributesLabels.append(getAttributeEntry().get(name.trim())+KimConstants.KimUIConstants.COMMA_SEPARATOR); | 
  | 90 |  |                  } | 
  | 91 | 0 |          if(commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR)) | 
  | 92 | 0 |                  commaDelimitedAttributesLabels.delete(commaDelimitedAttributesLabels.length()- KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length()); | 
  | 93 | 0 |          return commaDelimitedAttributesLabels.toString(); | 
  | 94 |  |          } | 
  | 95 |  |   | 
  | 96 |  |          public List<KimAttributeField> getDefinitions() { | 
  | 97 | 0 |                  if (definitions == null || definitions.isEmpty()) { | 
  | 98 | 0 |                  KimTypeService kimTypeService = getKimTypeService(getKimType()); | 
  | 99 | 0 |                  if(kimTypeService!=null) | 
  | 100 | 0 |                          this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId()); | 
  | 101 |  |                  } | 
  | 102 | 0 |                  return this.definitions; | 
  | 103 |  |          } | 
  | 104 |  |   | 
  | 105 |  |      public Map<String, KimAttributeField> getDefinitionsKeyedByAttributeName() { | 
  | 106 | 0 |          final Map<String, KimAttributeField> map = new HashMap<String, KimAttributeField>(); | 
  | 107 | 0 |          for (KimAttributeField field : getDefinitions()) { | 
  | 108 | 0 |              map.put(field.getAttributeField().getName(), field); | 
  | 109 |  |          } | 
  | 110 | 0 |          return map; | 
  | 111 |  |          } | 
  | 112 |  |   | 
  | 113 |  |   | 
  | 114 |  |          public void setDefinitions(List<KimAttributeField> definitions) { | 
  | 115 | 0 |                  this.definitions = definitions; | 
  | 116 | 0 |          } | 
  | 117 |  |   | 
  | 118 |  |          protected KimTypeService getKimTypeService(KimType kimType){ | 
  | 119 | 0 |                  if( kimTypeService==null){ | 
  | 120 | 0 |                      kimTypeService = KimFrameworkServiceLocator.getKimTypeService(kimType); | 
  | 121 |  |                  } | 
  | 122 | 0 |                  return kimTypeService; | 
  | 123 |  |          } | 
  | 124 |  |   | 
  | 125 |  |  } |