| 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.type.KimType; |
| 20 | |
import org.kuali.rice.kim.api.type.KimTypeService; |
| 21 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
| 22 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
| 23 | |
import org.kuali.rice.kim.document.IdentityManagementKimDocument; |
| 24 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
| 25 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 26 | |
import org.kuali.rice.kim.util.KimConstants; |
| 27 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinition; |
| 28 | |
|
| 29 | |
import javax.persistence.Transient; |
| 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 AttributeDefinitionMap 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 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public AttributeDefinitionMap getDefinitions() { |
| 102 | 0 | if (definitions == null || definitions.isEmpty()) { |
| 103 | 0 | KimTypeService kimTypeService = getKimTypeService(getKimType()); |
| 104 | 0 | if(kimTypeService!=null) |
| 105 | 0 | this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId()); |
| 106 | |
} |
| 107 | 0 | return this.definitions; |
| 108 | |
} |
| 109 | |
|
| 110 | |
public AttributeDefinitionMap getDefinitionsKeyedByAttributeName() { |
| 111 | 0 | AttributeDefinitionMap definitionsKeyedBySortCode = getDefinitions(); |
| 112 | 0 | AttributeDefinitionMap returnValue = new AttributeDefinitionMap(); |
| 113 | 0 | if (definitionsKeyedBySortCode != null) { |
| 114 | 0 | for (AttributeDefinition definition : definitionsKeyedBySortCode.values()) { |
| 115 | 0 | returnValue.put(definition.getName(), definition); |
| 116 | |
} |
| 117 | |
} |
| 118 | 0 | return returnValue; |
| 119 | |
} |
| 120 | |
|
| 121 | |
public void setDefinitions(AttributeDefinitionMap definitions) { |
| 122 | 0 | this.definitions = definitions; |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
protected KimTypeService getKimTypeService(KimType kimType){ |
| 126 | 0 | if( kimTypeService==null){ |
| 127 | 0 | kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType); |
| 128 | |
} |
| 129 | 0 | return kimTypeService; |
| 130 | |
} |
| 131 | |
|
| 132 | |
} |