01844f9c4d1647da7c28d1c2154e44f46e6b9877
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / componentspec / Auxilary.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 package org.onap.blueprintgenerator.models.componentspec;
21
22
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import com.fasterxml.jackson.annotation.JsonIgnore;
28 import com.fasterxml.jackson.annotation.JsonInclude;
29 import com.fasterxml.jackson.annotation.JsonInclude.Include;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31
32 import lombok.AllArgsConstructor;
33 import lombok.Builder;
34 import lombok.Getter; import lombok.Setter;
35 import lombok.NoArgsConstructor;
36
37 // TODO: Auto-generated Javadoc
38 /* (non-Javadoc)
39  * @see java.lang.Object#toString()
40  */
41 @Getter @Setter
42
43 /* (non-Javadoc)
44  * @see java.lang.Object#toString()
45  */
46
47
48 /**
49  * Instantiates a new auxilary.
50  */
51 @NoArgsConstructor
52
53 /**
54  * Instantiates a new auxilary.
55  *
56  * @param healthcheck the healthcheck
57  * @param volumes the volumes
58  * @param policy the policy
59  * @param ports the ports
60  * @param reconfigs the reconfigs
61  * @param databases the databases
62  */
63
64 @JsonInclude(value=Include.NON_NULL)
65 //Called in component Spec Object
66 public class Auxilary {
67         
68         /** The healthcheck. */
69         private HealthCheck healthcheck;
70         /** The volumes. */
71         private Volumes[] volumes;
72
73         /** The policy. */
74         private Policy policy;
75
76         /** The ports. */
77         private ArrayList<Object> ports;
78
79         /** The reconfigs. */
80         private ReconfigsObj reconfigs;
81
82         /** The databases. */
83         @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
84         private TreeMap<String, String> databases;
85
86
87         public TreeMap<String, LinkedHashMap<String, Object>> createPorts(TreeMap<String, LinkedHashMap<String, Object>> inps) {
88                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
89                 LinkedHashMap<String, Object> portType = new LinkedHashMap();
90                 portType.put("type", "string");
91
92                 ArrayList<Object> ports = new ArrayList();
93                 String external = "";
94                 boolean foundPort = false;
95                 for(Object o: this.getPorts()) {
96                         String internal = "";
97                         String p = o.toString();
98                         for(int i = 0; i < p.length(); i++) {
99                                 if(p.charAt(i) == ':') {
100                                         internal = '"' + internal + '"';
101                                         internal = "concat: ['" + internal + "', {get_input: external_port}]"; 
102                                         ports.add(internal);
103                                 }
104                                 if(p.charAt(i) == ':' && !foundPort) {
105                                         external = p.substring(i);
106                                         portType.put("default", external);
107                                         retInputs.put("external_port", portType);
108
109                                 }
110                                 internal = internal + p.charAt(i);
111
112                         }
113                 }
114
115                 this.setPorts(ports);
116                 return retInputs;
117         }
118 }