| 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 org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.util.AttributeSet; |
| 20 | |
import org.kuali.rice.kim.api.type.KimType; |
| 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.service.KIMServiceLocatorInternal; |
| 24 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 25 | |
import org.kuali.rice.kim.service.support.KimTypeService; |
| 26 | |
import org.kuali.rice.kim.util.KimConstants; |
| 27 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
| 28 | |
import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition; |
| 29 | |
import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition; |
| 30 | |
|
| 31 | |
import java.io.Serializable; |
| 32 | |
import java.util.List; |
| 33 | |
import java.util.Map; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public class KimTypeAttributesHelper implements Serializable { |
| 42 | |
|
| 43 | |
private KimType kimType; |
| 44 | |
private transient KimTypeService kimTypeService; |
| 45 | |
private List<? extends KimAttributes> attributes; |
| 46 | |
private transient AttributeDefinitionMap definitions; |
| 47 | |
private transient Map<String,Object> attributeEntry; |
| 48 | |
|
| 49 | 0 | public KimTypeAttributesHelper(KimType kimType){ |
| 50 | 0 | this.kimType = kimType; |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public List<? extends KimAttributes> getAttributes() { |
| 57 | 0 | return this.attributes; |
| 58 | |
} |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public KimType getKimType() { |
| 64 | 0 | return this.kimType; |
| 65 | |
} |
| 66 | |
|
| 67 | |
public KimTypeService getKimTypeService(KimType kimType){ |
| 68 | 0 | if(this.kimTypeService==null){ |
| 69 | 0 | this.kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType); |
| 70 | |
} |
| 71 | 0 | return this.kimTypeService; |
| 72 | |
} |
| 73 | |
|
| 74 | |
public Map<String,Object> getAttributeEntry() { |
| 75 | 0 | if(attributeEntry==null || attributeEntry.isEmpty()) |
| 76 | 0 | attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions()); |
| 77 | 0 | return attributeEntry; |
| 78 | |
} |
| 79 | |
|
| 80 | |
public String getKimAttributeDefnId(AttributeDefinition definition){ |
| 81 | 0 | if (definition instanceof KimDataDictionaryAttributeDefinition) { |
| 82 | 0 | return ((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
| 83 | |
} |
| 84 | 0 | return ((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public AttributeDefinitionMap getDefinitions() { |
| 93 | 0 | if (definitions == null || definitions.isEmpty()) { |
| 94 | 0 | KimTypeService kimTypeService = getKimTypeService(getKimType()); |
| 95 | 0 | if(kimTypeService!=null) |
| 96 | 0 | this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId()); |
| 97 | |
} |
| 98 | 0 | return this.definitions; |
| 99 | |
} |
| 100 | |
|
| 101 | |
public AttributeDefinitionMap getDefinitionsKeyedByAttributeName() { |
| 102 | 0 | AttributeDefinitionMap definitionsKeyedBySortCode = getDefinitions(); |
| 103 | 0 | AttributeDefinitionMap returnValue = new AttributeDefinitionMap(); |
| 104 | 0 | if (definitionsKeyedBySortCode != null) { |
| 105 | 0 | for (AttributeDefinition definition : definitionsKeyedBySortCode.values()) { |
| 106 | 0 | returnValue.put(definition.getName(), definition); |
| 107 | |
} |
| 108 | |
} |
| 109 | 0 | return returnValue; |
| 110 | |
} |
| 111 | |
|
| 112 | |
public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){ |
| 113 | 0 | String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR); |
| 114 | 0 | StringBuffer commaDelimitedAttributesLabels = new StringBuffer(); |
| 115 | 0 | for(String name: names){ |
| 116 | 0 | commaDelimitedAttributesLabels.append(getAttributeEntry().get(name.trim())+KimConstants.KimUIConstants.COMMA_SEPARATOR); |
| 117 | |
} |
| 118 | 0 | if(commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR)) |
| 119 | 0 | commaDelimitedAttributesLabels.delete(commaDelimitedAttributesLabels.length()-KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length()); |
| 120 | 0 | return commaDelimitedAttributesLabels.toString(); |
| 121 | |
} |
| 122 | |
|
| 123 | |
public AttributeDefinition getAttributeDefinition(String attributeName){ |
| 124 | 0 | return getDefinitionsKeyedByAttributeName().get(attributeName); |
| 125 | |
} |
| 126 | |
|
| 127 | |
public String getAttributeValue(AttributeSet aSet, String attributeName){ |
| 128 | 0 | if(StringUtils.isEmpty(attributeName) || aSet==null) return null; |
| 129 | 0 | for(String attributeNameKey: aSet.keySet()){ |
| 130 | 0 | if(attributeName.equals(attributeNameKey)) |
| 131 | 0 | return aSet.get(attributeNameKey); |
| 132 | |
} |
| 133 | 0 | return null; |
| 134 | |
} |
| 135 | |
} |