2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 - 2019 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.so.client.graphinventory.entities;
 
  23 import java.util.ArrayList;
 
  24 import java.util.Arrays;
 
  25 import java.util.List;
 
  26 import org.onap.so.client.aai.entities.QueryStep;
 
  27 import org.onap.so.client.graphinventory.GraphInventoryObjectName;
 
  29 public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep {
 
  31     protected final String nodeName;
 
  32     protected final List<DSLNodeKey> nodeKeys;
 
  33     protected final StringBuilder query;
 
  34     protected boolean output = false;
 
  36     public DSLNodeBase() {
 
  38         this.nodeKeys = new ArrayList<>();
 
  39         this.query = new StringBuilder();
 
  43     public DSLNodeBase(GraphInventoryObjectName name) {
 
  44         this.nodeName = name.typeName();
 
  45         this.nodeKeys = new ArrayList<>();
 
  46         this.query = new StringBuilder();
 
  47         query.append(nodeName);
 
  50     public DSLNodeBase(GraphInventoryObjectName name, DSLNodeKey... key) {
 
  51         this.nodeName = name.typeName();
 
  52         this.nodeKeys = Arrays.asList(key);
 
  53         this.query = new StringBuilder();
 
  54         query.append(nodeName);
 
  57     public DSLNodeBase(DSLNodeBase<?> copy) {
 
  58         this.nodeName = copy.nodeName;
 
  59         this.nodeKeys = copy.nodeKeys;
 
  60         this.query = new StringBuilder(copy.query);
 
  61         this.output = copy.output;
 
  64     public DSLOutputNode output() {
 
  67         return new DSLOutputNode(this);
 
  70     public T and(DSLNodeKey... key) {
 
  71         this.nodeKeys.addAll(Arrays.asList(key));
 
  77     public String build() {
 
  78         StringBuilder result = new StringBuilder(query);
 
  82         for (DSLNodeKey key : nodeKeys) {
 
  83             result.append(key.build());
 
  86         return result.toString();