Merge "YANG Model update for A1 Adapter"
[ccsdk/features.git] / sdnr / wt / data-provider / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / dataprovider / data / DataObjectAcessor.java
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.database.EsDataObjectReaderWriter;
24 import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderServiceImpl;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultcurrentListInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultcurrentListOutputBuilder;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class DataObjectAcessor<T extends DataObject> extends EsDataObjectReaderWriter<T> {
34
35         private static final Logger LOG = LoggerFactory.getLogger(DataObjectAcessor.class);
36
37         public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class<T> clazz) throws ClassNotFoundException {
38                 this(dbClient, entity, clazz, true);
39                 LOG.info("Create {}", this.getClass().getName());
40         }
41
42         public DataObjectAcessor(HtDatabaseClient dbClient, Entity entity, Class<T> clazz, boolean idSupported) throws ClassNotFoundException {
43                 super(dbClient, entity, clazz);
44                 if (idSupported)
45                         setEsIdAttributeName("_id");
46         }
47
48         QueryResult<T> getData(EntityInput input) {
49                 long page = QueryByFilter.getPage(input);
50                 long pageSize = QueryByFilter.getPageSize(input);
51         LOG.info("Request: {}", this.getDataTypeName());
52                 QueryBuilder query = QueryByFilter.fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize);
53                 QueryByFilter.setSortOrder(query, input.getSortorder());
54                 SearchResult<T> result = doReadAll(query,query.contains("range"));
55                 return new QueryResult<T>(page, pageSize, result);
56         }
57
58 }