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  import org.kuali.rice.krad.util.LegacyUtils;
23  
24  /**
25   * RelationshipsMapBuilder
26   * 
27   * @deprecated Only used by KNS classes, no replacement.
28   */
29  @Deprecated
30  public class RelationshipsMapBuilder {
31  
32      /**
33       * Default constructor
34       */
35      public RelationshipsMapBuilder() {
36      }
37  
38  
39      /**
40       * @param entry
41       * @return ExportMap containing the standard entries for the entry's RelationshipDefinitions
42       */
43      public ExportMap buildRelationshipsMap(DataDictionaryEntryBase entry) {
44          ExportMap relationshipsMap = new ExportMap("relationships");
45  
46          for ( RelationshipDefinition relationship : entry.getRelationships() ) {
47              //if in legacy context do not use any of the metadata injected stuff
48              //this prevents a problem with duplicate entries that exists
49              if(!(relationship.hasEmbeddedDataObjectMetadata() && LegacyUtils.isInLegacyContext())){
50                  relationshipsMap.set(buildRelationshipMap(relationship));
51              }
52          }
53  
54          return relationshipsMap;
55      }
56  
57      private ExportMap buildRelationshipMap(RelationshipDefinition relationship) {
58          ExportMap relationshipMap = new ExportMap(relationship.getObjectAttributeName());
59  
60          ExportMap attributesMap = new ExportMap("primitiveAttributes");
61  
62          int count = 0;
63          for (PrimitiveAttributeDefinition primitiveAttributeDefinition : relationship.getPrimitiveAttributes()) {
64              ExportMap attributeMap = new ExportMap(Integer.toString(count++));
65              attributeMap.set("sourceName", primitiveAttributeDefinition.getSourceName());
66              attributeMap.set("targetName", primitiveAttributeDefinition.getTargetName());
67  
68              attributesMap.set(attributeMap);
69          }
70  
71          relationshipMap.set(attributesMap);
72  
73          return relationshipMap;
74      }
75  
76  }