Change the header to SO
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / openecomp / mso / adapters / sdnc / sdncrest / SNIROResponse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.adapters.sdnc.sdncrest;
21
22 import org.openecomp.mso.adapters.sdnc.impl.Constants;
23 import org.openecomp.mso.logger.MessageEnum;
24 import org.openecomp.mso.logger.MsoAlarmLogger;
25 import org.openecomp.mso.logger.MsoLogger;
26
27 import javax.servlet.http.HttpServletResponse;
28 import javax.ws.rs.*;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31
32 /**
33  * A temporary interface to support notifications from SNIRO to BPMN.
34  * We added this to the SDNC adapter because we didn't have time to
35  * develop a SNIRO adapter in 1702.
36  */
37 @Path("/")
38 public class SNIROResponse {
39         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
40         private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger();
41
42         @POST
43         @Path("/SDNCNotify/SNIROResponse/{correlator}")
44         @Consumes("*/*")
45         @Produces({MediaType.TEXT_PLAIN})
46         public Response serviceNotification(@PathParam("correlator") String correlator, String content) {
47                 LOGGER.info(MessageEnum.RA_RECEIVE_SDNC_NOTIF, content, "SDNC", "SDNCNotify/SNIROResponse");
48
49                 long startTime = System.currentTimeMillis();
50
51                 String bpUrl = SDNCAdapterProperties.getProperty(Constants.BPEL_REST_URL_PROP, null);
52
53                 if (bpUrl == null) {
54                         String error = "Missing configuration for: " + Constants.BPEL_REST_URL_PROP;
55                         LOGGER.error(MessageEnum.RA_SDNC_MISS_CONFIG_PARAM, Constants.BPEL_REST_URL_PROP, "SDNC", "",
56                                 MsoLogger.ErrorCode.DataError, "Missing config param");
57                         ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
58                         return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity(error).build();
59                 }
60
61                 long bpStartTime = System.currentTimeMillis();
62                 BPRestCallback callback = new BPRestCallback();
63                 boolean callbackSuccess = callback.send(bpUrl, "SNIROResponse", correlator, content);
64
65                 if (callbackSuccess) {
66                         LOGGER.recordMetricEvent(bpStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
67                                 "Sent notification", "BPMN", bpUrl, null);
68                         LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
69                 } else {
70                         LOGGER.recordMetricEvent(bpStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
71                                 "Failed to send notification", "BPMN", bpUrl, null);
72                         LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
73                                 "Failed to send notification");
74                 }
75
76                 return Response.status(204).build();
77         }
78 }