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.onap.aai.edges.EdgeRule;
24 import org.onap.aai.edges.enums.AAIDirection;
25 import org.onap.aai.edges.enums.DirectionNotation;
26 import org.onap.aai.edges.enums.EdgeField;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class EdgeDescription {
32 private static final Logger logger = LoggerFactory.getLogger("EdgeDescription.class");
34 public static enum LineageType {
35 PARENT, CHILD, UNRELATED;
37 private String ruleKey;
39 // private String from;
40 private LineageType lineageType = LineageType.UNRELATED;
41 // private String direction;
42 // private String multiplicity;
43 // private String preventDelete;
44 // private String deleteOtherV;
45 // private String label;
46 // private String description;
48 public EdgeDescription(EdgeRule ed) {
50 if ( ed.getDirection().toString().equals(ed.getContains()) &&
51 AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
52 this.lineageType=LineageType.PARENT;
53 } else if ( AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
54 ed.getDirection().toString().equals(ed.getContains())) {
55 this.lineageType=LineageType.CHILD;
56 } else if ( AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getContains())) &&
57 AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getDirection()))) {
58 this.lineageType=LineageType.PARENT;
59 } else if ( AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
60 AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
61 this.lineageType=LineageType.PARENT;
63 this.lineageType=LineageType.UNRELATED;
65 this.ruleKey = ed.getFrom()+"|"+ed.getTo();
69 * @return the deleteOtherV
71 public String getDeleteOtherV() {
72 return ed.getDeleteOtherV();
75 * @return the preventDelete
77 public String getPreventDelete() {
78 return ed.getPreventDelete();
80 public String getAlsoDeleteFootnote(String targetNode) {
81 String returnVal = "";
82 if(ed.getDeleteOtherV().equals("IN") && ed.getTo().equals(targetNode) ) {
83 logger.debug("Edge: "+this.ruleKey);
84 logger.debug("IF this "+targetNode+" node is deleted, this FROM node is DELETED also");
87 if(ed.getDeleteOtherV().equals("OUT") && ed.getFrom().equals(targetNode) ) {
88 logger.debug("Edge: "+this.ruleKey);
89 logger.debug("IF this "+targetNode+" is deleted, this TO node is DELETED also");
92 if(ed.getDeleteOtherV().equals("OUT") && ed.getTo().equals(targetNode) ) {
93 logger.debug("Edge: "+this.ruleKey);
94 logger.debug("IF this FROM node is deleted, this "+targetNode+" is DELETED also");
97 if(ed.getDeleteOtherV().equals("IN") && ed.getFrom().equals(targetNode) ) {
98 logger.debug("Edge: "+this.ruleKey);
99 logger.debug("IF this TO node is deleted, this "+targetNode+" node is DELETED also");
107 public String getTo() {
113 public String getFrom() {
116 public String getRuleKey() {
119 public String getMultiplicity() {
120 return ed.getMultiplicityRule().toString();
122 public AAIDirection getDirection() {
123 return AAIDirection.getValue(ed.getDirection());
125 public String getDescription() {
126 return ed.getDescription();
128 public String getRelationshipDescription(String fromTo, String otherNodeName) {
132 if ("FROM".equals(fromTo)) {
133 if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
134 if (LineageType.PARENT == lineageType) {
135 result = " (PARENT of "+otherNodeName;
136 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
140 if (LineageType.CHILD == lineageType) {
141 result = " (CHILD of "+otherNodeName;
142 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
144 else if (LineageType.PARENT == lineageType) {
145 result = " (PARENT of "+otherNodeName;
146 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
149 if (result.length() == 0) result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
151 //if ("TO".equals(fromTo)
152 if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
153 if (LineageType.PARENT == lineageType) {
154 result = " (PARENT of "+otherNodeName;
155 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
158 if (LineageType.PARENT == lineageType) {
159 result = " (PARENT of "+otherNodeName;
160 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
163 if (result.length() == 0) result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
166 if (result.length() > 0) result = result + ")";
168 if (ed.getDescription() != null && ed.getDescription().length() > 0) result = result + "\n "+ ed.getDescription(); // 6 spaces is important for yaml
174 * @return the hasDelTarget
177 public boolean hasDelTarget() {
178 return StringUtils.isNotEmpty(ed.getDeleteOtherV()) && (! "NONE".equalsIgnoreCase(ed.getDeleteOtherV()));
184 public LineageType getType() {
191 public String getLabel() {
192 return ed.getLabel();
194 public String getShortLabel() {
195 String[] pieces = this.getLabel().split("[.]");
196 return pieces[pieces.length-1];