1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.service;
24 import java.io.IOException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.core.Context;
33 import org.apache.http.HttpStatus;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.beans.factory.annotation.Qualifier;
38 import org.springframework.stereotype.Component;
40 import com.att.aft.dme2.internal.jettison.json.JSONException;
41 import org.onap.dmaap.dmf.mr.CambriaApiException;
42 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
43 import org.onap.dmaap.dmf.mr.exception.DMaaPResponseCode;
44 import org.onap.dmaap.dmf.mr.exception.ErrorResponse;
45 import org.onap.dmaap.dmf.mr.service.TransactionService;
46 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
47 import com.att.nsa.configs.ConfigDbException;
50 * This class is a CXF REST service
51 * which acts as gateway for DMaaP
53 * @author rajashree.khare
58 public class TransactionRestService {
63 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(TransactionRestService.class);
66 * HttpServletRequest obj
69 private HttpServletRequest request;
72 * HttpServletResponse obj
75 private HttpServletResponse response;
81 @Qualifier("configurationReader")
82 private ConfigurationReader configReader;
85 private TransactionService transactionService;
89 * Returns a list of all the existing Transaction Ids
90 * @throws CambriaApiException
93 * @exception ConfigDbException
94 * @exception IOException
99 public void getAllTransactionObjs() throws CambriaApiException {
101 LOGGER.info("Retrieving list of all transactions.");
103 transactionService.getAllTransactionObjs(getDmaapContext());
105 LOGGER.info("Returning list of all transactions.");
106 } catch (ConfigDbException | IOException e) {
107 LOGGER.error("Error while retrieving list of all transactions: "
108 + e.getMessage(), e);
109 ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
110 DMaaPResponseCode.RETRIEVE_TRANSACTIONS.getResponseCode(),
111 "Error while retrieving list of all transactions:"+e.getMessage());
112 LOGGER.info(errRes.toString());
113 throw new CambriaApiException(errRes);
119 * Returns details of a particular transaction id whose <code>name</code> is
120 * passed as a parameter
122 * @param transactionId
123 * - id of transaction
124 * @throws CambriaApiException
125 * @throws IOException
126 * @exception ConfigDbException
127 * @exception IOException
128 * @exception JSONException
133 @Path("/{transactionId}")
134 public void getTransactionObj(
135 @PathParam("transactionId") String transactionId) throws CambriaApiException {
137 LOGGER.info("Fetching details of Transaction ID : " + transactionId);
140 transactionService.getTransactionObj(getDmaapContext(),
142 } catch (ConfigDbException | JSONException | IOException e) {
143 LOGGER.error("Error while retrieving transaction details for id: "
146 ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
147 DMaaPResponseCode.RETRIEVE_TRANSACTIONS_DETAILS.getResponseCode(),
148 "Error while retrieving transaction details for id: ["
149 + transactionId + "]: " + e.getMessage());
150 LOGGER.info(errRes.toString());
151 throw new CambriaApiException(errRes);
155 LOGGER.info("Returning details of transaction " + transactionId);
160 * This method is used for taking Configuration Object,HttpServletRequest
161 * Object,HttpServletRequest HttpServletResponse Object,HttpServletSession
164 * @return DMaaPContext object from where user can get Configuration
165 * Object,HttpServlet Object
168 private DMaaPContext getDmaapContext() {
169 DMaaPContext dmaapContext = new DMaaPContext();
170 dmaapContext.setConfigReader(configReader);
171 dmaapContext.setRequest(request);
172 dmaapContext.setResponse(response);