-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.controller;\r
-\r
-import java.util.Arrays;\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.openecomp.portalapp.portal.domain.EPUser;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;\r
-import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;\r
-import org.openecomp.portalapp.portal.service.UserNotificationService;\r
-import org.openecomp.portalapp.portal.transport.EpNotificationItem;\r
-import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;\r
-import org.openecomp.portalapp.portal.utils.PortalConstants;\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.context.annotation.Configuration;\r
-import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
-import org.springframework.web.bind.annotation.RequestBody;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestMethod;\r
-import org.springframework.web.bind.annotation.RestController;\r
-\r
-import com.fasterxml.jackson.databind.JsonNode;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-\r
-import io.swagger.annotations.ApiOperation;\r
-\r
-/**\r
- * Receives messages from the Collaboration Bus (C-BUS) notification and event\r
- * brokering tool. Creates notifications for ECOMP Portal users.\r
- */\r
-@RestController\r
-@RequestMapping(PortalConstants.REST_AUX_API)\r
-@Configuration\r
-@EnableAspectJAutoProxy\r
-@EPAuditLog\r
-public class TicketEventController implements BasicAuthenticationController {\r
-\r
- @Autowired\r
- private UserNotificationService userNotificationService;\r
-\r
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(TicketEventController.class);\r
-\r
- public boolean isAuxRESTfulCall() {\r
- return true;\r
- }\r
-\r
- private final ObjectMapper mapper = new ObjectMapper();\r
-\r
- @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)\r
- @RequestMapping(value = { "/ticketevent" }, method = RequestMethod.POST)\r
- public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,\r
- @RequestBody String ticketEventJson) throws Exception {\r
-\r
- logger.debug(EELFLoggerDelegate.debugLogger, "Ticket Event notification" + ticketEventJson);\r
- PortalRestResponse<String> portalResponse = new PortalRestResponse<>();\r
- try {\r
- JsonNode ticketEventNotif = mapper.readTree(ticketEventJson);\r
-\r
- // Reject request if required fields are missing.\r
- String error = validateTicketEventMessage(ticketEventNotif);\r
- if (error != null) {\r
- portalResponse.setStatus(PortalRestStatusEnum.ERROR);\r
- portalResponse.setMessage(error);\r
- response.setStatus(400);\r
- return portalResponse;\r
- }\r
-\r
- EpNotificationItem epItem = new EpNotificationItem();\r
- epItem.setCreatedDate(new Date());\r
- epItem.setIsForOnlineUsers("Y");\r
- epItem.setIsForAllRoles("N");\r
- epItem.setActiveYn("Y");\r
- //JsonNode application = ticketEventNotif.get("application");\r
- JsonNode event = ticketEventNotif.get("event");\r
- JsonNode header = event.get("header");\r
- JsonNode body = event.get("body");\r
- epItem.setMsgDescription(body.toString());\r
- Long eventDate = body.get("eventDate").asLong();\r
-\r
- String assetID = body.get("assetID").asText();\r
- epItem.setMsgHeader(assetID);\r
- String eventSource = header.get("eventSource").asText();\r
- epItem.setMsgSource(eventSource);\r
- epItem.setStartTime(new Date(eventDate));\r
- Calendar calendar = Calendar.getInstance();\r
- calendar.setTime(epItem.getStartTime());\r
- int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);\r
- calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth + 30);\r
- epItem.setEndTime(calendar.getTime());\r
- String severityString= (body.get("severity").toString()).substring(1, 2);\r
- Long severity=Long.parseLong(severityString);\r
- epItem.setPriority(severity);\r
- epItem.setCreatorId(null);\r
- Set<EpRoleNotificationItem> roles = new HashSet<>();\r
- JsonNode SubscriberInfo = ticketEventNotif.get("SubscriberInfo");\r
- JsonNode userList = SubscriberInfo.get("UserList");\r
- String UserIds[] = userList.toString().replace("[", "").replace("]", "").trim().replace("\"", "")\r
- .split(",");\r
- List<EPUser> users = userNotificationService.getUsersByOrgIds(Arrays.asList(UserIds));\r
- for (String userId : UserIds) {\r
- EpRoleNotificationItem roleNotifItem = new EpRoleNotificationItem();\r
- for (EPUser user : users) {\r
- if (user.getOrgUserId().equals(userId)) {\r
- roleNotifItem.setRecvUserId(user.getId().intValue());\r
- roles.add(roleNotifItem);\r
- break;\r
- }\r
- }\r
-\r
- }\r
- epItem.setRoles(roles);\r
- userNotificationService.saveNotification(epItem);\r
-\r
- portalResponse.setStatus(PortalRestStatusEnum.OK);\r
- portalResponse.setMessage("processEventNotification: notification created");\r
- portalResponse.setResponse("NotificationId is :" + epItem.notificationId);\r
- } catch (Exception ex) {\r
- portalResponse.setStatus(PortalRestStatusEnum.ERROR);\r
- response.setStatus(400);\r
- portalResponse.setMessage(ex.toString());\r
- }\r
- return portalResponse;\r
- }\r
-\r
- /**\r
- * Validates that mandatory fields are present.\r
- * \r
- * @param ticketEventNotif\r
- * @return Error message if a problem is found; null if all is well.\r
- */\r
- private String validateTicketEventMessage(JsonNode ticketEventNotif) {\r
- JsonNode application = ticketEventNotif.get("application");\r
- JsonNode event = ticketEventNotif.get("event");\r
- JsonNode header = event.get("header");\r
- JsonNode body = event.get("body");\r
- JsonNode SubscriberInfo = ticketEventNotif.get("SubscriberInfo");\r
- if (application == null)\r
- return "application is mandatory";\r
- if (body == null)\r
- return "body is mandatory";\r
- if (body.get("assetID") == null)\r
- return "Asset Id is mandatory";\r
- if (body.get("eventDate") == null)\r
- return "Event Date is mandatory";\r
- if (header.get("eventSource") == null)\r
- return "Message Source is mandatory";\r
- if (SubscriberInfo.get("UserList") == null)\r
- return "At least one user Id is mandatory";\r
- return null;\r
- }\r
- \r
-}\r
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright © 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.openecomp.portalapp.portal.controller;
+
+import java.util.Arrays;
+import java.util.Calendar;
+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 org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
+import org.openecomp.portalapp.portal.service.TicketEventService;
+import org.openecomp.portalapp.portal.service.UserNotificationService;
+import org.openecomp.portalapp.portal.transport.EpNotificationItem;
+import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;
+import org.openecomp.portalapp.portal.utils.PortalConstants;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+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;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * Receives messages from the Collaboration Bus (C-BUS) notification and event
+ * brokering tool. Creates notifications for ECOMP Portal users.
+ */
+@RestController
+@RequestMapping(PortalConstants.REST_AUX_API)
+@Configuration
+@EnableAspectJAutoProxy
+@EPAuditLog
+public class TicketEventController implements BasicAuthenticationController {
+
+
+ @Autowired
+ private UserNotificationService userNotificationService;
+
+ @Autowired
+ private TicketEventService ticketEventService;
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(TicketEventController.class);
+
+ public boolean isAuxRESTfulCall() {
+ return true;
+ }
+
+ private final ObjectMapper mapper = new ObjectMapper();
+
+
+
+ @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) throws Exception {
+
+ logger.debug(EELFLoggerDelegate.debugLogger, "Ticket Event notification" + ticketEventJson);
+ PortalRestResponse<String> portalResponse = new PortalRestResponse<>();
+ try {
+ JsonNode ticketEventNotif = mapper.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;
+ }
+
+ EpNotificationItem epItem = new EpNotificationItem();
+ epItem.setCreatedDate(new Date());
+ epItem.setIsForOnlineUsers("Y");
+ epItem.setIsForAllRoles("N");
+ epItem.setActiveYn("Y");
+
+ 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("eventDate") != null) {
+ eventDate = body.get("eventDate").asLong();
+ }
+ String eventSource = header.get("eventSource").asText();
+ epItem.setMsgSource(eventSource);
+ String ticket = body.get("ticketNum").asText();
+ String hyperlink = ticketEventService.getNotificationHyperLink(application, ticket, eventSource);
+ if(body.get("notificationHyperlink")!=null){
+ hyperlink=body.get("notificationHyperlink").asText();
+ }
+ epItem.setNotificationHyperlink(hyperlink);
+ epItem.setStartTime(new Date(eventDate));
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(epItem.getStartTime());
+ int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
+ calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth + 30);
+ epItem.setEndTime(calendar.getTime());
+ 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);
+ Set<EpRoleNotificationItem> roles = new HashSet<>();
+ 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<EPUser> users = userNotificationService.getUsersByOrgIds(Arrays.asList(UserIds));
+ for (String userId : UserIds) {
+ EpRoleNotificationItem roleNotifItem = new EpRoleNotificationItem();
+ for (EPUser user : users) {
+ if (user.getOrgUserId().equals(userId)) {
+ roleNotifItem.setRecvUserId(user.getId().intValue());
+ roles.add(roleNotifItem);
+ break;
+ }
+ }
+
+ }
+ epItem.setRoles(roles);
+ userNotificationService.saveNotification(epItem);
+
+ portalResponse.setStatus(PortalRestStatusEnum.OK);
+ portalResponse.setMessage("processEventNotification: notification created");
+ portalResponse.setResponse("NotificationId is :" + epItem.notificationId);
+ } catch (Exception ex) {
+ portalResponse.setStatus(PortalRestStatusEnum.ERROR);
+ response.setStatus(400);
+ portalResponse.setMessage(ex.toString());
+ }
+ return portalResponse;
+ }
+
+ /**
+ * Validates that mandatory fields are present.
+ *
+ * @param ticketEventNotif
+ * @return Error message if a problem is found; null if all is well.
+ */
+ 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||application.asText().equalsIgnoreCase("null"))
+ return "Application is mandatory";
+ if (body == null)
+ return "body is mandatory";
+ if (eventSource == null||eventSource.asText().trim().length()==0||eventSource.asText().equalsIgnoreCase("null"))
+ return "Message Source is mandatory";
+ if (userList == null)
+ return "At least one user Id is mandatory";
+ JsonNode eventDate=body.get("eventDate");
+
+ if(eventDate!=null&&eventDate.asText().length()==8)
+ return "EventDate is invalid";
+ String UserIds[] = userList.toString().replace("[", "").replace("]", "").trim().replace("\"", "")
+ .split(",");
+ List<EPUser> users = userNotificationService.getUsersByOrgIds(Arrays.asList(UserIds));
+ if(users==null||users.size()==0)
+ return "Invalid Org User ID";
+ return null;
+ }
+
+}