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=========================================================
21 package org.onap.aai.schemagen.genxsd;
23 import org.apache.commons.lang3.StringUtils;
24 import org.onap.aai.edges.EdgeRule;
25 import org.onap.aai.edges.enums.AAIDirection;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class EdgeDescription {
31 private static final Logger logger = LoggerFactory.getLogger(EdgeDescription.class);
34 public enum LineageType {
35 PARENT, CHILD, UNRELATED
38 private final String ruleKey;
39 private LineageType lineageType = LineageType.UNRELATED;
41 public EdgeDescription(EdgeRule ed) {
43 if (ed.getDirection().toString().equals(ed.getContains())
44 && AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
45 this.lineageType = LineageType.PARENT;
46 } else if (AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains()))
47 && ed.getDirection().toString().equals(ed.getContains())) {
48 this.lineageType = LineageType.CHILD;
49 } else if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getContains()))
50 && AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getDirection()))) {
51 this.lineageType = LineageType.PARENT;
52 } else if (AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains()))
53 && AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
54 this.lineageType = LineageType.PARENT;
56 this.lineageType = LineageType.UNRELATED;
58 this.ruleKey = ed.getFrom() + "|" + ed.getTo();
63 * @return the deleteOtherV
65 public String getDeleteOtherV() {
66 return ed.getDeleteOtherV();
70 * @return the preventDelete
72 public String getPreventDelete() {
73 return ed.getPreventDelete();
76 public String getAlsoDeleteFootnote(String targetNode) {
77 String returnVal = "";
78 if (ed.getDeleteOtherV().equals("IN") && ed.getTo().equals(targetNode)) {
79 logger.debug("Edge: " + this.ruleKey);
81 "IF this " + targetNode + " node is deleted, this FROM node is DELETED also");
84 if (ed.getDeleteOtherV().equals("OUT") && ed.getFrom().equals(targetNode)) {
85 logger.debug("Edge: " + this.ruleKey);
86 logger.debug("IF this " + targetNode + " is deleted, this TO node is DELETED also");
89 if (ed.getDeleteOtherV().equals("OUT") && ed.getTo().equals(targetNode)) {
90 logger.debug("Edge: " + this.ruleKey);
91 logger.debug("IF this FROM node is deleted, this " + targetNode + " is DELETED also");
94 if (ed.getDeleteOtherV().equals("IN") && ed.getFrom().equals(targetNode)) {
95 logger.debug("Edge: " + this.ruleKey);
97 .debug("IF this TO node is deleted, this " + targetNode + " node is DELETED also");
106 public String getTo() {
113 public String getFrom() {
117 public String getRuleKey() {
121 public String getMultiplicity() {
122 return ed.getMultiplicityRule().toString();
125 public AAIDirection getDirection() {
126 return AAIDirection.getValue(ed.getDirection());
129 public String getDescription() {
130 return ed.getDescription();
133 public String getRelationshipDescription(String fromTo, String otherNodeName) {
137 if ("FROM".equals(fromTo)) {
138 if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
139 if (LineageType.PARENT == lineageType) {
140 result = " (PARENT of " + otherNodeName;
141 result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
142 ed.getTo() + ",", this.getMultiplicity());
145 if (LineageType.CHILD == lineageType) {
146 result = " (CHILD of " + otherNodeName;
147 result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
148 ed.getTo() + ",", this.getMultiplicity());
149 } else if (LineageType.PARENT == lineageType) {
150 result = " (PARENT of " + otherNodeName;
151 result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
152 ed.getTo() + ",", this.getMultiplicity());
155 if (result.length() == 0) {
156 result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo() + ",",
157 this.getMultiplicity());
160 if (LineageType.PARENT == lineageType) {
161 result = " (PARENT of " + otherNodeName;
162 result = String.join(" ", result + ",", ed.getFrom(), this.getShortLabel(),
163 ed.getTo() + ",", this.getMultiplicity());
165 if (result.length() == 0) {
166 result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo() + ",",
167 this.getMultiplicity());
171 if (result.length() > 0) {
172 result = result + ")";
175 if (ed.getDescription() != null && ed.getDescription().length() > 0) {
176 result = result + "\n " + ed.getDescription(); // 6 spaces is important for yaml
183 * @return the hasDelTarget
186 public boolean hasDelTarget() {
187 return StringUtils.isNotEmpty(ed.getDeleteOtherV())
188 && (!"NONE".equalsIgnoreCase(ed.getDeleteOtherV()));
194 public LineageType getType() {
202 public String getLabel() {
203 return ed.getLabel();
206 public String getShortLabel() {
207 String[] pieces = this.getLabel().split("[.]");
208 return pieces[pieces.length - 1];