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/util | |
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/util')
6 files changed, 244 insertions, 266 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/CacheManager.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/CacheManager.java index 774943d4..ba68539d 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/CacheManager.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/CacheManager.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 * @@ -39,23 +39,26 @@ package org.onap.portalsdk.core.util; import org.onap.portalsdk.core.objectcache.jcs.JCSCacheManager; import org.springframework.context.annotation.Configuration; + @Configuration public class CacheManager extends JCSCacheManager { - public CacheManager() { - - } - - /* The following can be customized for your application to cache the appropriate data upon application startup. The provided - example retrieves a list of sample lookup data and puts the list in the Cache Manager. To retrieve that data, simply call the - Cache Manager's getObject(String key) method which will return an Object instance. To put additional data in the Cache Manager - outside of application startup, call the Cache Manager's putObject(String key, Object objectToCache) method. */ - public void loadLookUpCache() { - /* - List<Role> result = (List<Role>)getDataAccessService().getList(Role.class,null); + + public CacheManager() { + super(); + } - if (result != null) { - putObject("lookupRoles", result); - }*/ - } + /* + * The following can be customized for your application to cache the appropriate + * data upon application startup. The provided example retrieves a list of + * sample lookup data and puts the list in the Cache Manager. To retrieve that + * data, simply call the Cache Manager's getObject(String key) method which will + * return an Object instance. To put additional data in the Cache Manager + * outside of application startup, call the Cache Manager's putObject(String + * key, Object objectToCache) method. + */ + @Override + public void loadLookUpCache() { + // Example code removed to silence Sonar. + } } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/EncDecUtilTest.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/EncDecUtilTest.java index 3a13e362..926ed347 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/EncDecUtilTest.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/EncDecUtilTest.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 * @@ -36,12 +36,13 @@ * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.portalsdk.core.util; + +import java.io.UnsupportedEncodingException; import java.security.AlgorithmParameters; +import java.security.GeneralSecurityException; import java.security.SecureRandom; -import javax.crypto.BadPaddingException; import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.IvParameterSpec; @@ -49,82 +50,60 @@ import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; - + public class EncDecUtilTest { - - private static final String password = "test"; - private static final String salt = "r n�HN~��|f��X�" ; - private static int pswdIterations = 65536 ; - private static int keySize = 256; - private byte[] ivBytes; - - public String encrypt(String plainText) throws Exception { - - //get salt - //salt = generateSalt(); - byte[] saltBytes = salt.getBytes("UTF-8"); - - // Derive the key - SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); - PBEKeySpec spec = new PBEKeySpec( - password.toCharArray(), - saltBytes, - pswdIterations, - keySize - ); - - SecretKey secretKey = factory.generateSecret(spec); - SecretKeySpec secret = new SecretKeySpec(secretKey.getEncoded(), "AES"); - - //encrypt the message - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, secret); - AlgorithmParameters params = cipher.getParameters(); - ivBytes = params.getParameterSpec(IvParameterSpec.class).getIV(); - byte[] encryptedTextBytes = cipher.doFinal(plainText.getBytes("UTF-8")); - return new Base64().encodeAsString(encryptedTextBytes); - } - - @SuppressWarnings("static-access") - public String decrypt(String encryptedText) throws Exception { - - byte[] saltBytes = salt.getBytes("UTF-8"); - byte[] encryptedTextBytes = new Base64().decodeBase64(encryptedText); - - // Derive the key - SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); - PBEKeySpec spec = new PBEKeySpec( - password.toCharArray(), - saltBytes, - pswdIterations, - keySize - ); - - SecretKey secretKey = factory.generateSecret(spec); - SecretKeySpec secret = new SecretKeySpec(secretKey.getEncoded(), "AES"); - - // Decrypt the message - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(ivBytes)); - - - byte[] decryptedTextBytes = null; - try { - decryptedTextBytes = cipher.doFinal(encryptedTextBytes); - } catch (IllegalBlockSizeException e) { - e.printStackTrace(); - } catch (BadPaddingException e) { - e.printStackTrace(); - } - - return new String(decryptedTextBytes); - } - - public String generateSalt() { - SecureRandom random = new SecureRandom(); - byte bytes[] = new byte[20]; - random.nextBytes(bytes); - String s = new String(bytes); - return s; - } + + private static final String WORD = "test"; + private static final String SALT = "r n�HN~��|f��X�"; + private static final int ITERATIONS = 65536; + private static final int KEY_SIZE = 256; + private byte[] ivBytes; + + public String encrypt(String plainText) throws UnsupportedEncodingException, GeneralSecurityException { + + // get salt + // salt = generateSalt(); + byte[] saltBytes = SALT.getBytes("UTF-8"); + + // Derive the key + SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); + PBEKeySpec spec = new PBEKeySpec(WORD.toCharArray(), saltBytes, ITERATIONS, KEY_SIZE); + + SecretKey secretKey = factory.generateSecret(spec); + SecretKeySpec secret = new SecretKeySpec(secretKey.getEncoded(), "AES"); + + // encrypt the message + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, secret); + AlgorithmParameters params = cipher.getParameters(); + ivBytes = params.getParameterSpec(IvParameterSpec.class).getIV(); + byte[] encryptedTextBytes = cipher.doFinal(plainText.getBytes("UTF-8")); + return Base64.encodeBase64String(encryptedTextBytes); + } + + public String decrypt(String encryptedText) throws UnsupportedEncodingException, GeneralSecurityException { + byte[] saltBytes = SALT.getBytes("UTF-8"); + byte[] encryptedTextBytes = Base64.decodeBase64(encryptedText); + + // Derive the key + SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); + PBEKeySpec spec = new PBEKeySpec(WORD.toCharArray(), saltBytes, ITERATIONS, KEY_SIZE); + + SecretKey secretKey = factory.generateSecret(spec); + SecretKeySpec secret = new SecretKeySpec(secretKey.getEncoded(), "AES"); + + // Decrypt the message + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(ivBytes)); + + byte[] decryptedTextBytes = cipher.doFinal(encryptedTextBytes); + return new String(decryptedTextBytes); + } + + public String generateSalt() { + SecureRandom random = new SecureRandom(); + byte [] bytes = new byte[20]; + random.nextBytes(bytes); + return new String(bytes); + } }
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/JSONUtil.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/JSONUtil.java index 8bbd791a..3375bee7 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/JSONUtil.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/JSONUtil.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,14 +46,19 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class JSONUtil { - public static String convertResponseToJSON(String response) throws JsonProcessingException{ + + private JSONUtil() { + // Class has only static methods + } + + public static String convertResponseToJSON(String response) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); - Map<String, String> responseMap = new HashMap<String, String>(); + Map<String, String> responseMap = new HashMap<>(); responseMap.put("response", response); - response = mapper.writeValueAsString(responseMap); - return response; + String result = mapper.writeValueAsString(responseMap); + return result; } - + public static User mapToDomainUser(User domainUser, User editUser) { domainUser.setOrgId(editUser.getOrgId()); domainUser.setManagerId(editUser.getManagerId()); diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java index 31d2f04d..6f119104 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/SystemProperties.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 * @@ -69,82 +69,6 @@ public class SystemProperties { private ServletContext servletContext; - public SystemProperties() { - } - - protected Environment getEnvironment() { - return environment; - } - - @Autowired - public void setEnvironment(Environment environment) { - SystemProperties.environment = environment; - } - - public ServletContext getServletContext() { - return servletContext; - } - - public void setServletContext(ServletContext servletContext) { - this.servletContext = servletContext; - } - - /** - * Tests whether a property value is available for the specified key. - * - * @param key Property key - * @return True if the key is known, otherwise false. - */ - public static boolean containsProperty(String key) { - return environment.containsProperty(key); - } - - /** - * Returns the property value associated with the given key (never - * {@code null}), after trimming any trailing space. - * - * @param key - * Property key - * @return Property value; the empty string if the environment was not - * autowired, which should never happen. - * @throws IllegalStateException - * if the key cannot be resolved - */ - public static String getProperty(String key) { - String value = ""; - if (environment == null) { - logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!"); - } - else { - value = environment.getRequiredProperty(key); - // java.util.Properties preserves trailing space - if (value != null) - value = value.trim(); - } - return value; - } - - /** - * Gets the property value for the key {@link #APPLICATION_NAME}. - * - * method created to get around JSTL 1.0 limitation of not being able to - * access a static method of a bean - * - * @return Application name - */ - public String getApplicationName() { - return getProperty(APPLICATION_NAME); - } - - /** - * Gets the property value for the key {@link #APP_DISPLAY_NAME}. - * - * @return Application display name - */ - public String getAppDisplayName() { - return getProperty(APP_DISPLAY_NAME); - } - // keys used to reference values in the system properties file public static final String DOMAIN_CLASS_LOCATION = "domain_class_location"; public static final String DEFAULT_ERROR_MESSAGE = "default_error_message"; @@ -228,7 +152,6 @@ public class SystemProperties { public static final String LOGIN_METHOD_BACKDOOR = "login_method_backdoor"; public static final String LOGIN_METHOD_ATTRIBUTE_NAME = "login_method_attribute_name"; public static final String ROLE_FUNCTION_LIST = "role_function_list"; - // login error message keys public static final String MESSAGE_KEY_LOGIN_ERROR_COOKIE_EMPTY = "login.error.hrid.empty"; @@ -265,7 +188,7 @@ public class SystemProperties { public static final String HB_DIALECT = "hb.dialect"; public static final String HB_SHOW_SQL = "hb.show_sql"; public static final String IDLE_CONNECTION_TEST_PERIOD = "hb.idle_connection_test_period"; - + // DataSource public static final String DB_DRIVER = "db.driver"; public static final String DB_CONNECTIONURL = "db.connectionURL"; @@ -333,7 +256,14 @@ public class SystemProperties { public static final String HTTP = "HTTP"; public static final String HTTPS = "HTTPS"; public static final String SSO_VALUE = "sso"; - + + // Menu + public static final String CONTACT_US_LINK = "contact_us_link"; + + // Left Menu + public static final String LEFT_MENU_PARENT = "parentList"; + public static final String LEFT_MENU_CHILDREND = "childItemList"; + public enum RESULT_ENUM { SUCCESS, FAILURE } @@ -342,10 +272,81 @@ public class SystemProperties { FE_LOGIN_ATTEMPT, FE_LOGOUT, SSO_LOGIN_ATTEMPT_PHASE_1, SSO_LOGIN_ATTEMPT_PHASE_2, SSO_LOGOUT, LDAP_PHONEBOOK_USER_SEARCH, INCOMING_REST_MESSAGE, OUTGOING_REST_MESSAGE, REST_AUTHORIZATION_CREDENTIALS_MODIFIED, ECOMP_PORTAL_USER_MODIFIED, ECOMP_PORTAL_USER_ADDED, ECOMP_PORTAL_USER_REMOVED, ECOMP_PORTAL_WIDGET, INCOMING_UEB_MESSAGE, ECOMP_PORTAL_HEALTHCHECK } - // Menu - public static final String CONTACT_US_LINK = "contact_us_link"; + public SystemProperties() { + super(); + } + + protected Environment getEnvironment() { + return environment; + } + + @Autowired + public void setEnvironment(Environment environment) { + SystemProperties.environment = environment; + } + + public ServletContext getServletContext() { + return servletContext; + } + + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + + /** + * Tests whether a property value is available for the specified key. + * + * @param key + * Property key + * @return True if the key is known, otherwise false. + */ + public static boolean containsProperty(String key) { + return environment.containsProperty(key); + } + + /** + * Returns the property value associated with the given key (never + * {@code null}), after trimming any trailing space. + * + * @param key + * Property key + * @return Property value; the empty string if the environment was not + * autowired, which should never happen. + * @throws IllegalStateException + * if the key is not found + */ + public static String getProperty(String key) { + String value = ""; + if (environment == null) { + logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!"); + } else { + value = environment.getRequiredProperty(key); + // java.util.Properties preserves trailing space + if (value != null) + value = value.trim(); + } + return value; + } + + /** + * Gets the property value for the key {@link #APPLICATION_NAME}. + * + * method created to get around JSTL 1.0 limitation of not being able to access + * a static method of a bean + * + * @return Application name + */ + public String getApplicationName() { + return getProperty(APPLICATION_NAME); + } + + /** + * Gets the property value for the key {@link #APP_DISPLAY_NAME}. + * + * @return Application display name + */ + public String getAppDisplayName() { + return getProperty(APP_DISPLAY_NAME); + } - // Left Menu - public static final String LEFT_MENU_PARENT = "parentList"; - public static final String LEFT_MENU_CHILDREND = "childItemList"; } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java index faf410fc..569c2b87 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/UsageUtils.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 * @@ -40,8 +40,9 @@ package org.onap.portalsdk.core.util; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.Iterator; +import java.util.List; +import java.util.Map; import javax.servlet.http.HttpSession; @@ -49,62 +50,61 @@ import org.onap.portalsdk.core.command.UserRowBean; import org.onap.portalsdk.core.domain.User; public class UsageUtils { + + private UsageUtils() { + // Class has only static methods + } + @SuppressWarnings("rawtypes") - public static ArrayList<UserRowBean> getActiveUsers(HashMap activeUsers) { - ArrayList<UserRowBean> rows = new ArrayList<UserRowBean>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + public static List<UserRowBean> getActiveUsers(Map activeUsers) { + ArrayList<UserRowBean> rows = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + for (Iterator i = activeUsers.keySet().iterator(); i.hasNext();) { + String sessionId = (String) i.next(); + HttpSession session = (HttpSession) activeUsers.get(sessionId); + User userBean = (User) session.getAttribute("user"); + + // Not all sessions will be valid logins + if (null == userBean) + continue; - for(Iterator i = activeUsers.keySet().iterator(); i.hasNext(); ){ - String sessionId = (String)i.next(); - HttpSession session = (HttpSession)activeUsers.get(sessionId); - User userBean = (User)session.getAttribute("user"); - // - // Not all sessions will be valid logins - // Skip those ones - // - if(null == userBean) - continue; + UserRowBean userRow = new UserRowBean(); + userRow.setFirstName(userBean.getFirstName()); + userRow.setLastName(userBean.getLastName()); + userRow.setEmail(userBean.getEmail()); + userRow.setId(userBean.getId()); + userRow.setSessionId(sessionId); + userRow.setLoginTime(sdf.format(new Date(session.getCreationTime()))); + userRow.setLastLoginTime(sdf.format(userBean.getLastLoginDate())); - UserRowBean userRow = new UserRowBean(); - userRow.setFirstName(userBean.getFirstName()); - userRow.setLastName(userBean.getLastName()); - userRow.setEmail(userBean.getEmail()); - userRow.setId(userBean.getId()); - userRow.setSessionId(sessionId); - userRow.setLoginTime(sdf.format(new Date(session.getCreationTime()))); - userRow.setLastLoginTime(sdf.format(userBean.getLastLoginDate())); + // Calculate the last time and time remaining for these sessions. + int sessionLength = session.getMaxInactiveInterval(); + long now = new java.util.Date().getTime(); + long lastAccessed = (now - session.getLastAccessedTime()) / 1000; + long lengthInactive = now - session.getLastAccessedTime(); + long minutesRemaining = sessionLength - (lengthInactive / 1000); - // - // Calculate the last time and time remaining for these sessions. - // - int sessionLength = session.getMaxInactiveInterval(); - long now = new java.util.Date().getTime(); - long lastAccessed = (now - session.getLastAccessedTime()) / 1000; - long lengthInactive = (now - session.getLastAccessedTime()); - long minutesRemaining = sessionLength - (lengthInactive / 1000); + userRow.setLastAccess((lastAccessed / 60) + ":" + String.format("%02d", lastAccessed % 60)); + userRow.setRemaining((minutesRemaining / 60) + ":" + String.format("%02d", minutesRemaining % 60)); - userRow.setLastAccess((lastAccessed / 60) + ":" + String.format("%02d", (lastAccessed % 60))); - userRow.setRemaining((minutesRemaining / 60) + ":" + String.format("%02d", (minutesRemaining % 60))); + rows.add(userRow); + } - rows.add(userRow); - } - - return rows; + return rows; } - + @SuppressWarnings("rawtypes") - public static ArrayList<UserRowBean> getActiveUsersAfterDelete(HashMap activeUsers, final java.lang.Object data) { - return getActiveUsers(deleteSession(activeUsers,data)); - + public static List<UserRowBean> getActiveUsersAfterDelete(Map activeUsers, final java.lang.Object data) { + return getActiveUsers(deleteSession(activeUsers, data)); } - + @SuppressWarnings("rawtypes") - private static HashMap deleteSession(HashMap activeUsers, Object data) { - String sessionId = ((UserRowBean)data).getSessionId(); - HttpSession session = (HttpSession)activeUsers.get(sessionId); + private static Map deleteSession(Map activeUsers, Object data) { + String sessionId = ((UserRowBean) data).getSessionId(); + HttpSession session = (HttpSession) activeUsers.get(sessionId); session.invalidate(); activeUsers.remove(sessionId); - return activeUsers; } } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/YamlUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/YamlUtils.java index 38206d55..38bd2075 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/YamlUtils.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/util/YamlUtils.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 * @@ -38,7 +38,6 @@ package org.onap.portalsdk.core.util; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -48,43 +47,34 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; public class YamlUtils { - - static Yaml yaml; - - static { + private YamlUtils() { + // Class has only static methods + } + + private static Yaml yaml; + + static { Representer representer = new Representer(); - //representer.addClassTag(Domain.class, Tag.MAP); - - - yaml = new Yaml(representer); - + yaml = new Yaml(representer); } - - public static void writeYamlFile(String filePath, String fileName, - Map<String, Object> model) throws IOException { + + public static void writeYamlFile(String filePath, String fileName, Map<String, Object> model) throws IOException { FileWriter writer = new FileWriter(filePath + File.separator + fileName); - yaml.dump(model, writer); + yaml.dump(model, writer); writer.close(); } - - public static String returnYaml( - Map<String, Object> model) throws IOException { - - return yaml.dump(model); - + + public static String returnYaml(Map<String, Object> model) throws IOException { + return yaml.dump(model); } @SuppressWarnings("unchecked") - public static Map<String, Object> readYamlFile( - String filePath, String fileName) throws FileNotFoundException, - IOException { + public static Map<String, Object> readYamlFile(String filePath, String fileName) throws IOException { FileReader reader = new FileReader(filePath + File.separator + fileName); - - Map<String,Object> callFlowBs = (Map<String,Object>)yaml.load(reader); + Map<String, Object> callFlowBs = (Map<String, Object>) yaml.load(reader); reader.close(); return callFlowBs; } - } |