fix dmaap-listener startup and library
[sdnc/northbound.git] / ueb-listener / src / main / java / org / openecomp / sdnc / uebclient / SdncServiceModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                                      reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdnc.uebclient;
23
24 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
25 import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
26 import org.openecomp.sdc.toscaparser.api.Metadata;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class SdncServiceModel extends SdncBaseModel {
31         
32         private static final Logger LOG = LoggerFactory
33                         .getLogger(SdncServiceModel.class);
34         
35         private String UUID = null;
36         private String serviceInstanceNamePrefix = null;
37         private String filename = null;
38         
39         public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) {
40                 
41                 super(sdcCsarHelper, metadata);
42         
43                 UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID);
44                 
45                 // extract service topology template input data 
46                 addParameter("ecomp_naming",extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));
47                 addParameter("naming_policy",extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY));
48         }
49
50         public String getServiceUUID() {
51                 return ("\"" + UUID + "\"");
52         }
53         public void setServiceUUID(String serviceUUID) {
54                 this.UUID = serviceUUID;
55         }
56         public String getServiceInstanceNamePrefix() {
57                 return serviceInstanceNamePrefix;
58         }
59         public void setServiceInstanceNamePrefix(String serviceInstanceNamePrefix) {
60                 if (serviceInstanceNamePrefix != null && !serviceInstanceNamePrefix.isEmpty()) {
61                         this.serviceInstanceNamePrefix = serviceInstanceNamePrefix;
62                         params.put("service_instance_name_prefix", "\"" + serviceInstanceNamePrefix + "\"");
63                 }
64         }
65         public String getFilename() {
66                 return filename;
67         }
68         public void setFilename(String filename) {
69                 this.filename = filename;
70         }
71         
72         public String getSql(String model_yaml) {
73                 
74                 StringBuilder sb = new StringBuilder();
75                 sb.append("INSERT into SERVICE_MODEL (service_uuid, model_yaml, filename, ");
76                 
77                 int paramCount = 0;
78                 for (String paramKey :  params.keySet()) {
79                         paramCount++;
80                     sb.append(paramKey);
81                     if (paramCount < params.size()) sb.append(", ");
82                 }
83                 
84                 sb.append(") values (" + getServiceUUID() + ", \"" + model_yaml + "\", \"" + filename + "\", ");
85
86                 paramCount = 0;
87                 for (String paramKey :  params.keySet()) {
88                         paramCount++;
89                         String paramValue = params.get(paramKey);
90                     sb.append(paramValue);
91                     if (paramCount < params.size()) sb.append(", ");
92                 }
93
94                 sb.append(");");
95                 return sb.toString();
96         }
97         
98 }