2 * ============LICENSE_START=======================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.adapter.netconf.internal;
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;
37 import javax.sql.rowset.CachedRowSet;
38 import java.sql.SQLException;
39 import java.util.ArrayList;
41 public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
43 private final EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
45 private String schema;
47 private DbLibService dbLibService;
50 public void setSchema(String schema) {
55 public void setDbLibService(DbLibService service) {dbLibService = service;}
58 public String retrieveConfigFileName(String xmlID) {
59 String fileContent = "";
61 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
62 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
63 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
65 ArrayList<String> argList = new ArrayList<>();
69 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
71 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
73 } catch (Exception e) {
74 logger.error("Error Accessing Database " + e);
75 throw new DataAccessException(e);
82 public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) {
83 boolean recordFound = false;
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 + " = ?";
90 ArrayList<String> argList = new ArrayList<>();
94 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
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));
101 } catch (SQLException e) {
102 logger.error("Error Accessing Database " + e);
103 throw new DataAccessException(e);
110 public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) {
111 ConnectionDetails connDetails = new ConnectionDetails();
112 if(this.retrieveConnectionDetails(vnfType, connDetails))
114 connectionDetails.setHost(connDetails.getHost());
115 connectionDetails.setPort(connDetails.getPort());
116 connectionDetails.setUsername(connDetails.getUsername());
117 connectionDetails.setPassword(connDetails.getPassword());
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(?,?,?,?)";
131 ArrayList<String> argList = new ArrayList<>();
132 argList.add(instanceId);
133 argList.add(requestId);
134 argList.add(creationDate);
135 argList.add(logText);
138 dbLibService.writeData(queryString, argList, schema);
139 } catch (SQLException e) {
140 logger.error("Logging Device interaction failed - " + queryString);
141 throw new DataAccessException(e);