Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / serialization / db / EdgeRule.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.serialization.db;
21
22 import org.apache.tinkerpop.gremlin.structure.Direction;
23
24 import java.util.EnumMap;
25 import java.util.Map;
26
27 public class EdgeRule {
28
29         private String label = "";
30         private MultiplicityRule multiplicityRule = null;
31         private Direction direction = null;
32         private Map<EdgeProperty, String> edgeProperties = null;
33         private boolean isDefaultEdge = false;
34         private String from;
35         private String to;
36
37         /**
38          * Instantiates a new edge rule.
39          */
40         public EdgeRule() {
41                 edgeProperties = new EnumMap<>(EdgeProperty.class);
42         }
43
44         public String getFrom() {
45                 return from;
46         }
47
48         public void setFrom(String from) {
49                 this.from = from;
50         }
51
52         public String getTo() {
53                 return to;
54         }
55
56         public void setTo(String to) {
57                 this.to = to;
58         }
59
60         /**
61          * Gets the label.
62          *
63          * @return the label
64          */
65         public String getLabel() {
66                 return label;
67         }
68         
69         /**
70          * Sets the label.
71          *
72          * @param label the new label
73          */
74         public void setLabel(String label) {
75                 this.label = label;
76         }
77         
78         /**
79          * Gets the multiplicity rule.
80          *
81          * @return the multiplicity rule
82          */
83         public MultiplicityRule getMultiplicityRule() {
84                 return multiplicityRule;
85         }
86         
87         public void setMultiplicityRule(String multiplicity){
88                 if ("Many2Many".equalsIgnoreCase(multiplicity)) {
89                         this.multiplicityRule = MultiplicityRule.MANY2MANY;
90                 } else if ("One2Many".equalsIgnoreCase(multiplicity)) {
91                         this.multiplicityRule = MultiplicityRule.ONE2MANY;
92                 } else if ("One2One".equalsIgnoreCase(multiplicity)) {
93                         this.multiplicityRule = MultiplicityRule.ONE2ONE;
94                 } else { //should be "Many2One"
95                         this.multiplicityRule = MultiplicityRule.MANY2ONE;
96                 }
97         }
98         
99         /**
100          * Sets the multiplicity rule.
101          *
102          * @param multiplicityRule the new multiplicity rule
103          */
104         public void setMultiplicityRule(MultiplicityRule multiplicityRule) {
105                 this.multiplicityRule = multiplicityRule;
106         }
107         
108         /**
109          * Gets the direction.
110          *
111          * @return the direction
112          */
113         public Direction getDirection() {
114                 return direction;
115         }
116         
117         public void setDirection(String direction){
118                 if ("OUT".equalsIgnoreCase(direction)) {
119                         this.direction = Direction.OUT;
120                 } else if ("IN".equalsIgnoreCase(direction)) {
121                         this.direction = Direction.IN;
122                 } else {
123                         this.direction = Direction.BOTH;
124                 }
125         }
126         
127         /**
128          * Sets the direction.
129          *
130          * @param direction the new direction
131          */
132         public void setDirection(Direction direction) {
133                 this.direction = direction;
134         }
135         
136         /**
137          * Gets the checks if is parent.
138          *
139          * @return the checks if is parent
140          */
141         public String getContains() {
142                 return this.getProp(EdgeProperty.CONTAINS);
143         }
144         
145         /**
146          * Sets the checks if is parent.
147          *
148          * @param isParent the new checks if is parent
149          */
150         public void setContains(String isParent) {
151                 this.setProp(EdgeProperty.CONTAINS, isParent);
152         }
153         
154         /**
155          * Gets the checks for del target.
156          *
157          * @return the checks for del target
158          */
159         public String getDeleteOtherV() {
160                 return this.getProp(EdgeProperty.DELETE_OTHER_V);
161         }
162         
163         /**
164          * Sets the checks for del target.
165          *
166          * @param hasDelTarget the new checks for del target
167          */
168         public void setDeleteOtherV(String hasDelTarget) {
169                 this.setProp(EdgeProperty.DELETE_OTHER_V, hasDelTarget);
170         }
171         
172         /**
173          * Gets the service infrastructure.
174          *
175          * @return the service infrastructure
176          */
177         public String getServiceInfrastructure() {
178                 return this.getProp(EdgeProperty.SVC_INFRA);
179         }
180         
181         /**
182          * Sets the service infrastructure.
183          *
184          * @param serviceInfrastructure the new service infrastructure
185          */
186         public void setServiceInfrastructure(String serviceInfrastructure) {
187                 this.setProp(EdgeProperty.SVC_INFRA, serviceInfrastructure);
188         }
189         
190         public String getPreventDelete() {
191                 return this.getProp(EdgeProperty.PREVENT_DELETE);
192         }
193         
194         public void setPreventDelete(String preventDelete) {
195                 this.setProp(EdgeProperty.PREVENT_DELETE, preventDelete);
196         }
197         
198         /**
199          * Gets the edge properties.
200          *
201          * @return the edge properties
202          */
203         public Map<EdgeProperty, String> getEdgeProperties() {
204                 return this.edgeProperties;
205         }
206         
207         /**
208          * Sets the prop.
209          *
210          * @param key the key
211          * @param value the value
212          */
213         private void setProp(EdgeProperty key, String value) {
214                 this.edgeProperties.put(key, value);
215         }
216         
217         /**
218          * Gets the prop.
219          *
220          * @param key the key
221          * @return the prop
222          */
223         private String getProp(EdgeProperty key) {
224                 return this.edgeProperties.get(key);
225         }
226
227         public boolean isDefault() {
228                 return isDefaultEdge;
229         }
230
231         public void setIsDefault(boolean isDefault) {
232                 this.isDefaultEdge = isDefault;
233         }
234
235         public void setIsDefault(String isDefault) {
236                 this.isDefaultEdge = "true".equals(isDefault);
237         }
238
239
240 }