| 1 |  |  | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  |  | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  |  | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  |  | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 14 |  |  | 
            
  
    | 15 |  |  | 
            
  
    | 16 |  | package org.kuali.student.common.search.service.impl; | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  | import java.util.HashSet; | 
            
  
    | 19 |  | import java.util.List; | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  | import javax.xml.parsers.DocumentBuilder; | 
            
  
    | 22 |  | import javax.xml.parsers.DocumentBuilderFactory; | 
            
  
    | 23 |  |  | 
            
  
    | 24 |  | import org.apache.log4j.Logger; | 
            
  
    | 25 |  | import org.kuali.student.common.dictionary.old.dto.FieldDescriptor; | 
            
  
    | 26 |  | import org.kuali.student.common.search.dto.ComparisonParamInfo; | 
            
  
    | 27 |  | import org.kuali.student.common.search.dto.CrossSearchTypeInfo; | 
            
  
    | 28 |  | import org.kuali.student.common.search.dto.JoinComparisonInfo; | 
            
  
    | 29 |  | import org.kuali.student.common.search.dto.JoinCriteriaInfo; | 
            
  
    | 30 |  | import org.kuali.student.common.search.dto.JoinResultMappingInfo; | 
            
  
    | 31 |  | import org.kuali.student.common.search.dto.QueryParamInfo; | 
            
  
    | 32 |  | import org.kuali.student.common.search.dto.ResultColumnInfo; | 
            
  
    | 33 |  | import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo; | 
            
  
    | 34 |  | import org.kuali.student.common.search.dto.SearchResultTypeInfo; | 
            
  
    | 35 |  | import org.kuali.student.common.search.dto.SearchTypeInfo; | 
            
  
    | 36 |  | import org.kuali.student.common.search.dto.SubSearchInfo; | 
            
  
    | 37 |  | import org.kuali.student.common.search.dto.SubSearchParamMappingInfo; | 
            
  
    | 38 |  | import org.springframework.beans.factory.support.BeanDefinitionBuilder; | 
            
  
    | 39 |  | import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; | 
            
  
    | 40 |  | import org.springframework.beans.factory.xml.ParserContext; | 
            
  
    | 41 |  | import org.w3c.dom.Attr; | 
            
  
    | 42 |  | import org.w3c.dom.Document; | 
            
  
    | 43 |  | import org.w3c.dom.Element; | 
            
  
    | 44 |  | import org.w3c.dom.Node; | 
            
  
    | 45 |  |  | 
               
        |  |  | 
           
           |  | 93.6% | Uncovered Elements: 13 (203) | Complexity: 63 | Complexity Density: 0.57 |  | 
  
  
    | 46 |  | public class SearchBeanDefinitionParser extends | 
            
  
    | 47 |  | AbstractSingleBeanDefinitionParser { | 
            
  
    | 48 |  | private static final Logger logger = Logger.getLogger(SearchBeanDefinitionParser.class); | 
            
  
    | 49 |  |  | 
               
        |  |  | 
           
           |  | 93% | Uncovered Elements: 4 (57) | Complexity: 15 | Complexity Density: 0.52 |  | 
  
  
    | 50 | 6060 |  @Override... | 
            
  
    | 51 |  | protected Class<?> getBeanClass(Element element) { | 
            
  
    | 52 |  |  | 
            
  
    | 53 | 6060 | if (element.getLocalName().equals("fieldDescriptor")) { | 
            
  
    | 54 | 0 | return FieldDescriptor.class; | 
            
  
    | 55 |  | } | 
            
  
    | 56 | 6060 | if (element.getLocalName().equals("searchCriteriaTypeInfo")) { | 
            
  
    | 57 | 800 | return SearchCriteriaTypeInfo.class; | 
            
  
    | 58 |  | } | 
            
  
    | 59 | 5260 | if (element.getLocalName().equals("queryParam")) { | 
            
  
    | 60 | 1388 | return QueryParamInfo.class; | 
            
  
    | 61 |  | } | 
            
  
    | 62 | 3872 | if (element.getLocalName().equals("searchType")) { | 
            
  
    | 63 | 782 | return SearchTypeInfo.class; | 
            
  
    | 64 |  | } | 
            
  
    | 65 | 3090 | if (element.getLocalName().equals("resultColumn")) { | 
            
  
    | 66 | 1578 | return ResultColumnInfo.class; | 
            
  
    | 67 |  | } | 
            
  
    | 68 | 1512 | if (element.getLocalName().equals("searchResultTypeInfo")) { | 
            
  
    | 69 | 696 | return SearchResultTypeInfo.class; | 
            
  
    | 70 |  | } | 
            
  
    | 71 |  |  | 
            
  
    | 72 |  |  | 
            
  
    | 73 | 816 | if (element.getLocalName().equals("crossSearchType")) { | 
            
  
    | 74 | 26 | return CrossSearchTypeInfo.class; | 
            
  
    | 75 |  | } | 
            
  
    | 76 | 790 | if (element.getLocalName().equals("subSearch")) { | 
            
  
    | 77 | 52 | return SubSearchInfo.class; | 
            
  
    | 78 |  | } | 
            
  
    | 79 | 738 | if (element.getLocalName().equals("subSearchParamMappings")) { | 
            
  
    | 80 | 328 | return SubSearchParamMappingInfo.class; | 
            
  
    | 81 |  | } | 
            
  
    | 82 | 410 | if (element.getLocalName().equals("joinCriteria")) { | 
            
  
    | 83 | 26 | return JoinCriteriaInfo.class; | 
            
  
    | 84 |  | } | 
            
  
    | 85 | 384 | if (element.getLocalName().equals("comparison")) { | 
            
  
    | 86 | 8 | return JoinComparisonInfo.class; | 
            
  
    | 87 |  | } | 
            
  
    | 88 | 376 | if (element.getLocalName().equals("leftHandSide")) { | 
            
  
    | 89 | 8 | return ComparisonParamInfo.class; | 
            
  
    | 90 |  | } | 
            
  
    | 91 | 368 | if (element.getLocalName().equals("rightHandSide")) { | 
            
  
    | 92 | 8 | return ComparisonParamInfo.class; | 
            
  
    | 93 |  | } | 
            
  
    | 94 | 360 | if (element.getLocalName().equals("joinResultMapping")) { | 
            
  
    | 95 | 360 | return JoinResultMappingInfo.class; | 
            
  
    | 96 |  | } | 
            
  
    | 97 |  |  | 
            
  
    | 98 | 0 | return super.getBeanClass(element); | 
            
  
    | 99 |  | } | 
            
  
    | 100 |  |  | 
               
        |  |  | 
           
           |  | 96.2% | Uncovered Elements: 3 (80) | Complexity: 27 | Complexity Density: 0.61 |  | 
  
  
    | 101 | 6060 |  @Override... | 
            
  
    | 102 |  | protected void doParse(Element element, ParserContext pc, BeanDefinitionBuilder builder) { | 
            
  
    | 103 |  |  | 
            
  
    | 104 | 6060 | if(!"fieldDescriptor".equals(element.getLocalName())&&element.hasAttribute("id")){ | 
            
  
    | 105 | 5238 | builder.addPropertyValue("key", element.getAttributes().getNamedItem("id").getTextContent()); | 
            
  
    | 106 |  | } | 
            
  
    | 107 |  |  | 
            
  
    | 108 | 6060 | if("fieldDescriptor".equals(element.getLocalName())&&element.hasAttribute("parent")){ | 
            
  
    | 109 | 0 | builder.setParentName(element.getAttributes().getNamedItem("parent").getTextContent()); | 
            
  
    | 110 |  | } | 
            
  
    | 111 |  |  | 
            
  
    | 112 |  |  | 
            
  
    | 113 | 6060 | if("queryParam".equals(element.getLocalName())&&element.hasAttribute("optional")){ | 
            
  
    | 114 | 536 | builder.addPropertyValue("optional", "true".equals(element.getAttribute("optional"))?true:false); | 
            
  
    | 115 |  | } | 
            
  
    | 116 |  |  | 
            
  
    | 117 |  |  | 
            
  
    | 118 | 6060 | if(element.hasAttributes()){ | 
            
  
    | 119 | 18868 | for(int i = 0;i<element.getAttributes().getLength();i++){ | 
            
  
    | 120 | 12840 | Attr attr = (Attr) element.getAttributes().item(i); | 
            
  
    | 121 | 12840 | if("abstract".equals(attr.getName())){ | 
            
  
    | 122 | 2528 | builder.setAbstract(true); | 
            
  
    | 123 | 10312 | }else if(!"id".equals(attr.getName())&&!"parent".equals(attr.getName())){ | 
            
  
    | 124 | 2442 | String fieldName = resolveFieldName(element.getLocalName(),attr.getName()); | 
            
  
    | 125 | 2442 | builder.addPropertyValue(fieldName, attr.getValue()); | 
            
  
    | 126 |  | } | 
            
  
    | 127 |  | } | 
            
  
    | 128 |  | } | 
            
  
    | 129 |  |  | 
            
  
    | 130 |  |  | 
            
  
    | 131 | 6060 | HashSet<String> visitedNodes = new HashSet<String>(); | 
            
  
    | 132 |  |  | 
            
  
    | 133 | 24222 | for(int i = 0;i<element.getChildNodes().getLength();i++){ | 
            
  
    | 134 | 18162 | Node node = element.getChildNodes().item(i); | 
            
  
    | 135 |  |  | 
            
  
    | 136 | 18162 | if(Node.ELEMENT_NODE == node.getNodeType()){ | 
            
  
    | 137 | 7701 | String localName=node.getLocalName(); | 
            
  
    | 138 | 7701 | if(!visitedNodes.contains(localName)){ | 
            
  
    | 139 | 7057 | if(isWrappedList(node.getLocalName())){ | 
            
  
    | 140 | 728 | List<?> refList = pc.getDelegate().parseListElement((Element) node, pc.getContainingBeanDefinition()); | 
            
  
    | 141 | 728 | builder.addPropertyValue(node.getLocalName(),refList); | 
            
  
    | 142 | 6329 | }else if(isUnwrappedList(node.getLocalName())){ | 
            
  
    | 143 | 104 | Element childList=getChildList(element,node.getLocalName()); | 
            
  
    | 144 | 104 | visitedNodes.add(node.getLocalName()); | 
            
  
    | 145 | 104 | List<?> refList = pc.getDelegate().parseListElement(childList, pc.getContainingBeanDefinition()); | 
            
  
    | 146 | 104 | if(refList!=null&&!refList.isEmpty()){ | 
            
  
    | 147 | 104 | String fieldName=resolveFieldName(element.getLocalName(),node.getLocalName()); | 
            
  
    | 148 | 104 | builder.addPropertyValue(fieldName,refList); | 
            
  
    | 149 |  | } | 
            
  
    | 150 |  | }else{ | 
            
  
    | 151 | 6225 | Element childElement = getFirstChildElement(node); | 
            
  
    | 152 | 6225 | if(childElement!=null){ | 
            
  
    | 153 | 1092 | if("ref".equals(childElement.getLocalName())){ | 
            
  
    | 154 | 834 | Object childBean = pc.getDelegate().parsePropertySubElement(childElement, pc.getContainingBeanDefinition()); | 
            
  
    | 155 | 834 | builder.addPropertyValue(node.getLocalName(), childBean); | 
            
  
    | 156 |  | }else{ | 
            
  
    | 157 | 258 | Object childBean = pc.getDelegate().parsePropertySubElement((Element)node, pc.getContainingBeanDefinition()); | 
            
  
    | 158 | 258 | builder.addPropertyValue(node.getLocalName(), childBean); | 
            
  
    | 159 |  | } | 
            
  
    | 160 |  | }else{ | 
            
  
    | 161 | 5133 | if(("ref".equals(node.getLocalName())&&"queryParam".equals(element.getLocalName()))){ | 
            
  
    | 162 | 448 | Object childBean = pc.getDelegate().parsePropertySubElement((Element)node, pc.getContainingBeanDefinition()); | 
            
  
    | 163 | 448 | builder.addPropertyValue("fieldDescriptor", childBean); | 
            
  
    | 164 | 4685 | }else if("leftHandSide".equals(node.getLocalName()) | 
            
  
    | 165 |  | ||"rightHandSide".equals(node.getLocalName()) | 
            
  
    | 166 |  | ||"joinCriteria".equals(node.getLocalName())){ | 
            
  
    | 167 | 34 | Object childBean = pc.getDelegate().parsePropertySubElement((Element)node, pc.getContainingBeanDefinition()); | 
            
  
    | 168 | 34 | builder.addPropertyValue(node.getLocalName(), childBean); | 
            
  
    | 169 |  | }else{ | 
            
  
    | 170 | 4651 | builder.addPropertyValue(node.getLocalName(), node.getTextContent()); | 
            
  
    | 171 |  | } | 
            
  
    | 172 |  | } | 
            
  
    | 173 |  | } | 
            
  
    | 174 |  | } | 
            
  
    | 175 |  | } | 
            
  
    | 176 |  | } | 
            
  
    | 177 |  | } | 
            
  
    | 178 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 179 | 6329 |  private boolean isUnwrappedList(String localName) {... | 
            
  
    | 180 | 6329 | return localName.equals("subSearchParamMappings")|| | 
            
  
    | 181 |  | localName.equals("comparison")|| | 
            
  
    | 182 |  | localName.equals("subSearch")|| | 
            
  
    | 183 |  | localName.equals("joinResultMapping"); | 
            
  
    | 184 |  | } | 
            
  
    | 185 |  |  | 
            
  
    | 186 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (17) | Complexity: 6 | Complexity Density: 0.67 |  | 
  
  
    | 187 | 2546 |  private String resolveFieldName(String parentName, String nodeName) {... | 
            
  
    | 188 | 2546 | if("comparison".equals(nodeName)){ | 
            
  
    | 189 | 8 | return "comparisons"; | 
            
  
    | 190 |  | } | 
            
  
    | 191 | 2538 | if("subSearch".equals(nodeName)){ | 
            
  
    | 192 | 26 | return "subSearches"; | 
            
  
    | 193 |  | } | 
            
  
    | 194 | 2512 | if("joinResultMapping".equals(nodeName)){ | 
            
  
    | 195 | 26 | return "joinResultMappings"; | 
            
  
    | 196 |  | } | 
            
  
    | 197 | 2486 | if("joinCriteria".equals(parentName)&&"type".equals(nodeName)){ | 
            
  
    | 198 | 26 | return "joinType"; | 
            
  
    | 199 |  | } | 
            
  
    | 200 |  |  | 
            
  
    | 201 | 2460 | return nodeName; | 
            
  
    | 202 |  | } | 
            
  
    | 203 |  |  | 
            
  
    | 204 |  |  | 
            
  
    | 205 |  |  | 
               
        |  |  | 
           
           |  | 73.9% | Uncovered Elements: 6 (23) | Complexity: 7 | Complexity Density: 0.41 |  | 
  
  
    | 206 | 104 |  private Element getChildList(Element element, String localName) {... | 
            
  
    | 207 | 104 | try{ | 
            
  
    | 208 |  |  | 
            
  
    | 209 | 104 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | 
            
  
    | 210 | 104 | DocumentBuilder builder = dbf.newDocumentBuilder(); | 
            
  
    | 211 | 104 | Document doc = builder.newDocument(); | 
            
  
    | 212 |  |  | 
            
  
    | 213 | 104 | Element root = doc.createElement("listRoot"); | 
            
  
    | 214 |  |  | 
            
  
    | 215 | 3080 | for(int i = 0;i<element.getChildNodes().getLength();i++){ | 
            
  
    | 216 | 2976 | Node node = element.getChildNodes().item(i); | 
            
  
    | 217 | 2976 | if(Node.ELEMENT_NODE == node.getNodeType() && localName.equals(node.getLocalName())){ | 
            
  
    | 218 |  |  | 
            
  
    | 219 |  |  | 
            
  
    | 220 | 748 | Node copied = doc.importNode(node, true); | 
            
  
    | 221 | 748 | root.appendChild(copied); | 
            
  
    | 222 |  | } | 
            
  
    | 223 | 2976 | if(Node.ELEMENT_NODE == node.getNodeType() && (localName+"Ref").equals(node.getLocalName())){ | 
            
  
    | 224 |  |  | 
            
  
    | 225 |  |  | 
            
  
    | 226 | 0 | Element ref = doc.createElement("ref"); | 
            
  
    | 227 | 0 | ref.setAttribute("bean", ((Element)node).getAttribute("bean")); | 
            
  
    | 228 | 0 | root.appendChild(ref); | 
            
  
    | 229 |  | } | 
            
  
    | 230 |  | } | 
            
  
    | 231 |  |  | 
            
  
    | 232 | 104 | return root; | 
            
  
    | 233 |  | }catch(Exception e){ | 
            
  
    | 234 | 0 | logger.error("Exception occured: ", e); | 
            
  
    | 235 |  | } | 
            
  
    | 236 | 0 | return null; | 
            
  
    | 237 |  | } | 
            
  
    | 238 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (9) | Complexity: 3 | Complexity Density: 0.6 |  | 
  
  
    | 239 | 6225 |  private Element getFirstChildElement(Node node) {... | 
            
  
    | 240 | 12096 | for(int i = 0;i<node.getChildNodes().getLength();i++){ | 
            
  
    | 241 | 6963 | Node childNode = node.getChildNodes().item(i); | 
            
  
    | 242 | 6963 | if(Node.ELEMENT_NODE == childNode.getNodeType()){ | 
            
  
    | 243 | 1092 | return (Element) childNode; | 
            
  
    | 244 |  | } | 
            
  
    | 245 |  | } | 
            
  
    | 246 |  |  | 
            
  
    | 247 | 5133 | return null; | 
            
  
    | 248 |  | } | 
            
  
    | 249 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 250 | 7057 |  private boolean isWrappedList(String localName) {... | 
            
  
    | 251 | 7057 | return localName.equals("queryParams")|| | 
            
  
    | 252 |  | localName.equals("resultColumns"); | 
            
  
    | 253 |  | } | 
            
  
    | 254 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (5) | Complexity: 2 | Complexity Density: 0.67 |  | 
  
  
    | 255 | 6060 |  @Override... | 
            
  
    | 256 |  | protected String getParentName(Element element) { | 
            
  
    | 257 | 6060 | if(element.hasAttribute("parent")){ | 
            
  
    | 258 | 2632 | return element.getAttribute("parent"); | 
            
  
    | 259 |  | } | 
            
  
    | 260 | 3428 | return super.getParentName(element); | 
            
  
    | 261 |  | } | 
            
  
    | 262 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 263 | 822 |  @Override... | 
            
  
    | 264 |  | protected boolean shouldGenerateIdAsFallback() { | 
            
  
    | 265 | 822 | return true; | 
            
  
    | 266 |  | } | 
            
  
    | 267 |  | } |