Skip to content

Commit

Permalink
Fixed "limitExceed" value always false
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeLuise authored and Coduz committed Aug 4, 2021
1 parent 23c2232 commit 2c36ba7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Expand Up @@ -18,6 +18,9 @@
import org.eclipse.kapua.service.datastore.internal.mediator.MessageStoreConfiguration;
import org.eclipse.kapua.service.elasticsearch.client.ElasticsearchClient;
import org.eclipse.kapua.service.elasticsearch.client.exception.ClientUnavailableException;
import org.eclipse.kapua.service.storable.model.Storable;
import org.eclipse.kapua.service.storable.model.StorableListResult;
import org.eclipse.kapua.service.storable.model.query.StorableQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -45,4 +48,11 @@ protected boolean isDatastoreServiceEnabled(KapuaId scopeId) throws Configuratio
protected ElasticsearchClient<?> getElasticsearchClient() throws ClientUnavailableException {
return DatastoreClientFactory.getElasticsearchClient();
}

protected <T extends Storable> void setLimitExceed(StorableQuery query, StorableListResult<T> list) {
int offset = query.getOffset() != null ? query.getOffset() : 0;
if (query.getLimit() != null && list.getTotalCount() > offset + query.getLimit()) {
list.setLimitExceeded(true);
}
}
}
Expand Up @@ -193,7 +193,9 @@ public ChannelInfoListResult query(ChannelInfoQuery query) throws KapuaIllegalAr

String indexName = SchemaUtil.getChannelIndexName(query.getScopeId());
TypeDescriptor typeDescriptor = new TypeDescriptor(indexName, ChannelInfoSchema.CHANNEL_TYPE_NAME);
return new ChannelInfoListResultImpl(getElasticsearchClient().query(typeDescriptor, query, ChannelInfo.class));
ChannelInfoListResult result = new ChannelInfoListResultImpl(getElasticsearchClient().query(typeDescriptor, query, ChannelInfo.class));
setLimitExceed(query, result);
return result;
}

/**
Expand Down
Expand Up @@ -188,7 +188,9 @@ public ClientInfoListResult query(ClientInfoQuery query) throws KapuaIllegalArgu

String indexName = SchemaUtil.getClientIndexName(query.getScopeId());
TypeDescriptor typeDescriptor = new TypeDescriptor(indexName, ClientInfoSchema.CLIENT_TYPE_NAME);
return new ClientInfoListResultImpl(getElasticsearchClient().query(typeDescriptor, query, ClientInfo.class));
ClientInfoListResultImpl result = new ClientInfoListResultImpl(getElasticsearchClient().query(typeDescriptor, query, ClientInfo.class));
setLimitExceed(query, result);
return result;
}

/**
Expand Down
Expand Up @@ -293,8 +293,7 @@ public MessageListResult query(MessageQuery query)
String dataIndexName = SchemaUtil.getDataIndexName(query.getScopeId());
TypeDescriptor typeDescriptor = new TypeDescriptor(dataIndexName, MessageSchema.MESSAGE_TYPE_NAME);
MessageListResult result = new MessageListResultImpl(getElasticsearchClient().query(typeDescriptor, query, DatastoreMessage.class));
Integer offset = query.getOffset();
result.setLimitExceeded((offset == null ? 0 : offset) + result.getSize() < result.getTotalCount());
setLimitExceed(query, result);
return result;
}

Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.kapua.service.elasticsearch.client.exception.ClientException;
import org.eclipse.kapua.service.elasticsearch.client.model.BulkUpdateRequest;
import org.eclipse.kapua.service.elasticsearch.client.model.BulkUpdateResponse;
import org.eclipse.kapua.service.elasticsearch.client.model.ResultList;
import org.eclipse.kapua.service.elasticsearch.client.model.TypeDescriptor;
import org.eclipse.kapua.service.elasticsearch.client.model.UpdateRequest;
import org.eclipse.kapua.service.elasticsearch.client.model.UpdateResponse;
Expand Down Expand Up @@ -258,8 +257,9 @@ public MetricInfoListResult query(MetricInfoQuery query) throws KapuaIllegalArgu

String indexNme = SchemaUtil.getMetricIndexName(query.getScopeId());
TypeDescriptor typeDescriptor = new TypeDescriptor(indexNme, MetricInfoSchema.METRIC_TYPE_NAME);
ResultList<MetricInfo> result = getElasticsearchClient().query(typeDescriptor, query, MetricInfo.class);
return new MetricInfoListResultImpl(result);
MetricInfoListResult result = new MetricInfoListResultImpl(getElasticsearchClient().query(typeDescriptor, query, MetricInfo.class));
setLimitExceed(query, result);
return result;
}

/**
Expand Down

0 comments on commit 2c36ba7

Please sign in to comment.