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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=======================================================================
19 package org.commscope.tr069adapter.acs.nbi.mapper.service;
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.MAPPER_SERVICE_QUALILFIER;
23 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
24 import org.commscope.tr069adapter.acs.common.exception.DeviceOperationException;
25 import org.commscope.tr069adapter.acs.common.exception.MapperServiceException;
26 import org.commscope.tr069adapter.acs.common.mapper.ACSServiceAPI;
27 import org.commscope.tr069adapter.acs.common.utils.ConnectionStatusPOJO;
28 import org.commscope.tr069adapter.acs.common.utils.ErrorCode;
29 import org.commscope.tr069adapter.acs.requestprocessor.dao.DeviceRepository;
30 import org.commscope.tr069adapter.acs.requestprocessor.entity.TR069DeviceEntity;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.annotation.Qualifier;
35 import org.springframework.web.bind.annotation.PostMapping;
36 import org.springframework.web.bind.annotation.RequestBody;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RestController;
41 @RequestMapping("/MapperService")
42 public class MapperRequestRESTService {
44 private static final Logger logger = LoggerFactory.getLogger(MapperRequestRESTService.class);
46 @Qualifier(value = MAPPER_SERVICE_QUALILFIER)
48 ACSServiceAPI acsServiceAPI;
51 private DeviceRepository deviceRepository;
53 @PostMapping("/initiateDeviceOperation")
54 public Long initiateDeviceOperation(@RequestBody DeviceRPCRequest deviceRPCRequest) {
55 logger.debug("Received a Device operation request from Mapper");
56 Long operationId = 0l;
58 operationId = acsServiceAPI.performDeviceOperation(deviceRPCRequest);
60 "Successfully initiated device operation, The operation id for the request is: {}",
62 } catch (MapperServiceException e) {
63 logger.error("An exception occurred while calling the device operation, Reason: {}",
70 @PostMapping("/connectionStatusOperation")
71 public ConnectionStatusPOJO connectionStatusOperation(@RequestBody String deviceId)
72 throws DeviceOperationException {
73 logger.debug("Received a Connection Status operation request from Mapper");
74 ConnectionStatusPOJO connStatusPOJO = new ConnectionStatusPOJO();
76 TR069DeviceEntity tr069DeviceEntity = deviceRepository.findByDeviceId(deviceId);
77 if (tr069DeviceEntity == null) {
78 throw new DeviceOperationException(ErrorCode.DEVICE_NOT_EXISTS, deviceId);
80 connStatusPOJO.setStatus(tr069DeviceEntity.isConnStatus());
81 connStatusPOJO.setLastContactTime(tr069DeviceEntity.getLastUpdatedTime());
82 connStatusPOJO.setLastFailedAttemptTime(tr069DeviceEntity.getLastFailedAttemptTime());
83 connStatusPOJO.setErrorMessage(tr069DeviceEntity.getErrorMsg());
84 logger.info("connectionStatusOperation:: ConnectionStatusPOJO: {}", connStatusPOJO);
85 return connStatusPOJO;
86 } catch (DeviceOperationException doe) {
87 logger.error(doe.getMessage());