b7abe5950103974001f437126c07ef74afc6963a
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
23
24 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
25 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
26 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class DataObjectAcessor<T extends DataObject> extends EsDataObjectReaderWriter<T> {
35
36         private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessor.class);
37
38         public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class<T> clazz) throws ClassNotFoundException {
39                 this(dbClient, entity, clazz, true);
40                 LOG.info("Create {}", this.getClass().getName());
41         }
42
43         public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class<T> clazz, boolean idSupported) throws ClassNotFoundException {
44                 super(dbClient, entity, clazz);
45                 if (idSupported) {
46                         setEsIdAttributeName("_id");
47                 }
48         }
49
50         QueryResult<T> getData(EntityInput input) {
51                 long page = QueryByFilter.getPage(input);
52                 long pageSize = QueryByFilter.getPageSize(input);
53         LOG.info("Request: {}", this.getDataTypeName());
54                 QueryBuilder query = QueryByFilter.fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize);
55                 QueryByFilter.setSortOrder(query, input.getSortorder());
56                 SearchResult<T> result = doReadAll(query,query.contains("range"));
57                 return new QueryResult<>(page, pageSize, result);
58         }
59
60 }