View Javadoc

1   /**
2    * Copyright 2005-2014 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  package org.kuali.rice.kns.datadictionary.exporter;
17  
18  import org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase;
19  import org.kuali.rice.krad.datadictionary.PrimitiveAttributeDefinition;
20  import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
21  import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
22  
23  /**
24   * RelationshipsMapBuilder
25   * 
26   * 
27   */
28  @Deprecated
29  public class RelationshipsMapBuilder {
30  
31      /**
32       * Default constructor
33       */
34      public RelationshipsMapBuilder() {
35      }
36  
37  
38      /**
39       * @param entry
40       * @return ExportMap containing the standard entries for the entry's RelationshipDefinitions
41       */
42      public ExportMap buildRelationshipsMap(DataDictionaryEntryBase entry) {
43          ExportMap relationshipsMap = new ExportMap("relationships");
44  
45          for ( RelationshipDefinition relationship : entry.getRelationships() ) {
46              relationshipsMap.set(buildRelationshipMap(relationship));
47          }
48  
49          return relationshipsMap;
50      }
51  
52      private ExportMap buildRelationshipMap(RelationshipDefinition relationship) {
53          ExportMap relationshipMap = new ExportMap(relationship.getObjectAttributeName());
54  
55          ExportMap attributesMap = new ExportMap("primitiveAttributes");
56  
57          int count = 0;
58          for (PrimitiveAttributeDefinition primitiveAttributeDefinition : relationship.getPrimitiveAttributes()) {
59              ExportMap attributeMap = new ExportMap(Integer.toString(count++));
60              attributeMap.set("sourceName", primitiveAttributeDefinition.getSourceName());
61              attributeMap.set("targetName", primitiveAttributeDefinition.getTargetName());
62  
63              attributesMap.set(attributeMap);
64          }
65  
66          relationshipMap.set(attributesMap);
67  
68          return relationshipMap;
69      }
70  
71  }