rename package for external use
[so.git] / graph-inventory / aai-client / src / main / java / org / onap / aaiclient / client / graphinventory / entities / DSLNodeBase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.aaiclient.client.graphinventory.entities;
22
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import org.onap.aaiclient.client.aai.entities.QueryStep;
27 import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName;
28
29 public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep {
30
31     protected final String nodeName;
32     protected final List<DSLNodeKey> nodeKeys;
33     protected final StringBuilder query;
34     protected boolean output = false;
35
36     public DSLNodeBase() {
37         this.nodeName = "";
38         this.nodeKeys = new ArrayList<>();
39         this.query = new StringBuilder();
40
41     }
42
43     public DSLNodeBase(GraphInventoryObjectName name) {
44         this.nodeName = name.typeName();
45         this.nodeKeys = new ArrayList<>();
46         this.query = new StringBuilder();
47         query.append(nodeName);
48     }
49
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);
55     }
56
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;
62     }
63
64     public DSLOutputNode output() {
65         this.output = true;
66
67         return new DSLOutputNode(this);
68     }
69
70     public T and(DSLNodeKey... key) {
71         this.nodeKeys.addAll(Arrays.asList(key));
72
73         return (T) this;
74     }
75
76     @Override
77     public String build() {
78         StringBuilder result = new StringBuilder(query);
79         if (output) {
80             result.append("*");
81         }
82         for (DSLNodeKey key : nodeKeys) {
83             result.append(key.build());
84         }
85
86         return result.toString();
87     }
88 }