75a0b0764336f4fd435c7b579a675a1ee1484046
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / onap / so / 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  * Modifications Copyright (C) 2018 IBM.
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.so.adapters.sdnc.sdncrest;
25
26 import javax.servlet.http.HttpServletResponse;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.POST;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
34
35 import org.onap.so.adapters.sdnc.impl.Constants;
36 import org.onap.so.logger.MessageEnum;
37
38 import org.onap.so.logger.MsoLogger;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.core.env.Environment;
43 import org.springframework.stereotype.Component;
44
45 /**
46  * A temporary interface to support notifications from SNIRO to BPMN.
47  * We added this to the SDNC adapter because we didn't have time to
48  * develop a SNIRO adapter in 1702.
49  */
50 @Path("/")
51 @Component
52 public class SNIROResponse {
53         private static final Logger logger = LoggerFactory.getLogger(SNIROResponse.class);
54
55         
56         @Autowired
57         private Environment env;
58         
59         @Autowired
60         private BPRestCallback callback;
61
62         @POST
63         @Path("/SDNCNotify/SNIROResponse/{correlator}")
64         @Consumes("*/*")
65         @Produces({MediaType.TEXT_PLAIN})
66         public Response serviceNotification(@PathParam("correlator") String correlator, String content) {
67                 logger.info("{} {} {} {}", MessageEnum.RA_RECEIVE_SDNC_NOTIF.toString(), content, "SDNC",
68                         "SDNCNotify/SNIROResponse");
69
70                 String bpUrl = env.getProperty(Constants.BPEL_REST_URL_PROP, ""); 
71
72                 if (bpUrl == null || ("").equals(bpUrl)) {
73                         String error = "Missing configuration for: " + Constants.BPEL_REST_URL_PROP;
74                         logger.error("{} {} {} {} {}", MessageEnum.RA_SDNC_MISS_CONFIG_PARAM.toString(), Constants.BPEL_REST_URL_PROP,
75                                 "SDNC", MsoLogger.ErrorCode.DataError.getValue(), "Missing config param");
76
77                         return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity(error).build();
78                 }
79                 return Response.status(204).build();
80         }
81 }