Changed to unmaintained
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / main / java / org / onap / appc / adapter / netconf / internal / NetconfDataAccessServiceImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2019 Ericsson
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.adapter.netconf.internal;
27
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.onap.appc.adapter.netconf.ConnectionDetails;
31 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
32 import org.onap.appc.adapter.netconf.NetconfDataAccessService;
33 import org.onap.appc.adapter.netconf.exception.DataAccessException;
34 import org.onap.appc.adapter.netconf.util.Constants;
35 import org.onap.ccsdk.sli.core.dblib.DbLibService;
36
37 import javax.sql.rowset.CachedRowSet;
38 import java.sql.SQLException;
39 import java.util.ArrayList;
40
41 public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
42
43     private final EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
44
45     private String schema;
46
47     private DbLibService dbLibService;
48
49     @Override
50     public void setSchema(String schema) {
51         this.schema = schema;
52     }
53
54     @Override
55     public void setDbLibService(DbLibService service) {dbLibService = service;}
56
57     @Override
58     public String retrieveConfigFileName(String xmlID) {
59         String fileContent = "";
60
61         String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
62                 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
63                 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
64
65         ArrayList<String> argList = new ArrayList<>();
66         argList.add(xmlID);
67
68         try {
69             final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
70             if (data.first()) {
71                 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
72             }
73         } catch (Exception e) {
74             logger.error("Error Accessing Database " + e);
75             throw new DataAccessException(e);
76         }
77
78         return fileContent;
79     }
80
81     @Override
82     public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) {
83         boolean recordFound = false;
84
85         String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," +
86                 Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
87                 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
88                 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
89
90         ArrayList<String> argList = new ArrayList<>();
91         argList.add(vnfType);
92
93         try {
94             final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
95             if (data.first()) {
96                 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
97                 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
98                 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
99                 recordFound = true;
100             }
101         } catch (SQLException e) {
102             logger.error("Error Accessing Database " + e);
103             throw new DataAccessException(e);
104         }
105
106         return recordFound;
107     }
108
109     @Override
110     public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) {
111         ConnectionDetails connDetails = new ConnectionDetails();
112         if(this.retrieveConnectionDetails(vnfType, connDetails))
113         {
114             connectionDetails.setHost(connDetails.getHost());
115             connectionDetails.setPort(connDetails.getPort());
116             connectionDetails.setUsername(connDetails.getUsername());
117             connectionDetails.setPassword(connDetails.getPassword());
118         }
119         return true;
120     }
121
122     @Override
123     public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) {
124         String queryString = "INSERT INTO " + Constants.DEVICE_INTERFACE_LOG_TABLE_NAME + "(" +
125                 Constants.SERVICE_INSTANCE_ID_FIELD_NAME + "," +
126                 Constants.REQUEST_ID_FIELD_NAME + "," +
127                 Constants.CREATION_DATE_FIELD_NAME + "," +
128                 Constants.LOG_FIELD_NAME + ") ";
129         queryString += "values(?,?,?,?)";
130
131         ArrayList<String> argList = new ArrayList<>();
132         argList.add(instanceId);
133         argList.add(requestId);
134         argList.add(creationDate);
135         argList.add(logText);
136
137         try {
138             dbLibService.writeData(queryString, argList, schema);
139         } catch (SQLException e) {
140             logger.error("Logging Device interaction failed - " + queryString);
141             throw new DataAccessException(e);
142         }
143
144         return true;
145     }
146
147 }