Fixed the streams and the imports issues
[dcaegen2/platform/cli.git] / blueprint-generator / src / main / java / org / onap / blueprintgenerator / models / dmaapbp / DmaapNode.java
1 /**============LICENSE_START=======================================================
2  org.onap.dcae
3  ================================================================================
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5  ================================================================================
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17  ============LICENSE_END=========================================================
18
19  */
20
21 package org.onap.blueprintgenerator.models.dmaapbp;
22
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import org.onap.blueprintgenerator.models.blueprint.GetInput;
28 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
29 import org.onap.blueprintgenerator.models.blueprint.Node;
30 import org.onap.blueprintgenerator.models.blueprint.Properties;
31 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
32 import org.onap.blueprintgenerator.models.componentspec.Publishes;
33 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
34 import org.onap.blueprintgenerator.models.onapbp.OnapNode;
35
36 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
37 import com.fasterxml.jackson.annotation.JsonInclude;
38 import com.fasterxml.jackson.annotation.JsonInclude.Include;
39
40 import lombok.EqualsAndHashCode;
41 import lombok.Getter;
42 import lombok.NoArgsConstructor;
43 import lombok.Setter;
44
45 @JsonIgnoreProperties(ignoreUnknown = true)
46 @Getter @Setter
47 @EqualsAndHashCode(callSuper=false)
48 @NoArgsConstructor
49 @JsonInclude(value=Include.NON_NULL)
50
51 public class DmaapNode extends Node{
52
53         private TreeMap<String, Interfaces> interfaces;
54         private Properties properties;
55         private ArrayList<LinkedHashMap<String, String>> relationships;
56
57         public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) {
58                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
59
60                 //set the type
61                 this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap");
62
63                 //create the interface
64                 Interfaces inter = new Interfaces();
65                 retInputs = inter.createInterface(retInputs, cs);
66                 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
67                 interfaces.put("cloudify.interfaces.lifecycle", inter);
68                 this.setInterfaces(interfaces);
69
70                 //create and set the relationships
71                 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
72
73                 //go through the streams publishes
74                 int counter = 0;
75                 if(cs.getStreams().getPublishes() != null) {
76                         for(Publishes p: cs.getStreams().getPublishes()) {
77                                 LinkedHashMap<String, String> pubRelations = new LinkedHashMap();
78                                 if(p.getType().equals("message_router") || p.getType().equals("message router")) {
79                                         pubRelations.put("type", "ccsdk.relationships.publish_events");
80                                         pubRelations.put("target", "topic" + counter);
81                                 } else if(p.getType().equals("data_router") || p.getType().equals("data router")) {
82                                         pubRelations.put("type", "ccsdk.relationships.publish_files");
83                                         pubRelations.put("target", "feed" + counter);
84                                 }
85                                 rets.add(pubRelations);
86                                 counter++;
87                         }
88                 }
89                 //go through the stream subscribes
90                 if(cs.getStreams().getSubscribes() != null) {
91                         for(Subscribes s: cs.getStreams().getSubscribes()) {
92                                 LinkedHashMap<String, String> subRelations = new LinkedHashMap();
93                                 if(s.getType().equals("message_router") || s.getType().equals("message router")) {
94                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_events");
95                                         subRelations.put("target", "topic" + counter);
96                                 } else if(s.getType().equals("data_router") || s.getType().equals("data router")) {
97                                         subRelations.put("type", "ccsdk.relationships.subscribe_to_files");
98                                         subRelations.put("target", "feed" + counter);
99                                 }
100                                 rets.add(subRelations);
101                                 counter++;
102                         }
103                 }
104                 
105                 this.setRelationships(rets);
106
107                 //create and set the properties
108                 Properties props = new Properties();
109                 retInputs = props.createDmaapProperties(retInputs, cs, override);
110                 this.setProperties(props);
111
112                 return retInputs;
113         }
114         public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
115                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
116                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
117                 stringType.put("type", "string");
118
119                 //set the type
120                 this.setType("ccsdk.nodes.Feed");
121
122                 //create and set the properties
123                 Properties props = new Properties();
124                 GetInput topicInput = new GetInput();
125                 topicInput.setGet_input(name + "_name");
126                 props.setFeed_name(topicInput);
127                 //props.setUseExisting(true);
128                 retInputs.put(name + "_name", stringType);
129                 this.setProperties(props);
130
131                 return retInputs;
132         }
133
134         public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){
135                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
136                 LinkedHashMap<String, Object> stringType = new LinkedHashMap();
137                 stringType.put("type", "string");
138
139                 //set the type
140                 this.setType("ccsdk.nodes.Topic");
141
142                 //create and set the properties
143                 Properties props = new Properties();
144                 GetInput topicInput = new GetInput();
145                 topicInput.setGet_input(name + "_name");
146                 props.setTopic_name(topicInput);
147                 //props.setUseExisting(true);
148                 retInputs.put(name + "_name", stringType);
149                 this.setProperties(props);
150
151                 return retInputs;
152         }
153 }