From 1be1c979332d7665c6fa1da9bc4f97c4259eb0cc Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 4 Sep 2018 14:59:50 +0200 Subject: Fix DAO Fix critical errors reported by Sonar on CldsDAO Issue-ID: CLAMP-198 Change-Id: Ib7b93dabc69f3b8ba1d1037c6a2f952fdcd76a5b Signed-off-by: sebdet --- src/main/java/org/onap/clamp/clds/dao/CldsDao.java | 314 ++++++++------------- 1 file changed, 123 insertions(+), 191 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java index bdb8e4b14..54a5196c1 100644 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@ -29,9 +29,12 @@ import com.att.eelf.configuration.EELFManager; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import javax.sql.DataSource; @@ -47,8 +50,6 @@ import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.CldsToscaModel; -import org.onap.clamp.clds.model.CldsToscaModelDetails; -import org.onap.clamp.clds.model.CldsToscaModelRevision; import org.onap.clamp.clds.model.ValueItem; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; @@ -84,7 +85,7 @@ public class CldsDao { private SimpleJdbcCall procInsertDictionary; private SimpleJdbcCall procInsertDictionaryElement; - + private static final String DATE_FORMAT = "MM-dd-yyyy HH:mm:ss"; /** * Log message when instantiating */ @@ -108,7 +109,8 @@ public class CldsDao { this.procDelAllModelInstances = new SimpleJdbcCall(dataSource).withProcedureName("del_all_model_instances"); this.procDeleteModel = new SimpleJdbcCall(dataSource).withProcedureName("del_model"); this.procInsertToscaModel = new SimpleJdbcCall(dataSource).withProcedureName("set_tosca_model"); - this.procInsertNewToscaModelVersion = new SimpleJdbcCall(dataSource).withProcedureName("set_new_tosca_model_version"); + this.procInsertNewToscaModelVersion = new SimpleJdbcCall(dataSource) + .withProcedureName("set_new_tosca_model_version"); this.procInsertDictionary = new SimpleJdbcCall(dataSource).withProcedureName("set_dictionary"); this.procInsertDictionaryElement = new SimpleJdbcCall(dataSource).withProcedureName("set_dictionary_elements"); } @@ -139,8 +141,7 @@ public class CldsDao { } /** - * Get a model and template information from the database given the model - * name. + * Get a model and template information from the database given the model name. * * @param modelName * @return model @@ -150,14 +151,12 @@ public class CldsDao { model.setName(modelName); SqlParameterSource in = new MapSqlParameterSource().addValue("v_model_name", modelName); Map out = logSqlExecution(procGetModelTemplate, in); - // todo : rationalize populateModelProperties(model, out); Map modelResults = logSqlExecution(procGetModel, in); Object modelResultObject = modelResults.get("#result-set-1"); - if (modelResultObject != null && modelResultObject instanceof ArrayList) { - List modelInstanceRs = (List) modelResultObject; - for (Object currModelInstance : modelInstanceRs) { - if (currModelInstance != null && currModelInstance instanceof HashMap) { + if (modelResultObject instanceof ArrayList) { + for (Object currModelInstance : (List) modelResultObject) { + if (currModelInstance instanceof HashMap) { HashMap modelInstanceMap = (HashMap) currModelInstance; CldsModelInstance modelInstance = new CldsModelInstance(); modelInstance.setModelInstanceId(modelInstanceMap.get("model_instance_id")); @@ -172,8 +171,8 @@ public class CldsDao { } /** - * Update model in the database using parameter values and return updated - * model object. + * Update model in the database using parameter values and return updated model + * object. * * @param model * @param userid @@ -200,8 +199,8 @@ public class CldsDao { } /** - * Inserts new modelInstance in the database using parameter values and - * return updated model object. + * Inserts new modelInstance in the database using parameter values and return + * updated model object. * * @param model * @param modelInstancesList @@ -417,21 +416,20 @@ public class CldsDao { * Method to get deployed/active models with model properties. * * @return list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name - * used in the CLDS application (prefix: ClosedLoop- + unique - * ClosedLoop ID) MODEL_NAME | Model Name in CLDS application - * SERVICE_TYPE_ID | TypeId returned from the DCAE application when - * the ClosedLoop is submitted (DCAEServiceTypeRequest generated in - * DCAE application). DEPLOYMENT_ID | Id generated when the - * ClosedLoop is deployed in DCAE. TEMPLATE_NAME | Template used to - * generate the ClosedLoop model. ACTION_CD | Current state of the - * ClosedLoop in CLDS application. + * used in the CLDS application (prefix: ClosedLoop- + unique ClosedLoop + * ID) MODEL_NAME | Model Name in CLDS application SERVICE_TYPE_ID | + * TypeId returned from the DCAE application when the ClosedLoop is + * submitted (DCAEServiceTypeRequest generated in DCAE application). + * DEPLOYMENT_ID | Id generated when the ClosedLoop is deployed in DCAE. + * TEMPLATE_NAME | Template used to generate the ClosedLoop model. + * ACTION_CD | Current state of the ClosedLoop in CLDS application. */ public List getCLDSMonitoringDetails() { - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); - List cldsMonitoringDetailsList = new ArrayList(); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); + List cldsMonitoringDetailsList = new ArrayList<>(); String modelsSql = "SELECT CONCAT(M.CONTROL_NAME_PREFIX, M.CONTROL_NAME_UUID) AS CLOSELOOP_NAME , M.MODEL_NAME, M.SERVICE_TYPE_ID, M.DEPLOYMENT_ID, T.TEMPLATE_NAME, E.ACTION_CD, E.USER_ID, E.TIMESTAMP " - + "FROM MODEL M, TEMPLATE T, EVENT E " - + "WHERE M.TEMPLATE_ID = T.TEMPLATE_ID AND M.EVENT_ID = E.EVENT_ID " + "ORDER BY ACTION_CD"; + + "FROM MODEL M, TEMPLATE T, EVENT E " + "WHERE M.TEMPLATE_ID = T.TEMPLATE_ID AND M.EVENT_ID = E.EVENT_ID " + + "ORDER BY ACTION_CD"; List> rows = jdbcTemplateObject.queryForList(modelsSql); CldsMonitoringDetails cldsMonitoringDetails = null; for (Map row : rows) { @@ -460,7 +458,6 @@ public class CldsDao { } private void populateModelProperties(CldsModel model, Map out) { - // todo : rationalize model.setControlNamePrefix((String) out.get(V_CONTROL_NAME_PREFIX)); model.setControlNameUuid((String) out.get(V_CONTROL_NAME_UUID)); model.setId((String) (out.get("v_model_id"))); @@ -480,12 +477,11 @@ public class CldsDao { model.setDeploymentId((String) out.get("v_deployment_id")); } - /** * Method to retrieve a tosca models by Policy Type from database. - + * * @param policyType - * @return List of CldsToscaModel + * @return List of CldsToscaModel */ public List getAllToscaModels() { return getToscaModel(null, null); @@ -493,9 +489,9 @@ public class CldsDao { /** * Method to retrieve a tosca models by Policy Type from database. - + * * @param policyType - * @return List of CldsToscaModel + * @return List of CldsToscaModel */ public List getToscaModelByPolicyType(String policyType) { return getToscaModel(null, policyType); @@ -514,95 +510,38 @@ public class CldsDao { // Retrieve the latest tosca model for a policy type or by tosca model name private List getToscaModel(String toscaModelName, String policyType) { - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); List cldsToscaModels = new ArrayList<>(); + MapSqlParameterSource params = new MapSqlParameterSource(); - String toscaModelSql = "SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, tmr.tosca_model_revision_id, tmr.version, tmr.user_id, tmr.createdTimestamp, tmr.lastUpdatedTimestamp " - + ((toscaModelName != null) ? (", tmr.tosca_model_yaml ") : " ") - + "FROM tosca_model tm, tosca_model_revision tmr WHERE tm.tosca_model_id = tmr.tosca_model_id " - + ((toscaModelName != null) ? (" AND tm.tosca_model_name = '" + toscaModelName + "'") : " ") - + ((policyType != null) ? (" AND tm.policy_type = '" + policyType + "'") : " ") - + "AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id=st.tosca_model_id)"; - - List> rows = jdbcTemplateObject.queryForList(toscaModelSql); - - if (rows != null && rows.size() > 0) { - - rows.stream().forEach(row -> { - CldsToscaModel cldsToscaModel = new CldsToscaModel(); - cldsToscaModel.setId((String) row.get("tosca_model_id")); - cldsToscaModel.setPolicyType((String) row.get("policy_type")); - cldsToscaModel.setToscaModelName((String) row.get("tosca_model_name")); - cldsToscaModel.setUserId((String) row.get("user_id")); - cldsToscaModel.setRevisionId((String) row.get("tosca_model_revision_id")); - cldsToscaModel.setVersion(((Double) row.get("version"))); - cldsToscaModel.setCreatedDate(sdf.format(row.get("createdTimestamp"))); - cldsToscaModel.setLastUpdatedDate(sdf.format(row.get("lastUpdatedTimestamp"))); - if (toscaModelName != null) { - cldsToscaModel.setToscaModelYaml((String) row.get("tosca_model_yaml")); - } - cldsToscaModels.add(cldsToscaModel); - }); - + String toscaModelSql = "SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, tmr.tosca_model_revision_id, tmr.version, tmr.user_id, tmr.createdTimestamp, tmr.lastUpdatedTimestamp, tmr.tosca_model_yaml FROM tosca_model tm, tosca_model_revision tmr WHERE tm.tosca_model_id = tmr.tosca_model_id "; + if (toscaModelName != null) { + toscaModelSql += " AND tm.tosca_model_name = :toscaModelName"; + params.addValue("toscaModelName", toscaModelName); } - return cldsToscaModels; - } - - // Retrieve Tosca Models & its revisions by policy Type. - private List getAllToscaModelVersion(String toscaModelName, String policyType, - String version) { - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); - List cldsToscaModelDetailsList = new ArrayList<>(); - String toscaModelSql = "SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, tmr.tosca_model_revision_id, tmr.version, tmr.user_id, tmr.createdTimestamp, tmr.lastUpdatedTimestamp " - + "FROM tosca_model tm, tosca_model_revision tmr " + "WHERE tmr.tosca_model_id = tm.tosca_model_id " - + ((policyType != null) ? (" AND tm.policy_type = '" + policyType + "'") : " ") - + ((toscaModelName != null) ? (" AND tm.tosca_model_name = '" + toscaModelName + "'") : " ") - + ((version != null) ? (" AND tmr.version = '" + version + "'") : ""); - - List> rows = jdbcTemplateObject.queryForList(toscaModelSql); - - if (rows != null && rows.size() > 0) { - // Get list of all available modelIds - List listofModelIds = new ArrayList<>(); - for (Map r : rows) { - if (r != null) { - listofModelIds.add((String) r.get("tosca_model_id")); - } - } - // Filter Distinct elements using streams - listofModelIds = listofModelIds.stream().distinct().collect(Collectors.toList()); - - // TODO change logic using java8 - for (String modelId : listofModelIds) { - CldsToscaModelDetails cldsToscaModelDetails = new CldsToscaModelDetails(); - List revisions = new ArrayList<>(); - for (Map row : rows) { - String id = (String) row.get("tosca_model_id"); - if (modelId.equalsIgnoreCase(id)) { - cldsToscaModelDetails.setId(id); - cldsToscaModelDetails.setPolicyType((String) row.get("policy_type")); - cldsToscaModelDetails.setToscaModelName((String) row.get("tosca_model_name")); - cldsToscaModelDetails.setUserId((String) row.get("user_id")); - - CldsToscaModelRevision modelRevision = new CldsToscaModelRevision(); - modelRevision.setRevisionId((String) row.get("tosca_model_revision_id")); - modelRevision.setVersion(((Double) row.get("version"))); - modelRevision.setUserId((String) row.get("user_id")); - modelRevision.setCreatedDate(sdf.format(row.get("createdTimestamp"))); - modelRevision.setLastUpdatedDate(sdf.format(row.get("lastUpdatedTimestamp"))); - revisions.add(modelRevision); - } - } - cldsToscaModelDetails.setToscaModelRevisions(revisions); - cldsToscaModelDetailsList.add(cldsToscaModelDetails); - } + if (policyType != null) { + toscaModelSql += " AND tm.policy_type = :policyType"; + params.addValue("policyType", policyType); } - return cldsToscaModelDetailsList; + toscaModelSql += " AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id=st.tosca_model_id)"; + + Optional.ofNullable(jdbcTemplateObject.queryForList(toscaModelSql, params)).orElse(Collections.emptyList()).forEach(row -> { + CldsToscaModel cldsToscaModel = new CldsToscaModel(); + cldsToscaModel.setId((String) row.get("tosca_model_id")); + cldsToscaModel.setPolicyType((String) row.get("policy_type")); + cldsToscaModel.setToscaModelName((String) row.get("tosca_model_name")); + cldsToscaModel.setUserId((String) row.get("user_id")); + cldsToscaModel.setRevisionId((String) row.get("tosca_model_revision_id")); + cldsToscaModel.setVersion(((Double) row.get("version"))); + cldsToscaModel.setCreatedDate(sdf.format(row.get("createdTimestamp"))); + cldsToscaModel.setToscaModelYaml((String) row.get("tosca_model_yaml")); + cldsToscaModels.add(cldsToscaModel); + }); + return cldsToscaModels; } - /** - * Method to upload a new version of Tosca Model Yaml in Database + * Method to upload a new version of Tosca Model Yaml in Database * * @param cldsToscaModel * @param userId @@ -619,9 +558,8 @@ public class CldsDao { return cldsToscaModel; } - /** - * Method to upload a new Tosca model Yaml in DB. Default version is 1.0 + * Method to upload a new Tosca model Yaml in DB. Default version is 1.0 * * @param cldsToscaModel * @param userId @@ -654,7 +592,6 @@ public class CldsDao { cldsDictionary.setDictionaryId((String) (out.get("v_dictionary_id"))); } - /** * Method to update Dictionary with new info in Database * @@ -663,14 +600,14 @@ public class CldsDao { * @param userId */ public void updateDictionary(String dictionaryId, CldsDictionary cldsDictionary, String userId) { - - String dictionarySql = "UPDATE dictionary " + "SET dictionary_name = '" + cldsDictionary.getDictionaryName() - + "', modified_by = '" + userId + "'" + "WHERE dictionary_id = '" + dictionaryId + "'"; - jdbcTemplateObject.update(dictionarySql); + String dictionarySql = "UPDATE dictionary SET dictionary_name = :dictionary_name, modified_by = :modified_by WHERE dictionary_id = :dictionary_id"; + SqlParameterSource namedParameters = new MapSqlParameterSource() + .addValue("dictionary_name", cldsDictionary.getDictionaryName()).addValue("modified_by", userId) + .addValue("dictionary_id", dictionaryId); + jdbcTemplateObject.update(dictionarySql, namedParameters); cldsDictionary.setUpdatedBy(userId); } - /** * Method to get list of Dictionaries from the Database * @@ -679,27 +616,25 @@ public class CldsDao { * @return */ public List getDictionary(String dictionaryId, String dictionaryName) { - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); List dictionaries = new ArrayList<>(); - String dictionarySql = "SELECT dictionary_id, dictionary_name, created_by, modified_by, timestamp FROM dictionary" - + ((dictionaryId != null || dictionaryName != null) - ? (" WHERE " + ((dictionaryName != null) ? ("dictionary_name = '" + dictionaryName + "'") : "") - + ((dictionaryId != null && dictionaryName != null) ? (" AND ") : "") - + ((dictionaryId != null) ? ("dictionary_id = '" + dictionaryId + "'") : "")): ""); - - List> rows = jdbcTemplateObject.queryForList(dictionarySql); - - if (rows != null && rows.size() > 0) { - rows.stream().forEach(row -> { - CldsDictionary cldsDictionary = new CldsDictionary(); - cldsDictionary.setDictionaryId((String) row.get("dictionary_id")); - cldsDictionary.setDictionaryName((String) row.get("dictionary_name")); - cldsDictionary.setCreatedBy((String) row.get("created_by")); - cldsDictionary.setUpdatedBy((String) row.get("modified_by")); - cldsDictionary.setLastUpdatedDate(sdf.format(row.get("timestamp"))); - dictionaries.add(cldsDictionary); - }); - } + String dictionarySql = "SELECT dictionary_id, dictionary_name, created_by, modified_by, timestamp FROM dictionary WHERE "; + MapSqlParameterSource namedParameters = new MapSqlParameterSource(); + Optional.ofNullable(dictionaryName).ifPresent(dn -> namedParameters.addValue("dictionary_name", dn)); + Optional.ofNullable(dictionaryId).ifPresent(dn -> namedParameters.addValue("dictionary_id", dn)); + dictionarySql += Optional.ofNullable(namedParameters.getParameterNames()).filter(a -> a.length > 0) + .map(Arrays::stream).map(s -> s.map(param -> param + " = :" + param).collect(Collectors.joining(" AND "))) + .orElse("1"); + + Optional.ofNullable(jdbcTemplateObject.queryForList(dictionarySql, namedParameters)).orElse(Collections.emptyList()).forEach(row -> { + CldsDictionary cldsDictionary = new CldsDictionary(); + cldsDictionary.setDictionaryId((String) row.get("dictionary_id")); + cldsDictionary.setDictionaryName((String) row.get("dictionary_name")); + cldsDictionary.setCreatedBy((String) row.get("created_by")); + cldsDictionary.setUpdatedBy((String) row.get("modified_by")); + cldsDictionary.setLastUpdatedDate(sdf.format(row.get("timestamp"))); + dictionaries.add(cldsDictionary); + }); return dictionaries; } @@ -715,34 +650,37 @@ public class CldsDao { .addValue("v_dict_element_name", cldsDictionaryItem.getDictElementName()) .addValue("v_dict_element_short_name", cldsDictionaryItem.getDictElementShortName()) .addValue("v_dict_element_description", cldsDictionaryItem.getDictElementDesc()) - .addValue("v_dict_element_type", cldsDictionaryItem.getDictElementType()) - .addValue("v_user_id", userId); + .addValue("v_dict_element_type", cldsDictionaryItem.getDictElementType()).addValue("v_user_id", userId); Map out = logSqlExecution(procInsertDictionaryElement, in); cldsDictionaryItem.setDictElementId((String) (out.get("v_dict_element_id"))); } - /** - * Method to update Dictionary Elements with new info for a given dictionary in Database + * Method to update Dictionary Elements with new info for a given dictionary in + * Database * * @param dictionaryElementId * @param cldsDictionaryItem * @param userId */ - public void updateDictionaryElements(String dictionaryElementId, CldsDictionaryItem cldsDictionaryItem, String userId) { - - String dictionarySql = "UPDATE dictionary_elements SET dict_element_name = '" - + cldsDictionaryItem.getDictElementName() + "', dict_element_short_name = '" - + cldsDictionaryItem.getDictElementShortName() + "', dict_element_description= '" - + cldsDictionaryItem.getDictElementDesc() + "', dict_element_type = '" - + cldsDictionaryItem.getDictElementType() + "', modified_by = '" + userId + "' " - + "WHERE dict_element_id = '" + dictionaryElementId + "'"; - jdbcTemplateObject.update(dictionarySql); + public void updateDictionaryElements(String dictionaryElementId, CldsDictionaryItem cldsDictionaryItem, + String userId) { + + String dictionarySql = "UPDATE dictionary_elements SET dict_element_name = :dict_element_name, dict_element_short_name = :dict_element_short_name, dict_element_description = :dict_element_description,dict_element_type=:dict_element_type, modified_by = :modified_by WHERE dict_element_id = :dict_element_id"; + SqlParameterSource namedParameters = new MapSqlParameterSource() + .addValue("dict_element_name", cldsDictionaryItem.getDictElementName()) + .addValue("dict_element_short_name", cldsDictionaryItem.getDictElementShortName()) + .addValue("dict_element_description", cldsDictionaryItem.getDictElementDesc()) + .addValue("dict_element_type", cldsDictionaryItem.getDictElementType()) + .addValue("modified_by", userId) + .addValue("dict_element_id", dictionaryElementId); + jdbcTemplateObject.update(dictionarySql, namedParameters); cldsDictionaryItem.setUpdatedBy(userId); } /** - * Method to get list of all dictionary elements for a given dictionary in the Database + * Method to get list of all dictionary elements for a given dictionary in the + * Database * * @param dictionaryName * @param dictionaryId @@ -751,43 +689,37 @@ public class CldsDao { */ public List getDictionaryElements(String dictionaryName, String dictionaryId, String dictElementShortName) { - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); List dictionaryItems = new ArrayList<>(); + MapSqlParameterSource namedParameters = new MapSqlParameterSource(); String dictionarySql = "SELECT de.dict_element_id, de.dictionary_id, de.dict_element_name, de.dict_element_short_name, de.dict_element_description, de.dict_element_type, de.created_by, de.modified_by, de.timestamp " - + "FROM dictionary_elements de, dictionary d WHERE de.dictionary_id = d.dictionary_id " - + ((dictionaryId != null) ? (" AND d.dictionary_id = '" + dictionaryId + "'") : "") - + ((dictElementShortName != null) ? (" AND de.dict_element_short_name = '" + dictElementShortName + "'"): "") - + ((dictionaryName != null) ? (" AND dictionary_name = '" + dictionaryName + "'") : ""); - - List> rows = jdbcTemplateObject.queryForList(dictionarySql); - - if (rows != null && rows.size() > 0) { - rows.stream().forEach(row -> { - CldsDictionaryItem dictionaryItem = new CldsDictionaryItem(); - dictionaryItem.setDictElementId((String) row.get("dict_element_id")); - dictionaryItem.setDictionaryId((String) row.get("dictionary_id")); - dictionaryItem.setDictElementName((String) row.get("dict_element_name")); - dictionaryItem.setDictElementShortName((String) row.get("dict_element_short_name")); - dictionaryItem.setDictElementDesc((String) row.get("dict_element_description")); - dictionaryItem.setDictElementType((String) row.get("dict_element_type")); - dictionaryItem.setCreatedBy((String) row.get("created_by")); - dictionaryItem.setUpdatedBy((String) row.get("modified_by")); - dictionaryItem.setLastUpdatedDate(sdf.format(row.get("timestamp"))); - dictionaryItems.add(dictionaryItem); - }); + + "FROM dictionary_elements de, dictionary d WHERE de.dictionary_id = d.dictionary_id "; + if (dictionaryId != null) { + dictionarySql+=" AND d.dictionary_id = :dictionaryId"; + namedParameters.addValue("dictionaryId", dictionaryId); + } + if (dictElementShortName!=null) { + dictionarySql+=" AND de.dict_element_short_name = :dictElementShortName"; + namedParameters.addValue("dictElementShortName", dictElementShortName); } + if (dictionaryName!=null) { + dictionarySql+=" AND dictionary_name = :dictionaryName"; + namedParameters.addValue("dictionaryName", dictionaryName); + } + + Optional.ofNullable(jdbcTemplateObject.queryForList(dictionarySql,namedParameters)).orElse(Collections.emptyList()).forEach(row -> { + CldsDictionaryItem dictionaryItem = new CldsDictionaryItem(); + dictionaryItem.setDictElementId((String) row.get("dict_element_id")); + dictionaryItem.setDictionaryId((String) row.get("dictionary_id")); + dictionaryItem.setDictElementName((String) row.get("dict_element_name")); + dictionaryItem.setDictElementShortName((String) row.get("dict_element_short_name")); + dictionaryItem.setDictElementDesc((String) row.get("dict_element_description")); + dictionaryItem.setDictElementType((String) row.get("dict_element_type")); + dictionaryItem.setCreatedBy((String) row.get("created_by")); + dictionaryItem.setUpdatedBy((String) row.get("modified_by")); + dictionaryItem.setLastUpdatedDate(sdf.format(row.get("timestamp"))); + dictionaryItems.add(dictionaryItem); + }); return dictionaryItems; } - - /** - * Method to delete a tosca model from database. - * - * @param toscaModelId - * @param revisionId - */ - /*public void deleteModel(String toscaModelId, String revisionId) { - SqlParameterSource in = new MapSqlParameterSource().addValue("v_tosca_model_id", toscaModelId) - .addValue("v_revision_id", revisionId); - logSqlExecution(procDelToscaModel, in); - }*/ } -- cgit 1.2.3-korg