Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / acs / requestprocessor / src / main / java / org / commscope / tr069adapter / acs / requestprocessor / handler / DeviceRPCRequestHandler.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : tr-069-adapter
4  * =================================================================================================
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.
6  * =================================================================================================
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9  * may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ===============LICENSE_END=======================================================================
17  */
18
19
20 package org.commscope.tr069adapter.acs.requestprocessor.handler;
21
22 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.TR069_NBI_REQUEST_CF;
23 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.TR069_NBI_REQUEST_Q;
24
25 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
26 import org.commscope.tr069adapter.acs.common.exception.SessionConcurrentAccessException;
27 import org.commscope.tr069adapter.acs.common.exception.TR069EventProcessingException;
28 import org.commscope.tr069adapter.acs.requestprocessor.impl.TR069RequestProcessEngine;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.slf4j.MDC;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.jms.annotation.JmsListener;
34 import org.springframework.stereotype.Component;
35 import org.springframework.transaction.annotation.Transactional;
36
37 @Component
38 public class DeviceRPCRequestHandler {
39
40   private static final Logger logger = LoggerFactory.getLogger(DeviceRPCRequestHandler.class);
41
42   private static final String CLIENT_STR = "client";
43
44   @Autowired
45   private TR069RequestProcessEngine tr069RequestProcessEngine;
46
47   @JmsListener(destination = TR069_NBI_REQUEST_Q, containerFactory = TR069_NBI_REQUEST_CF)
48   @Transactional(rollbackFor = Exception.class)
49   public void onMessage(DeviceRPCRequest mapperDeviceOperationRequest)
50       throws SessionConcurrentAccessException, TR069EventProcessingException {
51     logger.debug("Received a JMS message from Mapper for TR069 Device RPC operation");
52     try {
53       if (mapperDeviceOperationRequest != null) {
54         MDC.put(CLIENT_STR, mapperDeviceOperationRequest.getDeviceDetails().getDeviceId());
55         logger.debug("Received a TR069 operation request from Mapper with operation ID: {} ",
56             mapperDeviceOperationRequest.getOperationId());
57         tr069RequestProcessEngine.processDeviceRPCRequest(mapperDeviceOperationRequest);
58         logger.debug("Processed a TR069 operation request from Mapper with operation ID: {} ",
59             mapperDeviceOperationRequest.getOperationId());
60
61       }
62     } finally {
63       MDC.remove(CLIENT_STR);
64     }
65     logger.debug("Processed JMS message from Mapper for TR069 Device RPC operation");
66
67   }
68
69 }