Merge "Update schema-service dep to 1.6.0"
[aai/gizmo.git] / src / main / java / org / onap / crud / service / GraphEventUpdater.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.crud.service;
22
23 import org.onap.aai.cl.api.Logger;
24 import org.onap.aai.cl.eelf.LoggerFactory;
25 import org.onap.crud.event.GraphEvent;
26 import org.onap.crud.event.envelope.GraphEventEnvelope;
27 import org.onap.crud.logging.CrudServiceMsgs;
28
29
30 public class GraphEventUpdater {
31
32     private static Logger logger = LoggerFactory.getInstance().getLogger(GraphEventUpdater
33         .class.getName());
34
35     private static Logger auditLogger = LoggerFactory.getInstance()
36         .getAuditLogger(GraphEventUpdater.class.getName());
37
38     public void update(String eventAsJson) {
39         try {
40
41             GraphEventEnvelope graphEventEnvelope = GraphEventEnvelope.fromJson(eventAsJson);
42             GraphEvent graphEvent = graphEventEnvelope.getBody();
43             auditLogger.info(CrudServiceMsgs.ASYNC_RESPONSE_CONSUMER_INFO,
44                 "Event received of type: " + graphEvent.getObjectType() + " with key: "
45                     + graphEvent.getObjectKey() + " , transaction-id: "
46                     + graphEvent.getTransactionId() + " , operation: "
47                     + graphEvent.getOperation().toString());
48             logger.info(CrudServiceMsgs.ASYNC_RESPONSE_CONSUMER_INFO,
49                 "Event received of type: " + graphEvent.getObjectType() + " with key: "
50                     + graphEvent.getObjectKey() + " , transaction-id: "
51                     + graphEvent.getTransactionId() + " , operation: "
52                     + graphEvent.getOperation().toString());
53             logger.debug(CrudServiceMsgs.ASYNC_RESPONSE_CONSUMER_INFO,
54                 "Event received with payload:" + eventAsJson);
55
56             if (CrudAsyncGraphEventCache.get(graphEvent.getTransactionId()) != null) {
57                 CrudAsyncGraphEventCache.get(graphEvent.getTransactionId())
58                     .populateGraphEventEnvelope(graphEventEnvelope);
59             } else {
60                 logger.error(CrudServiceMsgs.ASYNC_DATA_SERVICE_ERROR,
61                     "Request timed out. Not sending response for transaction-id: "
62                         + graphEvent.getTransactionId());
63             }
64
65         } catch (Exception e) {
66             logger.error(CrudServiceMsgs.ASYNC_RESPONSE_CONSUMER_ERROR, e.getMessage());
67         }
68     }
69 }