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