summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Mizyn <d.mizyn@samsung.com>2020-01-15 14:13:40 +0100
committerDominik Mizyn <d.mizyn@samsung.com>2020-01-15 14:14:18 +0100
commitcbc896f277fcf24dc52fcd591667e4ede1e9a9ab (patch)
tree08d61ef4e5fbb86cc41e01143a0af48388b4af94
parent1d76d572d920e9c77ca1fb0db35169a90a5ecf3a (diff)
TicketEventVersionController up
TicketEventVersionController up with all needed services Issue-ID: PORTAL-710 Change-Id: I36b832887b06244ec2f69054752a4bd143349a9d Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/TicketEventController.java241
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/TicketEventVersionController.java61
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpNotification.java21
3 files changed, 308 insertions, 15 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/TicketEventController.java b/portal-BE/src/main/java/org/onap/portal/controller/TicketEventController.java
new file mode 100644
index 00000000..1e8945b0
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/controller/TicketEventController.java
@@ -0,0 +1,241 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * 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 com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiOperation;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import org.onap.portal.domain.db.ep.EpNotification;
+import org.onap.portal.domain.db.ep.EpRoleNotification;
+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.logging.aop.EPAuditLog;
+import org.onap.portal.service.epNotification.EpNotificationService;
+import org.onap.portal.service.user.FnUserService;
+import org.onap.portal.utils.EPCommonSystemProperties;
+import org.onap.portal.utils.PortalConstants;
+import org.onap.portal.validation.SecureString;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+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.RestController;
+
+@RestController
+@RequestMapping(PortalConstants.REST_AUX_API)
+@Configuration
+@EnableAspectJAutoProxy
+@EPAuditLog
+public class TicketEventController {
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(TicketEventController.class);
+
+ private static final String EVENT_DATE = "eventDate";
+ private final ObjectMapper objectMapper = new ObjectMapper();
+ private static final ValidatorFactory VALIDATOR_FACTORY = Validation.buildDefaultValidatorFactory();
+
+ private final FnUserService fnUserService;
+ private final EpNotificationService epNotificationService;
+
+ @Autowired
+ public TicketEventController(final FnUserService fnUserService,
+ final EpNotificationService epNotificationService) {
+ this.fnUserService = fnUserService;
+ this.epNotificationService = epNotificationService;
+ }
+
+ @ApiOperation(
+ value = "Accepts messages from external ticketing systems and creates notifications for Portal users.",
+ response = PortalRestResponse.class)
+ @RequestMapping(value = { "/ticketevent" }, method = RequestMethod.POST)
+ public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
+ @RequestBody String ticketEventJson) {
+
+ logger.debug(EELFLoggerDelegate.debugLogger, "Ticket Event notification" + ticketEventJson);
+ PortalRestResponse<String> portalResponse = new PortalRestResponse<>();
+
+ if (ticketEventJson != null) {
+ SecureString secureString = new SecureString(ticketEventJson);
+ Validator validator = VALIDATOR_FACTORY.getValidator();
+
+ Set<ConstraintViolation<SecureString>> constraintViolations = validator.validate(secureString);
+ if (!constraintViolations.isEmpty()) {
+ portalResponse.setStatus(PortalRestStatusEnum.ERROR);
+ portalResponse.setMessage("Data is not valid");
+ return portalResponse;
+ }
+ }
+
+ try {
+ JsonNode ticketEventNotif = objectMapper.readTree(ticketEventJson);
+
+ // Reject request if required fields are missing.
+ String error = validateTicketEventMessage(ticketEventNotif);
+ if (error != null) {
+ portalResponse.setStatus(PortalRestStatusEnum.ERROR);
+ portalResponse.setMessage(error);
+ response.setStatus(400);
+ return portalResponse;
+ }
+
+ EpNotification epItem = new EpNotification();
+ epItem.setCreatedDate(LocalDateTime.now());
+ epItem.setIsForOnlineUsers(true);
+ epItem.setIsForAllRoles(false);
+ epItem.setActiveYn(false);
+
+ JsonNode event = ticketEventNotif.get("event");
+ JsonNode header = event.get("header");
+ JsonNode body = event.get("body");
+ JsonNode application = ticketEventNotif.get("application");
+ epItem.setMsgDescription(body.toString());
+ long eventDate = System.currentTimeMillis();
+ if (body.get(EVENT_DATE) != null) {
+ eventDate = body.get(EVENT_DATE).asLong();
+ }
+ String eventSource = header.get("eventSource").asText();
+ epItem.setMsgSource(eventSource);
+ String ticket = body.get("ticketNum").asText();
+ String hyperlink = this.getNotificationHyperLink(application, ticket, eventSource);
+ if (body.get("notificationHyperlink") != null) {
+ hyperlink = body.get("notificationHyperlink").asText();
+ }
+ epItem.setNotificationHyperlink(hyperlink);
+ epItem.setStartTime(LocalDateTime.now());
+ epItem.setEndTime(epItem.getStartTime().plusDays(30));
+ String severityString = "1";
+ if (body.get("severity") != null) {
+ severityString = (body.get("severity").toString()).substring(1, 2);
+ }
+ Long severity = Long.parseLong(severityString);
+ epItem.setPriority(severity);
+ epItem.setCreatorId(null);
+ JsonNode subscriberInfo = ticketEventNotif.get("SubscriberInfo");
+ JsonNode userList = subscriberInfo.get("UserList");
+ String[] userIds = userList.toString().replace("[", "").replace("]", "").trim().replace("\"", "")
+ .split(",");
+ String assetID = eventSource + ' '
+ + userList.toString().replace("[", "").replace("]", "").trim().replace("\"", "") + ' '
+ + new Date(eventDate);
+ if (body.get("assetID") != null) {
+ assetID = body.get("assetID").asText();
+ }
+ epItem.setMsgHeader(assetID);
+ List<FnUser> users = fnUserService.getUsersByOrgIds(new ArrayList<>(Arrays.asList(userIds)));
+ Set<EpRoleNotification> roles = new HashSet<>();
+ for (String userId : userIds) {
+ EpRoleNotification roleNotifItem = new EpRoleNotification();
+ for (FnUser user : users) {
+ if (user.getOrgUserId().equals(userId)) {
+ roleNotifItem.setRecvUserId(user.getId());
+ roles.add(roleNotifItem);
+ break;
+ }
+ }
+
+ }
+ epItem.setEpRoleNotifications(roles);
+ epNotificationService.saveNotification(epItem);
+
+ portalResponse.setStatus(PortalRestStatusEnum.OK);
+ portalResponse.setMessage("processEventNotification: notification created");
+ portalResponse.setResponse("NotificationId is :" + epItem.getNotificationId());
+ } catch (Exception ex) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Expection in handleRequest", ex);
+ portalResponse.setStatus(PortalRestStatusEnum.ERROR);
+ response.setStatus(400);
+ portalResponse.setMessage(ex.toString());
+ }
+ return portalResponse;
+ }
+
+ private String getNotificationHyperLink(JsonNode application, String ticket, String eventSource) {
+ return (SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_SYSTEM_NOTIFICATION_URL)+ticket);
+ }
+
+ private String validateTicketEventMessage(JsonNode ticketEventNotif) {
+ JsonNode application = ticketEventNotif.get("application");
+ JsonNode event = ticketEventNotif.get("event");
+ JsonNode header = event.get("header");
+ JsonNode eventSource = header.get("eventSource");
+ JsonNode body = event.get("body");
+ JsonNode subscriberInfo = ticketEventNotif.get("SubscriberInfo");
+ JsonNode userList = subscriberInfo.get("UserList");
+
+ if (application == null || application.asText().length() == 0 || "null".equalsIgnoreCase(application.asText()))
+ return "Application is mandatory";
+ if (body == null)
+ return "body is mandatory";
+ if (eventSource == null || eventSource.asText().trim().length() == 0
+ || "null".equalsIgnoreCase(eventSource.asText()))
+ return "Message Source is mandatory";
+ if (userList == null)
+ return "At least one user Id is mandatory";
+ JsonNode eventDate = body.get(EVENT_DATE);
+
+ if (eventDate != null && eventDate.asText().length() == 8)
+ return "EventDate is invalid";
+ String[] userIds = userList.toString().replace("[", "").replace("]", "").trim().replace("\"", "")
+ .split(",");
+ List<FnUser> users = fnUserService.getUsersByOrgIds(new ArrayList<>(Arrays.asList(userIds)));
+ fnUserService.getUsersByOrgIds(new ArrayList<>(Arrays.asList(userIds)));
+ if (users == null || users.isEmpty())
+ return "Invalid Org User ID";
+ return null;
+ }
+
+}
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/TicketEventVersionController.java b/portal-BE/src/main/java/org/onap/portal/controller/TicketEventVersionController.java
new file mode 100644
index 00000000..5524e6ae
--- /dev/null
+++ b/portal-BE/src/main/java/org/onap/portal/controller/TicketEventVersionController.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * 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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.onap.portal.annotation.ApiVersion;
+import org.onap.portal.domain.dto.PortalRestResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.web.bind.annotation.RestController;
+
+@ApiVersion
+@RestController
+@EnableAspectJAutoProxy
+public class TicketEventVersionController {
+
+ @Autowired
+ TicketEventController ticketEventController;
+
+ @ApiVersion(max = "v3", service = "/v3/ticketevent", min = 0, method = "POST")
+ public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
+ String ticketEventJson) throws Exception {
+ return ticketEventController.handleRequest(request, response, ticketEventJson);
+ }
+
+}
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 4da1bd99..8083b24d 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
@@ -178,21 +178,12 @@ public class EpNotification implements Serializable {
@Column(name = "notification_ID", length = 11, nullable = false)
@Digits(integer = 11, fraction = 0)
private Long notificationId;
- @Column(name = "is_for_online_users", length = 1, columnDefinition = "char(1) default 'N'")
- @Pattern(regexp = "[YNyn]")
- @Size(max = 1)
- @SafeHtml
- private String isForOnlineUsers;
- @Column(name = "is_for_all_roles", length = 1, columnDefinition = "char(1) default 'N'")
- @Pattern(regexp = "[YNyn]")
- @Size(max = 1)
- @SafeHtml
- private String isForAllRoles;
- @Column(name = "active_yn", length = 1, columnDefinition = "char(1) default 'Y'")
- @Pattern(regexp = "[YNyn]")
- @Size(max = 1)
- @SafeHtml
- private String activeYn;
+ @Column(name = "is_for_online_users")
+ private Boolean isForOnlineUsers = false;
+ @Column(name = "is_for_all_roles")
+ private Boolean isForAllRoles = false;
+ @Column(name = "active_yn")
+ private Boolean activeYn = true;
@Column(name = "msg_header", length = 100)
@Size(max = 100)
@SafeHtml