From: Sébastien Determe Date: Tue, 23 Apr 2019 08:24:54 +0000 (+0000) Subject: Merge "Fixed generic Sonar issue in the clamp project" X-Git-Tag: 4.0.0~19 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=f9433d61033f65e9ed1f685d1e0db99b077bb7e1;hp=-c;p=clamp.git Merge "Fixed generic Sonar issue in the clamp project" --- f9433d61033f65e9ed1f685d1e0db99b077bb7e1 diff --combined src/main/java/org/onap/clamp/clds/Application.java index c144a146,9ca505c5..f6dfdc0c --- a/src/main/java/org/onap/clamp/clds/Application.java +++ b/src/main/java/org/onap/clamp/clds/Application.java @@@ -5,6 -5,8 +5,8 @@@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights * reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@@ -54,9 -56,8 +56,8 @@@ import org.springframework.scheduling.a import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.annotation.EnableTransactionManagement; - @SpringBootApplication @ComponentScan(basePackages = { "org.onap.clamp" }) - @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class, + @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class }) @EnableJpaRepositories(basePackages = { "org.onap.clamp" }) @EntityScan(basePackages = { "org.onap.clamp" }) @@@ -135,8 -136,7 +136,8 @@@ public class Application extends Spring private Connector createRedirectConnector(int redirectSecuredPort) { if (redirectSecuredPort <= 0) { eelfLogger.warn( - "HTTP port redirection to HTTPS is disabled because the HTTPS port is 0 (random port) or -1 (Connector disabled)"); + "HTTP port redirection to HTTPS is disabled because the HTTPS port is 0 (random port) or -1" + + " (Connector disabled)"); return null; } Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); diff --combined src/main/java/org/onap/clamp/clds/dao/CldsDao.java index 1cff6bb2,e0d67dbf..44228b22 --- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java +++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java @@@ -199,17 -199,13 +199,13 @@@ public class CldsDao .addValue("v_model_blueprint_text", model.getBlueprintText()) .addValue("v_service_type_id", model.getTypeId()).addValue("v_deployment_id", model.getDeploymentId()) .addValue("v_deployment_status_url", model.getDeploymentStatusUrl()) - .addValue("v_control_name_prefix", model.getControlNamePrefix()) + .addValue(V_CONTROL_NAME_PREFIX, model.getControlNamePrefix()) .addValue(V_CONTROL_NAME_UUID, model.getControlNameUuid()); Map out = logSqlExecution(procSetModel, in); 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"))); - model.getEvent().setId((String) (out.get("v_event_id"))); - model.getEvent().setActionCd((String) out.get("v_action_cd")); - model.getEvent().setActionStateCd((String) out.get("v_action_state_cd")); - model.getEvent().setProcessInstanceId((String) out.get("v_event_process_instance_id")); - model.getEvent().setUserid((String) out.get("v_event_user_id")); + setEventProp(model.getEvent(), out); return model; } @@@ -318,14 -314,9 +314,9 @@@ .addValue("v_user_id", userid).addValue("v_template_bpmn_text", template.getBpmnText()) .addValue("v_template_image_text", template.getImageText()) .addValue("v_template_doc_text", template.getPropText()); - Map out = logSqlExecution(procSetTemplate, in); - template.setId((String) (out.get("v_template_id"))); - template.setBpmnUserid((String) (out.get("v_template_bpmn_user_id"))); - template.setBpmnId((String) (out.get("v_template_bpmn_id"))); - template.setImageId((String) (out.get("v_template_image_id"))); - template.setImageUserid((String) out.get("v_template_image_user_id")); - template.setPropId((String) (out.get("v_template_doc_id"))); - template.setPropUserid((String) out.get("v_template_doc_user_id")); + + // properties to setup the template is return from the logSqlExecution method + setTemplateBaseProp(template, logSqlExecution(procSetTemplate, in)); } /** @@@ -349,20 -340,35 +340,35 @@@ CldsTemplate template = new CldsTemplate(); template.setName(templateName); SqlParameterSource in = new MapSqlParameterSource().addValue("v_template_name", templateName); + Map out = logSqlExecution(procGetTemplate, in); - template.setId((String) (out.get("v_template_id"))); - template.setBpmnUserid((String) (out.get("v_template_bpmn_user_id"))); - template.setBpmnId((String) (out.get("v_template_bpmn_id"))); - template.setBpmnText((String) (out.get("v_template_bpmn_text"))); - template.setImageId((String) (out.get("v_template_image_id"))); - template.setImageUserid((String) out.get("v_template_image_user_id")); - template.setImageText((String) out.get("v_template_image_text")); - template.setPropId((String) (out.get("v_template_doc_id"))); - template.setPropUserid((String) out.get("v_template_doc_user_id")); + setTemplateBaseProp(template, out); + + // additional template setting's template.setPropText((String) out.get("v_template_doc_text")); + template.setBpmnText((String) out.get("v_template_bpmn_text")); + template.setImageText((String) out.get("v_template_image_text")); return template; } + /** + * Helper method to setup the base template properties + * + * @param template + * the template + * @param prop + * collection with the properties + */ + private void setTemplateBaseProp(CldsTemplate template, Map prop) { + template.setId((String) prop.get("v_template_id")); + template.setBpmnUserid((String) prop.get("v_template_bpmn_user_id")); + template.setBpmnId((String) prop.get("v_template_bpmn_id")); + template.setImageId((String) prop.get("v_template_image_id")); + template.setImageUserid((String) prop.get("v_template_image_user_id")); + template.setPropId((String) prop.get("v_template_doc_id")); + template.setPropUserid((String) prop.get("v_template_doc_user_id")); + } + private static Map logSqlExecution(SimpleJdbcCall call, SqlParameterSource source) { try { return call.execute(source); @@@ -452,22 -458,35 +458,35 @@@ private void populateModelProperties(CldsModel model, Map out) { 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"))); - model.setTemplateId((String) (out.get("v_template_id"))); + model.setId((String) out.get("v_model_id")); + model.setTemplateId((String) out.get("v_template_id")); model.setTemplateName((String) (out.get("v_template_name"))); model.setBpmnText((String) out.get("v_template_bpmn_text")); model.setPropText((String) out.get("v_model_prop_text")); model.setImageText((String) out.get("v_template_image_text")); model.setDocText((String) out.get("v_template_doc_text")); model.setBlueprintText((String) out.get("v_model_blueprint_text")); - model.getEvent().setId((String) (out.get("v_event_id"))); - model.getEvent().setActionCd((String) out.get("v_action_cd")); - model.getEvent().setActionStateCd((String) out.get("v_action_state_cd")); - model.getEvent().setProcessInstanceId((String) out.get("v_event_process_instance_id")); - model.getEvent().setUserid((String) out.get("v_event_user_id")); model.setTypeId((String) out.get("v_service_type_id")); model.setDeploymentId((String) out.get("v_deployment_id")); model.setDeploymentStatusUrl((String) out.get("v_deployment_status_url")); + + setEventProp(model.getEvent(), out); + } + + /** + * Helper method to setup the event prop to the CldsEvent class + * + * @param event + * the clds event + * @param prop + * collection with the configuration + */ + private void setEventProp(CldsEvent event, Map prop) { + event.setId((String) prop.get("v_event_id")); + event.setActionCd((String) prop.get("v_action_cd")); + event.setActionStateCd((String) prop.get("v_action_state_cd")); + event.setProcessInstanceId((String) prop.get("v_event_process_instance_id")); + event.setUserid((String) prop.get("v_event_user_id")); } /** @@@ -507,14 -526,14 +526,14 @@@ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); List cldsToscaModels = new ArrayList<>(); - String toscaModelSql = new StringBuilder("SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, " + - "tmr.tosca_model_revision_id, tmr.tosca_model_json, tmr.version, tmr.user_id, tmr.createdTimestamp, " + - "tmr.lastUpdatedTimestamp") - .append(toscaModelName != null ? (", tmr.tosca_model_yaml") : "") + String toscaModelSql = new StringBuilder("SELECT tm.tosca_model_name, tm.tosca_model_id, tm.policy_type, " + + "tmr.tosca_model_revision_id, tmr.tosca_model_json, tmr.version, tmr.user_id, tmr.createdTimestamp," + + "tmr.lastUpdatedTimestamp").append(toscaModelName != null ? (", tmr.tosca_model_yaml") : "") .append(" FROM tosca_model tm, tosca_model_revision tmr WHERE tm.tosca_model_id = tmr.tosca_model_id") .append(toscaModelName != null ? (" AND tm.tosca_model_name = '" + toscaModelName + "'") : "") .append(policyType != null ? (" AND tm.policy_type = '" + policyType + "'") : "") - .append(" AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id=st.tosca_model_id)") + .append(" AND tmr.version = (select max(version) from tosca_model_revision st where tmr.tosca_model_id" + + "=st.tosca_model_id)") .toString(); List> rows = jdbcTemplateObject.queryForList(toscaModelSql); @@@ -555,7 -574,7 +574,7 @@@ .addValue("v_tosca_model_yaml", cldsToscaModel.getToscaModelYaml()) .addValue("v_tosca_model_json", cldsToscaModel.getToscaModelJson()).addValue("v_user_id", userId); Map out = logSqlExecution(procInsertNewToscaModelVersion, in); - cldsToscaModel.setRevisionId((String) (out.get("v_revision_id"))); + cldsToscaModel.setRevisionId((String) out.get("v_revision_id")); return cldsToscaModel; } @@@ -593,7 -612,7 +612,7 @@@ .addValue("v_dictionary_name", cldsDictionary.getDictionaryName()) .addValue("v_user_id", cldsDictionary.getCreatedBy()); Map out = logSqlExecution(procInsertDictionary, in); - cldsDictionary.setDictionaryId((String) (out.get("v_dictionary_id"))); + cldsDictionary.setDictionaryId((String) out.get("v_dictionary_id")); } /** @@@ -633,7 -652,7 +652,7 @@@ String whereFilter = " WHERE "; if (dictionaryName != null) { whereFilter += "dictionary_name = '" + dictionaryName + "'"; - if (dictionaryId != null){ + if (dictionaryId != null) { whereFilter += " AND dictionary_id = '" + dictionaryId + "'"; } } else if (dictionaryId != null) { @@@ -641,8 -660,8 +660,8 @@@ } else { whereFilter = ""; } - String dictionarySql = new StringBuilder("SELECT dictionary_id, dictionary_name, created_by, " + - "modified_by, timestamp FROM dictionary") + String dictionarySql = new StringBuilder("SELECT dictionary_id, dictionary_name, created_by, " + + "modified_by, timestamp FROM dictionary") .append(whereFilter).toString(); List> rows = jdbcTemplateObject.queryForList(dictionarySql); @@@ -677,7 -696,7 +696,7 @@@ .addValue("v_dict_element_description", cldsDictionaryItem.getDictElementDesc()) .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"))); + cldsDictionaryItem.setDictElementId((String) out.get("v_dict_element_id")); } /** diff --combined src/main/java/org/onap/clamp/clds/service/CldsService.java index 2a89b198,71dd5c4f..bf7c502a --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@@ -32,18 -32,15 +32,15 @@@ import com.google.gson.JsonObject import com.google.gson.reflect.TypeToken; import java.io.IOException; import java.lang.reflect.Type; - import java.security.GeneralSecurityException; import java.util.Date; import java.util.List; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.BadRequestException; - import javax.ws.rs.NotAuthorizedException; import javax.xml.transform.TransformerException; import org.apache.camel.Produce; - import org.apache.commons.codec.DecoderException; import org.json.simple.parser.ParseException; import org.onap.clamp.clds.camel.CamelProxy; import org.onap.clamp.clds.client.DcaeDispatcherServices; @@@ -85,7 -82,7 +82,7 @@@ public class CldsService extends Secure * The constant LIST_OF_SDC_SERVICE_INFO_TYPE. */ public static final Type LIST_OF_SDC_SERVICE_INFO_TYPE = new TypeToken>() { - }.getType(); + }.getType(); @Produce(uri = "direct:processSubmit") private CamelProxy camelProxy; /** @@@ -551,7 -548,7 +548,7 @@@ * UUID. If not authorized, then NotAuthorizedException is thrown. * * @param model The clds model - * @return + * @return boolean or throws NotAuthorizedException */ private boolean isAuthorizedForVf(CldsModel model) { String vf = ModelProperties.getVf(model);