2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.edges;
22 import org.apache.tinkerpop.gremlin.structure.Direction;
23 import org.onap.aai.edges.enums.AAIDirection;
24 import org.onap.aai.edges.enums.DirectionNotation;
25 import org.onap.aai.edges.enums.EdgeField;
26 import org.onap.aai.edges.enums.EdgeProperty;
27 import org.onap.aai.edges.enums.MultiplicityRule;
29 import java.util.EnumMap;
33 * Container for A&AI edge rule information
35 public class EdgeRule {
39 private Direction direction;
40 private MultiplicityRule multiplicityRule;
41 private Map<EdgeProperty, AAIDirection> edgeFields;
42 private boolean isDefaultEdge;
43 private String description;
46 * Instantiates a new edge rule.
48 * @param fieldVals - Map<String, String> where first string is
49 * an EdgeField value and second string is the
52 public EdgeRule(Map<String, String> fieldVals) {
53 edgeFields = new EnumMap<>(EdgeProperty.class);
55 from = fieldVals.get(EdgeField.FROM.toString());
56 to = fieldVals.get(EdgeField.TO.toString());
57 label = fieldVals.get(EdgeField.LABEL.toString());
58 direction = Direction.valueOf(fieldVals.get(EdgeField.DIRECTION.toString()));
59 multiplicityRule = MultiplicityRule.getValue(fieldVals.get(EdgeField.MULTIPLICITY.toString()));
61 for (EdgeProperty prop : EdgeProperty.values()) {
62 String rawVal = fieldVals.get(prop.toString());
63 edgeFields.put(prop, convertNotation(direction, rawVal));
66 isDefaultEdge = Boolean.valueOf(fieldVals.get(EdgeField.DEFAULT.toString()));
68 description = fieldVals.get(EdgeField.DESCRIPTION.toString());
69 if (description == null) { //bc description is optional and not in v12 and earlier
75 * Converts whatever string was in the json for an edge property value into
76 * the appropriate AAIDirection
78 * @param Direction dir - the edge direction
79 * @param String rawVal - property value from the json, may be
80 * IN, OUT, BOTH, NONE, ${direction}, or !${direction}
81 * @return AAIDirection - IN/OUT/BOTH/NONE if that's the rawVal, or
82 * translates the direction notation into the correct IN/OUT
84 private AAIDirection convertNotation(Direction dir, String rawVal) {
85 if (AAIDirection.NONE.toString().equals(rawVal)) {
86 return AAIDirection.NONE;
87 } else if (AAIDirection.BOTH.toString().equals(rawVal)) {
88 return AAIDirection.BOTH;
89 } else if (AAIDirection.OUT.toString().equals(rawVal)) {
90 return AAIDirection.OUT;
91 } else if (AAIDirection.IN.toString().equals(rawVal)) {
92 return AAIDirection.IN;
95 DirectionNotation rawDN = DirectionNotation.getValue(rawVal);
96 if (DirectionNotation.DIRECTION.equals(rawDN)) {
97 return AAIDirection.getValue(dir);
99 return AAIDirection.getValue(dir.opposite());
104 * Gets the name of the node type in the "from" field
105 * @return String nodetype
107 public String getFrom() {
112 * Gets the name of the node type in the "to" field
113 * @return String nodetype
115 public String getTo() {
120 * Gets the edge label
122 * @return String label
124 public String getLabel() {
129 * Gets the multiplicity rule.
131 * @return MultiplicityRule
133 public MultiplicityRule getMultiplicityRule() {
134 return multiplicityRule;
138 * Gets the edge direction
142 public Direction getDirection() {
147 * Gets the value of contains-other-v
149 * @return the value of contains-other-v
151 public String getContains() {
152 return edgeFields.get(EdgeProperty.CONTAINS).toString();
156 * Gets the value of delete-other-v
158 * @return the value of delete-other-v
160 public String getDeleteOtherV() {
161 return edgeFields.get(EdgeProperty.DELETE_OTHER_V).toString();
165 * Gets the value of the prevent-delete property
167 * @return String prevent-delete property value
169 public String getPreventDelete() {
170 return edgeFields.get(EdgeProperty.PREVENT_DELETE).toString();
174 * Returns if this rule is a default or not
178 public boolean isDefault() {
179 return isDefaultEdge;
183 * Gets the description on the edge rule (if there is one)
184 * @return String description
186 public String getDescription() {
187 return this.description;