Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / acs / requestprocessor / src / main / java / org / commscope / tr069adapter / acs / requestprocessor / util / TR069NBIUtility.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 package org.commscope.tr069adapter.acs.requestprocessor.util;
20
21 import java.util.Date;
22
23 import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;
24 import org.commscope.tr069adapter.acs.requestprocessor.entity.TR069DeviceEntity;
25
26 public class TR069NBIUtility {
27
28   private TR069NBIUtility() {
29     super();
30   }
31
32   /**
33    * A utility method to convert the DTO to Domain object
34    * 
35    * @param tr069DeviceDetails
36    * @return
37    */
38
39   public static TR069DeviceEntity convertToEntity(TR069DeviceDetails tr069DeviceDetails) {
40     TR069DeviceEntity tr069DeviceEntity = new TR069DeviceEntity();
41     tr069DeviceEntity.setDeviceId(tr069DeviceDetails.getDeviceId());
42     tr069DeviceEntity.setUserName(tr069DeviceDetails.getUsername());
43     tr069DeviceEntity.setPassword(tr069DeviceDetails.getPassword());
44     tr069DeviceEntity.setLastUpdatedTime(new Date());
45     tr069DeviceEntity.setConnStatus(true);
46     tr069DeviceEntity.setErrorMsg(null);
47
48     if (tr069DeviceDetails.getConnectionRequestURL() != null) {
49       tr069DeviceEntity.setConnectionReqURL(tr069DeviceDetails.getConnectionRequestURL());
50     }
51     if (tr069DeviceDetails.getSoftwareVersion() != null) {
52       tr069DeviceEntity.setSwVersion(tr069DeviceDetails.getSoftwareVersion());
53     }
54     if (tr069DeviceDetails.getHardwareVersion() != null) {
55       tr069DeviceEntity.setHwVersion(tr069DeviceDetails.getHardwareVersion());
56     }
57
58     return tr069DeviceEntity;
59   }
60
61   /**
62    * A utility method to convert the Domain object to DTO
63    * 
64    * @param entity
65    * @return
66    */
67   public static TR069DeviceDetails convertToDTO(TR069DeviceEntity entity) {
68     TR069DeviceDetails tr069DeviceDetails = new TR069DeviceDetails();
69
70     tr069DeviceDetails.setDeviceId(entity.getDeviceId());
71     tr069DeviceDetails.setUsername(entity.getUserName());
72     tr069DeviceDetails.setPassword(entity.getPassword());
73     tr069DeviceDetails.setSoftwareVersion(entity.getSwVersion());
74     tr069DeviceDetails.setHardwareVersion(entity.getHwVersion());
75     tr069DeviceDetails.setConnectionRequestURL(entity.getConnectionReqURL());
76
77     return tr069DeviceDetails;
78   }
79
80 }