aef63560df7ea4cda958f28a89b1aa09b571633b
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
19
20 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
21 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
22 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class DataObjectAcessor<T extends DataObject> extends EsDataObjectReaderWriter<T> {
31
32         private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessor.class);
33
34         public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class<T> clazz) throws ClassNotFoundException {
35                 this(dbClient, entity, clazz, true);
36                 LOG.info("Create {}", this.getClass().getName());
37         }
38
39         public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class<T> clazz, boolean idSupported) throws ClassNotFoundException {
40                 super(dbClient, entity, clazz);
41                 if (idSupported) {
42                         setEsIdAttributeName("_id");
43                 }
44         }
45
46         QueryResult<T> getData(EntityInput input) {
47                 long page = QueryByFilter.getPage(input);
48                 long pageSize = QueryByFilter.getPageSize(input);
49         LOG.info("Request: {}", this.getDataTypeName());
50                 QueryBuilder query = QueryByFilter.fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize);
51                 QueryByFilter.setSortOrder(query, input.getSortorder());
52                 SearchResult<T> result = doReadAll(query,query.contains("range"));
53                 return new QueryResult<>(page, pageSize, result);
54         }
55
56 }