diff options
author | Dominik Mizyn <d.mizyn@samsung.com> | 2020-01-14 15:46:06 +0100 |
---|---|---|
committer | Dominik Mizyn <d.mizyn@samsung.com> | 2020-01-14 15:46:45 +0100 |
commit | 1d76d572d920e9c77ca1fb0db35169a90a5ecf3a (patch) | |
tree | 681a2f6c302555f10ce885d4b97fae49ac33636f /portal-BE/src/main | |
parent | f7966b9ae53834f9eb664b81ab2d0a3da3f7a9b5 (diff) |
UserNotificationController up
This patch provide UserNotificationController witch all services and DTO
needed.
Issue-ID: PORTAL-710
Change-Id: I129c127c48aa8d00f9aa09b401735862b35b07c7
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'portal-BE/src/main')
17 files changed, 1159 insertions, 22 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/aop/service/ep/EpPersUserWidgetSelServiceAOP.java b/portal-BE/src/main/java/org/onap/portal/aop/service/ep/EpPersUserWidgetSelServiceAOP.java new file mode 100644 index 00000000..ae5bf8b5 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/aop/service/ep/EpPersUserWidgetSelServiceAOP.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.aop.service.ep; + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.onap.portal.domain.db.ep.EpPersUserWidgetSel; +import org.onap.portal.validation.DataValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Aspect +@Component +public class EpPersUserWidgetSelServiceAOP { + + private static final Logger LOGGER = LoggerFactory.getLogger(EpPersUserWidgetSelServiceAOP.class); + + private final DataValidator dataValidator; + + @Autowired + public EpPersUserWidgetSelServiceAOP(DataValidator dataValidator) { + this.dataValidator = dataValidator; + } + + @Before("execution(* org.onap.portal.service.persUserWidgetSel.EpPersUserWidgetSelService.saveAndFlush(..)) && args(epPersUserWidgetSel)") + public void setPersUserAppValue(final EpPersUserWidgetSel epPersUserWidgetSel) { + if (!dataValidator.isValid(epPersUserWidgetSel)) { + LOGGER.error("IllegalArgumentException"); + throw new IllegalArgumentException(dataValidator.getConstraintViolationsString(epPersUserWidgetSel)); + } + } + +} diff --git a/portal-BE/src/main/java/org/onap/portal/aop/service/FnLanguageServiceAOP.java b/portal-BE/src/main/java/org/onap/portal/aop/service/fn/FnLanguageServiceAOP.java index b62e7f7a..49db257e 100644 --- a/portal-BE/src/main/java/org/onap/portal/aop/service/FnLanguageServiceAOP.java +++ b/portal-BE/src/main/java/org/onap/portal/aop/service/fn/FnLanguageServiceAOP.java @@ -38,7 +38,7 @@ * */ -package org.onap.portal.aop.service; +package org.onap.portal.aop.service.fn; import java.security.Principal; import java.util.stream.Collectors; 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/fn/FnUserServiceAOP.java index 5cbec719..274d23ad 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/fn/FnUserServiceAOP.java @@ -38,7 +38,7 @@ * */ -package org.onap.portal.aop.service; +package org.onap.portal.aop.service.fn; import java.security.Principal; import java.util.stream.Collectors; diff --git a/portal-BE/src/main/java/org/onap/portal/controller/UserNotificationController.java b/portal-BE/src/main/java/org/onap/portal/controller/UserNotificationController.java new file mode 100644 index 00000000..12dc922f --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/controller/UserNotificationController.java @@ -0,0 +1,254 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.controller; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.onap.portal.domain.db.ep.EpNotification; +import org.onap.portal.domain.db.ep.EpRoleNotification; +import org.onap.portal.domain.db.fn.FnMenuFunctionalRoles; +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.EcompAppRole; +import org.onap.portal.domain.dto.transport.EpNotificationItemVO; +import org.onap.portal.logging.aop.EPAuditLog; +import org.onap.portal.service.EcompAppRoleService; +import org.onap.portal.service.EpNotificationItemVOService; +import org.onap.portal.service.epNotification.EpNotificationService; +import org.onap.portal.service.epRoleNotification.EpRoleNotificationService; +import org.onap.portal.service.epUserNotification.EpUserNotificationService; +import org.onap.portal.service.menuFunctionalRoles.FnMenuFunctionalRolesService; +import org.onap.portal.service.user.FnUserService; +import org.onap.portal.utils.EPCommonSystemProperties; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@EnableAspectJAutoProxy +@EPAuditLog +public class UserNotificationController { + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserNotificationController.class); + + private final FnMenuFunctionalRolesService functionalMenuService; + private final FnUserService fnUserService; + private final EpNotificationService userNotificationService; + private final EpUserNotificationService epUserNotificationService; + private final EpRoleNotificationService roleNotificationService; + private final EcompAppRoleService ecompAppRoleService; + private final EpNotificationItemVOService epNotificationItemVOService; + + private static final String SUCCESS = "success"; + private static final String FAILURE = "FAILURE"; + + @Autowired + public UserNotificationController( + final FnMenuFunctionalRolesService functionalMenuService, final FnUserService fnUserService, + final EpNotificationService epNotificationService, + final EpUserNotificationService epUserNotificationService, + final EpRoleNotificationService roleNotificationService, + final EcompAppRoleService ecompAppRoleService, + final EpNotificationItemVOService epNotificationItemVOService) { + this.functionalMenuService = functionalMenuService; + this.fnUserService = fnUserService; + this.userNotificationService = epNotificationService; + this.epUserNotificationService = epUserNotificationService; + this.roleNotificationService = roleNotificationService; + this.ecompAppRoleService = ecompAppRoleService; + this.epNotificationItemVOService = epNotificationItemVOService; + } + + @RequestMapping(value = { + "/portalApi/getFunctionalMenuRole" }, method = RequestMethod.GET, produces = "application/json") + public List<FnMenuFunctionalRoles> getMenuIdRoleId(Principal principal, HttpServletRequest request, HttpServletResponse response) { + return functionalMenuService.findAll(); + } + + @RequestMapping(value = { + "/portalApi/getNotifications" }, method = RequestMethod.GET, produces = "application/json") + public PortalRestResponse<List<EpNotification>> getNotifications(Principal principal, HttpServletRequest request, + HttpServletResponse response) { + FnUser user = fnUserService.loadUserByUsername(principal.getName()); + PortalRestResponse<List<EpNotification>> portalRestResponse = null; + try { + List<EpNotification> notificationList = userNotificationService.getNotifications(user.getId()); + portalRestResponse = new PortalRestResponse<>(PortalRestStatusEnum.OK, SUCCESS, + notificationList); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getAllAppsAndContacts failed", e); + portalRestResponse = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, + e.getMessage(), null); + } + return portalRestResponse; + } + + @RequestMapping(value = { + "/portalApi/getAdminNotifications" }, method = RequestMethod.GET, produces = "application/json") + public List<EpNotificationItemVO> getAdminNotifications(Principal principal, HttpServletRequest request, HttpServletResponse response) { + List<EpNotificationItemVO> adminNotificationList = null; + FnUser user = fnUserService.loadUserByUsername(principal.getName()); + adminNotificationList = userNotificationService.getAdminNotificationVOS(user.getId()); + return adminNotificationList; + } + + @RequestMapping(value = "/portalApi/saveNotification", method = RequestMethod.POST, produces = "application/json") + public PortalRestResponse<String> save(Principal principal, HttpServletRequest request, HttpServletResponse response, + @RequestBody EpNotification notificationItem) { + FnUser fnUser = fnUserService.loadUserByUsername(principal.getName()); + if (notificationItem == null || notificationItem.getMsgHeader() == null) + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, FAILURE, + "Notification Header cannot be null or empty"); + if (notificationItem.getEndTime().compareTo(notificationItem.getStartTime()) < 0) { + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, FAILURE, + "End Time should be greater than start time"); + } + + if (("N".equals(notificationItem.getIsForAllRoles())) && notificationItem.getRoleIds().isEmpty()) { + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, FAILURE, + "No Roles Ids Exist for the selected Roles"); + } + + Long creatorId = UserUtils.getUserIdAsLong(request); + notificationItem.setCreatorId(fnUser); + + //TODO + // Front-end date picker does not accept a time value, so all + // values are the start of the chosen day in the local time zone. + // Move the end time value to the very end of the chosen day. + // Avoid Calendar.getDefault() which uses the server's locale. + //Long endTime = notificationItem.getEndTime() + //endTime += (23 * 3600 + 59 * 60 + 59) * 1000; + //notificationItem.getEndTime().setTime(endTime); + + try { + userNotificationService.saveNotification(notificationItem); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveNotification failed", e); + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, FAILURE, e.getMessage()); + } + return new PortalRestResponse<>(PortalRestStatusEnum.OK, "SUCCESS", ""); + } + + @RequestMapping(value = { + "/portalApi/notificationUpdateRate" }, method = RequestMethod.GET, produces = "application/json") + public PortalRestResponse<Map<String, String>> getNotificationUpdateRate(HttpServletRequest request) { + try { + String updateRate = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_RATE); + String updateDuration = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_DURATION); + Integer rateInMiliSec = Integer.parseInt(updateRate) * 1000; + Integer durationInMiliSec = Integer.parseInt(updateDuration) * 1000; + Map<String, String> results = new HashMap<>(); + results.put("updateRate", String.valueOf(rateInMiliSec)); + results.put("updateDuration", String.valueOf(durationInMiliSec)); + return new PortalRestResponse<>(PortalRestStatusEnum.OK, SUCCESS, results); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getNotificationUpdateRate failed", e); + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null); + } + } + + @RequestMapping(value = { + "/portalApi/notificationRead" }, method = RequestMethod.GET, produces = "application/json") + public PortalRestResponse<Map<String, String>> notificationRead( + @RequestParam("notificationId") Long notificationID, HttpServletRequest request) { + try { + epUserNotificationService.setNotificationRead(notificationID, UserUtils.getUserId(request)); + return new PortalRestResponse<>(PortalRestStatusEnum.OK, SUCCESS, null); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "notificationRead failed", e); + return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null); + } + } + + @RequestMapping(value = { + "/portalApi/getNotificationHistory" }, method = RequestMethod.GET, produces = "application/json") + public List<EpNotificationItemVO> getNotificationHistory(Principal principal, HttpServletRequest request, HttpServletResponse response) { + FnUser user = fnUserService.loadUserByUsername(principal.getName()); + return epNotificationItemVOService.getNotificationHistoryVO(user.getId()); + } + + @RequestMapping(value = { "/portalApi/notificationRole/{notificationId}/roles" }, method = { + RequestMethod.GET }, produces = "application/json") + public List<Long> testGetRoles(HttpServletRequest request, @PathVariable("notificationId") Long notificationId) { + List<EpRoleNotification> notifRoles = roleNotificationService.getNotificationRoles(notificationId); + ArrayList<Long> rolesList = new ArrayList<>(); + for (EpRoleNotification notifRole : notifRoles) { + rolesList.add(notifRole.getRoleId().getId()); + } + return rolesList; + } + + @RequestMapping(value = { "/portalApi/getNotificationAppRoles" }, method = { + RequestMethod.GET }, produces = "application/json") + public List<EcompAppRole> getNotificationAppRoles(HttpServletRequest request, HttpServletResponse response) { + List<EcompAppRole> epAppRoleList = null; + try { + epAppRoleList = ecompAppRoleService.getAppRoleList(); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred while performing UserNofiticationController.getNotificationAppRoles. Details: ", + e); + } + return epAppRoleList; + } + + @RequestMapping(value = { + "/portalApi/getMessageRecipients" }, method = RequestMethod.GET, produces = "application/json") + public List<String> getMessageRecipients(@RequestParam("notificationId") Long notificationID) { + return userNotificationService.getMessageRecipients(notificationID); + } + +} diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpNotification.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpNotification.java index a10cc3e3..4da1bd99 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpNotification.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpNotification.java @@ -42,17 +42,26 @@ package org.onap.portal.domain.db.ep; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.ColumnResult; +import javax.persistence.ConstructorResult; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.NamedNativeQueries; +import javax.persistence.NamedNativeQuery; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; +import javax.persistence.SqlResultSetMapping; import javax.persistence.Table; +import javax.persistence.Transient; import javax.validation.constraints.Digits; import javax.validation.constraints.FutureOrPresent; import javax.validation.constraints.NotNull; @@ -64,6 +73,8 @@ 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.transport.EpNotificationItemVO; /* CREATE TABLE `ep_notification` ( @@ -84,6 +95,77 @@ CREATE TABLE `ep_notification` ( ) */ +@NamedNativeQueries({ + @NamedNativeQuery( + name = "EpNotification.getNotifications", + query = "select rowId, notification_ID, is_for_online_users,is_for_all_roles, msg_header, msg_description,msg_source, start_Time, end_time, priority, created_date, creator_ID,notification_hyperlink, active_YN from\n" + + "( \n" + + "select notification_ID, is_for_online_users, is_for_all_roles, msg_header, msg_description, msg_source,start_Time, end_time, priority,created_date, creator_ID,notification_hyperlink,active_YN\n" + + "from\n" + + " (\n" + + " select user_id, notification_id, is_for_online_users, is_for_all_roles, msg_header, msg_description,msg_source,start_Time, end_time, priority, created_date,notification_hyperlink, creator_ID,active_YN\n" + + " from\n" + + " (\n" + + " select a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n" + + " a.msg_header,a.msg_description,a.msg_source,a.start_time,a.end_time,a.priority,a.creator_ID,a.notification_hyperlink,a.created_date,b.role_id,b.recv_user_id \n" + + " from ep_notification a, ep_role_notification b\n" + + " where a.notification_id = b.notification_id\n" + + " and (end_time is null || SYSDATE() <= end_time )\n" + + " and (start_time is null || SYSDATE() >= start_time)\n" + + " and a.is_for_all_roles = 'N'\n" + + " ) a,\n" + + " (\n" + + " select distinct a.user_id, c.role_id, c.app_id, d.APP_NAME\n" + + " from fn_user a, fn_user_role b, fn_role c, fn_app d\n" + + " where COALESCE(c.app_id,1) = d.app_id\n" + + " and a.user_id = b.user_id\n" + + " and a.user_id = :user_id\n" + + " and b.role_id = c.role_id\n" + + " and (d.enabled='Y' or d.app_id=1)\n" + + " )b\n" + + " where\n" + + " (\n" + + " a.role_id = b.role_id\n" + + " )\n" + + " union\n" + + " select :user_id, notification_id, is_for_online_users, is_for_all_roles, msg_header, msg_description,msg_source,start_Time, end_time, priority, created_date,notification_hyperlink, creator_ID,active_YN\n" + + " from\n" + + " (\n" + + " select a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n" + + " a.msg_header,a.msg_description,a.msg_source,a.start_time,a.end_time,a.priority,a.creator_ID,a.created_date, a.notification_hyperlink,b.role_id,b.recv_user_id \n" + + " from ep_notification a, ep_role_notification b\n" + + " where a.notification_id = b.notification_id\n" + + " and (end_time is null || SYSDATE() <= end_time )\n" + + " and (start_time is null || SYSDATE() >= start_time)\n" + + " and a.is_for_all_roles = 'N'\n" + + " ) a\n" + + " where\n" + + " (\n" + + " a.recv_user_id=:user_id\n" + + " )\n" + + " union\n" + + " (\n" + + " select :user_id user_id, notification_id, is_for_online_users, is_for_all_roles, msg_header, msg_description, msg_source,start_Time, end_time, priority, created_date,notification_hyperlink, creator_ID,active_YN\n" + + " from ep_notification a\n" + + " where a.notification_id\n" + + " and (end_time is null || SYSDATE() <= end_time )\n" + + " and (start_time is null || SYSDATE() >= start_time)\n" + + " and a.is_for_all_roles = 'Y'\n" + + " )\n" + + " ) a\n" + + " where\n" + + " active_YN = 'Y'\n" + + " and\n" + + " not exists\n" + + " (\n" + + " select ID,User_ID,notification_ID,is_viewed,updated_time from ep_user_notification m where user_id = :user_id and m.notification_id = a.notification_id and is_viewed = 'Y'\n" + + " )\n" + + " order by priority desc, created_date desc,start_Time desc\n" + + "\n" + + "\n" + + " ) t,\n")} +) + @Table(name = "ep_notification") @NoArgsConstructor @AllArgsConstructor @@ -92,11 +174,10 @@ CREATE TABLE `ep_notification` ( @Entity public class EpNotification implements Serializable { @Id - - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "notification_ID", length = 11, nullable = false) @Digits(integer = 11, fraction = 0) - private Long notificationID; + private Long notificationId; @Column(name = "is_for_online_users", length = 1, columnDefinition = "char(1) default 'N'") @Pattern(regexp = "[YNyn]") @Size(max = 1) @@ -130,13 +211,13 @@ public class EpNotification implements Serializable { private LocalDateTime startTime; @Column(name = "end_time") @FutureOrPresent - private LocalDateTime end_time; + private LocalDateTime endTime; @Column(name = "priority", length = 11) @Digits(integer = 11, fraction = 0) private Long priority; - @Column(name = "creator_ID", length = 11) + @Column(name = "creator_Id", length = 11) @Digits(integer = 11, fraction = 0) - private Long creatorID; + private FnUser creatorId; @Column(name = "created_date") @FutureOrPresent private LocalDateTime createdDate; @@ -144,9 +225,11 @@ public class EpNotification implements Serializable { @Size(max = 512) @SafeHtml private String notificationHyperlink; + @Transient + private List<Long> roleIds; @OneToMany( targetEntity = EpRoleNotification.class, - mappedBy = "notificationID", + mappedBy = "notificationId", cascade = CascadeType.MERGE, fetch = FetchType.LAZY ) diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpRoleNotification.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpRoleNotification.java index 53e48073..95ffbf2c 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpRoleNotification.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpRoleNotification.java @@ -51,6 +51,8 @@ import javax.persistence.Id; import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.validation.Valid; @@ -76,6 +78,16 @@ CREATE TABLE `ep_role_notification` ( ) */ +@NamedQueries({ + @NamedQuery( + name = "EpRoleNotification.getNotificationRoles", + query = "from\n" + + " EpRoleNotification r\n" + + " where\n" + + " r.notificationId.notificationId = :notificationID\n" + ) +}) + @Table(name = "ep_role_notification", indexes = { @Index(name = "ep_notif_recv_user_id_idx", columnList = "recv_user_id"), @Index(name = "fk_ep_role_notif_fn_notif", columnList = "notification_ID"), @@ -88,19 +100,18 @@ CREATE TABLE `ep_role_notification` ( @Entity public class EpRoleNotification implements Serializable { @Id - - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT") @Digits(integer = 11, fraction = 0) private Long id; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @JoinColumn(name = "notification_ID") @Valid - private EpNotification notificationID; + private EpNotification notificationId; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @JoinColumn(name = "role_ID", columnDefinition = "bigint") @Valid - private FnRole roleID; + private FnRole roleId; @Column(name = "recv_user_id", length = 11, columnDefinition = "int(11) DEFAULT NULL") @Digits(integer = 11, fraction = 0) private Long recvUserId; diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserNotification.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserNotification.java index 441eb524..ad3e2fd8 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserNotification.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpUserNotification.java @@ -92,11 +92,10 @@ CREATE TABLE `ep_user_notification` ( @Entity public class EpUserNotification implements Serializable { @Id - - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID", length = 11, nullable = false, columnDefinition = "int(11) AUTO_INCREMENT") @Digits(integer = 11, fraction = 0) - private Integer id; + private Long id; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @JoinColumn(name = "User_ID", columnDefinition = "bigint") @Valid @@ -105,11 +104,8 @@ public class EpUserNotification implements Serializable { @JoinColumn(name = "notification_ID") @Valid private EpNotification notificationId; - @Column(name = "is_viewed", length = 1, columnDefinition = "char(1) default 'N'") - @Pattern(regexp = "[YNyn]") - @Size(max = 1) - @SafeHtml - private String isViewed; + @Column(name = "is_viewed", length = 1) + private Boolean isViewed = false; @Column(name = "updated_time", nullable = false, columnDefinition = "datetime default now()") @NotNull private LocalDateTime updatedTime; diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnRole.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnRole.java index 2c16d00a..6bb13d70 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnRole.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnRole.java @@ -162,7 +162,7 @@ public class FnRole extends Role { private Set<FnRoleFunction> roleFunctions; @OneToMany( targetEntity = EpRoleNotification.class, - mappedBy = "notificationID", + mappedBy = "notificationId", cascade = CascadeType.MERGE, fetch = FetchType.LAZY ) diff --git a/portal-BE/src/main/java/org/onap/portal/service/EcompAppRoleService.java b/portal-BE/src/main/java/org/onap/portal/service/EcompAppRoleService.java new file mode 100644 index 00000000..41291757 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/EcompAppRoleService.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service; + +import java.util.List; +import javax.persistence.EntityManager; +import javax.transaction.Transactional; +import org.onap.portal.domain.dto.ecomp.EcompAppRole; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class EcompAppRoleService { + + private final String notificationAppRoles = + "select a.app_id, a.app_name, b.role_id, b.role_name from\n" + + "(select * from fn_app where app_id = 1) a,\n" + + "(select * from fn_role where app_id is null and active_yn = 'Y' and role_id <> 1) b\n" + + "union\n" + + "select fn_role.app_id,fn_app.app_name, fn_role.role_id ,fn_role.role_name\n" + + "from fn_app, fn_role\n" + + "where fn_role.app_id = fn_app.app_id and fn_app.enabled='Y' and fn_role.active_yn='Y' order by app_name"; + + private final EntityManager entityManager; + + @Autowired + public EcompAppRoleService(EntityManager entityManager) { + this.entityManager = entityManager; + } + + public List<EcompAppRole> getAppRoleList() { + return entityManager.createQuery(notificationAppRoles, EcompAppRole.class).getResultList(); + } +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/EpNotificationItemVOService.java b/portal-BE/src/main/java/org/onap/portal/service/EpNotificationItemVOService.java new file mode 100644 index 00000000..6a282e81 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/EpNotificationItemVOService.java @@ -0,0 +1,186 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service; + +import java.util.List; +import javax.persistence.EntityManager; +import javax.transaction.Transactional; +import org.onap.portal.domain.dto.transport.EpNotificationItemVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class EpNotificationItemVOService { + + private final EntityManager entityManager; + + private final String notificationHistoryVOResult = + "\t\tSELECT\n" + + "\t\t\tnotificationId, isForOnlineUsers, isForAllRoles, msgHeader,\tmsgDescription,msgSource,\n" + + "\t\t\tstartTime, endTime, priority, createdDate,notificationHyperlink,creatorId, loginId,\tactiveYn \n" + + "\t\tFROM\n" + + "\t\t\t(\n" + + "\t\t\t\t\tselect distinct \n" + + "\t\t\t\t\ta.notification_ID AS notificationId, \n" + + "\t\t\t\t\tis_for_online_users AS isForOnlineUsers, \n" + + "\t\t\t\t\tis_for_all_roles AS isForAllRoles, \n" + + "\t\t\t\t\tmsg_header AS msgHeader, \n" + + "\t\t\t\t\tmsg_description AS msgDescription,\n" + + "\t\t\t\t\tmsg_source AS msgSource, \n" + + "\t\t\t\t\tstart_Time AS startTime, \n" + + "\t\t\t\t\tend_time AS endTime, \n" + + "\t\t\t\t\tpriority,\n" + + "\t\t\t\t\tcreated_date AS createdDate, \n" + + "\t\t\t\t\tcreator_ID AS creatorId,\n" + + "\t\t\t\t\tnotification_hyperlink AS notificationHyperlink,\n" + + "\t\t\t\t\tlogin_id AS loginId,\n" + + "\t\t\t\t\tactive_YN AS activeYn, \n" + + "\t\t\t\t\tif (is_viewed is null, 'N', is_viewed)\n" + + "\t\t\tfrom\n" + + "\t\t\t(\n" + + "\t\t\t\tselect \n" + + "\t\t\t\t\tuser_id, login_id,notification_id, is_for_online_users, is_for_all_roles, \n" + + "\t\t\t\t\tmsg_header, msg_description,msg_source, start_Time, end_time, priority, created_date, \n" + + "\t\t\t\t\tcreator_ID,notification_hyperlink,active_YN\n" + + "\t\t\t\tfrom\n" + + "\t\t\t\t(\n" + + "\t\t\t\t\tselect a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n" + + "\t\t\t\t\ta.msg_header,a.msg_description,a.msg_source,a.start_time,a.end_time,a.priority,a.creator_ID,a.notification_hyperlink,a.created_date, \n" + + "\t\t\t\t\t b.role_id,CASE WHEN a.creator_ID IS NOT NULL THEN u.org_user_id\n" + + " \n" + + " ELSE NULL\n" + + " END AS login_id,b.recv_user_id \n" + + "\t\t\t\tfrom ep_notification a, ep_role_notification b,fn_user u\n" + + "\t\t\t\twhere a.notification_id = b.notification_id and (u.user_id=a.creator_ID OR a.creator_ID IS NULL)\n" + + "\t\t\t\tand a.is_for_all_roles = 'N'\n" + + "\t\t\t\tand (\n" + + "\t\t\t\t(start_time is null and end_time is null and a.created_date >= DATE_ADD(curdate(),INTERVAL-31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is not null and end_time is null and start_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is not null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\t)\n" + + "\t\t\t\t) a,\n" + + "\t\t\t\t(\n" + + "\t\t\t\tselect distinct a.user_id, c.role_id, c.app_id, d.APP_NAME\n" + + "\t\t\t\tfrom fn_user a, fn_user_role b, fn_role c, fn_app d\n" + + "\t\t\t\twhere COALESCE(c.app_id,1) = d.app_id\n" + + " \t\tand a.user_id = b.user_id\n" + + "\t\t\t\tand a.user_id = :user_id\n" + + "\t\t\t\tand b.role_id = c.role_id\n" + + " \t\t\tand (d.enabled='Y' or d.app_id=1)\n" + + "\t\t\t\t) b\n" + + "\t\t\t\twhere\n" + + "\t\t\t\t(\n" + + "\t\t\t\ta.role_id = b.role_id\n" + + "\t\t\t\t)\n" + + "\t\t\t\t UNION\n" + + " \t\tselect \n" + + "\t\t\t\t\t:user_id, login_id,notification_id, is_for_online_users, is_for_all_roles, \n" + + "\t\t\t\t\tmsg_header, msg_description,msg_source, start_Time, end_time, priority, created_date, \n" + + "\t\t\t\t\tcreator_ID,notification_hyperlink,active_YN\n" + + "\t\t\t\tfrom\n" + + "\t\t\t\t(\n" + + "\t\t\t\t\tselect a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n" + + "\t\t\t\t\ta.msg_header,a.msg_description,a.msg_source,a.start_time,a.end_time,a.priority,a.creator_ID,a.created_date,a.notification_hyperlink, \n" + + "\t\t\t\t\t b.role_id,CASE WHEN a.creator_ID IS NOT NULL THEN u.org_user_id\n" + + " \n" + + " ELSE NULL\n" + + " END AS login_id,b.recv_user_id \n" + + "\t\t\t\tfrom ep_notification a, ep_role_notification b,fn_user u\n" + + "\t\t\t\twhere a.notification_id = b.notification_id and (u.user_id=a.creator_ID OR a.creator_ID IS NULL)\n" + + "\t\t\t\tand a.is_for_all_roles = 'N'\n" + + "\t\t\t\tand (\n" + + "\t\t\t\t(start_time is null and end_time is null and a.created_date >= DATE_ADD(curdate(),INTERVAL-31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is not null and end_time is null and start_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is not null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\t)\n" + + "\t\t\t\t) a\n" + + "\t\t where\n" + + "\t\t (\n" + + "\t\t a.recv_user_id=:user_id\n" + + "\t\t )\n" + + "\t\t\t\tunion\n" + + "\t\t\t\t(\n" + + "\t\t\t\tselect \n" + + "\t\t\t\t\t:user_id user_id, b.login_id,notification_id, is_for_online_users, is_for_all_roles,\n" + + "\t\t\t\t\tmsg_header, msg_description,msg_source, start_Time, end_time, priority, a.created_date, \n" + + "\t\t\t\t\tcreator_ID, a.notification_hyperlink,a.active_YN\n" + + "\t\t\t\tfrom ep_notification a JOIN fn_user b on b.user_id=a.creator_ID\n" + + "\t\t\t\twhere a.notification_id\n" + + "\t\t\t\tand a.is_for_all_roles = 'Y'\n" + + "\t\t\t\tand (\n" + + "\t\t\t\t(start_time is null and end_time is null and a.created_date >= DATE_ADD(curdate(),INTERVAL-31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is not null and end_time is null and start_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\tor\n" + + "\t\t\t\t(start_time is not null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n" + + "\t\t\t\t)\n" + + "\t\t\t\t)\n" + + "\t\t\t\t) a left outer join (\n" + + "\t\t\t\tselect m.notification_ID, m.is_viewed from ep_user_notification m where user_id = :user_id\n" + + "\t\t\t\t) m\n" + + "\t\t\t\ton a.notification_id = m.notification_ID\n" + + "\t\t\t\twhere\n" + + "\t\t\t\tactive_YN = 'Y'\n" + + "\t\t\t\t\n" + + "\t\t\t\torder by start_Time desc,end_time desc\n" + + "\t\t\t) t,\n" + + " (SELECT @rn /*'*/:=/*'*/ 0) t2 where startTime<=SYSDATE() "; + + @Autowired + public EpNotificationItemVOService(EntityManager entityManager) { + this.entityManager = entityManager; + } + + public List<EpNotificationItemVO> getNotificationHistoryVO(Long id) { + return entityManager.createQuery(notificationHistoryVOResult, EpNotificationItemVO.class).setParameter("user_id", id).getResultList(); + } +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/epNotification/EpNotificationDao.java b/portal-BE/src/main/java/org/onap/portal/service/epNotification/EpNotificationDao.java new file mode 100644 index 00000000..57ea5a09 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/epNotification/EpNotificationDao.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.epNotification; + +import java.util.List; +import org.onap.portal.domain.db.ep.EpNotification; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +@Repository +interface EpNotificationDao extends JpaRepository<EpNotification, Long> { + + @Query + List<EpNotification> getNotifications(@Param("user_id") final Long userId); +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/epNotification/EpNotificationService.java b/portal-BE/src/main/java/org/onap/portal/service/epNotification/EpNotificationService.java new file mode 100644 index 00000000..e4a5c025 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/epNotification/EpNotificationService.java @@ -0,0 +1,139 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.epNotification; + +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import javax.persistence.EntityManager; +import javax.transaction.Transactional; +import org.hibernate.transform.Transformers; +import org.onap.portal.domain.db.ep.EpNotification; +import org.onap.portal.domain.db.ep.EpRoleNotification; +import org.onap.portal.domain.db.fn.FnRole; +import org.onap.portal.domain.dto.transport.EpNotificationItemVO; +import org.onap.portal.service.role.FnRoleService; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class EpNotificationService { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(EpNotificationService.class); + + + private final EpNotificationDao epNotificationDao; + private final FnRoleService fnRoleService; + private final EntityManager entityManager; + + private final String messageRecipients = "select u.org_user_id from ep_notification n join ep_role_notification r on " + + " r.notification_ID=n.notification_ID join fn_user u on u.user_id=r.recv_user_id where n.notification_id=:notificationId\n"; + + @Autowired + public EpNotificationService( + final EpNotificationDao epNotificationDao, + FnRoleService fnRoleService, final EntityManager entityManager) { + this.epNotificationDao = epNotificationDao; + this.fnRoleService = fnRoleService; + this.entityManager = entityManager; + } + + public Optional<EpNotification> getOne(final long notficationId){ + return Optional.of(epNotificationDao.getOne(notficationId)); + } + + public List<EpNotification> getNotifications(final Long userId) { + List<EpNotification> notificationList = epNotificationDao.getNotifications(userId); + for (EpNotification item : notificationList) { + item.setEpRoleNotifications(null); + } + return notificationList; + } + + public List<EpNotificationItemVO> getAdminNotificationVOS(final Long userId) { + return entityManager.createNamedQuery("getAdminNotificationHistoryVO") + .setParameter("user_id", userId).unwrap(org.hibernate.query.NativeQuery.class) + .setResultTransformer(Transformers.aliasToBean( EpNotificationItemVO.class )) + .getResultList(); + } + + + public EpNotification saveNotification(final EpNotification notificationItem) { + + // gather the roles + if (notificationItem.getRoleIds() != null && !notificationItem.getIsForAllRoles().equals("Y")) { + if (notificationItem.getEpRoleNotifications() == null) { + Set<EpRoleNotification> roleSet = new HashSet<>(); + notificationItem.setEpRoleNotifications(roleSet); + } + for (Long roleId : notificationItem.getRoleIds()) { + FnRole role = null; + try { + role = fnRoleService.getById(roleId); + EpRoleNotification roleItem = new EpRoleNotification(); + roleItem.setNotificationId(notificationItem); + roleItem.setRoleId(role); + notificationItem.getEpRoleNotifications().add(roleItem); + }catch (Exception e){ + LOGGER.error(e.getMessage()); + } + } + } + + // for updates fetch roles and then save + if (notificationItem.getNotificationId() != null) { + Optional<EpNotification> updateNotificationItem = Optional.of(epNotificationDao.getOne(notificationItem.getNotificationId())); + updateNotificationItem.ifPresent( + epNotification -> notificationItem.setEpRoleNotifications(epNotification.getEpRoleNotifications())); + } + if (notificationItem.getMsgSource() == null) { + notificationItem.setMsgSource("EP"); + } + return epNotificationDao.saveAndFlush(notificationItem); + } + + public List<String> getMessageRecipients(final Long notificationId) { + return entityManager.createQuery(messageRecipients, String.class).setParameter("notificationId", notificationId).getResultList(); + } +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/epRoleNotification/EpRoleNotificationDao.java b/portal-BE/src/main/java/org/onap/portal/service/epRoleNotification/EpRoleNotificationDao.java new file mode 100644 index 00000000..b1dd19c9 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/epRoleNotification/EpRoleNotificationDao.java @@ -0,0 +1,58 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.epRoleNotification; + +import java.util.List; +import java.util.Optional; +import javax.transaction.Transactional; +import org.onap.portal.domain.db.ep.EpRoleNotification; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +@Repository +@Transactional +interface EpRoleNotificationDao extends JpaRepository<EpRoleNotification, Long> { + + @Query + Optional<List<EpRoleNotification>> getNotificationRoles(@Param("notificationId") long notificationId); +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/epRoleNotification/EpRoleNotificationService.java b/portal-BE/src/main/java/org/onap/portal/service/epRoleNotification/EpRoleNotificationService.java new file mode 100644 index 00000000..9c467095 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/epRoleNotification/EpRoleNotificationService.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.epRoleNotification; + +import java.util.ArrayList; +import java.util.List; +import javax.transaction.Transactional; +import org.onap.portal.domain.db.ep.EpRoleNotification; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class EpRoleNotificationService { + + private final EpRoleNotificationDao epRoleNotificationDao; + + @Autowired + public EpRoleNotificationService( + EpRoleNotificationDao epRoleNotificationDao) { + this.epRoleNotificationDao = epRoleNotificationDao; + } + + public List<EpRoleNotification> getNotificationRoles(final Long notificationId) { + return epRoleNotificationDao.getNotificationRoles(notificationId).orElse(new ArrayList<>()); + } +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/epUserNotification/EpUserNotificationDao.java b/portal-BE/src/main/java/org/onap/portal/service/epUserNotification/EpUserNotificationDao.java new file mode 100644 index 00000000..c59988d0 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/epUserNotification/EpUserNotificationDao.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.epUserNotification; + +import org.onap.portal.domain.db.ep.EpUserNotification; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +@Repository +interface EpUserNotificationDao extends JpaRepository<EpUserNotification, Long> { + +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/epUserNotification/EpUserNotificationService.java b/portal-BE/src/main/java/org/onap/portal/service/epUserNotification/EpUserNotificationService.java new file mode 100644 index 00000000..b2815438 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/epUserNotification/EpUserNotificationService.java @@ -0,0 +1,86 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 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"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.epUserNotification; + +import java.time.LocalDateTime; +import javax.persistence.EntityExistsException; +import javax.transaction.Transactional; +import org.onap.portal.domain.db.ep.EpNotification; +import org.onap.portal.domain.db.ep.EpUserNotification; +import org.onap.portal.domain.db.fn.FnUser; +import org.onap.portal.service.epNotification.EpNotificationService; +import org.onap.portal.service.user.FnUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class EpUserNotificationService { + + private final EpUserNotificationDao epUserNotificationDao; + private final EpNotificationService epNotificationService; + private final FnUserService fnUserService; + + @Autowired + public EpUserNotificationService( + final EpUserNotificationDao epUserNotificationDao, + final EpNotificationService epNotificationService, + final FnUserService fnUserService) { + this.epUserNotificationDao = epUserNotificationDao; + this.epNotificationService = epNotificationService; + this.fnUserService = fnUserService; + } + + public void setNotificationRead(Long notificationId, long userId) { + + EpNotification notification = epNotificationService.getOne(notificationId).orElse(new EpNotification()); + FnUser user = fnUserService.getUser(userId).orElseThrow(EntityExistsException::new); + + EpUserNotification userNotification = new EpUserNotification(); + userNotification.setNotificationId(notification); + userNotification.setUpdatedTime(LocalDateTime.now()); + userNotification.setIsViewed(true); + userNotification.setUserId(user); + + epUserNotificationDao.saveAndFlush(userNotification); + } + +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/menuFunctionalRoles/FnMenuFunctionalRolesService.java b/portal-BE/src/main/java/org/onap/portal/service/menuFunctionalRoles/FnMenuFunctionalRolesService.java index 3a2c62a5..92511dfb 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/menuFunctionalRoles/FnMenuFunctionalRolesService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/menuFunctionalRoles/FnMenuFunctionalRolesService.java @@ -76,4 +76,8 @@ public class FnMenuFunctionalRolesService { public List<FnMenuFunctionalRoles> saveAll(List<FnMenuFunctionalRoles> functionalRoles) { return fnMenuFunctionalRolesDao.saveAll(functionalRoles); } + + public List<FnMenuFunctionalRoles> findAll(){ + return fnMenuFunctionalRolesDao.findAll(); + } } |