From 5609cc58c9e4abdb743bfcf0a66033f04452f23a Mon Sep 17 00:00:00 2001 From: burdziak Date: Mon, 8 Jul 2019 14:47:39 +0200 Subject: Fix sonar issues in MusicService Change-Id: Ie5426cad77194eea3b328b22f7b1adaa5b9043a2 Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../onap/portalapp/music/service/MusicService.java | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'ecomp-sdk/epsdk-music') diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/service/MusicService.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/service/MusicService.java index 2cbc5a94..a057c496 100644 --- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/service/MusicService.java +++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/service/MusicService.java @@ -97,7 +97,7 @@ public class MusicService { * @return ReturnType that includes required body information for Music api * @throws Exception */ - public static ReturnType setAttribute(String attributeName, Object value, String sessionId) throws Exception { + public static ReturnType setAttribute(String attributeName, Object value, String sessionId) throws MusicLockingException { logger.debug(EELFLoggerDelegate.debugLogger, "setAttribute: start with id " + sessionId); String tableName = null; ReturnType result = null; @@ -168,7 +168,7 @@ public class MusicService { * @return MusicSession * @throws Exception */ - public static MusicSession getMetaAttribute(String sessionId) throws Exception { + public static MusicSession getMetaAttribute(String sessionId) throws MusicLockingException,MusicServiceException { logger.debug(EELFLoggerDelegate.debugLogger, "getMetaAttribute: start with session Id: "+ sessionId); ResultSet result = null; PreparedQueryObject queryObject = new PreparedQueryObject(); @@ -380,7 +380,7 @@ public class MusicService { public static RestResponse setAttributeAPI(String attributeName, Object value, Session session, String sessionId, String className, boolean isMeta) throws JsonProcessingException { - System.out.println("setAttribute: " + attributeName); + logger.debug(EELFLoggerDelegate.debugLogger, "setAttribute: " + attributeName); RestResponse portalRestResponse = null; HttpEntity> entity = new HttpEntity<>( getMusicRestBody(attributeName, value, sessionId, session, className, isMeta), getMusicHeader()); @@ -390,6 +390,7 @@ public class MusicService { response = template.exchange(url, HttpMethod.POST, entity, String.class); portalRestResponse = new RestResponse<>(RestStatusEnum.OK, SUCCESS, response.getBody()); } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, e.getLocalizedMessage()); portalRestResponse = new RestResponse<>(RestStatusEnum.ERROR, e.getMessage(), null); } return portalRestResponse; @@ -407,7 +408,7 @@ public class MusicService { public static RestResponse getAttributeAPI(String attributeName, Object value, String sessionId, boolean isMeta) { - System.out.println("getAttribute: " + attributeName); + logger.debug(EELFLoggerDelegate.debugLogger, "setAttribute: " + attributeName); RestResponse portalRestResponse = null; HttpEntity entity = new HttpEntity<>(null, getMusicHeader()); ResponseEntity response = null; @@ -416,6 +417,7 @@ public class MusicService { response = template.exchange(url, HttpMethod.GET, entity, String.class); portalRestResponse = new RestResponse<>(RestStatusEnum.OK, SUCCESS, response.getBody()); } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, e.getLocalizedMessage()); portalRestResponse = new RestResponse<>(RestStatusEnum.ERROR, e.getMessage(), null); } return portalRestResponse; @@ -439,6 +441,7 @@ public class MusicService { response = template.exchange(url, HttpMethod.DELETE, entity, String.class); portalRestResponse = new RestResponse<>(RestStatusEnum.OK, SUCCESS, response.getBody()); } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, e.getLocalizedMessage()); portalRestResponse = new RestResponse<>(RestStatusEnum.ERROR, e.getMessage(), null); } return portalRestResponse; @@ -485,14 +488,14 @@ public class MusicService { * calls * @throws JsonProcessingException */ - public static Map getMusicDelRestBody(String attribute_name) { + public static Map getMusicDelRestBody(String attributeName) { Map map = new HashMap<>(); Map consistencyInfoMap = new HashMap<>(); consistencyInfoMap.put(MusicProperties.getProperty(MusicProperties.MUSIC_CONSISTENCYINFO), MusicProperties.getProperty(MusicProperties.MUSIC_CONSISTENCYINFO_VALUE)); - if (attribute_name != null && !attribute_name.equals("")) { + if (attributeName != null && !attributeName.isEmpty()) { Map conditionsMap = new HashMap<>(); - conditionsMap.put("attribute_name", attribute_name); + conditionsMap.put("attribute_name", attributeName); map.put("conditions", conditionsMap); } map.put("consistencyInfo", consistencyInfoMap); @@ -596,11 +599,11 @@ public class MusicService { */ public static void cleanUpMusic() { boolean timeToCleanUp = MusicUtil.cleanUp(); // Decide whether to clean up or not - ReturnType result = null; + if(timeToCleanUp){ /**Getting a list of sessions that need to be cleaned up*/ List sessionIDList = getSessionToBeDeleted(); - if(sessionIDList!=null || sessionIDList.size()!=0){ + if(sessionIDList!=null || !sessionIDList.isEmpty()){ StringBuilder sessionIDListCondition = new StringBuilder(); sessionIDListCondition.append("('"); for(String s : sessionIDList){ @@ -621,9 +624,9 @@ public class MusicService { queryObject.appendQueryString(querySB.toString()); try{ if (isAtomicPut) - result = MusicCore.atomicPut(musicKeySpace, null, null, queryObject, null); + MusicCore.atomicPut(musicKeySpace, null, null, queryObject, null); else - result = MusicCore.eventualPut(queryObject); + MusicCore.eventualPut(queryObject); }catch(Exception e){ logger.error(EELFLoggerDelegate.errorLogger, "Error while cleaning up music attributes tables" , e); } @@ -639,9 +642,9 @@ public class MusicService { queryObject.appendQueryString(querySB.toString()); try{ if (isAtomicPut) - result = MusicCore.atomicPut(musicKeySpace, null, null, queryObject, null); + MusicCore.atomicPut(musicKeySpace, null, null, queryObject, null); else - result = MusicCore.eventualPut(queryObject); + MusicCore.eventualPut(queryObject); }catch(Exception e){ logger.error(EELFLoggerDelegate.errorLogger, "Error while cleaning up music meta tables" , e); } -- cgit 1.2.3-korg