Sync the latest code changes
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.serialization.db;
23
24 import org.apache.tinkerpop.gremlin.structure.Direction;
25
26 import java.util.EnumMap;
27 import java.util.Map;
28
29 public class EdgeRule {
30
31         private String label = "";
32         private MultiplicityRule multiplicityRule = null;
33         private Direction direction = null;
34         private Map<EdgeProperty, String> edgeProperties = null;
35         private boolean isDefaultEdge = false;
36         private String from;
37         private String to;
38
39         /**
40          * Instantiates a new edge rule.
41          */
42         public EdgeRule() {
43                 edgeProperties = new EnumMap<>(EdgeProperty.class);
44         }
45
46         public String getFrom() {
47                 return from;
48         }
49
50         public void setFrom(String from) {
51                 this.from = from;
52         }
53
54         public String getTo() {
55                 return to;
56         }
57
58         public void setTo(String to) {
59                 this.to = to;
60         }
61
62         /**
63          * Gets the label.
64          *
65          * @return the label
66          */
67         public String getLabel() {
68                 return label;
69         }
70         
71         /**
72          * Sets the label.
73          *
74          * @param label the new label
75          */
76         public void setLabel(String label) {
77                 this.label = label;
78         }
79         
80         /**
81          * Gets the multiplicity rule.
82          *
83          * @return the multiplicity rule
84          */
85         public MultiplicityRule getMultiplicityRule() {
86                 return multiplicityRule;
87         }
88         
89         public void setMultiplicityRule(String multiplicity){
90                 if ("Many2Many".equalsIgnoreCase(multiplicity)) {
91                         this.multiplicityRule = MultiplicityRule.MANY2MANY;
92                 } else if ("One2Many".equalsIgnoreCase(multiplicity)) {
93                         this.multiplicityRule = MultiplicityRule.ONE2MANY;
94                 } else if ("One2One".equalsIgnoreCase(multiplicity)) {
95                         this.multiplicityRule = MultiplicityRule.ONE2ONE;
96                 } else { //should be "Many2One"
97                         this.multiplicityRule = MultiplicityRule.MANY2ONE;
98                 }
99         }
100         
101         /**
102          * Sets the multiplicity rule.
103          *
104          * @param multiplicityRule the new multiplicity rule
105          */
106         public void setMultiplicityRule(MultiplicityRule multiplicityRule) {
107                 this.multiplicityRule = multiplicityRule;
108         }
109         
110         /**
111          * Gets the direction.
112          *
113          * @return the direction
114          */
115         public Direction getDirection() {
116                 return direction;
117         }
118         
119         public void setDirection(String direction){
120                 if ("OUT".equalsIgnoreCase(direction)) {
121                         this.direction = Direction.OUT;
122                 } else if ("IN".equalsIgnoreCase(direction)) {
123                         this.direction = Direction.IN;
124                 } else {
125                         this.direction = Direction.BOTH;
126                 }
127         }
128         
129         /**
130          * Sets the direction.
131          *
132          * @param direction the new direction
133          */
134         public void setDirection(Direction direction) {
135                 this.direction = direction;
136         }
137         
138         /**
139          * Gets the checks if is parent.
140          *
141          * @return the checks if is parent
142          */
143         public String getContains() {
144                 return this.getProp(EdgeProperty.CONTAINS);
145         }
146         
147         /**
148          * Sets the checks if is parent.
149          *
150          * @param isParent the new checks if is parent
151          */
152         public void setContains(String isParent) {
153                 this.setProp(EdgeProperty.CONTAINS, isParent);
154         }
155         
156         /**
157          * Gets the checks for del target.
158          *
159          * @return the checks for del target
160          */
161         public String getDeleteOtherV() {
162                 return this.getProp(EdgeProperty.DELETE_OTHER_V);
163         }
164         
165         /**
166          * Sets the checks for del target.
167          *
168          * @param hasDelTarget the new checks for del target
169          */
170         public void setDeleteOtherV(String hasDelTarget) {
171                 this.setProp(EdgeProperty.DELETE_OTHER_V, hasDelTarget);
172         }
173         
174         /**
175          * Gets the service infrastructure.
176          *
177          * @return the service infrastructure
178          */
179         public String getServiceInfrastructure() {
180                 return this.getProp(EdgeProperty.SVC_INFRA);
181         }
182         
183         /**
184          * Sets the service infrastructure.
185          *
186          * @param serviceInfrastructure the new service infrastructure
187          */
188         public void setServiceInfrastructure(String serviceInfrastructure) {
189                 this.setProp(EdgeProperty.SVC_INFRA, serviceInfrastructure);
190         }
191         
192         public String getPreventDelete() {
193                 return this.getProp(EdgeProperty.PREVENT_DELETE);
194         }
195         
196         public void setPreventDelete(String preventDelete) {
197                 this.setProp(EdgeProperty.PREVENT_DELETE, preventDelete);
198         }
199         
200         /**
201          * Gets the edge properties.
202          *
203          * @return the edge properties
204          */
205         public Map<EdgeProperty, String> getEdgeProperties() {
206                 return this.edgeProperties;
207         }
208         
209         /**
210          * Sets the prop.
211          *
212          * @param key the key
213          * @param value the value
214          */
215         private void setProp(EdgeProperty key, String value) {
216                 this.edgeProperties.put(key, value);
217         }
218         
219         /**
220          * Gets the prop.
221          *
222          * @param key the key
223          * @return the prop
224          */
225         private String getProp(EdgeProperty key) {
226                 return this.edgeProperties.get(key);
227         }
228
229         public boolean isDefault() {
230                 return isDefaultEdge;
231         }
232
233         public void setIsDefault(boolean isDefault) {
234                 this.isDefaultEdge = isDefault;
235         }
236
237         public void setIsDefault(String isDefault) {
238                 this.isDefaultEdge = "true".equals(isDefault);
239         }
240
241
242 }