2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.netconf.internal;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import org.onap.appc.adapter.netconf.ConnectionDetails;
29 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
30 import org.onap.appc.adapter.netconf.NetconfDataAccessService;
31 import org.onap.appc.adapter.netconf.exception.DataAccessException;
32 import org.onap.appc.adapter.netconf.util.Constants;
33 import org.onap.ccsdk.sli.core.dblib.DbLibService;
35 import javax.sql.rowset.CachedRowSet;
36 import java.sql.SQLException;
37 import java.util.ArrayList;
39 public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
41 private final EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
43 private String schema;
45 private DbLibService dbLibService;
48 public void setSchema(String schema) {
53 public void setDbLibService(DbLibService service) {dbLibService = service;}
56 public String retrieveConfigFileName(String xmlID) {
57 String fileContent = "";
59 String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
60 "from " + Constants.CONFIGFILES_TABLE_NAME + " " +
61 "where " + Constants.FILE_NAME_TABLE_FIELD_NAME + " = ?";
63 ArrayList<String> argList = new ArrayList<>();
67 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
69 fileContent = data.getString(Constants.FILE_CONTENT_TABLE_FIELD_NAME);
71 } catch (Exception e) {
72 logger.error("Error Accessing Database " + e);
73 throw new DataAccessException(e);
80 public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) {
81 boolean recordFound = false;
83 String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," +
84 Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
85 "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
86 "where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
88 ArrayList<String> argList = new ArrayList<>();
92 final CachedRowSet data = dbLibService.getData(queryString, argList, schema);
94 connectionDetails.setUsername(data.getString(Constants.USER_NAME_TABLE_FIELD_NAME));
95 connectionDetails.setPassword(data.getString(Constants.PASSWORD_TABLE_FIELD_NAME));
96 connectionDetails.setPort(data.getInt(Constants.PORT_NUMBER_TABLE_FIELD_NAME));
99 } catch (SQLException e) {
100 logger.error("Error Accessing Database " + e);
101 throw new DataAccessException(e);
108 public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) {
109 ConnectionDetails connDetails = new ConnectionDetails();
110 if(this.retrieveConnectionDetails(vnfType, connDetails))
112 connectionDetails.setHost(connDetails.getHost());
113 connectionDetails.setPort(connDetails.getPort());
114 connectionDetails.setUsername(connDetails.getUsername());
115 connectionDetails.setPassword(connDetails.getPassword());
121 public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) {
122 String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+
123 Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+
124 Constants.REQUEST_ID_FIELD_NAME+","+
125 Constants.CREATION_DATE_FIELD_NAME+","+
126 Constants.LOG_FIELD_NAME+") ";
127 queryString += "values(?,?,?,?)";
129 ArrayList<String> argList = new ArrayList<>();
130 argList.add(instanceId);
131 argList.add(requestId);
132 argList.add(creationDate);
133 argList.add(logText);
136 dbLibService.writeData(queryString, argList, schema);
137 } catch (SQLException e) {
138 logger.error("Logging Device interaction failed - "+ queryString);
139 throw new DataAccessException(e);