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