Tests coverage up and some minor bug fixes
[portal.git] / portal-BE / src / main / java / org / onap / portal / service / ep / EpWidgetCatalogParameterService.java
index f2497f8..d43acc0 100644 (file)
@@ -42,45 +42,60 @@ package org.onap.portal.service.ep;
 
 import java.util.ArrayList;
 import java.util.List;
-import javax.transaction.Transactional;
-import org.onap.portal.dao.ep.EpMicroserviceParameterDao;
 import org.onap.portal.dao.ep.EpWidgetCatalogParameterDao;
 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 @Service
+@Transactional
 public class EpWidgetCatalogParameterService {
 
        EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EpWidgetCatalogParameterService.class);
 
        private final EpWidgetCatalogParameterDao epWidgetCatalogParameterDao;
-       private final EpMicroserviceParameterDao epMicroserviceParameterDao;
+       private final EpMicroserviceParameterService epMicroserviceParameterService;
 
        @Autowired
        public EpWidgetCatalogParameterService(
                final EpWidgetCatalogParameterDao epWidgetCatalogParameterDao,
-               final EpMicroserviceParameterDao epMicroserviceParameterDao) {
+               final EpMicroserviceParameterService epMicroserviceParameterService) {
               this.epWidgetCatalogParameterDao = epWidgetCatalogParameterDao;
-              this.epMicroserviceParameterDao = epMicroserviceParameterDao;
+              this.epMicroserviceParameterService = epMicroserviceParameterService;
        }
 
-       public List<EpWidgetCatalogParameter> getUserParameterById(Long paramId) {
+       public List<EpWidgetCatalogParameter> getUserParameterById(final Long paramId) {
               return epWidgetCatalogParameterDao.retrieveByParamId(paramId).orElse(new ArrayList<>());
        }
 
-       public void deleteUserParameterById(Long paramId) {
-              epWidgetCatalogParameterDao.deleteWidgetCatalogParameter(paramId);
-              epMicroserviceParameterDao.deleteMicroserviceParameterById(paramId);
+       public boolean deleteUserParameterById(final Long paramId) {
+              return (deleteByParamId(paramId) &&
+                      epMicroserviceParameterService.deleteMicroserviceParameterById(paramId));
        }
 
-       public EpWidgetCatalogParameter getUserParamById(Long widgetId, Long userId, Long paramId) {
+       public EpWidgetCatalogParameter getById(final Long id){
+              return epWidgetCatalogParameterDao.getOne(id);
+       }
+
+       @Transactional
+       public boolean deleteByParamId(final Long paramId) {
+              try {
+                     epWidgetCatalogParameterDao.deleteWidgetCatalogParameter(paramId);
+                     return true;
+              } catch (Exception e) {
+                     logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+                     return false;
+              }
+       }
+
+       public EpWidgetCatalogParameter getUserParamById(final Long widgetId, final Long userId, final Long paramId) {
               EpWidgetCatalogParameter widgetParam = null;
               List<EpWidgetCatalogParameter> list = epWidgetCatalogParameterDao
                       .getUserParamById(widgetId, userId, paramId)
-                      .orElse(new ArrayList<>());
-              if (list.size() != 0) {
+                      .orElse(null);
+              if (list != null && !list.isEmpty()) {
                      widgetParam = list.get(0);
               }
               logger.debug(EELFLoggerDelegate.debugLogger,
@@ -88,8 +103,7 @@ public class EpWidgetCatalogParameterService {
               return widgetParam;
        }
 
-       @Transactional
-       public void saveUserParameter(EpWidgetCatalogParameter newParameter) {
+       public void saveUserParameter(final EpWidgetCatalogParameter newParameter) {
               epWidgetCatalogParameterDao.save(newParameter);
        }
 }