2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.edges;
24 import org.apache.tinkerpop.gremlin.structure.Direction;
25 import org.onap.aai.edges.enums.AAIDirection;
26 import org.onap.aai.edges.enums.DirectionNotation;
27 import org.onap.aai.edges.enums.EdgeField;
28 import org.onap.aai.edges.enums.EdgeProperty;
29 import org.onap.aai.edges.enums.MultiplicityRule;
31 import java.util.EnumMap;
35 * Container for A&AI edge rule information
37 public class EdgeRule {
41 private Direction direction;
42 private MultiplicityRule multiplicityRule;
43 private Map<EdgeProperty, AAIDirection> edgeFields;
44 private boolean isDefaultEdge;
45 private String description;
48 * Instantiates a new edge rule.
50 * @param fieldVals - Map<String, String> where first string is
51 * an EdgeField value and second string is the
54 public EdgeRule(Map<String, String> fieldVals) {
55 edgeFields = new EnumMap<>(EdgeProperty.class);
57 from = fieldVals.get(EdgeField.FROM.toString());
58 to = fieldVals.get(EdgeField.TO.toString());
59 label = fieldVals.get(EdgeField.LABEL.toString());
60 direction = Direction.valueOf(fieldVals.get(EdgeField.DIRECTION.toString()));
61 multiplicityRule = MultiplicityRule.getValue(fieldVals.get(EdgeField.MULTIPLICITY.toString()));
63 for (EdgeProperty prop : EdgeProperty.values()) {
64 String rawVal = fieldVals.get(prop.toString());
65 edgeFields.put(prop, convertNotation(direction, rawVal));
68 isDefaultEdge = Boolean.valueOf(fieldVals.get(EdgeField.DEFAULT.toString()));
70 description = fieldVals.get(EdgeField.DESCRIPTION.toString());
71 if (description == null) { //bc description is optional and not in v12 and earlier
77 * Converts whatever string was in the json for an edge property value into
78 * the appropriate AAIDirection
80 * @param Direction dir - the edge direction
81 * @param String rawVal - property value from the json, may be
82 * IN, OUT, BOTH, NONE, ${direction}, or !${direction}
83 * @return AAIDirection - IN/OUT/BOTH/NONE if that's the rawVal, or
84 * translates the direction notation into the correct IN/OUT
86 private AAIDirection convertNotation(Direction dir, String rawVal) {
87 if (AAIDirection.NONE.toString().equals(rawVal)) {
88 return AAIDirection.NONE;
89 } else if (AAIDirection.BOTH.toString().equals(rawVal)) {
90 return AAIDirection.BOTH;
91 } else if (AAIDirection.OUT.toString().equals(rawVal)) {
92 return AAIDirection.OUT;
93 } else if (AAIDirection.IN.toString().equals(rawVal)) {
94 return AAIDirection.IN;
97 DirectionNotation rawDN = DirectionNotation.getValue(rawVal);
98 if (DirectionNotation.DIRECTION.equals(rawDN)) {
99 return AAIDirection.getValue(dir);
101 return AAIDirection.getValue(dir.opposite());
106 * Gets the name of the node type in the "from" field
107 * @return String nodetype
109 public String getFrom() {
114 * Gets the name of the node type in the "to" field
115 * @return String nodetype
117 public String getTo() {
122 * Gets the edge label
124 * @return String label
126 public String getLabel() {
131 * Gets the multiplicity rule.
133 * @return MultiplicityRule
135 public MultiplicityRule getMultiplicityRule() {
136 return multiplicityRule;
140 * Gets the edge direction
144 public Direction getDirection() {
149 * Gets the value of contains-other-v
151 * @return the value of contains-other-v
153 public String getContains() {
154 return edgeFields.get(EdgeProperty.CONTAINS).toString();
158 * Gets the value of delete-other-v
160 * @return the value of delete-other-v
162 public String getDeleteOtherV() {
163 return edgeFields.get(EdgeProperty.DELETE_OTHER_V).toString();
167 * Gets the value of the prevent-delete property
169 * @return String prevent-delete property value
171 public String getPreventDelete() {
172 return edgeFields.get(EdgeProperty.PREVENT_DELETE).toString();
176 * Returns if this rule is a default or not
180 public boolean isDefault() {
181 return isDefaultEdge;
185 * Gets the description on the edge rule (if there is one)
186 * @return String description
188 public String getDescription() {
189 return this.description;