2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import java.io.IOException;
26 import java.lang.reflect.InvocationTargetException;
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.util.ArrayList;
30 import java.util.List;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey;
41 import org.opendaylight.yangtools.yang.binding.DataObject;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 public class SqlDBReaderWriterPm<T extends DataObject> extends SqlDBReaderWriter<T> {
47 private final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriterPm.class);
49 private static final String UUID_KEY = "uuid-interface";
50 private static final String NODE_KEY = "node-name";
51 private static final String KEY = "node-name";
53 private static final FilterKey FILTERKEY = new FilterKey(KEY);
55 public SqlDBReaderWriterPm(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz, String dbName,
56 String controllerId) {
57 super(dbService, e, dbSuffix, clazz, dbName, controllerId);
61 * get aggregated list of ltps for filter NODE_KEY
67 public QueryResult<String> getDataLtpList(EntityInput input) throws IOException {
69 SelectQuery query = new SelectQuery(this.tableName, UUID_KEY, this.controllerId).groupBy(UUID_KEY);
70 query.setPagination(input.getPagination());
71 Map<FilterKey, Filter> filter = input.nonnullFilter();
72 if (!filter.containsKey(FILTERKEY)) {
73 String msg = "no node-name in filter found ";
75 throw new IllegalArgumentException(msg);
77 for (Filter f : filter.values()) {
78 query.addFilter(f.getProperty(), f.getFiltervalue());
83 ResultSet data = this.dbService.read(query.toSql());
84 List<String> mappedData = SqlDBMapper.read(data, String.class, UUID_KEY);
85 long total = this.count(input.getFilter() != null ? new ArrayList<>(input.getFilter().values()) : null,
87 return new QueryResult<String>(mappedData, query.getPage(), query.getPageSize(), total);
88 } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
89 | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
90 LOG.warn("problem reading ltp list: ", e);
96 * get aggregated devices list
98 * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name')
100 * @throws IOException
102 public QueryResult<String> getDataDeviceList(EntityInput input) throws IOException {
104 SelectQuery query = new SelectQuery(this.tableName, NODE_KEY, this.controllerId).groupBy(NODE_KEY);
105 query.setPagination(input.getPagination());
106 Map<FilterKey, Filter> filter = input.getFilter();
107 if (filter != null) {
108 for (Filter f : filter.values()) {
109 query.addFilter(f.getProperty(), f.getFiltervalue());
114 ResultSet data = this.dbService.read(query.toSql());
115 List<String> mappedData = SqlDBMapper.read(data, String.class, NODE_KEY);
116 long total = this.count(input.getFilter() != null ? new ArrayList<>(input.getFilter().values()) : null,
118 return new QueryResult<String>(mappedData, query.getPage(), query.getPageSize(), total);
119 } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
120 | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
121 LOG.warn("problem reading device list: ", e);
126 public void write(PmdataEntity pmData) {
127 DateAndTime date = pmData.getTimeStamp();
128 final String id = String.format("%s/%s/%s", pmData.getNodeName(), pmData.getUuidInterface(),
129 date != null ? date.getValue() : "null");
130 this.updateOrInsert(pmData, id);