Clover Coverage Report - krad-web-framework 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
22   124   20   3.14
12   50   0.91   7
7     2.86  
1    
 
  PrimitiveAttributeDefinition       Line # 37 22 0% 20 41 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2006-2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.kuali.rice.kns.datadictionary;
18   
19    import org.apache.commons.lang.StringUtils;
20    import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
21   
22    /**
23    The primitiveAttribute element identifies one pair of
24    corresponding fields in the primary business object and
25    the related business object.
26   
27    JSTL: primitiveAttribute is a Map which is accessed by the
28    sequential key of "0", "1", etc. Each entry contains the following
29    keys:
30    * sourceName (String)
31    * targetName (String)
32    The value corresponding to the sourceName key is the attribute name defined
33    for the primary business object.
34    The value corresponding to the targetName key is the attribute name for
35    the object being referenced by objectAttributeName.
36    */
 
37    public class PrimitiveAttributeDefinition extends DataDictionaryDefinitionBase {
38    private static final long serialVersionUID = -715128943756700821L;
39   
40    protected String sourceName;
41    protected String targetName;
42   
 
43  0 toggle public PrimitiveAttributeDefinition() {}
44   
45   
46    /**
47    * @return sourceName
48    */
 
49  0 toggle public String getSourceName() {
50  0 return sourceName;
51    }
52   
53    /**
54    * sourceName is the name of the POJO property of the business object
55    *
56    * @throws IllegalArgumentException if the given sourceName is blank
57    */
 
58  0 toggle public void setSourceName(String sourceName) {
59  0 if (StringUtils.isBlank(sourceName)) {
60  0 throw new IllegalArgumentException("invalid (blank) sourceName");
61    }
62   
63  0 this.sourceName = sourceName;
64    }
65   
66   
67    /**
68    * @return targetName
69    */
 
70  0 toggle public String getTargetName() {
71  0 return targetName;
72    }
73   
74    /**
75    * targetName is the name of attribute that corresponds to the sourceName in the looked up BO
76    *
77    * @throws IllegalArgumentException if the given targetName is blank
78    */
 
79  0 toggle public void setTargetName(String targetName) {
80  0 if (StringUtils.isBlank(targetName)) {
81  0 throw new IllegalArgumentException("invalid (blank) targetName");
82    }
83   
84  0 this.targetName = targetName;
85    }
86   
87   
88    /**
89    * Directly validate simple fields.
90    *
91    * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
92    */
 
93  0 toggle public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
94  0 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, sourceName)) {
95  0 throw new AttributeValidationException("unable to find attribute '" + sourceName + "' in relationship class '" + rootBusinessObjectClass + "' (" + "" + ")");
96    }
97  0 if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, targetName)) {
98  0 throw new AttributeValidationException("unable to find attribute '" + targetName + "' in related class '" + otherBusinessObjectClass.getName() + "' (" + "" + ")");
99    }
100   
101  0 Class sourceClass = DataDictionary.getAttributeClass(rootBusinessObjectClass, sourceName);
102  0 Class targetClass = DataDictionary.getAttributeClass(otherBusinessObjectClass, targetName);
103  0 if ((null == sourceClass && null != targetClass) || (null != sourceClass && null == targetClass) || !StringUtils.equals(sourceClass.getName(), targetClass.getName())) {
104  0 String sourceClassName = rootBusinessObjectClass.getName();
105  0 String targetClassName = otherBusinessObjectClass.getName();
106  0 String sourcePath = sourceClassName + "." + sourceName;
107  0 String targetPath = targetClassName + "." + targetName;
108   
109    // Just a temp hack to ignore null Person objects
110  0 if ((sourcePath != null && !StringUtils.contains(sourcePath, ".principalId")) && (targetPath != null && !StringUtils.contains(targetPath, ".principalId"))) {
111  0 throw new AttributeValidationException("source attribute '" + sourcePath + "' (" + sourceClass + ") and target attribute '" + targetPath + "' (" + targetClass + ") are of differing types (" + "" + ")");
112    }
113    }
114    }
115   
116   
117    /**
118    * @see java.lang.Object#toString()
119    */
 
120  0 toggle @Override
121    public String toString() {
122  0 return "PrimitiveAttributeDefinition (" + getSourceName()+","+getTargetName()+")";
123    }
124    }