diff options
author | 2019-10-03 12:21:10 +0200 | |
---|---|---|
committer | 2019-10-03 12:22:12 +0200 | |
commit | 1a7472103bde3d850f1f410a7d2ae5b249aef92e (patch) | |
tree | 6a56a85ff3b5f04011dbcfb149e9230fbfe92c3b /portal-BE/src/main/java | |
parent | e90cfa3b65b9879d22fc4522f45a22f1014e224e (diff) |
Tests coverage up and some minor bug fixes
Tests coverage up and some minor bug fixes
Issue-ID: PORTAL-710
Change-Id: I796bc731dec6fedae92cac2a659b27f2c0f6d406
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'portal-BE/src/main/java')
12 files changed, 59 insertions, 35 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java b/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java index b96575c6..8c2ff74b 100644 --- a/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java +++ b/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java @@ -93,7 +93,7 @@ public class FnUserServiceAOP { LOGGER.error("User " + principal.getName() + " try to save not valid fnUser: " + violations); throw new IllegalArgumentException("FnUser is not valid, " + violations); } else { - LOGGER.error("User " + principal.getName() + " send valid fnUser"); + LOGGER.info("User " + principal.getName() + " send valid fnUser"); } } } diff --git a/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java b/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java index d1039f0c..ff8426a3 100644 --- a/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java +++ b/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java @@ -343,8 +343,14 @@ public class WidgetsCatalogController { } @DeleteMapping(value = {"/portalApi/microservices/services/{paramId}"}) - public void deleteUserParameterById(@PathVariable("paramId") long paramId) { - epWidgetCatalogParameterService.deleteUserParameterById(paramId); + public boolean deleteUserParameterById(@PathVariable("paramId") long paramId) { + try { + epWidgetCatalogParameterService.deleteUserParameterById(paramId); + return true; + }catch (Exception e){ + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); + return false; + } } @GetMapping(value = {"/portalApi/microservices/download/{widgetId}"}) diff --git a/portal-BE/src/main/java/org/onap/portal/dao/ep/EpMicroserviceParameterDao.java b/portal-BE/src/main/java/org/onap/portal/dao/ep/EpMicroserviceParameterDao.java index 4bcca7ef..add897c9 100644 --- a/portal-BE/src/main/java/org/onap/portal/dao/ep/EpMicroserviceParameterDao.java +++ b/portal-BE/src/main/java/org/onap/portal/dao/ep/EpMicroserviceParameterDao.java @@ -55,7 +55,5 @@ public interface EpMicroserviceParameterDao extends JpaRepository<EpMicroservice @Query void deleteByServiceId(@Param("SERVICEID") Long userId); @Query - void deleteMicroserviceParameterById(@Param("PARAMID") Long userId); - @Query List<EpMicroserviceParameter> getParametersById(@Param("SERVICEID") long serviceId); } diff --git a/portal-BE/src/main/java/org/onap/portal/dao/ep/EpWidgetCatalogParameterDao.java b/portal-BE/src/main/java/org/onap/portal/dao/ep/EpWidgetCatalogParameterDao.java index 04c12324..c5ec1248 100644 --- a/portal-BE/src/main/java/org/onap/portal/dao/ep/EpWidgetCatalogParameterDao.java +++ b/portal-BE/src/main/java/org/onap/portal/dao/ep/EpWidgetCatalogParameterDao.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -17,6 +18,7 @@ public interface EpWidgetCatalogParameterDao extends JpaRepository<EpWidgetCatal Optional<List<EpWidgetCatalogParameter>> retrieveByParamId(@Param("PARAMID") Long paramId); @Query + @Modifying void deleteWidgetCatalogParameter(@Param("PARAMID") Long paramId); @Query diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpMicroserviceParameter.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpMicroserviceParameter.java index 554dd7b5..36c073ac 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpMicroserviceParameter.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpMicroserviceParameter.java @@ -59,6 +59,7 @@ import javax.persistence.Table; import javax.validation.constraints.Digits; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -82,11 +83,7 @@ CREATE TABLE `ep_microservice_parameter` ( query = "DELETE FROM EpMicroserviceParameter WHERE service_id =:SERVICEID"), @NamedQuery( name = "EpMicroserviceParameter.getParametersById", - query = "FROM EpMicroserviceParameter WHERE service_id =:SERVICEID"), - @NamedQuery( - name = "EpMicroserviceParameter.deleteMicroserviceParameterById", - query = "DELETE FROM EpMicroserviceParameter WHERE id =:PARAMID" - ) + query = "FROM EpMicroserviceParameter WHERE service_id =:SERVICEID") }) @Table(name = "ep_microservice_parameter", indexes = { @@ -94,13 +91,14 @@ CREATE TABLE `ep_microservice_parameter` ( }) @NoArgsConstructor @AllArgsConstructor +@Builder @Getter @Setter @Entity public class EpMicroserviceParameter implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", length = 11, nullable = false) @Digits(integer = 11, fraction = 0) private Long id; diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java index 2068e212..061aafc4 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java @@ -87,7 +87,7 @@ CREATE TABLE `ep_widget_catalog` ( @Builder public class EpWidgetCatalog implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "widget_id", nullable = false) private Long widgetId; @Column(name = "wdg_name", length = 100, columnDefinition = "varchar(100) default '?'", nullable = false) diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java index 8088a8fd..ec6bb563 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java @@ -84,16 +84,17 @@ CREATE TABLE `ep_widget_catalog_parameter` ( ) */ + @NamedQueries({ @NamedQuery( name = "EpWidgetCatalogParameter.retrieveByParamId", query = "FROM EpWidgetCatalogParameter WHERE paramId.id = :PARAMID"), @NamedQuery( name = "EpWidgetCatalogParameter.deleteWidgetCatalogParameter", - query = "DELETE FROM EpWidgetCatalogParameter WHERE paramId = :PARAMID"), + query = "DELETE FROM EpWidgetCatalogParameter WHERE paramId.id = :PARAMID"), @NamedQuery( name = "EpWidgetCatalogParameter.getUserParamById", - query = "FROM EpWidgetCatalogParameter WHERE paramId = :PARAMID and userId = :USERID and widgetId = :WIDGETID" + query = "FROM EpWidgetCatalogParameter WHERE paramId.id = :PARAMID and userId.userId = :USERID and widgetId.widgetId = :WIDGETID" ) }) @@ -126,7 +127,7 @@ public class EpWidgetCatalogParameter extends DomainVo implements Serializable { @NotNull @Valid private FnUser userId; - @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) @JoinColumn(name = "param_id", nullable = false) @NotNull @Valid diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java index 0582508d..ad976fc6 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java @@ -80,13 +80,11 @@ CREATE TABLE `fn_language` ( @Setter @Entity @JsonInclude() -@SequenceGenerator(name="seq", initialValue=1000, allocationSize=100000) public class FnLanguage implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq") - @Column(name = "language_id", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT") - @Digits(integer = 11, fraction = 0) + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "language_id", length = 11, nullable = false) private Long languageId; @Column(name = "language_name", length = 100, nullable = false) @Size(max = 100) diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnQzSimpleTriggers.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnQzSimpleTriggers.java index 6f67381f..8bdb1e02 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnQzSimpleTriggers.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnQzSimpleTriggers.java @@ -76,7 +76,6 @@ CREATE TABLE `fn_qz_simple_triggers` ( @Table(name = "fn_qz_simple_triggers") @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @Entity diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java index ce28d0fd..9b0727d9 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java @@ -183,13 +183,11 @@ CREATE TABLE `fn_user` ( @NoArgsConstructor @AllArgsConstructor @DynamicUpdate -@SequenceGenerator(name = "seq", initialValue = 1000, allocationSize = 100000) public class FnUser extends DomainVo implements UserDetails, Serializable { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq") - @Column(name = "user_id", length = 11, nullable = false) - @Digits(integer = 11, fraction = 0) + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id", nullable = false) private Long userId; @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "org_id") diff --git a/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java b/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java index e5f84e72..6fa8b7d7 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java @@ -51,8 +51,10 @@ import org.onap.portal.domain.dto.ecomp.MicroserviceParameter; 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 EpMicroserviceParameterService { EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EpWidgetCatalogParameterService.class); @@ -88,4 +90,15 @@ public class EpMicroserviceParameterService { public EpMicroserviceParameter save(EpMicroserviceParameter epMicroserviceParameter){ return epMicroserviceParameterDao.save(epMicroserviceParameter); } + + @Transactional + public boolean deleteMicroserviceParameterById(final Long paramid){ + try { + epMicroserviceParameterDao.deleteById(paramid); + return true; + }catch (Exception e){ + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); + return false; + } + } } 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..75cc9aa7 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,40 +42,51 @@ 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) { + @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) @@ -89,7 +100,7 @@ public class EpWidgetCatalogParameterService { } @Transactional - public void saveUserParameter(EpWidgetCatalogParameter newParameter) { + public void saveUserParameter(final EpWidgetCatalogParameter newParameter) { epWidgetCatalogParameterDao.save(newParameter); } } |