use of eu.bcvsolutions.idm.core.api.dto.filter.ModifiedFromFilter in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManager method baseCheckDeferredResult.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void baseCheckDeferredResult(DeferredResult<OperationResultDto> deferredResult, LongPollingSubscriber subscriber, ModifiedFromFilter filter, ReadDtoService service, boolean checkCount) {
Assert.notNull(deferredResult, "Deferred result is required to check.");
Assert.notNull(subscriber.getEntityId(), "Subscriber is required to check deferred result.");
LOG.debug("Start baseCheckDeferredResult for deferred-result [{}] and subscriber [{}]", deferredResult, subscriber);
if (checkCount) {
long countOfentities = service.count(filter);
Long lastNumberOfEntities = subscriber.getLastNumberOfEntities();
subscriber.setLastNumberOfEntities(countOfentities);
if (lastNumberOfEntities != null && countOfentities != lastNumberOfEntities) {
// Notify FE -> Some of an entities were changed (refresh must be executed)
deferredResult.setResult(new OperationResultDto(OperationState.RUNNING));
return;
}
}
ZonedDateTime timeStamp = subscriber.getLastTimeStamp();
if (timeStamp == null) {
List<AbstractDto> entities = service.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
if (entities.isEmpty()) {
subscriber.setLastTimeStamp(ZonedDateTime.now());
return;
}
ZonedDateTime lastModified = this.getLastTimeStamp(entities.get(0));
subscriber.setLastTimeStamp(lastModified);
return;
}
// Try to find, if some from not finished entities were changed
// TODO: For search SysSyncLogs the filter by modifiedFrom didn't work properly.
// I didn't found reason why, but I hope using sort by created and modified fields will be works better.
// filter.setModifiedFrom(timeStamp);
List<AbstractDto> changedRequestsFromLastChecks = service.find(filter, PageRequest.of(0, 1, Sort.by(Direction.DESC, AbstractEntity_.created.getName(), AbstractEntity_.modified.getName()))).getContent();
if (!changedRequestsFromLastChecks.isEmpty()) {
AbstractDto changedRequestsFromLastCheck = changedRequestsFromLastChecks.get(0);
ZonedDateTime lastModified = this.getLastTimeStamp(changedRequestsFromLastCheck);
if (lastModified.isAfter(timeStamp)) {
// Notify FE -> Some of the entity was changed (refresh must be executed).
// Notified will be all suspended request for same entity ID!
this.suspendedRequests.stream().filter(request -> request.getEntityId().equals(subscriber.getEntityId())).forEach(request -> {
request.getResult().setResult(new OperationResultDto(OperationState.RUNNING));
});
subscriber.setLastTimeStamp(lastModified);
return;
}
}
// Nothing was changed
}
Aggregations