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.util.genxsd;
22 import org.apache.commons.lang3.StringUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class EdgeDescription {
27 private static final Logger logger = LoggerFactory.getLogger("EdgeDescription.class");
29 public static enum LineageType {
30 PARENT, CHILD, UNRELATED;
32 private String ruleKey;
35 private LineageType type = LineageType.UNRELATED;
36 private String direction;
37 private String multiplicity;
38 private String preventDelete;
39 private String deleteOtherV;
41 private String description;
43 * @return the deleteOtherV
45 public String getDeleteOtherV() {
49 * @param deleteOtherV the deleteOtherV to set
51 public void setDeleteOtherV(String deleteOtherV) {
52 logger.debug("Edge: "+this.getRuleKey());
53 logger.debug("Truth: "+(("${direction}".equals(deleteOtherV)) ? "true" : "false"));
54 logger.debug("Truth: "+(("!${direction}".equals(deleteOtherV)) ? "true" : "false"));
56 if("${direction}".equals(deleteOtherV) ) {
57 this.deleteOtherV = this.direction;
58 } else if("!${direction}".equals(deleteOtherV) ) {
59 this.deleteOtherV = this.direction.equals("IN") ? "OUT" : ((this.direction.equals("OUT")) ? "IN" : deleteOtherV);
61 this.deleteOtherV = deleteOtherV;
63 logger.debug("DeleteOtherV="+deleteOtherV+"/"+this.direction+"="+this.deleteOtherV);
66 * @return the preventDelete
68 public String getPreventDelete() {
72 * @param preventDelete the preventDelete to set
74 public void setPreventDelete(String preventDelete) {
75 if(this.getTo().equals("flavor") || this.getFrom().equals("flavor") ){
76 logger.debug("Edge: "+this.getRuleKey());
77 logger.debug("Truth: "+(("${direction}".equals(preventDelete)) ? "true" : "false"));
78 logger.debug("Truth: "+(("!${direction}".equals(preventDelete)) ? "true" : "false"));
81 if("${direction}".equals(preventDelete) ) {
82 this.preventDelete = this.direction;
83 } else if("!${direction}".equals(preventDelete) ) {
84 this.preventDelete = this.direction.equals("IN") ? "OUT" : ((this.direction.equals("OUT")) ? "IN" : preventDelete);
86 this.preventDelete = preventDelete;
89 public String getAlsoDeleteFootnote(String targetNode) {
90 String returnVal = "";
91 if(this.deleteOtherV.equals("IN") && this.to.equals(targetNode) ) {
92 logger.debug("Edge: "+this.getRuleKey());
93 logger.debug("IF this "+targetNode+" node is deleted, this FROM node is DELETED also");
96 if(this.deleteOtherV.equals("OUT") && this.from.equals(targetNode) ) {
97 logger.debug("Edge: "+this.getRuleKey());
98 logger.debug("IF this "+targetNode+" is deleted, this TO node is DELETED also");
101 if(this.deleteOtherV.equals("OUT") && this.to.equals(targetNode) ) {
102 logger.debug("Edge: "+this.getRuleKey());
103 logger.debug("IF this FROM node is deleted, this "+targetNode+" is DELETED also");
106 if(this.deleteOtherV.equals("IN") && this.from.equals(targetNode) ) {
107 logger.debug("Edge: "+this.getRuleKey());
108 logger.debug("IF this TO node is deleted, this "+targetNode+" node is DELETED also");
116 public String getTo() {
120 * @param to the to to set
122 public void setTo(String to) {
128 public String getFrom() {
132 * @param from the from to set
134 public void setFrom(String from) {
139 public String getRuleKey() {
142 public String getMultiplicity() {
145 public String getDirection() {
148 public String getDescription() {
149 return this.description;
151 public void setRuleKey(String val) {
154 public void setType(LineageType val) {
157 public void setDirection(String val) {
158 this.direction = val;
160 public void setMultiplicity(String val) {
161 this.multiplicity=val;
164 public void setDescription(String val) {
165 this.description = val;
168 public String getRelationshipDescription(String fromTo, String otherNodeName) {
172 if ("FROM".equals(fromTo)) {
173 if ("OUT".equals(direction)) {
174 if (LineageType.PARENT == type) {
175 result = " (PARENT of "+otherNodeName;
176 result = String.join(" ", result+",", this.from, this.getShortLabel(), this.to);
180 if (LineageType.CHILD == type) {
181 result = " (CHILD of "+otherNodeName;
182 result = String.join(" ", result+",", this.from, this.getShortLabel(), this.to);
184 else if (LineageType.PARENT == type) {
185 result = " (PARENT of "+otherNodeName;
186 result = String.join(" ", result+",", this.from, this.getShortLabel(), this.to);
189 if (result.length() == 0) result = String.join(" ", "(", this.from, this.getShortLabel(), this.to+",", this.getMultiplicity());
191 //if ("TO".equals(fromTo)
192 if ("OUT".equals(direction)) {
193 if (LineageType.PARENT == type) {
194 result = " (CHILD of "+otherNodeName;
195 result = String.join(" ", result+",", this.from, this.getShortLabel(), this.to+",", this.getMultiplicity());
198 if (LineageType.PARENT == type) {
199 result = " (PARENT of "+otherNodeName;
200 result = String.join(" ", result+",", this.from, this.getShortLabel(), this.to+",", this.getMultiplicity());
203 if (result.length() == 0) result = String.join(" ", "(", this.from, this.getShortLabel(), this.to+",", this.getMultiplicity());
206 // if (hasDelTarget()) result = result + ", will delete target node";
208 if (result.length() > 0) result = result + ")";
210 if (description != null && description.length() > 0) result = result + "\n "+ description; // 6 spaces is important for yaml
216 * @return the hasDelTarget
219 public boolean hasDelTarget() {
220 return StringUtils.isNotEmpty(this.deleteOtherV) && (! "NONE".equalsIgnoreCase(this.deleteOtherV));
226 public LineageType getType() {
232 public String getLabel() {
235 public String getShortLabel() {
236 String[] pieces = this.getLabel().split("[.]");
237 return pieces[pieces.length-1];
239 public void setLabel(String string) {