X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=portal-BE%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportal%2Fservice%2Fep%2FEpWidgetCatalogParameterService.java;h=029c316ee2cec635121e1a389e7f7618a195ca19;hb=ffd9af970318c1f5a0bad46d7aad5d4611414aae;hp=f2497f8555afac43c99ef604af7b02b05f170d1d;hpb=e90cfa3b65b9879d22fc4522f45a22f1014e224e;p=portal.git diff --git a/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java index f2497f85..029c316e 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java @@ -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); + final 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 getUserParameterById(Long paramId) { + public List 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 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); } }