From e90cfa3b65b9879d22fc4522f45a22f1014e224e Mon Sep 17 00:00:00 2001 From: Dominik Mizyn Date: Tue, 1 Oct 2019 14:52:49 +0200 Subject: WidgetsCatalogControllerTest up WidgetsCatalogControllerTest up Issue-ID: PORTAL-710 Change-Id: I09c2ee9ab72108b2f62939a3a5ac2441376774e2 Signed-off-by: Dominik Mizyn --- .../controller/WidgetsCatalogController.java | 16 +++---- .../onap/portal/domain/db/ep/EpWidgetCatalog.java | 12 ++--- .../domain/db/ep/EpWidgetCatalogParameter.java | 12 +++-- .../org/onap/portal/domain/db/fn/FnLanguage.java | 7 +-- .../service/ep/EpMicroserviceParameterService.java | 4 ++ .../ep/EpWidgetCatalogParameterService.java | 56 +++++----------------- .../portal/service/ep/EpWidgetCatalogService.java | 21 ++++++++ 7 files changed, 62 insertions(+), 66 deletions(-) create mode 100644 portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java (limited to 'portal-BE/src/main') 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 decf625d..d1039f0c 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 @@ -49,12 +49,12 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.domain.dto.PortalRestResponse; import org.onap.portal.domain.dto.PortalRestStatusEnum; import org.onap.portal.domain.dto.ecomp.MicroserviceParameter; import org.onap.portal.domain.dto.ecomp.WidgetCatalog; -import org.onap.portal.domain.dto.ecomp.WidgetCatalogParameter; import org.onap.portal.domain.dto.ecomp.WidgetParameterResult; import org.onap.portal.domain.dto.ecomp.WidgetServiceHeaders; import org.onap.portal.logging.aop.EPAuditLog; @@ -323,7 +323,7 @@ public class WidgetsCatalogController { userResult.setParamId(param.getId()); userResult.setDefaultValue(param.getPara_value()); userResult.setParamKey(param.getPara_key()); - WidgetCatalogParameter userValue = epWidgetCatalogParameterService + EpWidgetCatalogParameter userValue = epWidgetCatalogParameterService .getUserParamById(widgetId, user.getId(), param.getId()); if (userValue == null) { @@ -338,7 +338,7 @@ public class WidgetsCatalogController { } @GetMapping(value = {"/portalApi/microservices/services/{paramId}"}) - public List getUserParameterById(@PathVariable("paramId") long paramId) { + public List getUserParameterById(@PathVariable("paramId") long paramId) { return epWidgetCatalogParameterService.getUserParameterById(paramId); } @@ -396,13 +396,13 @@ public class WidgetsCatalogController { @PostMapping(value = {"/portalApi/microservices/parameters"}) public PortalRestResponse saveWidgetParameter(Principal principal, HttpServletRequest request, - @RequestBody WidgetCatalogParameter widgetParameters) { + @RequestBody EpWidgetCatalogParameter widgetParameters) { FnUser user = fnUserService.loadUserByUsername(principal.getName()); - widgetParameters.setUserId(user.getId()); + widgetParameters.setUserId(user); try { - WidgetCatalogParameter oldParam = epWidgetCatalogParameterService - .getUserParamById(widgetParameters.getWidgetId(), - widgetParameters.getUserId(), widgetParameters.getParamId()); + EpWidgetCatalogParameter oldParam = epWidgetCatalogParameterService + .getUserParamById(widgetParameters.getWidgetId().getWidgetId(), + widgetParameters.getUserId().getId(), widgetParameters.getParamId().getId()); if (oldParam != null) { widgetParameters.setId(oldParam.getId()); } 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 a19af285..2068e212 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 @@ -60,6 +60,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -83,11 +84,11 @@ CREATE TABLE `ep_widget_catalog` ( @Getter @Setter @Entity +@Builder public class EpWidgetCatalog implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "widget_id", length = 11, nullable = false) - @Digits(integer = 11, fraction = 0) + @Column(name = "widget_id", nullable = false) private Long widgetId; @Column(name = "wdg_name", length = 100, columnDefinition = "varchar(100) default '?'", nullable = false) @Size(max = 100) @@ -106,12 +107,9 @@ public class EpWidgetCatalog implements Serializable { @NotNull @SafeHtml private String wdgFileLoc; - @Column(name = "all_user_flag", length = 1, columnDefinition = "char(1) not null default 'N'", nullable = false) - @Pattern(regexp = "[YNyn]") - @Size(max = 1) - @SafeHtml + @Column(name = "all_user_flag", length = 1, columnDefinition = "boolean default '0'", nullable = false) @NotNull - private String allUserFlag; + private Boolean allUserFlag; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable( name = "ep_widget_microservice", 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 2ac07cc3..8088a8fd 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 @@ -59,11 +59,13 @@ import javax.validation.constraints.Digits; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.validator.constraints.SafeHtml; import org.onap.portal.domain.db.fn.FnUser; +import org.onap.portal.domain.dto.DomainVo; /* CREATE TABLE `ep_widget_catalog_parameter` ( @@ -85,7 +87,7 @@ CREATE TABLE `ep_widget_catalog_parameter` ( @NamedQueries({ @NamedQuery( name = "EpWidgetCatalogParameter.retrieveByParamId", - query = "FROM EpWidgetCatalogParameter WHERE paramId = :PARAMID"), + query = "FROM EpWidgetCatalogParameter WHERE paramId.id = :PARAMID"), @NamedQuery( name = "EpWidgetCatalogParameter.deleteWidgetCatalogParameter", query = "DELETE FROM EpWidgetCatalogParameter WHERE paramId = :PARAMID"), @@ -100,12 +102,14 @@ CREATE TABLE `ep_widget_catalog_parameter` ( @Index(name = "EP_WIDGET_CATALOG_WIDGET_PARAMETER_FK", columnList = "widget_id"), @Index(name = "EP_PARAMETER_ID_WIDGET_PARAMETER_FK", columnList = "param_id") }) -@NoArgsConstructor -@AllArgsConstructor + @Getter @Setter @Entity -public class EpWidgetCatalogParameter implements Serializable { +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class EpWidgetCatalogParameter extends DomainVo implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) 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 4b9186eb..0582508d 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 @@ -42,6 +42,7 @@ package org.onap.portal.domain.db.fn; import com.fasterxml.jackson.annotation.JsonInclude; import java.io.Serializable; +import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -100,10 +101,10 @@ public class FnLanguage implements Serializable { @OneToMany( targetEntity = FnUser.class, mappedBy = "languageId", - cascade = CascadeType.ALL, - fetch = FetchType.LAZY + cascade = CascadeType.PERSIST, + fetch = FetchType.EAGER ) - private Set fnUsers; + private Set fnUsers = new HashSet<>(); @Override public String toString() { 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 2544ae6a..e5f84e72 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 @@ -84,4 +84,8 @@ public class EpMicroserviceParameterService { private List mapToMicroserviceParameterList(final List list){ return list.stream().map(this::epWidgetCatalogParameterToMicroserviceParameter).collect(Collectors.toList()); } + + public EpMicroserviceParameter save(EpMicroserviceParameter epMicroserviceParameter){ + return epMicroserviceParameterDao.save(epMicroserviceParameter); + } } 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 8488e5ad..f2497f85 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,13 +42,10 @@ package org.onap.portal.service.ep; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; +import javax.transaction.Transactional; import org.onap.portal.dao.ep.EpMicroserviceParameterDao; import org.onap.portal.dao.ep.EpWidgetCatalogParameterDao; -import org.onap.portal.dao.fn.EpWidgetCatalogDao; -import org.onap.portal.dao.fn.FnUserDao; import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; -import org.onap.portal.domain.dto.ecomp.WidgetCatalogParameter; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -60,23 +57,17 @@ public class EpWidgetCatalogParameterService { private final EpWidgetCatalogParameterDao epWidgetCatalogParameterDao; private final EpMicroserviceParameterDao epMicroserviceParameterDao; - private final EpWidgetCatalogDao epWidgetCatalogDao; - private final FnUserDao fnUserDao; @Autowired public EpWidgetCatalogParameterService( final EpWidgetCatalogParameterDao epWidgetCatalogParameterDao, - final EpMicroserviceParameterDao epMicroserviceParameterDao, - EpWidgetCatalogDao epWidgetCatalogDao, FnUserDao fnUserDao) { + final EpMicroserviceParameterDao epMicroserviceParameterDao) { this.epWidgetCatalogParameterDao = epWidgetCatalogParameterDao; this.epMicroserviceParameterDao = epMicroserviceParameterDao; - this.epWidgetCatalogDao = epWidgetCatalogDao; - this.fnUserDao = fnUserDao; } - public List getUserParameterById(Long paramId) { - return mapEpWidgetListToWidgetList( - epWidgetCatalogParameterDao.retrieveByParamId(paramId).orElse(new ArrayList<>())); + public List getUserParameterById(Long paramId) { + return epWidgetCatalogParameterDao.retrieveByParamId(paramId).orElse(new ArrayList<>()); } public void deleteUserParameterById(Long paramId) { @@ -84,11 +75,11 @@ public class EpWidgetCatalogParameterService { epMicroserviceParameterDao.deleteMicroserviceParameterById(paramId); } - public WidgetCatalogParameter getUserParamById(Long widgetId, Long userId, Long paramId) { - WidgetCatalogParameter widgetParam = null; - List list = mapEpWidgetListToWidgetList( - epWidgetCatalogParameterDao.getUserParamById(widgetId, userId, paramId) - .orElse(new ArrayList<>())); + public EpWidgetCatalogParameter getUserParamById(Long widgetId, Long userId, Long paramId) { + EpWidgetCatalogParameter widgetParam = null; + List list = epWidgetCatalogParameterDao + .getUserParamById(widgetId, userId, paramId) + .orElse(new ArrayList<>()); if (list.size() != 0) { widgetParam = list.get(0); } @@ -97,31 +88,8 @@ public class EpWidgetCatalogParameterService { return widgetParam; } - public void saveUserParameter(WidgetCatalogParameter newParameter) { - epWidgetCatalogParameterDao.saveAndFlush(mapToEpWidgetCatalogParameter(newParameter)); - } - - private EpWidgetCatalogParameter mapToEpWidgetCatalogParameter(WidgetCatalogParameter wcp){ - - return new EpWidgetCatalogParameter(wcp.getId(), epWidgetCatalogDao.findById(wcp.getWidgetId()).get(), - fnUserDao.findById(wcp.getUserId()).get(), - epMicroserviceParameterDao.findById(wcp.getParamId()).get(), - wcp.getUserValue()); - } - - private List mapToList(List list){ - return list.stream().map(this::mapToEpWidgetCatalogParameter).collect(Collectors.toList()); - } - - private WidgetCatalogParameter mapEpWidgetCatalogParametertoWidgetCatalogParameter( - EpWidgetCatalogParameter ewcp) { - return new WidgetCatalogParameter(ewcp.getId(), ewcp.getWidgetId().getWidgetId(), - ewcp.getUserId().getId(), ewcp.getParamId().getId(), ewcp.getUserValue()); - } - - private List mapEpWidgetListToWidgetList( - List epWidgetCatalogParameters) { - return epWidgetCatalogParameters.stream().map(this::mapEpWidgetCatalogParametertoWidgetCatalogParameter) - .collect(Collectors.toList()); + @Transactional + public void saveUserParameter(EpWidgetCatalogParameter newParameter) { + epWidgetCatalogParameterDao.save(newParameter); } } diff --git a/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java new file mode 100644 index 00000000..f0c273ad --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java @@ -0,0 +1,21 @@ +package org.onap.portal.service.ep; + +import org.onap.portal.dao.fn.EpWidgetCatalogDao; +import org.onap.portal.domain.db.ep.EpWidgetCatalog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class EpWidgetCatalogService { + + private final EpWidgetCatalogDao epWidgetCatalogDao; + + @Autowired + public EpWidgetCatalogService(EpWidgetCatalogDao epWidgetCatalogDao) { + this.epWidgetCatalogDao = epWidgetCatalogDao; + } + + public EpWidgetCatalog save(final EpWidgetCatalog epWidgetCatalog){ + return epWidgetCatalogDao.save(epWidgetCatalog); + } +} -- cgit 1.2.3-korg