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.entity.DatabaseIdGenerator;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper.QueryResult;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey;
42 import org.opendaylight.yangtools.yang.binding.DataObject;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 public class SqlDBReaderWriterPm<T extends DataObject> extends SqlDBReaderWriter<T> {
48 private final Logger LOG = LoggerFactory.getLogger(SqlDBReaderWriterPm.class);
50 private static final String UUID_KEY = "uuid-interface";
51 private static final String NODE_KEY = "node-name";
52 private static final String KEY = "node-name";
54 private static final FilterKey FILTERKEY = new FilterKey(KEY);
56 public SqlDBReaderWriterPm(SqlDBClient dbService, Entity e, String dbSuffix, Class<T> clazz,
57 String controllerId) {
58 super(dbService, e, dbSuffix, clazz, controllerId);
62 * get aggregated list of ltps for filter NODE_KEY
68 public QueryResult<String> getDataLtpList(EntityInput input) throws IOException {
70 SelectQuery query = new SelectQuery(this.tableName, UUID_KEY, this.controllerId).groupBy(UUID_KEY);
71 query.setPagination(input.getPagination());
72 Map<FilterKey, Filter> filter = input.nonnullFilter();
73 if (!filter.containsKey(FILTERKEY)) {
74 String msg = "no node-name in filter found ";
76 throw new IllegalArgumentException(msg);
78 for (Filter f : filter.values()) {
79 query.addFilter(f.getProperty(), f.getFiltervalue());
84 ResultSet data = this.dbService.read(query.toSql());
85 List<String> mappedData = SqlDBMapper.read(data, String.class, UUID_KEY);
86 try { data.close(); } catch (SQLException ignore) { }
87 Map<FilterKey, Filter> inpFilter = input.getFilter();
88 long total = this.count(inpFilter != null ? new ArrayList<>(inpFilter.values()) : null, this.controllerId);
89 return new QueryResult<>(mappedData, query.getPage(), query.getPageSize(), total);
90 } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
91 | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
92 LOG.warn("problem reading ltp list: ", e);
98 * get aggregated devices list
100 * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name')
102 * @throws IOException
104 public QueryResult<String> getDataDeviceList(EntityInput input) throws IOException {
106 SelectQuery query = new SelectQuery(this.tableName, NODE_KEY, this.controllerId).groupBy(NODE_KEY);
107 query.setPagination(input.getPagination());
108 Map<FilterKey, Filter> filter = input.getFilter();
109 if (filter != null) {
110 for (Filter f : filter.values()) {
111 query.addFilter(f.getProperty(), f.getFiltervalue());
116 ResultSet data = this.dbService.read(query.toSql());
117 List<String> mappedData = SqlDBMapper.read(data, String.class, NODE_KEY);
118 try { data.close(); } catch (SQLException ignore) { }
119 Map<FilterKey, Filter> inpFilter = input.getFilter();
120 long total = this.count(inpFilter != null ? new ArrayList<>(inpFilter.values()) : null, this.controllerId);
121 return new QueryResult<>(mappedData, query.getPage(), query.getPageSize(), total);
122 } catch (SQLException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
123 | InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
124 LOG.warn("problem reading device list: ", e);
129 public void write(PmdataEntity pmData) {
130 DateAndTime date = pmData.getTimeStamp();
131 final String id = DatabaseIdGenerator.getPmData15mId(pmData.getNodeName(), pmData.getUuidInterface(),
132 date != null ? date.getValue() : "null");
133 this.updateOrInsert(pmData, id);