Changed to unmaintained
[appc.git] / appc-adapters / appc-ssh-adapter / appc-ssh-adapter-sshd / src / main / java / org / onap / appc / adapter / ssh / sshd / SshdDataAccessService.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.ssh.sshd;
27
28 import java.sql.SQLException;
29 import java.util.ArrayList;
30 import javax.sql.rowset.CachedRowSet;
31 import org.onap.appc.adapter.ssh.Constants;
32 import org.onap.appc.adapter.ssh.SshConnectionDetails;
33 import org.onap.appc.adapter.ssh.SshDataAccessException;
34 import org.onap.appc.adapter.ssh.SshDataAccessService;
35 import org.onap.ccsdk.sli.core.dblib.DbLibService;
36
37 public class SshdDataAccessService implements SshDataAccessService {
38
39     private String schema = Constants.NETCONF_SCHEMA;
40     private DbLibService dbLibService;
41
42     @Override
43     public void setSchema(String schema) {
44         this.schema = schema;
45     }
46
47     public String getSchema() {
48         return this.schema;
49     }
50
51     @Override
52     public void setDbLibService(DbLibService dbLibService) {
53         this.dbLibService = dbLibService;
54     }
55
56     public DbLibService getDbLibService() {
57         return this.dbLibService;
58     }
59
60     @Override
61     public boolean retrieveConnectionDetails(String vnfType, SshConnectionDetails connectionDetails) throws SshDataAccessException {
62
63         boolean recordFound = false;
64
65         String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," +
66                 Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " + "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
67                 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
68
69         ArrayList<String> argList = new ArrayList<>();
70         argList.add(vnfType);
71
72         try {
73
74             final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
75             if (data.first()) {
76                 recordFound = true;
77                 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
78                 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
79                 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
80             }
81
82         } catch (SQLException e) {
83             throw new SshDataAccessException(e);
84         }
85
86         return recordFound;
87     }
88
89     @Override
90     public String retrieveConfigFileName(String xmlID) throws SshDataAccessException {
91         String fileContent;
92
93         String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
94                 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
95                 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
96
97         ArrayList<String> argList = new ArrayList<>();
98         argList.add(xmlID);
99
100         try {
101
102             final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
103             fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
104
105         } catch (SQLException e) {
106             throw new SshDataAccessException(e);
107         }
108
109         return fileContent;
110     }
111
112
113 }