Merge "Sonar critical fixes in MicroserviceServiceImpl"
authorSunder Tattavarada <statta@research.att.com>
Fri, 14 Jun 2019 17:19:57 +0000 (17:19 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 14 Jun 2019 17:19:57 +0000 (17:19 +0000)
1  2 
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java

@@@ -4,6 -4,8 +4,8 @@@
   * ===================================================================
   * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
   * ===================================================================
+  * Modifications Copyright (c) 2019 Samsung
+  * ===================================================================
   *
   * Unless otherwise specified, all software contained herein is licensed
   * under the Apache License, Version 2.0 (the "License");
@@@ -73,8 -75,9 +75,8 @@@ public class MicroserviceServiceImpl im
                return newService.getId();
        }
  
 -      public void saveServiceParameters(long serviceId, List<MicroserviceParameter> list) throws Exception {
 -              for (int i = 0; i < list.size(); i++) {
 -                      MicroserviceParameter para = list.get(i);
 +      public void saveServiceParameters(long serviceId, List<MicroserviceParameter> list) {
 +              for (MicroserviceParameter para : list) {
                        para.setServiceId(serviceId);
                        getDataAccessService().saveDomainObject(para, null);
                }
@@@ -82,9 -85,9 +84,9 @@@
  
        @Override
        public MicroserviceData getMicroserviceDataById(long id) {
 -              MicroserviceData data = null;
 +              MicroserviceData data;
                try {
 -                      List<Criterion> restrictionsList = new ArrayList<Criterion>();
 +                      List<Criterion> restrictionsList = new ArrayList<>();
                        Criterion idCriterion = Restrictions.eq("id", id);
                        restrictionsList.add(idCriterion);
                        data = (MicroserviceData) dataAccessService.getList(MicroserviceData.class, null, restrictionsList, null).get(0);
  
        @SuppressWarnings("unchecked")
        @Override
 -      public List<MicroserviceData> getMicroserviceData() throws Exception {
 +      public List<MicroserviceData> getMicroserviceData() {
                List<MicroserviceData> list = (List<MicroserviceData>) dataAccessService.getList(MicroserviceData.class, null);
 -              for (int i = 0; i < list.size(); i++) {
 -                      if (list.get(i).getPassword() != null)
 -                              list.get(i).setPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);  //to hide password from get request
 -                      list.get(i).setParameterList(getServiceParameters(list.get(i).getId()));
 +              for (MicroserviceData microserviceData : list) {
 +                      if (microserviceData.getPassword() != null) {
 +                              microserviceData
 +                                      .setPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);  //to hide password from get request
 +                      }
 +                      microserviceData.setParameterList(getServiceParameters(microserviceData.getId()));
                }
                return list;
        }
  
        private List<MicroserviceParameter> getServiceParameters(long serviceId) {
 -              List<MicroserviceParameter> list = getMicroServiceParametersList(serviceId);
 -              return list;
 +              return getMicroServiceParametersList(serviceId);
        }
  
        @SuppressWarnings("unchecked")
        private List<MicroserviceParameter> getMicroServiceParametersList(long serviceId) {
 -              List<Criterion> restrictionsList = new ArrayList<Criterion>();
 +              List<Criterion> restrictionsList = new ArrayList<>();
                Criterion serviceIdCriterion = Restrictions.eq("serviceId", serviceId);
                restrictionsList.add(serviceIdCriterion);
                return (List<MicroserviceParameter>) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList, null);
        }
  
        @Override
 -      public void deleteMicroservice(long serviceId) throws Exception {
 +      public void deleteMicroservice(long serviceId) {
  
                try {
 -                      Map<String, String> params = new HashMap<String, String>();
 +                      Map<String, String> params = new HashMap<>();
                        params.put("serviceId", Long.toString(serviceId));
  
                        dataAccessService.executeNamedQuery("deleteMicroserviceParameter", params, null);
                        getDataAccessService().saveDomainObject(newService, null);
                        List<MicroserviceParameter> oldService = getServiceParameters(serviceId);
                        boolean foundParam;
 -                      for (int i = 0; i < oldService.size(); i++) {
 +                      for (MicroserviceParameter microserviceParameter : oldService) {
                                foundParam = false;
                                for (int n = 0; n < newService.getParameterList().size(); n++) {
 -                                      if (newService.getParameterList().get(n).getId().equals(oldService.get(i).getId())) {
 +                                      if (newService.getParameterList().get(n).getId().equals(microserviceParameter.getId())) {
                                                foundParam = true;
                                                break;
                                        }
                                }
 -                              if (foundParam == false) {
 -                                      MicroserviceParameter pd = oldService.get(i);
 -                                      getDataAccessService().deleteDomainObject(pd, null);
 +                              if (!foundParam) {
 +                                      getDataAccessService().deleteDomainObject(microserviceParameter, null);
                                }
                        }
                        for (int i = 0; i < newService.getParameterList().size(); i++) {
        @Override
        @SuppressWarnings("unchecked")
        public List<MicroserviceParameter> getParametersById(long serviceId) {
 -              List<Criterion> restrictionsList = new ArrayList<Criterion>();
 +              List<Criterion> restrictionsList = new ArrayList<>();
                Criterion contextIdCrit = Restrictions.eq("serviceId", serviceId);
                restrictionsList.add(contextIdCrit);
                List<MicroserviceParameter> list = (List<MicroserviceParameter>) dataAccessService