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.schemagen.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.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class EdgeDescription {
30 private static final Logger logger = LoggerFactory.getLogger("EdgeDescription.class");
32 public static enum LineageType {
33 PARENT, CHILD, UNRELATED;
35 private String ruleKey;
37 // private String from;
38 private LineageType lineageType = LineageType.UNRELATED;
39 // private String direction;
40 // private String multiplicity;
41 // private String preventDelete;
42 // private String deleteOtherV;
43 // private String label;
44 // private String description;
46 public EdgeDescription(EdgeRule ed) {
48 if ( ed.getDirection().toString().equals(ed.getContains()) &&
49 AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
50 this.lineageType= LineageType.PARENT;
51 } else if ( AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
52 ed.getDirection().toString().equals(ed.getContains())) {
53 this.lineageType= LineageType.CHILD;
54 } else if ( AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getContains())) &&
55 AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getDirection()))) {
56 this.lineageType= LineageType.PARENT;
57 } else if ( AAIDirection.getValue("IN").equals(AAIDirection.getValue(ed.getContains())) &&
58 AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
59 this.lineageType= LineageType.PARENT;
61 this.lineageType= LineageType.UNRELATED;
63 this.ruleKey = ed.getFrom()+"|"+ed.getTo();
67 * @return the deleteOtherV
69 public String getDeleteOtherV() {
70 return ed.getDeleteOtherV();
73 * @return the preventDelete
75 public String getPreventDelete() {
76 return ed.getPreventDelete();
78 public String getAlsoDeleteFootnote(String targetNode) {
79 String returnVal = "";
80 if(ed.getDeleteOtherV().equals("IN") && ed.getTo().equals(targetNode) ) {
81 logger.debug("Edge: "+this.ruleKey);
82 logger.debug("IF this "+targetNode+" node is deleted, this FROM node is DELETED also");
85 if(ed.getDeleteOtherV().equals("OUT") && ed.getFrom().equals(targetNode) ) {
86 logger.debug("Edge: "+this.ruleKey);
87 logger.debug("IF this "+targetNode+" is deleted, this TO node is DELETED also");
90 if(ed.getDeleteOtherV().equals("OUT") && ed.getTo().equals(targetNode) ) {
91 logger.debug("Edge: "+this.ruleKey);
92 logger.debug("IF this FROM node is deleted, this "+targetNode+" is DELETED also");
95 if(ed.getDeleteOtherV().equals("IN") && ed.getFrom().equals(targetNode) ) {
96 logger.debug("Edge: "+this.ruleKey);
97 logger.debug("IF this TO node is deleted, this "+targetNode+" node is DELETED also");
105 public String getTo() {
111 public String getFrom() {
114 public String getRuleKey() {
117 public String getMultiplicity() {
118 return ed.getMultiplicityRule().toString();
120 public AAIDirection getDirection() {
121 return AAIDirection.getValue(ed.getDirection());
123 public String getDescription() {
124 return ed.getDescription();
126 public String getRelationshipDescription(String fromTo, String otherNodeName) {
130 if ("FROM".equals(fromTo)) {
131 if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
132 if (LineageType.PARENT == lineageType) {
133 result = " (PARENT of "+otherNodeName;
134 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
138 if (LineageType.CHILD == lineageType) {
139 result = " (CHILD of "+otherNodeName;
140 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
142 else if (LineageType.PARENT == lineageType) {
143 result = " (PARENT of "+otherNodeName;
144 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
147 if (result.length() == 0) result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
149 //if ("TO".equals(fromTo)
150 if (AAIDirection.getValue("OUT").equals(AAIDirection.getValue(ed.getDirection()))) {
151 if (LineageType.PARENT == lineageType) {
152 result = " (PARENT of "+otherNodeName;
153 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
156 if (LineageType.PARENT == lineageType) {
157 result = " (PARENT of "+otherNodeName;
158 result = String.join(" ", result+",", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
161 if (result.length() == 0) result = String.join(" ", "(", ed.getFrom(), this.getShortLabel(), ed.getTo()+",", this.getMultiplicity());
164 if (result.length() > 0) result = result + ")";
166 if (ed.getDescription() != null && ed.getDescription().length() > 0) result = result + "\n "+ ed.getDescription(); // 6 spaces is important for yaml
172 * @return the hasDelTarget
175 public boolean hasDelTarget() {
176 return StringUtils.isNotEmpty(ed.getDeleteOtherV()) && (! "NONE".equalsIgnoreCase(ed.getDeleteOtherV()));
182 public LineageType getType() {
189 public String getLabel() {
190 return ed.getLabel();
192 public String getShortLabel() {
193 String[] pieces = this.getLabel().split("[.]");
194 return pieces[pieces.length-1];