diff options
author | Christopher Lott (cl778h) <clott@research.att.com> | 2017-09-07 08:52:41 -0400 |
---|---|---|
committer | Christopher Lott (cl778h) <clott@research.att.com> | 2017-09-07 08:54:52 -0400 |
commit | 8cd208ebaa33627daf05d8ffff7b28e53a7067d0 (patch) | |
tree | 0b07ec3c6305c46f34eae69d8fb6fa824aaae256 /ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf | |
parent | b52d4cebc430a083ec1e6881c4f01dfe709ac726 (diff) |
Adjust code for Sonar issues
Made non-functional updates to address static code analysis issues.
Update license header with simple double-quote characters.
Issue: PORTAL-72, PORTAL-90
Change-Id: Ic2c330daea07d721f0e6b350ebf03da97073f7ce
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf')
5 files changed, 74 insertions, 102 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java index 26624359..60888b6d 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -51,17 +51,12 @@ import org.onap.portalsdk.core.menu.MenuBuilder; import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.service.DataAccessServiceImpl; -import org.onap.portalsdk.core.service.LocalAccessCondition; -import org.onap.portalsdk.core.service.RestApiRequestBuilder; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.web.support.AppUtils; import org.onap.portalsdk.core.web.support.UserUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @@ -83,7 +78,9 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppConfig.class); - private final List<String> tileDefinitions = new ArrayList<String>(); + private final List<String> tileDefinitions = new ArrayList<>(); + private String[] excludeUrlPathsForSessionTimeout = {}; + protected ApplicationContext appApplicationContext = null; public AppConfig() { @@ -94,12 +91,13 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, /** * Creates and returns a new instance of a secondary (order=2) - * {@link ViewResolver} that finds files by adding prefix "/WEB-INF/jsp/" - * and suffix ".jsp" to the base view name. + * {@link ViewResolver} that finds files by adding prefix "/WEB-INF/jsp/" and + * suffix ".jsp" to the base view name. * * @return New instance of {@link ViewResolver}. */ @Bean + @Override public ViewResolver viewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setViewClass(JstlView.class); @@ -110,21 +108,20 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, } /** - * Loads all the default logging fields into the global MDC context and - * marks each log file type that logging has been started. + * Loads all the default logging fields into the global MDC context and marks + * each log file type that logging has been started. */ private void initGlobalLocalContext() { logger.init(); } - /* + /** * Any requests from the url pattern /static/**, Spring will look for the - * resources from the /static/ Same as <mvc:resources mapping="/static/**" - * location="/static/"/> in xml + * resources from the /static/ Same as + * <mvc:resources mapping="/static/**" location="/static/"/> in xml */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - // registry.addResourceHandler("/static/**").addResourceLocations("/static/"); registry.addResourceHandler("/**").addResourceLocations("/"); } @@ -134,6 +131,7 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, * @return New instance of {@link DataAccessService}. */ @Bean + @Override public DataAccessService dataAccessService() { return new DataAccessServiceImpl(); } @@ -157,15 +155,14 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, public MenuBuilder menuBuilder() { return new MenuBuilder(); } - + /** * Creates and returns a new instance of a {@link UserUtils} class. * * @return New instance of {@link UserUtils}. */ @Bean - public UserUtils userUtil() - { + public UserUtils userUtil() { return new UserUtils(); } @@ -213,7 +210,7 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, String password = SystemProperties.getProperty(SystemProperties.DB_PASSWORD); if (SystemProperties.containsProperty(SystemProperties.DB_ENCRYPT_FLAG)) { String encryptFlag = SystemProperties.getProperty(SystemProperties.DB_ENCRYPT_FLAG); - if (encryptFlag != null && encryptFlag.equalsIgnoreCase("true")) { + if (encryptFlag != null && "true".equalsIgnoreCase(encryptFlag)) { password = CipherUtil.decrypt(password); } } @@ -227,14 +224,12 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, dataSource.setTestConnectionOnCheckout(getConnectionOnCheckout()); dataSource.setPreferredTestQuery(getPreferredTestQuery()); } catch (Exception e) { + // Show details logger.error(EELFLoggerDelegate.errorLogger, - "Error initializing database, verify database settings in properties file: " - + UserUtils.getStackTrace(e), - AlarmSeverityEnum.CRITICAL); + "Error initializing database, verify database settings in properties file", e); + // Include alarm in log logger.error(EELFLoggerDelegate.debugLogger, - "Error initializing database, verify database settings in properties file: " - + UserUtils.getStackTrace(e), - AlarmSeverityEnum.CRITICAL); + "Error initializing database", AlarmSeverityEnum.CRITICAL); // Raise an alarm that opening a connection to the database failed. logger.logEcompError(AppMessagesEnum.BeDaoSystemError); throw e; @@ -243,9 +238,8 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, } /** - * Gets the value of the property - * {@link SystemProperties#PREFERRED_TEST_QUERY}; defaults to "Select 1" if - * the property is not defined. + * Gets the value of the property {@link SystemProperties#PREFERRED_TEST_QUERY}; + * defaults to "Select 1" if the property is not defined. * * @return String value that is a SQL query */ @@ -266,8 +260,8 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, /** * Gets the value of the property - * {@link SystemProperties#TEST_CONNECTION_ON_CHECKOUT}; defaults to true if - * the property is not defined. + * {@link SystemProperties#TEST_CONNECTION_ON_CHECKOUT}; defaults to true if the + * property is not defined. * * @return Boolean value */ @@ -288,8 +282,8 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, } /* - * TODO: Check whether it is appropriate to extend the list of tile - * definitions at every invocation. + * TODO: Check whether it is appropriate to extend the list of tile definitions + * at every invocation. */ protected String[] tileDefinitions() { tileDefinitions.add("/WEB-INF/fusion/defs/definitions.xml"); @@ -304,8 +298,9 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, * * @return An empty list. */ + @Override public List<String> addTileDefinitions() { - return new ArrayList<String>(); + return new ArrayList<>(); } /** @@ -324,9 +319,8 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, } /** - * Adds new instances of the following interceptors to the specified - * interceptor registry: {@link SessionTimeoutInterceptor}, - * {@link ResourceInterceptor} + * Adds new instances of the following interceptors to the specified interceptor + * registry: {@link SessionTimeoutInterceptor}, {@link ResourceInterceptor} */ @Override public void addInterceptors(InterceptorRegistry registry) { @@ -345,8 +339,6 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, return new ResourceInterceptor(); } - private String[] excludeUrlPathsForSessionTimeout = {}; - /** * Gets the array of Strings that are paths excluded for session timeout. * @@ -374,9 +366,8 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable, * (org.springframework.context.ApplicationContext) */ @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(ApplicationContext applicationContext) { appApplicationContext = applicationContext; - } } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppInitializer.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppInitializer.java index 0865b987..d2690c8d 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppInitializer.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppInitializer.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -46,34 +46,29 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatche public abstract class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppInitializer.class); - - private final String activeProfile = "src"; + + private static final String activeProfile = "src"; @Override protected WebApplicationContext createServletApplicationContext() { WebApplicationContext context = super.createServletApplicationContext(); - try { - ((ConfigurableEnvironment) context.getEnvironment()).setActiveProfiles(activeProfile); } catch (Exception e) { - - logger.error(EELFLoggerDelegate.errorLogger, "Unable to set the active profile" + e.getMessage(),AlarmSeverityEnum.MAJOR); + logger.error(EELFLoggerDelegate.errorLogger, "Unable to set the active profile" + e.getMessage(), + AlarmSeverityEnum.MAJOR); throw e; - } - return context; } @Override protected Class<?>[] getRootConfigClasses() { - return null; + return new Class<?>[0]; } @Override protected Class<?>[] getServletConfigClasses() { - return new Class[] { AppConfig.class }; } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/Configurable.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/Configurable.java index d890e609..647315d5 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/Configurable.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/Configurable.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -44,13 +44,13 @@ import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; public interface Configurable { - - public ViewResolver viewResolver(); - - public void addResourceHandlers(ResourceHandlerRegistry registry) ; - - public DataAccessService dataAccessService(); - - public List<String> addTileDefinitions(); - + + public ViewResolver viewResolver(); + + public void addResourceHandlers(ResourceHandlerRegistry registry); + + public DataAccessService dataAccessService(); + + public List<String> addTileDefinitions(); + } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java index 54512865..4c142a2c 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -48,7 +48,6 @@ import java.util.Properties; import javax.sql.DataSource; import org.hibernate.SessionFactory; -import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; @@ -83,7 +82,8 @@ public class HibernateConfiguration { } /** - * Builds a properties object with Hibernate properties in te system.properties file. + * Builds a properties object with Hibernate properties in te system.properties + * file. * * @return Properties object */ @@ -107,27 +107,18 @@ public class HibernateConfiguration { String sql = "SELECT schema_id,datasource_type,connection_url,user_name,password,driver_class,min_pool_size,max_pool_size,idle_connection_test_period FROM schema_info"; rs = stmt.executeQuery(sql); while (rs.next()) { - ComboPooledDataSource dataSource = new ComboPooledDataSource(); - dataSource.setDriverClass(rs.getString("driver_class")); - dataSource.setJdbcUrl(rs.getString("connection_url")); - dataSource.setUser(rs.getString("user_name")); - dataSource.setPassword(rs.getString("password")); - dataSource.setMinPoolSize(rs.getInt("min_pool_size")); - dataSource.setMaxPoolSize(rs.getInt("max_pool_size")); - dataSource.setIdleConnectionTestPeriod(rs.getInt("idle_connection_test_period")); - dataSourceMap.put(rs.getString("schema_id"), dataSource); + ComboPooledDataSource pool = new ComboPooledDataSource(); + pool.setDriverClass(rs.getString("driver_class")); + pool.setJdbcUrl(rs.getString("connection_url")); + pool.setUser(rs.getString("user_name")); + pool.setPassword(rs.getString("password")); + pool.setMinPoolSize(rs.getInt("min_pool_size")); + pool.setMaxPoolSize(rs.getInt("max_pool_size")); + pool.setIdleConnectionTestPeriod(rs.getInt("idle_connection_test_period")); + dataSourceMap.put(rs.getString("schema_id"), pool); } - rs.close(); - rs = null; - stmt.close(); - stmt = null; - conn.close(); - conn = null; } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, - "Error initializing database, verify database settings in properties file: " + e.getMessage(), - AlarmSeverityEnum.CRITICAL); - e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger, "dataSourceMap failed", e); dataSourceMap = null; throw e; } finally { @@ -139,15 +130,9 @@ public class HibernateConfiguration { if (conn != null) conn.close(); } catch (SQLException se2) { - } - try { - if (conn != null) - conn.close(); - } catch (SQLException se) { - se.printStackTrace(); + logger.warn(EELFLoggerDelegate.errorLogger, "dataSourceMap failed to close", se2); } } - return dataSourceMap; } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateMappingLocatable.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateMappingLocatable.java index 743d4b76..11effb62 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateMappingLocatable.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateMappingLocatable.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -43,19 +43,20 @@ import org.springframework.core.io.Resource; * Defines methods used by developers to supply Hibernate configuration. */ public interface HibernateMappingLocatable { - + /** * Gets Hibernate mapping locations. * - * @return Array of Resource objects (usually ClassPathResource that's a - * file) which contain Hibernate mapping information. + * @return Array of Resource objects (usually ClassPathResource that's a file) + * which contain Hibernate mapping information. */ - public Resource [] getMappingLocations(); + public Resource[] getMappingLocations(); /** * Gets package names. * - * @return Array of Java package names to scan for classes with Hibernate annotations. + * @return Array of Java package names to scan for classes with Hibernate + * annotations. */ - public String [] getPackagesToScan(); + public String[] getPackagesToScan(); } |