Java Code Examples for io.micronaut.core.async.publisher.Publishers#map()
The following examples show how to use
io.micronaut.core.async.publisher.Publishers#map() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDeleteOneReactiveInterceptor.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override public Object intercept(RepositoryMethodKey methodKey, MethodInvocationContext<Object, Object> context) { Object[] parameterValues = context.getParameterValues(); if (parameterValues.length == 1) { Class<Object> rootEntity = (Class<Object>) getRequiredRootEntity(context); Object o = parameterValues[0]; if (o != null) { BatchOperation<Object> batchOperation = getBatchOperation(context, rootEntity, Collections.singletonList(o)); Publisher<Number> publisher = Publishers.map(reactiveOperations.deleteAll(batchOperation), n -> convertNumberArgumentIfNecessary(n, context.getReturnType().asArgument()) ); return Publishers.convertPublisher( publisher, context.getReturnType().getType() ); } else { throw new IllegalArgumentException("Entity to delete cannot be null"); } } else { throw new IllegalStateException("Expected exactly one argument"); } }
Example 2
Source File: DefaultUpdateReactiveInterceptor.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public Object intercept(RepositoryMethodKey methodKey, MethodInvocationContext<Object, Object> context) { PreparedQuery<?, Number> preparedQuery = (PreparedQuery<?, Number>) prepareQuery(methodKey, context); ReturnType<Object> returnType = context.getReturnType(); Publisher<Number> publisher = Publishers.map(reactiveOperations.executeUpdate(preparedQuery), n -> convertNumberArgumentIfNecessary(n, returnType.asArgument()) ); return Publishers.convertPublisher(publisher, returnType.getType()); }
Example 3
Source File: DefaultFindOneReactiveInterceptor.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public Object intercept(RepositoryMethodKey methodKey, MethodInvocationContext<Object, Object> context) { PreparedQuery<Object, Object> preparedQuery = (PreparedQuery<Object, Object>) prepareQuery(methodKey, context); Publisher<Object> publisher = reactiveOperations.findOptional(preparedQuery); Argument<Object> returnType = context.getReturnType().asArgument(); Argument<?> type = returnType.getFirstTypeVariable().orElse(Argument.OBJECT_ARGUMENT); Publisher<Object> mappedPublisher = Publishers.map(publisher, o -> { if (!type.getType().isInstance(o)) { return ConversionService.SHARED.convert(o, type) .orElseThrow(() -> new IllegalStateException("Unexpected return type: " + o)); } return o; }); return Publishers.convertPublisher(mappedPublisher, returnType.getType()); }
Example 4
Source File: GraphQLController.java From micronaut-graphql with Apache License 2.0 | 5 votes |
/** * Executes the GraphQL request and returns the serialized {@link GraphQLResponseBody}. * * @param query the GraphQL query * @param operationName the GraphQL operation name * @param variables the GraphQL variables * @param httpRequest the HTTP request * @return the serialized GraphQL response */ private Publisher<String> executeRequest( String query, String operationName, Map<String, Object> variables, HttpRequest httpRequest) { GraphQLInvocationData invocationData = new GraphQLInvocationData(query, operationName, variables); Publisher<ExecutionResult> executionResult = graphQLInvocation.invoke(invocationData, httpRequest); Publisher<GraphQLResponseBody> responseBody = graphQLExecutionResultHandler.handleExecutionResult(executionResult); return Publishers.map(responseBody, graphQLJsonSerializer::serialize); }
Example 5
Source File: DefaultGraphQLExecutionResultHandler.java From micronaut-graphql with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Publisher<GraphQLResponseBody> handleExecutionResult(Publisher<ExecutionResult> executionResultPublisher) { return Publishers.map(executionResultPublisher, executionResult -> new GraphQLResponseBody(executionResult.toSpecification())); }