private Source<Optional<Instant>, NotUsed> retrieveLastSuccessfulStreamEndAsync() { return Source.fromPublisher(lastSuccessfulSearchSyncCollection.find()) .limit(1) .flatMapConcat(doc -> { final Date date = doc.getDate(FIELD_TIMESTAMP); final Instant timestamp = date.toInstant(); LOGGER.debug("Returning last timestamp of search synchronization: <{}>.", timestamp); return Source.single(Optional.of(timestamp)); }) .orElse(Source.single(Optional.empty())); }
private Source<Optional<Instant>, NotUsed> retrieveLastSuccessfulStreamEndAsync() { return Source.fromPublisher(lastSuccessfulSearchSyncCollection.find()) .limit(1) .flatMapConcat(doc -> { final Date date = doc.getDate(FIELD_TIMESTAMP); final Instant timestamp = date.toInstant(); LOGGER.debug("Returning last timestamp of search synchronization: <{}>.", timestamp); return Source.single(Optional.of(timestamp)); }) .orElse(Source.single(Optional.empty())); }
/** * {@inheritDoc} */ @Override public final Source<ThingMetadata, NotUsed> getThingMetadata(final String thingId) { log.debug("Retrieving Thing Metadata for Thing: <{}>", thingId); final Bson filter = eq(FIELD_ID, thingId); return Source.fromPublisher(collection.find(filter) .projection(Projections.include(FIELD_REVISION, FIELD_POLICY_ID, FIELD_POLICY_REVISION))) .map(mapThingMetadataToModel()) .orElse(defaultThingMetadata()); }
/** * {@inheritDoc} */ @Override public final Source<ThingMetadata, NotUsed> getThingMetadata(final String thingId) { log.debug("Retrieving Thing Metadata for Thing: <{}>", thingId); final Bson filter = eq(FIELD_ID, thingId); return Source.fromPublisher(collection.find(filter) .projection(Projections.include(FIELD_REVISION, FIELD_POLICY_ID, FIELD_POLICY_REVISION))) .map(mapThingMetadataToModel()) .orElse(defaultThingMetadata()); }
@Override public Source<Long, NotUsed> count(final PolicyRestrictedSearchAggregation policyRestrictedSearchAggregation) { checkNotNull(policyRestrictedSearchAggregation, "policy restricted aggregation"); final Source<Document, NotUsed> source = policyRestrictedSearchAggregation.execute(collection, maxQueryTime); return source.map(doc -> doc.get(PersistenceConstants.COUNT_RESULT_NAME)) .map(countResult -> (Number) countResult) .map(Number::longValue) // use Number.longValue() to support both Integer and Long values .orElse(Source.<Long>single(0L)) .mapError(handleMongoExecutionTimeExceededException()) .log("count"); }
@Override public Source<Long, NotUsed> count(final PolicyRestrictedSearchAggregation policyRestrictedSearchAggregation) { checkNotNull(policyRestrictedSearchAggregation, "policy restricted aggregation"); final Source<Document, NotUsed> source = policyRestrictedSearchAggregation.execute(collection, maxQueryTime); return source.map(doc -> doc.get(PersistenceConstants.COUNT_RESULT_NAME)) .map(countResult -> (Number) countResult) .map(Number::longValue) // use Number.longValue() to support both Integer and Long values .orElse(Source.<Long>single(0L)) .mapError(handleMongoExecutionTimeExceededException()) .log("count"); }
.orElse(Source.single(ThingNotAccessibleException.newBuilder("").build())) .filterNot(el -> el instanceof DittoRuntimeException) .map(param -> thingPlainJsonSupplier.apply((Jsonifiable<?>) param))