Search in sources :

Example 1 with AssetInfo

use of org.eclipse.kapua.service.datastore.model.AssetInfo in project kapua by eclipse.

the class AssetInfoStoreServiceImpl method find.

@Override
public AssetInfo find(KapuaId scopeId, StorableId id) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(id, "id");
    // 
    // Check Access
    this.checkDataAccess(scopeId, Actions.read);
    AssetInfoQueryImpl q = new AssetInfoQueryImpl();
    q.setLimit(1);
    ArrayList<StorableId> ids = new ArrayList<StorableId>();
    ids.add(id);
    AndPredicateImpl allPredicates = new AndPredicateImpl();
    allPredicates.addPredicate(new IdsPredicateImpl(EsMessageField.ID, ids));
    AssetInfoListResult result = this.query(scopeId, q);
    if (result == null || result.size() == 0)
        return null;
    AssetInfo assetInfo = result.get(0);
    return assetInfo;
}
Also used : StorableId(org.eclipse.kapua.service.datastore.model.StorableId) IdsPredicateImpl(org.eclipse.kapua.service.datastore.internal.model.query.IdsPredicateImpl) AndPredicateImpl(org.eclipse.kapua.service.datastore.internal.model.query.AndPredicateImpl) AssetInfoListResult(org.eclipse.kapua.service.datastore.model.AssetInfoListResult) ArrayList(java.util.ArrayList) AssetInfoQueryImpl(org.eclipse.kapua.service.datastore.internal.model.query.AssetInfoQueryImpl) AssetInfo(org.eclipse.kapua.service.datastore.model.AssetInfo)

Example 2 with AssetInfo

use of org.eclipse.kapua.service.datastore.model.AssetInfo in project kapua by eclipse.

the class EsAssetDAO method query.

// 
// public void deleteByAccount(long start, long end)
// {
// this.deleteByQuery(this.getQueryByAssetAndDate(KapuaTopic.SINGLE_LEVEL_WCARD, true, start, end));
// }
// 
// public void deleteByAsset(String asset, boolean isAnyAsset)
// {
// this.deleteByQuery(this.getQueryByAsset(asset, isAnyAsset));
// }
public AssetInfoListResult query(AssetInfoQuery query) throws UnknownHostException, KapuaException, EsDatastoreException, ParseException {
    AssetInfoQueryImpl localQuery = new AssetInfoQueryImpl();
    localQuery.copy(query);
    // get one plus (if there is one) to later get the next key value
    localQuery.setLimit(query.getLimit() + 1);
    AssetInfoQueryConverter aic = new AssetInfoQueryConverter();
    SearchRequestBuilder builder = aic.toSearchRequestBuilder(esTypeDAO.getIndexName(), esTypeDAO.getTypeName(), query);
    SearchResponse response = builder.get(TimeValue.timeValueMillis(EsUtils.getQueryTimeout()));
    SearchHits searchHits = response.getHits();
    if (searchHits == null || searchHits.getTotalHits() == 0)
        return new AssetInfoListResultImpl();
    int i = 0;
    int searchHitsSize = searchHits.getHits().length;
    List<AssetInfo> assetInfos = new ArrayList<AssetInfo>();
    AssetInfoBuilder assetInfoBuilder = new AssetInfoBuilder();
    for (SearchHit searchHit : searchHits.getHits()) {
        if (i < query.getLimit()) {
            AssetInfo assetInfo = assetInfoBuilder.build(searchHit).getAssetInfo();
            assetInfos.add(assetInfo);
        }
        i++;
    }
    // TODO check equivalence with CX with Pierantonio
    // TODO what is this nextKey
    Object nextKey = null;
    if (searchHits.getTotalHits() > query.getLimit()) {
        nextKey = query.getLimit();
    }
    AssetInfoListResultImpl result = new AssetInfoListResultImpl(nextKey, searchHitsSize);
    result.addAll(assetInfos);
    return result;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) AssetInfoQueryConverter(org.eclipse.kapua.service.datastore.internal.elasticsearch.AssetInfoQueryConverter) ArrayList(java.util.ArrayList) AssetInfoBuilder(org.eclipse.kapua.service.datastore.internal.elasticsearch.AssetInfoBuilder) AssetInfo(org.eclipse.kapua.service.datastore.model.AssetInfo) SearchResponse(org.elasticsearch.action.search.SearchResponse) AssetInfoQueryImpl(org.eclipse.kapua.service.datastore.internal.model.query.AssetInfoQueryImpl) SearchHits(org.elasticsearch.search.SearchHits) AssetInfoListResultImpl(org.eclipse.kapua.service.datastore.internal.model.AssetInfoListResultImpl)

Aggregations

ArrayList (java.util.ArrayList)2 AssetInfoQueryImpl (org.eclipse.kapua.service.datastore.internal.model.query.AssetInfoQueryImpl)2 AssetInfo (org.eclipse.kapua.service.datastore.model.AssetInfo)2 AssetInfoBuilder (org.eclipse.kapua.service.datastore.internal.elasticsearch.AssetInfoBuilder)1 AssetInfoQueryConverter (org.eclipse.kapua.service.datastore.internal.elasticsearch.AssetInfoQueryConverter)1 AssetInfoListResultImpl (org.eclipse.kapua.service.datastore.internal.model.AssetInfoListResultImpl)1 AndPredicateImpl (org.eclipse.kapua.service.datastore.internal.model.query.AndPredicateImpl)1 IdsPredicateImpl (org.eclipse.kapua.service.datastore.internal.model.query.IdsPredicateImpl)1 AssetInfoListResult (org.eclipse.kapua.service.datastore.model.AssetInfoListResult)1 StorableId (org.eclipse.kapua.service.datastore.model.StorableId)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 SearchHit (org.elasticsearch.search.SearchHit)1 SearchHits (org.elasticsearch.search.SearchHits)1