RA: Support for using allocated number in the entity id
[ccsdk/sli.git] / northbound / ueb-listener / src / main / java / org / onap / ccsdk / sli / northbound / uebclient / SdncBaseModel.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.onap.ccsdk.sli.northbound.uebclient;
23
24 import java.io.IOException;
25 import java.sql.SQLException;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.LinkedHashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import javax.sql.rowset.CachedRowSet;
33
34 import org.onap.sdc.tosca.parser.api.IEntityDetails;
35 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
36 import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
37 import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
38 import org.onap.sdc.tosca.parser.enums.SdcTypes;
39 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
40 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
41 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
42 import org.onap.sdc.toscaparser.api.Property;
43 import org.onap.sdc.toscaparser.api.elements.Metadata;
44 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 public class SdncBaseModel {
49         
50         private static final Logger LOG = LoggerFactory
51                         .getLogger(SdncBaseModel.class);
52         
53         protected String customizationUUID = null;
54         protected String invariantUUID = null;
55         protected String UUID = null;
56         protected String model_yaml = null;     
57         protected String version = null;        
58         protected String name = null;
59
60         protected String PARAM_INVARIANT_UUID_KEY = "invariant_uuid";
61         protected String PARAM_CUSTOMIZATION_UUID_KEY = "customization_uuid";
62         protected String PARAM_UUID_KEY = "uuid";
63         protected String PARAM_VERSION_KEY = "version";
64         protected String PARAM_NAME_KEY = "name";
65         protected String PARAM_DESCRIPTION_KEY = "description";
66         protected String PARAM_TYPE_KEY = "type";
67         protected String PARAM_CATEGORY_KEY = "category";
68
69         protected Map<String, String> params = null;
70         protected Map<String, String> attributeValueParams = null;
71         protected ISdcCsarHelper sdcCsarHelper = null;
72         protected static DBResourceManager jdbcDataSource = null;
73         protected static SdncUebConfiguration config = null;
74         protected IEntityDetails entityDetails = null;
75
76         
77         public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException {
78                 this (sdcCsarHelper, entityDetails);
79                 this.sdcCsarHelper = sdcCsarHelper;
80                 this.entityDetails = entityDetails;
81                 SdncBaseModel.jdbcDataSource = jdbcDataSource;          
82                 SdncBaseModel.config = config;
83         }
84
85         public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) {
86
87                 params = new HashMap<String, String>();
88                 this.sdcCsarHelper = sdcCsarHelper;
89                 SdncBaseModel.jdbcDataSource = jdbcDataSource;
90
91                 // extract service metadata
92                 invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
93                 addParameter(PARAM_INVARIANT_UUID_KEY,invariantUUID);
94                 addParameter(PARAM_VERSION_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION));
95                 name = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME);
96                 addParameter(PARAM_NAME_KEY,name);
97                 addParameter(PARAM_DESCRIPTION_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
98                 addParameter(PARAM_TYPE_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE));
99                 addParameter(PARAM_CATEGORY_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY));
100         }
101         
102         public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails) {
103
104                 params = new HashMap<String, String>();
105                 attributeValueParams = new HashMap<String, String>();
106                 this.sdcCsarHelper = sdcCsarHelper;
107                 this.entityDetails = entityDetails;
108
109                 // extract common nodeTemplate metadata
110                 Metadata metadata = entityDetails.getMetadata();
111                 customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
112                 invariantUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
113                 addParameter(PARAM_INVARIANT_UUID_KEY, invariantUUID);
114                 UUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID);
115                 addParameter(PARAM_UUID_KEY, UUID);
116                 addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION));
117         }
118
119         
120 /*      This is the generic approach Shoujit attempted for 18.06 but can't be implemented without parser API to 
121  *  get properties with substring match on the name
122  * protected void extractRelevantAttributeData(List<Property> propList, SdncUebConfiguration config) {
123
124                 //List<Property> propList = nodeTemplate.getPropertiesObjects();
125                 for (Property prop : propList) {
126                         String propName = prop.getName();
127                         Object propValue = prop.getValue();
128                         
129                         if (propValue instanceof Map)
130                         
131                         LOG.info("Property: propertyName: " + propName + " propertyValue: " + propValue.toString());
132                         
133                         // Compare this property name with each config.relevant-attribute-name
134                         List<String> attributeNames =  config.getRelevantAttributeNames();
135                         for (String attributeName : attributeNames) {
136                                 if (prop.getName().contains(attributeName))
137                                 addParameter(prop.getName(), prop.getValue().toString(), attributeValueParams);
138                         }                       
139
140                 }
141
142         }*/
143         
144         protected void insertRelevantAttributeData() throws IOException{
145                 
146                 insertRelevantAttributeData("");
147         }
148
149         protected void insertRelevantAttributeData(String type) throws IOException{
150                 
151                 // type can be passed as "group" or taken from the nodeTemplate
152                 String metadataType = "";
153                 if (!type.isEmpty()) metadataType = type;
154                 else {
155                         Metadata metadata = entityDetails.getMetadata();
156                         metadataType = extractValue (metadata, PARAM_TYPE_KEY);
157                 }
158                 
159                 // Clean up all attributes for this resource
160                 try {
161                         cleanUpExistingToscaData("ATTRIBUTE_VALUE_PAIR", "resource_uuid", getUUID(), "resource_type", "\"" + metadataType + "\"");
162                 } catch (IOException e) {
163                         LOG.error("Could not cleanup Tosca CSAR data from the ATTRIBUTE_VALUE_PAIR table");
164                         throw new IOException (e);
165                 }
166                 
167                 for (String paramName : attributeValueParams.keySet()) {
168                         String paramValue = attributeValueParams.get(paramName);
169                         
170                         Map<String, String> attributeParams = new HashMap<String, String>();
171                         addParameter("attribute_name", paramName, attributeParams);
172                         addParameter("attribute_value", paramValue, attributeParams);                   
173                         addParameter("resource_type", metadataType, attributeParams);
174                         addParameter("resource_customization_uuid", getCustomizationUUID(), attributeParams);
175         
176                         LOG.info("Call insertToscaData for ATTRIBUTE_VALUE_PAIR where resource_uuid = " + getUUID() + " and attribute_name = \"" + paramName + "\"");
177                         try {
178                                 insertToscaData(buildSql("ATTRIBUTE_VALUE_PAIR", "resource_uuid", getUUID(), model_yaml, attributeParams), null);
179                         } catch (IOException e) {
180                                 LOG.error("Could not insert Tosca CSAR data into the ATTRIBUTE_VALUE_PAIR table");
181                                 throw new IOException (e);
182                         }
183                 }               
184         }
185         
186         protected void insertEntityGroupData (IEntityDetails entityDetails, IEntityDetails targetNode, String groupType) throws IOException {
187                 
188                 // Get the Groups on a node - Convert to use getEntity in 19.08
189                 EntityQuery entityQuery = EntityQuery.newBuilder(groupType).build();
190                 String customizationUuid = getCustomizationUUIDNoQuotes();
191                 SdcTypes entitySdcType = SdcTypes.valueOf(extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE));
192                 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(entitySdcType)
193                                 .customizationUUID(customizationUuid).build();
194                 List<IEntityDetails> groupList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
195                 if (groupList == null) {
196                         return;
197                 }
198
199                 for (IEntityDetails group : groupList){
200                         
201                         // Insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR and RESOURCE_GROUP_TO_TARGET_NODE_MAPPING
202                         // RESOURCE_GROUP (group metadata): resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version
203                         // ATTRIBUTE_VALUE_PAIR (group properties): group_type, group_role, group_function
204                         // RESOURCE_GROUP_TO_TARGET_NODE_MAPPING: group_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name
205
206                         SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, entityDetails, config, jdbcDataSource);   
207                         String resourceUuid = getUUID();
208                         groupModel.insertGroupData(resourceUuid);
209                         
210                         // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING
211                         try {
212                                 Map<String, String> mappingCleanupParams = new HashMap<String, String>();
213                                 addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); 
214                                 addParameter("parent_uuid", extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams);
215                                 addParameter("target_node_uuid", extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams);
216                                 cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams);
217                                 
218                                 Map<String, String> mappingParams = new HashMap<String, String>();
219                                 addParameter("parent_uuid", extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams);
220                                 addParameter("target_node_uuid", extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams);
221                                 String targetType = extractValue(targetNode.getMetadata(), PARAM_TYPE_KEY);
222                                 addParameter("target_type", targetType, mappingParams);
223                                 String tableName = "";
224                                 switch (targetType) {
225                                 case "CVFC":
226                                         tableName = "VFC_MODEL";
227                                         break;
228                                 case "VL":
229                                         tableName = "NETWORK_MODEL";
230                                         break;
231                                 }                                       
232                                 addParameter("table_name", tableName, mappingParams);  
233                                 LOG.info("Call insertToscaData for RESOURCE_GROUP_TO_TARGET_NODE_MAPPING where group_uuid = " + groupModel.getUUID());
234                                 insertToscaData(buildSql("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", "group_uuid", groupModel.getUUID(), model_yaml, mappingParams), null);
235
236                         } catch (IOException e) {
237                                 LOG.error("Could not insert Tosca CSAR data into the RESOURCE_GROUP_TO_TARGET_NODE_MAPPING");
238                                 throw new IOException (e);
239                         }                       
240                 }               
241         }
242         
243         protected void insertEntityPolicyData (String nodeTemplateCustomizationUuid, String nodeTemplateUuid, SdcTypes queryType, String targetCustomizationUuid, String targetUuid, String targetType, String policyType) throws IOException {
244                 
245                 EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build();
246             TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(nodeTemplateCustomizationUuid).build();
247             List<IEntityDetails> policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false);
248                 if (policyEntities == null || policyEntities.isEmpty()) {
249                         LOG.debug("insertPolicyData: Could not find policy data for: " + nodeTemplateCustomizationUuid);
250                         return;
251                 }
252                 
253                 String resourceUuid = getUUID();
254
255                 for (IEntityDetails policyEntity : policyEntities) {
256                         
257                         // extract policy metadata
258                         String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
259                         String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
260
261                         insertResourcePolicyData(policyEntity, resourceUuid);
262                         insertResourcePolicyToTargetNodeMappingData(policyUuid, nodeTemplateUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType);    
263                 }
264         }
265         
266         public void insertEntityPolicyData (String resourceCustomizationUuid, String resourceUuid, String parentUuid, String policyType, SdcTypes queryType) throws IOException {
267                 
268                 EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build();
269                 TopologyTemplateQuery topologyTemplateQuery;
270                 if (queryType == SdcTypes.VF) {
271                         topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(resourceCustomizationUuid).build();
272                 } else {
273                         topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).build();
274                 }
275                 
276                 List<IEntityDetails> policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false);
277                 if (policyEntities == null || policyEntities.isEmpty()) {
278                         LOG.debug("insertPolicyData: Could not find policy data for Service/VF: " + resourceUuid);
279                         return;
280                 }               
281         
282                 for (IEntityDetails policyEntity : policyEntities) {
283                         
284                         // extract policy metadata
285                         String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
286                         String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
287
288                         insertResourcePolicyData(policyEntity, resourceUuid);
289                         List<IEntityDetails> targetEntities = policyEntity.getTargetEntities();
290                         if (targetEntities == null || targetEntities.isEmpty()) {
291                                 LOG.debug("insertPolicyData: Could not find targetEntites for policy: " + policyUuid);
292                                 continue;
293                         }               
294                         
295                         for (IEntityDetails targetEntity : targetEntities) {
296                 
297                                 String targetUuid = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
298                                 String targetCustomizationUuid = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
299                                 String targetType = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE);
300                                 insertResourcePolicyToTargetNodeMappingData(policyUuid, parentUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType);
301                         }
302                 }
303         }
304         
305         protected void insertResourcePolicyData (IEntityDetails policyEntity, String resourceUuid) throws IOException { 
306                 
307                 // extract policy metadata
308                 String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
309                 String policyInvariantUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
310                 String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
311                 
312                 // cleanup existing RESOURCE_POLICY data
313                 Map<String, String> cleanupParams = new HashMap<String, String>();
314                 addParameter("resource_uuid", resourceUuid, cleanupParams); 
315                 addParameter("policy_uuid", policyUuid, cleanupParams);
316                 addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
317                 
318                 // insert into RESOURCE_POLICY
319                 Map<String, String> policyParams = new HashMap<String, String>();
320                 addParameter("policy_uuid", policyUuid, policyParams);
321                 addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams);
322                 addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams);
323                 addParameter("policy_name", extractValue(policyEntity.getMetadata(), PARAM_NAME_KEY), policyParams);
324                 addParameter(PARAM_VERSION_KEY, extractValue(policyEntity.getMetadata(), PARAM_VERSION_KEY), policyParams);
325                 addParameter("policy_type", policyEntity.getToscaType(), policyParams);
326                 
327                 // extract properties
328                 addParameter("property_type", extractValue(policyEntity, PARAM_TYPE_KEY), policyParams);
329                 addParameter("property_source", extractValue(policyEntity, "source"), policyParams);
330                 addParameter("property_name", extractValue(policyEntity, PARAM_NAME_KEY), policyParams);
331
332                 // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
333                 // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type, 
334                 // property_type, property_source, property_name
335                 
336                 try {
337                         
338                         // insert into RESOURCE_POLICY
339                         cleanupExistingToscaData("RESOURCE_POLICY", cleanupParams);
340                         LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid + " and policy_uuid = " + "\"" + policyUuid + "\"" );
341                         insertToscaData(buildSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, model_yaml, policyParams), null);
342
343                 } catch (IOException e) {
344                         LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table");
345                         throw new IOException (e);
346                 }
347         
348         }
349         
350         protected void insertResourcePolicyToTargetNodeMappingData(String policyUuid, String parentUuid, String targetUuid, String targetCustomizationUuid, String policyCustomizationUuid, String targetType) throws IOException {
351                 
352                 // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name
353                 try {
354                         Map<String, String> mappingCleanupParams = new HashMap<String, String>();
355                         addParameter("policy_uuid", policyUuid, mappingCleanupParams); 
356                         addParameter("parent_uuid", parentUuid, mappingCleanupParams);
357                         addParameter("target_node_uuid", targetUuid, mappingCleanupParams);
358                         cleanupExistingToscaData("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams);
359                         
360                         Map<String, String> mappingParams = new HashMap<String, String>();
361                         addParameter("parent_uuid", parentUuid, mappingParams);
362                         addParameter("target_node_uuid", targetUuid, mappingParams);
363                         addParameter("target_node_customization_uuid", targetCustomizationUuid, mappingParams);
364                         addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams);
365                         addParameter("target_type", targetType, mappingParams);
366                         LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + "\"" + policyUuid + "\" and parent_uuid = " + "\"" + parentUuid + "\" and target_node_uuid = " + "\"" + targetUuid + "\"");
367                         insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null);
368
369                 } catch (IOException e) {
370                         LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING");
371                         throw new IOException (e);
372                 }                       
373         }
374
375                 
376         protected void insertNodeCapabilitiesData (CapabilityAssignments capabilities) throws IOException {             
377                 
378                 // Process the capabilities on the node template
379                 
380                 List<CapabilityAssignment> capabilityList = capabilities.getAll();
381                 
382                 for (CapabilityAssignment capability : capabilities.getAll()) {
383                                                         
384                         // Insert into NODE_CAPABILITY: 
385                         // capability_id (generated) 
386                         // capability_provider_uuid - UUID of this node 
387                         // capability_provider_customization_uuid - customization UUID of this node
388                         // capability_name - capability.getName()
389                         // capability_type - ?
390
391                         // Check capability name against relevant capabilities
392                         boolean capabilityIsRelevant = false;
393                         /*List<String> relevantCapabilities = config.getRelevantCapabilityNames();
394                         for (String relevantCapabilityName : relevantCapabilities ) {
395                                 
396                                 if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) {
397                                         capabilityIsRelevant = true;
398                                 }
399                         }*/
400                         
401                         if (capabilityIsRelevant == false){
402                                 continue;
403                         }
404                         
405                         String capabilityProviderUuid = getUUID(); 
406
407                         Map<String, String> cleanupParams = new HashMap<String, String>();
408                         addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams);  // node customization UUID
409                         addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams);  // node customization UUID
410                         addParameter("capability_name", capability.getName(), cleanupParams);
411
412                         Map<String, String> nodeCapabilityParams = new HashMap<String, String>();
413                         addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams);  // node customization UUID
414                         addParameter("capability_name", capability.getName(), nodeCapabilityParams);
415                         addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams);
416                         
417                         // Insert NODE_CAPABILITY data for each capability
418                         String capabilityId = "";
419                         try {
420
421                                 cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id
422                                 LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = \"" + capability.getName() + "\"");
423                                 insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null);
424                                 
425                                 // Get capabilityId for capability just inserted
426                                 CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams);
427                                 rowData.first();
428                                 int capabilityIdint = rowData.getInt("capability_id");
429                                 capabilityId = String.valueOf(capabilityIdint);
430                                 
431                         } catch (IOException | SQLException e) {
432                                 LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table");
433                                 throw new IOException (e);
434                         }
435
436                         insertNodeCapabilityPropertyData (capability, capabilityId);
437                 }
438         }
439         
440         protected void insertNodeCapabilitiesEntityData (List<CapabilityAssignment> capabilities) throws IOException {          
441                 
442                 // Process the capabilities             
443                 for (CapabilityAssignment capability :  capabilities) {
444                         
445                         // Insert into NODE_CAPABILITY: 
446                         // capability_id (generated) 
447                         // capability_provider_uuid - UUID of this node 
448                         // capability_provider_customization_uuid - customization UUID of this node
449                         // capability_name - capability.getName()
450                         // capability_type - ?
451
452                         // Check capability name against relevant capabilities
453                         boolean capabilityIsRelevant = false;
454                         /*List<String> relevantCapabilities = config.getRelevantCapabilityNames();
455                         for (String relevantCapabilityName : relevantCapabilities ) {
456                                 
457                                 if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) {
458                                         capabilityIsRelevant = true;
459                                 }
460                         }*/
461                         
462                         if (capabilityIsRelevant == false){
463                                 continue;
464                         }
465                         
466                         String capabilityProviderUuid = getUUID(); 
467
468                         Map<String, String> cleanupParams = new HashMap<String, String>();
469                         addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams);  // node customization UUID
470                         addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams);  // node customization UUID
471                         addParameter("capability_name", capability.getName(), cleanupParams);
472
473                         Map<String, String> nodeCapabilityParams = new HashMap<String, String>();
474                         addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams);  // node customization UUID
475                         addParameter("capability_name", capability.getName(), nodeCapabilityParams);
476                         addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams);
477                         
478                         // Insert NODE_CAPABILITY data for each capability
479                         String capabilityId = "";
480                         try {
481
482                                 cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id
483                                 LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = \"" + capability.getName()+ "\"");
484                                 insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null);
485                                 
486                                 // Get capabilityId for capability just inserted
487                                 CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams);
488                                 rowData.first();
489                                 int capabilityIdint = rowData.getInt("capability_id");
490                                 capabilityId = String.valueOf(capabilityIdint);
491                                 
492                         } catch (IOException | SQLException e) {
493                                 LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table");
494                                 throw new IOException (e);
495                         }
496
497                         insertNodeCapabilityPropertyData (capability, capabilityId);
498                 }
499         }
500         
501         protected void insertNodeCapabilityPropertyData(CapabilityAssignment capability, String capabilityId) throws IOException {
502                 
503                 // Insert property name / value into NODE_CAPABILITY_PROPERTY
504                 LinkedHashMap<String, Property> propertiesMap = capability.getProperties();
505                 Map<String, String> nodeCapabilityPropertyParams = new HashMap<String, String>();
506                 
507                 for (String propertyMapKey : propertiesMap.keySet() ) {
508                         //LOG.info("property map key = " + propertyMapKey);                             
509                         Property property = propertiesMap.get(propertyMapKey);
510                         
511                         addParameter ("capability_property_name", property.getName(), nodeCapabilityPropertyParams);
512                         addParameter ("capability_property_type", property.getValue().toString(), nodeCapabilityPropertyParams);
513                         
514                         try {
515                                 // Data from NODE_CAPABILITY_PROPERTY is cleaned up via cascade delete on NODE_CAPABILITY  
516                                 LOG.info("Call insertToscaData for NODE_CAPABILITY_PROPERTY where capability_id = \"" + capabilityId + "\" and capability_property_name = \"" + property.getName() + "\" and capability_property_type =  \"" + property.getValue().toString() + "\"");
517                                 insertToscaData(buildSql("NODE_CAPABILITY_PROPERTY", "capability_id", capabilityId, model_yaml, nodeCapabilityPropertyParams), null);
518                         } catch (IOException e) {
519                                 LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY_PROPERTY table");
520                                 throw new IOException (e);
521                         }
522                 }
523
524         }
525
526         protected void addParameter (String name, String value) {
527                 if (value != null && !value.isEmpty()) {
528                         // check if value already contain quotes
529                         if (value.startsWith("\"", 0) && value.endsWith("\"")) {
530                                 params.put(name, value);
531                         } else {
532                                 params.put(name, "\"" + value + "\"");
533                         }
534                 }
535         }
536
537         protected void addIntParameter (String name, String value) {
538                 if (value != null && !value.isEmpty()) {
539                         params.put(name, value);
540                 }
541         }
542
543         public static void addParameter (String name, String value, Map<String, String> params) {
544                 if (value != null && !value.isEmpty()) {
545                         // remove any quotes within the string
546                         String strippedValue = value.replace("\"","");
547
548                         // check if value already contain quotes
549                         if (strippedValue.startsWith("\"", 0) && value.endsWith("\"")) {
550                                 params.put(name, strippedValue);
551                         } else {
552                                 params.put(name, "\"" + strippedValue + "\"");
553                         }
554                 }
555         }
556
557         protected String extractValue (Metadata metadata, String name) {
558                 String value = metadata.getValue(name);
559                 if (value != null) {
560                         return value;
561                 } else {
562                         return "";
563                 }       
564         }
565
566         protected String extractBooleanValue (Metadata metadata, String name) {
567                 String value = metadata.getValue(name);
568                 if (value != null && !value.isEmpty()) {
569                         return value.contains("true") ? "Y" : "N";
570                 } else {
571                         return "";
572                 }
573         }
574
575         public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) {
576                 String value = metadata.getValue(name);
577                 if (value != null) {
578                         return value;
579                 } else {
580                         return "";
581                 }
582         }
583
584         protected String extractValue (IEntityDetails  entityDetails, String name) {
585                 String value = ""; 
586                 if (entityDetails.getProperties().containsKey(name)) {
587                         Property property = entityDetails.getProperties().get(name);
588                         if (property != null && property.getValue() != null) {
589                                 value = property.getValue().toString();
590                         }
591                 }
592                 
593                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
594                         return value;
595                 } else {
596                         return "";
597                 }
598         }
599
600         protected String extractValue (IEntityDetails  entityDetails, String path, String name) {
601                 String value = ""; 
602                 
603                 if (entityDetails.getProperties().containsKey(path)) {
604                         Property property = entityDetails.getProperties().get(path);
605                         if (property != null && !property.getLeafPropertyValue(name).isEmpty()) {
606                                 value = property.getLeafPropertyValue(name).get(0);
607                         }
608                 }                       
609
610                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
611                         return value;
612                 } else {
613                         return "";
614                 }
615         }
616
617         protected String extractValue (IEntityDetails  entityDetails, String path1, String path2, String name) {
618                 String value = ""; 
619                 
620                 value = extractNestedValue (entityDetails, path1, path2, name);         
621
622                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
623                         return value;
624                 } else {
625                         return "";
626                 }
627         }
628         
629         protected String extractValue (IEntityDetails  entityDetails, String path1, String path2, String path3, String name) {
630                 String value = ""; 
631                 
632                 value = extractNestedValue (entityDetails, path1, path2, path3, name);          
633
634                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
635                         return value;
636                 } else {
637                         return "";
638                 }
639         }
640         
641         protected String extractBooleanValue (IEntityDetails  entityDetails, String path1, String path2, String name) {
642                 String value = ""; 
643                 
644                 value = extractNestedValue (entityDetails, path1, path2, name);                         
645                 
646                 if (value != null && !value.isEmpty()) {
647                         return value.contains("true") ? "Y" : "N";
648                 } else {
649                         return "";
650                 }
651         }
652         
653         protected String extractNestedValue (IEntityDetails  entityDetails, String path1, String path2, String name) {
654                 String value = ""; 
655                 
656                 if (entityDetails.getProperties().containsKey(path1)) {
657                         Property path1Property = entityDetails.getProperties().get(path1);
658                         if (path1Property != null) {
659                                 Map<String, Object> path1PropertyValue = (Map<String, Object>) path1Property.getValue();
660                                 if (path1PropertyValue.containsKey(path2)) {
661                                         Map<String, Object> path2PropertyValue = (Map<String, Object>) path1PropertyValue.get(path2);
662                                         if (path2PropertyValue != null && path2PropertyValue.containsKey(name)) {
663                                                 value = path2PropertyValue.get(name).toString();
664                                         }
665                                 }
666                         }
667                 }                       
668
669                 return value;
670         }
671
672         protected String extractNestedValue (IEntityDetails  entityDetails, String path1, String path2, String path3, String name) {
673                 String value = ""; 
674                 
675                 if (entityDetails.getProperties().containsKey(path1)) {
676                         Property path1Property = entityDetails.getProperties().get(path1);
677                         if (path1Property != null) {
678                                 Map<String, Object> path1PropertyValue = (Map<String, Object>) path1Property.getValue();
679                                 if (path1PropertyValue.containsKey(path2)) {
680                                         Map<String, Object> path2PropertyValue = (Map<String, Object>) path1PropertyValue.get(path2);
681                                         if (path2PropertyValue != null && path2PropertyValue.containsKey(path3)) {
682                                                 Map<String, Object> path3PropertyValue = (Map<String, Object>) path2PropertyValue.get(path3);
683                                                 if (path3PropertyValue != null && path3PropertyValue.containsKey(name)) {
684                                                         value = path3PropertyValue.get(name).toString();
685                                                 }
686                                         }
687                                 }
688                         }
689                 }                       
690
691                 return value;
692         }
693
694         protected String extractIntegerValue (Property property, String name) {
695                 String value = ""; 
696                 
697                 if (!property.getLeafPropertyValue(name).isEmpty()) {
698                         value = property.getLeafPropertyValue(name).get(0);
699                 }
700                 
701                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
702                         return value;
703                 } else {
704                         return "";
705                 }
706         }
707         
708         protected String extractGetInputValue (IEntityDetails group, IEntityDetails entityDetails, String name) {
709
710                 // Extract the property on entityDetails after getting the property name from the group
711                 String getInputName = extractGetInputName (group, name);
712                 String entityPropertyValue = "";
713                 
714                 if (entityDetails.getProperties().containsKey(getInputName)) {
715                         Property entityProperty = entityDetails.getProperties().get(getInputName);
716                         entityPropertyValue = entityProperty.getValue().toString();
717                 }
718                 
719                 if (!entityPropertyValue.isEmpty()) {
720                         return entityPropertyValue;
721                 } else {
722                         return "";
723                 }
724         }
725
726         protected String extractGetInputName (IEntityDetails group, String name) {
727                 
728                 String getInputName = name;
729                 String groupPropertyValue = "";
730                 if (group.getProperties().containsKey(name)) {
731                         Property groupProperty = group.getProperties().get(name);
732                         groupPropertyValue = groupProperty.getValue().toString();
733                 }
734                 if (!groupPropertyValue.isEmpty()) {
735                         int getInputIndex = groupPropertyValue.indexOf("{get_input=");
736                         if (getInputIndex > -1) {
737                                 getInputName = groupPropertyValue.substring(getInputIndex+11, groupPropertyValue.length()-1);
738                         }
739                 }
740                 
741                 return getInputName;
742
743         }
744
745         protected String extractValue (CapabilityAssignment capability, String name) {
746                 String value = "";
747                 
748                 if (capability.getProperties().containsKey(name)) {
749                         Property property = capability.getProperties().get(name);
750                         value = property.getLeafPropertyValue(name).get(0);
751                 }                       
752                 
753                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
754                         return value;
755                 } else {
756                         return "";
757                 }
758         }
759
760         protected String extractValue (CapabilityAssignment  capability, String path, String name) {
761                 String value = ""; 
762                 
763                 if (capability.getProperties().containsKey(path)) {
764                         Property property = capability.getProperties().get(path);
765                         if (property != null && !property.getLeafPropertyValue(name).isEmpty()) {
766                                 value = property.getLeafPropertyValue(name).get(0);
767                         }
768                 }                       
769
770                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
771                         return value;
772                 } else {
773                         return "";
774                 }
775         }
776
777         protected String extractBooleanValue (IEntityDetails entityDetails, String name) {
778                 String value = null; 
779                 if (entityDetails.getProperties().containsKey(name)) {
780                         Property property = entityDetails.getProperties().get(name);
781                         if (property != null && property.getValue() != null) {
782                                 value = property.getValue().toString();
783                         }
784                 }
785                 
786                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
787                         return value.contains("true") ? "Y" : "N";
788                 } else {
789                         return "";
790                 }
791         }
792
793         protected String extractBooleanValue (IEntityDetails entityDetails, String path, String name) {
794                 String value = null; 
795                 if (entityDetails.getProperties().containsKey(path)) {
796                         Property property = entityDetails.getProperties().get(path);
797                         if (property != null) {
798                                 if (property != null && !property.getLeafPropertyValue(name).isEmpty()) {
799                                         value = property.getLeafPropertyValue(name).get(0);
800                                 }       
801                         }
802                 }
803                 
804                 if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) {
805                         return value.contains("true") ? "Y" : "N";
806                 } else {
807                         return "";
808                 }
809         }
810
811         protected Object extractObjectValue (IEntityDetails entityDetails, String name) {
812                 Object value = ""; 
813                 if (entityDetails.getProperties().containsKey(name)) {
814                         Property property = entityDetails.getProperties().get(name);
815                         if (property != null && property.getValue() != null) {
816                                 value = property.getValue();
817                         }
818                 }
819                 
820                 if (value != null) {
821                         return value;
822                 } else {
823                         return "";
824                 }
825         }
826
827         public static String extractSubstitutionMappingTypeName (ISdcCsarHelper sdcCsarHelper) {
828                 String value = sdcCsarHelper.getServiceSubstitutionMappingsTypeName();
829                 if (value != null) {
830                         return value;
831                 } else {
832                         return "";
833                 }
834         }
835
836         protected String getUUID() {
837                 return ("\"" + UUID + "\"");
838         }
839         public String getInvariantUUID() {
840                 return ("\"" + invariantUUID + "\"");
841         }
842         public String getCustomizationUUID() {
843                 return ("\"" + customizationUUID + "\"");
844         }
845         public String getCustomizationUUIDNoQuotes() {
846                 return (customizationUUID);
847         }
848         public void setCustomizationUUID(String customizationUUID) {
849                 this.customizationUUID = customizationUUID;
850         }
851         public String getName() {
852                 return name;
853         }
854         
855         public String buildSql(String tableName, String model_yaml) {
856                 
857                 StringBuilder sb = new StringBuilder();
858                 sb.append("INSERT into " + tableName + " (customization_uuid, model_yaml, ");
859
860                 int paramCount = 0;
861                 for (String paramKey :  params.keySet()) {
862                         paramCount++;
863                     sb.append(paramKey);
864                     if (paramCount < params.size()) sb.append(", ");
865                 }
866
867                 sb.append(") values (" + getCustomizationUUID() + ", \"" + model_yaml + "\", ");
868
869                 paramCount = 0;
870                 for (String paramKey :  params.keySet()) {
871                         paramCount++;
872                         String paramValue = params.get(paramKey);
873                     sb.append(paramValue);
874                     if (paramCount < params.size()) sb.append(", ");
875                 }
876
877                 sb.append(");");
878                 return sb.toString();
879         }
880         
881         public String buildSql(String tableName, String keyName, String keyValue, String model_yaml, Map<String, String> params) {
882                 
883                 StringBuilder sb = new StringBuilder();
884                 sb.append("INSERT into " + tableName + " (" + keyName + ", ");
885                 
886                 int paramCount = 0;
887                 for (String paramKey :  params.keySet()) {
888                         paramCount++;
889                     sb.append(paramKey);
890                     if (paramCount < params.size()) sb.append(", ");
891                 }
892                 
893                 sb.append(") values (" + keyValue + ", ");
894
895                 paramCount = 0;
896                 for (String paramKey :  params.keySet()) {
897                         paramCount++;
898                         String paramValue = params.get(paramKey);
899                     sb.append(paramValue);
900                     if (paramCount < params.size()) sb.append(", ");
901                 }
902
903                 sb.append(");");
904                 return sb.toString();
905         }
906         
907         public static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map<String, String> params) {
908
909                 StringBuilder sb = new StringBuilder();
910                 sb.append("INSERT into " + tableName + " (" + keyName + ", ");
911
912                 int paramCount = 0;
913                 for (String paramKey :  params.keySet()) {
914                         paramCount++;
915                     sb.append(paramKey);
916                     if (paramCount < params.size()) sb.append(", ");
917                 }
918
919                 sb.append(") values (" + keyValue + ", ");
920
921                 paramCount = 0;
922                 for (String paramKey :  params.keySet()) {
923                         paramCount++;
924                         String paramValue = params.get(paramKey);
925                     sb.append(paramValue);
926                     if (paramCount < params.size()) sb.append(", ");
927                 }
928
929                 sb.append(");");
930                 return sb.toString();
931         }
932         
933          protected void insertToscaData(String toscaDataString, ArrayList<String> arguments) throws IOException
934      {
935             LOG.debug("insertToscaData: " + toscaDataString);
936
937              try {
938
939                                 jdbcDataSource.writeData(toscaDataString, arguments, null);
940
941                         } catch (SQLException e) {
942                                 LOG.error("Could not insert Tosca data into the database");
943                                 throw new IOException (e);
944                         }
945
946      }
947          
948         protected void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException
949      {
950
951              try {
952                 int rowCount = 0;
953                 CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, "");
954                 if (data != null) {
955                         while(data.next()) {
956                                 rowCount ++;
957                         }
958                         if (rowCount != 0) {
959                         LOG.debug("cleanUpExistingToscaData from: " + tableName + " for " + keyValue);
960                                 jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null);
961                         }
962                 }
963
964                         } catch (SQLException e) {
965                                 LOG.error("Could not clean up existing " + tableName  + " for " + keyValue, e);
966                         }
967
968      }
969         
970         protected void cleanUpExistingToscaData(String tableName, String key1Name, String key1Value, String key2Name, String key2Value) throws IOException
971     {
972
973             try {
974                 int rowCount = 0;
975                 CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, "");
976                 if (data != null) {
977                         while(data.next()) {
978                                 rowCount ++;
979                         }
980                         if (rowCount != 0) {
981                         LOG.debug("cleanUpExistingToscaData from : " + tableName + " for " + key1Value + " and " + key2Value);
982                                 jdbcDataSource.writeData("DELETE from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, null);
983                         }
984                 }
985
986                         } catch (SQLException e) {
987                                 LOG.error("Could not clean up existing " + tableName  + " for " + key1Value  + " and " + key2Value, e);
988                         }
989
990     }
991         
992         protected boolean cleanupExistingToscaData(String tableName, Map<String, String> keyParams) throws IOException
993     {
994                         return SdncBaseModel.cleanupExistingToscaData(SdncBaseModel.jdbcDataSource, tableName, keyParams);
995     }
996         
997         public static boolean cleanupExistingToscaData(DBResourceManager jdbcDataSource, String tableName, Map<String, String> keyParams) throws IOException
998     {
999                 boolean dataExists = false;
1000                 StringBuilder sb = new StringBuilder();
1001                 sb.append("SELECT * from " + tableName + " where ");
1002                 
1003                 int paramCount = 0;
1004                 for (String paramKey :  keyParams.keySet()) {
1005                         paramCount++;
1006                         String paramValue = keyParams.get(paramKey);
1007                     sb.append(paramKey);
1008                     sb.append(" = ");
1009                     sb.append(paramValue);
1010                     if (paramCount < keyParams.size()) sb.append(" AND ");
1011                 }
1012
1013                 sb.append(";");
1014         
1015         try {
1016         int rowCount = 0;
1017         CachedRowSet data = jdbcDataSource.getData(sb.toString(), null, "");
1018         while(data.next()) {
1019                                 rowCount ++;
1020                                 data.deleteRow();
1021         }
1022         if (rowCount != 0) {
1023                LOG.debug("cleanupExistingToscaData in " + tableName + ": Data FOUND");
1024                String deleteStmt = sb.replace(sb.indexOf("SELECT *"), sb.indexOf("SELECT")+8, "DELETE").toString();
1025                    jdbcDataSource.writeData(deleteStmt, null, null);
1026                dataExists = true;
1027         }
1028
1029                 } catch (SQLException e) {
1030                         LOG.error("Could not get data in " + tableName, e);
1031                 }
1032
1033         return dataExists;
1034     }
1035         
1036         protected boolean checkForExistingToscaData(String tableName, Map<String, String> keyParams) throws IOException
1037     {
1038                         boolean dataExists = false;
1039                         StringBuilder sb = new StringBuilder();
1040                         sb.append("SELECT * from " + tableName + " where ");
1041                         
1042                         int paramCount = 0;
1043                         for (String paramKey :  keyParams.keySet()) {
1044                                 paramCount++;
1045                                 String paramValue = keyParams.get(paramKey);
1046                             sb.append(paramKey);
1047                             sb.append(" = ");
1048                             sb.append(paramValue);
1049                             if (paramCount < keyParams.size()) sb.append(" AND ");
1050                         }
1051
1052                         sb.append(";");
1053                 
1054             try {
1055                 int rowCount = 0;
1056                 CachedRowSet data = jdbcDataSource.getData(sb.toString(), null, "");
1057                 while(data.next()) {
1058                                 rowCount ++;
1059                 }
1060                 if (rowCount != 0) {
1061                    LOG.debug("checkForExistingToscaData in " + tableName + ": Data FOUND");
1062                    dataExists = true;
1063                 }
1064
1065                         } catch (SQLException e) {
1066                                 LOG.error("Could not get data in " + tableName, e);
1067                         }
1068
1069             return dataExists;
1070     }
1071         
1072         protected CachedRowSet getToscaData(String tableName, Map<String, String> keyParams) throws IOException
1073     {
1074                         StringBuilder sb = new StringBuilder();
1075                         sb.append("SELECT * from " + tableName + " where ");
1076                         
1077                         int paramCount = 0;
1078                         for (String paramKey :  keyParams.keySet()) {
1079                                 paramCount++;
1080                                 String paramValue = keyParams.get(paramKey);
1081                             sb.append(paramKey);
1082                             sb.append(" = ");
1083                             sb.append(paramValue);
1084                             if (paramCount < keyParams.size()) sb.append(" AND ");
1085                         }
1086
1087                         sb.append(";");
1088                 
1089                         CachedRowSet data = null;
1090             try {
1091                         int rowCount = 0;
1092                         data = jdbcDataSource.getData(sb.toString(), null, "");
1093                         while(data.next()) {
1094                                 rowCount ++;
1095                         }
1096                         if (rowCount == 0) {
1097                         LOG.info("getToscaData in " + tableName + ": Data NOT found");
1098                         }
1099
1100                         } catch (SQLException e) {
1101                                 LOG.error("Could not get data in " + tableName, e);
1102                         }
1103
1104             return data;
1105     }
1106         
1107         protected void addParamsToMap (Map<String, String> fromMap, Map<String, String> toMap) {
1108                 for (String key : fromMap.keySet()) {
1109                     if (!toMap.containsKey(key)) {
1110                         toMap.put(key, fromMap.get(key));
1111                     }
1112                 }
1113         }
1114         
1115         protected String nullCheck (Object extractedObject) {
1116                 String stringValue = "";
1117                 if (extractedObject != null) {
1118                         return extractedObject.toString();
1119                 }
1120                 return stringValue;
1121         }
1122
1123 }