Initial ONAP Synapse commit
[aai/data-router.git] / src / main / java / org / openecomp / datarouter / util / CrossEntityReference.java
1 /**
2  * ============LICENSE_START=======================================================
3  * DataRouter
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.datarouter.util;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 /**
31  * Processing and entity wrapper for property transposition logic and UEB processing
32  * 
33  * @author DAVEA
34  */
35 public class CrossEntityReference {
36
37   private String targetEntityType;
38
39   private List<String> attributeNames;
40
41   public CrossEntityReference() {
42     this.targetEntityType = null;
43     this.attributeNames = new ArrayList<String>();
44   }
45
46   public String getTargetEntityType() {
47     return targetEntityType;
48   }
49
50   public void setTargetEntityType(String targetEntityType) {
51     this.targetEntityType = targetEntityType;
52   }
53
54   public List<String> getAttributeNames() {
55     return attributeNames;
56   }
57
58   public void setAttributeNames(List<String> attributeNames) {
59     this.attributeNames = attributeNames;
60   }
61
62   public void addAttributeName(String attributeName) {
63     if (!this.attributeNames.contains(attributeName)) {
64       this.attributeNames.add(attributeName);
65     }
66   }
67
68   public void initialize(String crossEntityReferenceValueFromModel) {
69
70     if (crossEntityReferenceValueFromModel == null
71         || crossEntityReferenceValueFromModel.length() == 0) {
72       // or throw an exception due to failure to initialize
73       return;
74     }
75
76     String[] tokens = crossEntityReferenceValueFromModel.split(",");
77
78     if (tokens.length >= 2) {
79       this.targetEntityType = tokens[0];
80
81       for (int x = 1; x < tokens.length; x++) {
82         this.attributeNames.add(tokens[x]);
83       }
84     } else {
85       // throw a CrossEntityReferenceInitializationException??
86     }
87
88   }
89
90   @Override
91   public String toString() {
92     return "CrossEntityReference ["
93         + (targetEntityType != null ? "entityType=" + targetEntityType + ", " : "")
94         + (attributeNames != null ? "attributeNames=" + attributeNames : "") + "]";
95   }
96
97 }