1 package org.onap.champ;
3 import java.io.IOException;
4 import java.util.HashMap;
5 import java.util.HashSet;
8 import java.util.Optional;
9 import java.util.Timer;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.ws.rs.Consumes;
13 import javax.ws.rs.DELETE;
14 import javax.ws.rs.GET;
15 import javax.ws.rs.POST;
16 import javax.ws.rs.PUT;
17 import javax.ws.rs.Path;
18 import javax.ws.rs.PathParam;
19 import javax.ws.rs.Produces;
20 import javax.ws.rs.QueryParam;
21 import javax.ws.rs.core.Context;
22 import javax.ws.rs.core.HttpHeaders;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import javax.ws.rs.core.Response.Status;
26 import javax.ws.rs.core.UriInfo;
28 import org.json.JSONException;
29 import org.json.JSONObject;
30 import org.onap.aai.champcore.ChampTransaction;
31 import org.onap.aai.champcore.exceptions.ChampObjectNotExistsException;
32 import org.onap.aai.champcore.exceptions.ChampRelationshipNotExistsException;
33 import org.onap.aai.champcore.exceptions.ChampTransactionException;
34 import org.onap.aai.champcore.exceptions.ChampUnmarshallingException;
35 import org.onap.aai.champcore.model.ChampObject;
36 import org.onap.aai.champcore.model.ChampRelationship;
37 import org.onap.aai.cl.api.Logger;
38 import org.onap.aai.cl.eelf.LoggerFactory;
39 import org.onap.champ.async.ChampAsyncRequestProcessor;
40 import org.onap.champ.entity.ChampObjectDeserializer;
41 import org.onap.champ.entity.ChampObjectSerializer;
42 import org.onap.champ.entity.ChampRelationshipDeserializer;
43 import org.onap.champ.entity.ChampRelationshipSerializer;
44 import org.onap.champ.exception.ChampServiceException;
45 import org.onap.champ.service.ChampDataService;
46 import org.onap.champ.service.logging.ChampMsgs;
47 import org.onap.champ.service.logging.LoggingUtil;
48 import org.onap.champ.util.ChampProperties;
49 import org.onap.champ.util.ChampServiceConstants;
51 import com.fasterxml.jackson.core.JsonProcessingException;
52 import com.fasterxml.jackson.databind.ObjectMapper;
53 import com.fasterxml.jackson.databind.module.SimpleModule;
56 public class ChampRESTAPI {
58 private ObjectMapper mapper;
60 private ChampDataService champDataService;
61 private String TRANSACTION_METHOD = "method";
64 private Logger logger = LoggerFactory.getInstance().getLogger(ChampRESTAPI.class);
65 Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(ChampRESTAPI.class.getName());
66 private static Logger metricsLogger = LoggerFactory.getInstance().getMetricsLogger(ChampRESTAPI.class.getName());
68 public ChampRESTAPI(ChampDataService champDataService, ChampAsyncRequestProcessor champAsyncRequestProcessor) {
69 this.champDataService = champDataService;
71 // Async request handling is optional.
72 if (champAsyncRequestProcessor != null) {
73 timer = new Timer("ChampAsyncRequestProcessor-1");
74 timer.schedule(champAsyncRequestProcessor, champAsyncRequestProcessor.getRequestPollingTimeSeconds(),
75 champAsyncRequestProcessor.getRequestPollingTimeSeconds());
78 mapper = new ObjectMapper();
79 SimpleModule module = new SimpleModule();
80 module.addSerializer(ChampObject.class, new ChampObjectSerializer());
81 module.addDeserializer(ChampObject.class, new ChampObjectDeserializer());
82 module.addSerializer(ChampRelationship.class, new ChampRelationshipSerializer());
83 module.addDeserializer(ChampRelationship.class, new ChampRelationshipDeserializer());
84 mapper.registerModule(module);
89 @Produces(MediaType.TEXT_PLAIN)
90 public Response echo() {
91 return Response.ok().entity("alive").build();
95 @Path("objects/{objectId}")
96 @Produces(MediaType.APPLICATION_JSON)
97 public Response getObject(@PathParam("objectId") String objectId, @QueryParam("transactionId") String tId,
98 @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context HttpServletRequest req) {
99 LoggingUtil.initMdcContext(req, headers);
100 long startTimeInMs = System.currentTimeMillis();
101 logger.info(ChampMsgs.INCOMING_REQUEST, tId, objectId);
103 Response response = null;
104 ChampObject retrieved;
107 ChampTransaction transaction = champDataService.getTransaction(tId);
109 if (tId != null && transaction == null) {
110 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
112 retrieved = champDataService.getObject(objectId, Optional.ofNullable(transaction));
113 if (retrieved == null) {
114 response = Response.status(Status.NOT_FOUND).entity(objectId + " not found").build();
116 response = Response.status(Status.OK).entity(mapper.writeValueAsString(retrieved)).build();
119 } catch (JsonProcessingException e) {
120 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
121 } catch (ChampServiceException ce) {
122 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
124 logger.debug(response.getEntity().toString());
125 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
126 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
133 @Path("objects/{objectId}")
134 public Response deleteObject(@PathParam("objectId") String objectId, @QueryParam("transactionId") String tId,
135 @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context HttpServletRequest req) {
136 LoggingUtil.initMdcContext(req, headers);
137 long startTimeInMs = System.currentTimeMillis();
138 logger.info(ChampMsgs.INCOMING_REQUEST, tId, objectId);
139 ChampObject retrieved;
140 Response response = null;
142 ChampTransaction transaction = champDataService.getTransaction(tId);
144 if (tId != null && transaction == null) {
145 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
147 champDataService.deleteObject(objectId, Optional.ofNullable(transaction));
149 response = Response.status(Status.OK).build();
150 } catch (ChampObjectNotExistsException e) {
151 response = Response.status(Status.NOT_FOUND).entity(objectId + " not found").build();
152 } catch (ChampServiceException ce) {
153 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
154 } catch (ChampTransactionException | ChampUnmarshallingException e) {
155 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
157 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
158 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "DELETE",
159 Long.toString(System.currentTimeMillis() - startTimeInMs));
166 @Consumes(MediaType.APPLICATION_JSON)
167 @Produces(MediaType.APPLICATION_JSON)
168 public Response postObject(String champObj, @QueryParam("transactionId") String tId, @Context HttpHeaders headers,
169 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
170 LoggingUtil.initMdcContext(req, headers);
171 long startTimeInMs = System.currentTimeMillis();
172 logger.info(ChampMsgs.INCOMING_REQUEST, tId, champObj);
173 Response response = null;
175 ChampTransaction transaction = champDataService.getTransaction(tId);
176 if (tId != null && transaction == null) {
177 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
179 ChampObject champObject = mapper.readValue(champObj, ChampObject.class);
181 ChampObject created = champDataService.storeObject(champObject, Optional.ofNullable(transaction));
182 response = Response.status(Status.CREATED).entity(mapper.writeValueAsString(created)).build();
183 } catch (IOException e) {
184 response = Response.status(Status.BAD_REQUEST).entity("Unable to parse the payload").build();
185 } catch (ChampServiceException ce) {
186 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
187 } catch (Exception e) {
188 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
189 LoggingUtil.logInternalError(logger, e);
191 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
192 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "POST",
193 Long.toString(System.currentTimeMillis() - startTimeInMs));
199 @Path("objects/{objectId}")
200 @Consumes(MediaType.APPLICATION_JSON)
201 @Produces(MediaType.APPLICATION_JSON)
202 public Response putObject(@PathParam("objectId") String objectId, String champObj,
203 @QueryParam("transactionId") String tId, @Context HttpHeaders headers, @Context UriInfo uriInfo,
204 @Context HttpServletRequest req) {
205 LoggingUtil.initMdcContext(req, headers);
206 long startTimeInMs = System.currentTimeMillis();
207 logger.info(ChampMsgs.INCOMING_REQUEST, tId, objectId + " " + champObj);
209 Response response = null;
211 ChampTransaction transaction = champDataService.getTransaction(tId);
212 if (tId != null && transaction == null) {
213 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
216 ChampObject co = mapper.readValue(champObj, ChampObject.class);
217 // check if key is present or if it equals the key that is in the URI
218 ChampObject updated = champDataService.replaceObject(co, objectId, Optional.ofNullable(transaction));
220 response = Response.status(Status.OK).entity(mapper.writeValueAsString(updated)).build();
221 } catch (IOException e) {
222 response = Response.status(Status.BAD_REQUEST).entity("Unable to parse the payload").build();
223 } catch (ChampServiceException ce) {
224 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
225 } catch (Exception e) {
226 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
227 LoggingUtil.logInternalError(logger, e);
229 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
230 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "PUT", Long.toString(System.currentTimeMillis() - startTimeInMs));
236 @Path("objects/relationships/{oId}")
237 @Produces(MediaType.APPLICATION_JSON)
238 public Response getEdges(@PathParam("oId") String oId, @QueryParam("transactionId") String tId,
239 @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context HttpServletRequest req) {
240 LoggingUtil.initMdcContext(req, headers);
241 long startTimeInMs = System.currentTimeMillis();
242 List<ChampRelationship> retrieved;
243 Optional<ChampObject> rObject;
244 Response response = null;
245 ChampTransaction transaction = null;
248 retrieved = champDataService.getRelationshipsByObject(oId, Optional.ofNullable(transaction));
249 response = Response.status(Status.OK).entity(mapper.writeValueAsString(retrieved)).build();
250 } catch (JsonProcessingException e) {
251 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
252 } catch (ChampServiceException ce) {
253 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
254 } catch (Exception e) {
255 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
256 LoggingUtil.logInternalError(logger, e);
258 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
259 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
265 @Path("objects/filter/")
266 @Produces(MediaType.APPLICATION_JSON)
267 public Response filterObject(@Context HttpHeaders headers, @Context UriInfo uriInfo,
268 @Context HttpServletRequest req) {
269 LoggingUtil.initMdcContext(req, headers);
270 long startTimeInMs = System.currentTimeMillis();
271 String propertiesKey = ChampProperties.get(ChampServiceConstants.CHAMP_COLLECTION_PROPERTIES_KEY);
272 List<ChampObject> objects;
273 Map<String, Object> filter = new HashMap<>();
275 for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
276 if (!e.getKey().equals(propertiesKey)) {
277 filter.put(e.getKey(), e.getValue().get(0));
281 HashSet<String> properties;
282 if (uriInfo.getQueryParameters().containsKey(propertiesKey)) {
283 properties = new HashSet<>(uriInfo.getQueryParameters().get(propertiesKey));
285 properties = new HashSet<>();
288 Response response = null;
290 objects = champDataService.queryObjects(filter, properties);
291 response = Response.status(Status.OK).type(MediaType.APPLICATION_JSON).entity(mapper.writeValueAsString(objects))
293 } catch (JsonProcessingException e) {
295 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
296 } catch (ChampServiceException e1) {
297 response = Response.status(e1.getHttpStatus()).entity(e1.getMessage()).build();
298 } catch (Exception e) {
299 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
300 LoggingUtil.logInternalError(logger, e);
302 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
303 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
309 @Path("relationships/{rId}")
310 @Produces(MediaType.APPLICATION_JSON)
311 public Response getRelationship(@PathParam("rId") String rId, @QueryParam("transactionId") String tId,
312 @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context HttpServletRequest req) {
313 LoggingUtil.initMdcContext(req, headers);
314 long startTimeInMs = System.currentTimeMillis();
315 logger.info(ChampMsgs.INCOMING_REQUEST, tId, rId);
316 ChampRelationship retrieved;
317 Response response = null;
319 ChampTransaction transaction = champDataService.getTransaction(tId);
321 if (tId != null && transaction == null) {
322 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
324 retrieved = champDataService.getRelationship(rId, Optional.ofNullable(transaction));
325 if (retrieved == null) {
326 response = Response.status(Status.NOT_FOUND).entity(rId + " not found").build();
329 response = Response.status(Status.OK).entity(mapper.writeValueAsString(retrieved)).build();
331 } catch (IOException e) {
332 response = Response.status(Status.BAD_REQUEST).entity("Unable to parse the payload").build();
333 } catch (ChampServiceException ce) {
334 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
335 } catch (Exception e) {
336 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
337 LoggingUtil.logInternalError(logger, e);
339 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
340 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
346 @Path("relationships")
347 @Consumes(MediaType.APPLICATION_JSON)
348 @Produces(MediaType.APPLICATION_JSON)
349 public Response postRelationships(String relationship, @QueryParam("transactionId") String tId,
350 @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context HttpServletRequest req) {
351 LoggingUtil.initMdcContext(req, headers);
352 long startTimeInMs = System.currentTimeMillis();
353 logger.info(ChampMsgs.INCOMING_REQUEST, tId, relationship);
354 Response response = null;
356 ChampTransaction transaction = champDataService.getTransaction(tId);
357 if (tId != null && transaction == null) {
358 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
360 ChampRelationship r = mapper.readValue(relationship, ChampRelationship.class);
362 ChampRelationship created = champDataService.storeRelationship(r, Optional.ofNullable(transaction));
364 response = Response.status(Status.CREATED).entity(mapper.writeValueAsString(created)).build();
365 } catch (IOException e) {
366 response = Response.status(Status.BAD_REQUEST).entity("Unable to parse the payload").build();
367 } catch (ChampServiceException ce) {
368 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
369 } catch (Exception e) {
370 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
371 LoggingUtil.logInternalError(logger, e);
373 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
374 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "POST",
375 Long.toString(System.currentTimeMillis() - startTimeInMs));
381 @Path("relationships/{rId}")
382 @Consumes(MediaType.APPLICATION_JSON)
383 @Produces(MediaType.APPLICATION_JSON)
384 public Response updateRelationship(@PathParam("rId") String rId, String relationship,
385 @QueryParam("transactionId") String tId, @Context HttpHeaders headers, @Context UriInfo uriInfo,
386 @Context HttpServletRequest req) {
387 LoggingUtil.initMdcContext(req, headers);
388 long startTimeInMs = System.currentTimeMillis();
389 logger.info(ChampMsgs.INCOMING_REQUEST, tId, relationship);
391 Response response = null;
393 ChampTransaction transaction = champDataService.getTransaction(tId);
394 if (tId != null && transaction == null) {
395 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
397 ChampRelationship r = mapper.readValue(relationship, ChampRelationship.class);
398 ChampRelationship updated = champDataService.updateRelationship(r, rId, Optional.ofNullable(transaction));
400 response = Response.status(Status.OK).entity(mapper.writeValueAsString(updated)).build();
401 } catch (IOException e) {
402 response = Response.status(Status.BAD_REQUEST).entity("Unable to parse the payload").build();
403 } catch (ChampServiceException ce) {
404 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
405 } catch (Exception e) {
406 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
407 LoggingUtil.logInternalError(logger, e);
409 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
410 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "PUT", Long.toString(System.currentTimeMillis() - startTimeInMs));
416 @Path("relationships/{relationshipId}")
417 public Response deleteRelationship(@PathParam("relationshipId") String relationshipId,
418 @QueryParam("transactionId") String tId, @Context HttpHeaders headers, @Context UriInfo uriInfo,
419 @Context HttpServletRequest req) {
420 LoggingUtil.initMdcContext(req, headers);
421 long startTimeInMs = System.currentTimeMillis();
422 logger.info(ChampMsgs.INCOMING_REQUEST, tId, relationshipId);
424 Response response = null;
426 ChampTransaction transaction = champDataService.getTransaction(tId);
427 if (tId != null && transaction == null) {
428 throw new ChampServiceException("transactionId not found", Status.BAD_REQUEST);
430 champDataService.deleteRelationship(relationshipId, Optional.ofNullable(transaction));
431 response = Response.status(Status.OK).build();
433 } catch (ChampRelationshipNotExistsException e) {
434 response = Response.status(Status.NOT_FOUND).entity(relationshipId + " not found").build();
435 } catch (ChampServiceException ce) {
436 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
437 } catch (ChampTransactionException | ChampUnmarshallingException e) {
438 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
440 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
441 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "DELETE",
442 Long.toString(System.currentTimeMillis() - startTimeInMs));
448 @Path("relationships/filter/")
449 @Produces(MediaType.APPLICATION_JSON)
450 public Response filterMethod(@Context HttpHeaders headers, @Context UriInfo uriInfo,
451 @Context HttpServletRequest req) {
452 LoggingUtil.initMdcContext(req, headers);
453 long startTimeInMs = System.currentTimeMillis();
454 List<ChampRelationship> list;
455 Map<String, Object> filter = new HashMap<>();
456 for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
457 filter.put(e.getKey(), e.getValue().get(0));
459 Response response = null;
461 list = champDataService.queryRelationships(filter);
462 response = Response.status(Status.OK).type(MediaType.APPLICATION_JSON).entity(mapper.writeValueAsString(list))
464 } catch (JsonProcessingException e) {
466 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
467 } catch (ChampServiceException e1) {
468 response = Response.status(e1.getHttpStatus()).entity(e1.getMessage()).build();
469 } catch (Exception e) {
470 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
471 LoggingUtil.logInternalError(logger, e);
473 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
474 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
481 @Produces(MediaType.TEXT_PLAIN)
482 public Response openTransaction(@Context HttpHeaders headers, @Context UriInfo uriInfo,
483 @Context HttpServletRequest req) {
484 LoggingUtil.initMdcContext(req, headers);
485 long startTimeInMs = System.currentTimeMillis();
487 String transaction = champDataService.openTransaction();
490 Response response = Response.status(s).entity(transaction).build();
491 logger.info(ChampMsgs.PROCESS_EVENT, "Opened Transaction with ID: " + transaction, s.toString());
492 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
493 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "POST", Long.toString(System.currentTimeMillis() - startTimeInMs));
498 @Path("transaction/{tId}")
499 public Response getSpecificTransaction(@PathParam("tId") String tId, @Context HttpHeaders headers,
500 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
501 LoggingUtil.initMdcContext(req, headers);
502 long startTimeInMs = System.currentTimeMillis();
504 Response response = null;
505 ChampTransaction transaction = champDataService.getTransaction(tId);
506 if (transaction == null) {
507 response = Response.status(Status.NOT_FOUND).entity("transaction " + tId + " not found").build();
512 response = Response.status(Status.OK).entity(mapper.writeValueAsString(tId + " is OPEN")).build();
513 } catch (JsonProcessingException e) {
514 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
515 } catch (Exception e) {
516 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
517 LoggingUtil.logInternalError(logger, e);
519 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
520 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
526 @Path("transaction/{tId}")
527 @Produces(MediaType.TEXT_PLAIN)
528 @Consumes(MediaType.APPLICATION_JSON)
529 public Response updateTransaction(String t, @PathParam("tId") String tId, @Context HttpHeaders headers,
530 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
531 LoggingUtil.initMdcContext(req, headers);
532 long startTimeInMs = System.currentTimeMillis();
533 logger.info(ChampMsgs.INCOMING_REQUEST, tId, "COMMIT/ROLLBACK");
535 Response response = null;
537 JSONObject jsonObj = new JSONObject(t);
538 String method = jsonObj.getString(this.TRANSACTION_METHOD);
540 if (method.equals("commit")) {
541 champDataService.commitTransaction(tId);
542 response = Response.status(Status.OK).entity("COMMITTED").build();
544 } else if (method.equals("rollback")) {
545 champDataService.rollbackTransaction(tId);
546 response = Response.status(Status.OK).entity("ROLLED BACK").build();
548 response = Response.status(Status.BAD_REQUEST).entity("Invalid Method: " + method).build();
552 } catch (ChampTransactionException e) {
553 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
554 } catch (JSONException e) {
555 response = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
556 } catch (ChampServiceException e) {
557 response = Response.status(e.getHttpStatus()).entity(e.getMessage()).build();
558 } catch (Exception e) {
559 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
560 LoggingUtil.logInternalError(logger, e);
562 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
563 metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "PUT", Long.toString(System.currentTimeMillis() - startTimeInMs));