com.lightbend.lagom.javadsl.api.ServiceCall Java Examples
The following examples show how to use
com.lightbend.lagom.javadsl.api.ServiceCall.
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: GreetingServiceImpl.java From tutorials with MIT License | 6 votes |
@Override public ServiceCall<NotUsed, String> handleGreetFrom(String user) { return request -> { // Look up the hello world entity for the given ID. PersistentEntityRef<GreetingCommand> ref = persistentEntityRegistry.refFor(GreetingEntity.class, user); CompletableFuture<String> greetingResponse = ref.ask(new ReceivedGreetingCommand(user)) .toCompletableFuture(); CompletableFuture<WeatherStats> todaysWeatherInfo = (CompletableFuture<WeatherStats>) weatherService.weatherStatsForToday().invoke(); try { return CompletableFuture.completedFuture(greetingResponse.get() + " Today's weather stats: " + todaysWeatherInfo.get().getMessage()); } catch (InterruptedException | ExecutionException e) { return CompletableFuture.completedFuture("Sorry Some Error at our end, working on it"); } }; }
Example #2
Source File: PortfolioServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 6 votes |
@Override public ServiceCall<NotUsed, PSequence<PortfolioSummary>> getAllPortfolios() { return request -> { CompletionStage<PSequence<PortfolioSummary>> result = db.selectAll( "SELECT portfolioId, name FROM portfolio_summary;").thenApply(rows -> { List<PortfolioSummary> summary = rows.stream().map(row -> PortfolioSummary.builder() .portfolioId(new PortfolioId(row.getString("portfolioId"))) .name(row.getString("name")) .build()) .collect(Collectors.toList()); return TreePVector.from(summary); }); return result; }; }
Example #3
Source File: PortfolioServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 6 votes |
@Override public ServiceCall<FundsTransfer, Done> processTransfer(PortfolioId portfolioId) { val portfolioRef = portfolioRepository .getRef(portfolioId); return fundsTransfer -> fundsTransfer.visit(new FundsTransfer.Visitor<CompletionStage<Done>>() { @Override public CompletionStage<Done> visit(FundsTransfer.Deposit deposit) { return portfolioRef.ask(new PortfolioCommand.ReceiveFunds(deposit.getFunds())); } @Override public CompletionStage<Done> visit(FundsTransfer.Withdrawl withdrawl) { return portfolioRef.ask(new PortfolioCommand.SendFunds(withdrawl.getFunds())); } @Override public CompletionStage<Done> visit(FundsTransfer.Refund refund) { return portfolioRef.ask(new PortfolioCommand.AcceptRefund(refund.getFunds(), refund.getTransferId())); } }); }
Example #4
Source File: SecurityService.java From lagom-openapi with Apache License 2.0 | 6 votes |
@Operation( responses = { @ApiResponse( description = "test description", content = @Content( mediaType = "application/json", schema = @Schema(implementation = String.class) ) ) }, operationId = "Operation Id 2", description = "description 2" ) @SecurityRequirement( name = "security_key2", scopes = {"write:pets", "generate:pets"} ) ServiceCall<String, NotUsed> test2();
Example #5
Source File: SecurityService.java From lagom-openapi with Apache License 2.0 | 6 votes |
@Operation( responses = { @ApiResponse( description = "test description", content = @Content( mediaType = "application/json", schema = @Schema(implementation = String.class) ) ) }, operationId = "Operation Id", description = "description" ) @SecurityRequirement( name = "security_key", scopes = {"write:pets", "generate:pets"} ) ServiceCall<String, NotUsed> test1();
Example #6
Source File: WireTransferServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 6 votes |
@Override public ServiceCall<NotUsed, PSequence<TransactionSummary>> getAllTransactionsFor(String portfolioId) { return request -> { Predicate<TransactionSummary> predicate = s -> s.source.equals(portfolioId) || s.destination.equals(portfolioId); CompletionStage<PSequence<TransactionSummary>> result = db.selectAll( "SELECT transferId, status, dateTime, source, destination, amount FROM transfer_summary;").thenApply(rows -> { List<TransactionSummary> summary = rows.stream().map(row -> TransactionSummary.builder() .id(row.getString("transferid")) .status(row.getString("status")) .dateTime(row.getString("dateTime")) .source(row.getString("source")) .destination(row.getString("destination")) .amount(row.getString("amount")) .build()) .filter(predicate) .collect(Collectors.toList()); return TreePVector.from(summary); }); return result; }; }
Example #7
Source File: ServersService.java From lagom-openapi with Apache License 2.0 | 6 votes |
@Operation( responses = { @ApiResponse( responseCode = "201", description = "Null response" ) }, servers = { @Server( description = "operation server 1", url = "http://op1", variables = { @ServerVariable(name = "var1", description = "var 1", defaultValue = "1", allowableValues = {"1", "2"}) }) }) @Server( description = "method server 1", url = "http://method1", variables = { @ServerVariable(name = "var1", description = "var 1", defaultValue = "1", allowableValues = {"1", "2"}) }) @Server( description = "method server 2", url = "http://method2" ) ServiceCall<NotUsed, NotUsed> test();
Example #8
Source File: ParameterService.java From lagom-openapi with Apache License 2.0 | 6 votes |
@Operation(parameters = { @Parameter( in = ParameterIn.PATH, name = "id", required = true, description = "parameter description", allowReserved = true, style = ParameterStyle.SIMPLE, schema = @Schema( type = "string", format = "uuid", description = "the generated UUID", accessMode = Schema.AccessMode.READ_ONLY) )} ) ServiceCall<NotUsed, NotUsed> test(String id);
Example #9
Source File: RegistrationServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 6 votes |
/** * Get all registered Cargo * * @return */ @Override public ServiceCall<NotUsed, NotUsed, PSequence<Cargo>> getAllRegistrations() { return (userId, req) -> { CompletionStage<PSequence<Cargo>> result = db.selectAll("SELECT cargoid, name, description, owner, destination FROM cargo") .thenApply(rows -> { List<Cargo> cargos = rows.stream().map(row -> Cargo.of(row.getString("cargoid"), row.getString("name"), row.getString("description"), row.getString("owner"), row.getString("destination"))).collect(Collectors.toList()); return TreePVector.from(cargos); }); return result; }; }
Example #10
Source File: HelloServiceImpl.java From lagom-example with Apache License 2.0 | 5 votes |
@Override public ServiceCall<GreetingMessage, Done> useGreeting(String id) { return request -> { // Look up the hello world entity for the given ID. PersistentEntityRef<HelloCommand> ref = persistentEntityRegistry.refFor(HelloEntity.class, id); // Tell the entity to use the greeting message specified. return ref.ask(new UseGreetingMessage(request.message)); }; }
Example #11
Source File: PetsService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "findById", description = "Returns a user based on a single ID, if the user does not have access to the pet", parameters = { @Parameter( name = "id", description = "ID of pet to fetch", in = PATH, required = true, schema = @Schema(implementation = Long.class) ) }, responses = { @ApiResponse( responseCode = "200", description = "pet response", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Pet.class) ) ), @ApiResponse( description = "unexpected error", content = @Content( mediaType = "application/json", schema = @Schema(implementation = LagomError.class) ) ) } ) ServiceCall<NotUsed, Pet> findBy(Long id);
Example #12
Source File: PetsService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "delete", description = "deletes a single pet based on the ID supplied", parameters = { @Parameter( name = "id", description = "ID of pet to delete", in = PATH, required = true, schema = @Schema(implementation = Long.class) ) }, responses = { @ApiResponse( responseCode = "204", description = "pet deleted" ), @ApiResponse( description = "unexpected error", content = @Content( mediaType = "application/json", schema = @Schema(implementation = LagomError.class) ) ) } ) ServiceCall<NotUsed, NotUsed> delete(Long id);
Example #13
Source File: LinksService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "getUserWithAddress", parameters = @Parameter( description = "User identity", name = "userId", in = QUERY, schema = @Schema(implementation = String.class) ), responses = { @ApiResponse( description = "test description", content = @Content( mediaType = "application/json", schema = @Schema(implementation = User.class) ), links = { @Link( name = "Link", operationId = "getAddress", parameters = @LinkParameter( name = "userId", expression = "$request.query.userId" )) }) } ) ServiceCall<NotUsed, User> test(String userId);
Example #14
Source File: RefSecurityService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "test", summary = "Secured method example", tags = "cases", responses = { @ApiResponse( responseCode = "201", description = "Null response" ) } ) ServiceCall<NotUsed, NotUsed> secured();
Example #15
Source File: RequestBodyService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( summary = "Creates a new user.", requestBody = @RequestBody( content = @Content( mediaType = "application/json", schema = @Schema(implementation = User.class) ) ), responses = { @ApiResponse(responseCode = "201", description = "User created") }) ServiceCall<User, NotUsed> create();
Example #16
Source File: ArrayParameterService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "test", description = "array schema param test", parameters = { @Parameter(in = ParameterIn.QUERY, name = "params", required = true, explode = Explode.TRUE, array = @ArraySchema(maxItems = 10, minItems = 1, schema = @Schema(implementation = String.class), uniqueItems = true ) ), } ) ServiceCall<NotUsed, NotUsed> test(List<String> params);
Example #17
Source File: PetsService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "find", description = "Returns all pets from the system that the user has access to", parameters = { @Parameter( name = "tags", description = "tags to filter by", in = QUERY, style = ParameterStyle.FORM, array = @ArraySchema(schema = @Schema(implementation = String.class)) ), @Parameter( name = "limit", description = "maximum number of results to return", in = QUERY, schema = @Schema(implementation = Integer.class) ) }, responses = { @ApiResponse( responseCode = "200", description = "pet response", content = @Content( mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Pet.class)) ) ), @ApiResponse( description = "unexpected error", content = @Content( mediaType = "application/json", schema = @Schema(implementation = LagomError.class) ) ) } ) ServiceCall<NotUsed, List<Pet>> find(List<String> tags, Optional<Integer> limit);
Example #18
Source File: PortfolioServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, Done> closePortfolio(PortfolioId portfolioId) { return notUsed -> portfolioRepository .getRef(portfolioId) .ask(PortfolioCommand.ClosePortfolio.INSTANCE); }
Example #19
Source File: PortfolioServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, PortfolioView> getPortfolio(PortfolioId portfolioId) { return notUsed -> portfolioRepository .get(portfolioId) .view(); }
Example #20
Source File: PetsService.java From lagom-openapi with Apache License 2.0 | 5 votes |
@Operation( operationId = "create", description = "Creates a new pet in the store. Duplicates are allowed", requestBody = @RequestBody( description = "Pet to add to the store", required = true, content = @Content( mediaType = "application/json", schema = @Schema(implementation = NewPet.class) ) ), responses = { @ApiResponse( responseCode = "200", description = "pet response", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Pet.class) ) ), @ApiResponse( description = "unexpected error", content = @Content( mediaType = "application/json", schema = @Schema(implementation = LagomError.class) ) ) } ) ServiceCall<NewPet, Pet> create();
Example #21
Source File: RegistrationServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
/** * Register Cargo service call * * @return */ @Override public ServiceCall<NotUsed, Cargo, Done> register() { return (id, request) -> { /* Publish received entity into topic named "Topic" */ PubSubRef<Cargo> topic = topics.refFor(TopicId.of(Cargo.class, "topic")); topic.publish(request); log.info("Cargo ID: {}.", request.getId()); /* Look up the Cargo entity for the given ID. */ PersistentEntityRef<RegistrationCommand> ref = persistentEntityRegistry.refFor(CargoEntity.class, request.getId()); /* Tell the entity to use the Cargo information in the request. */ return ref.ask(RegisterCargo.of(request)); }; }
Example #22
Source File: PortfolioServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@Override public ServiceCall<OrderDetails, OrderId> placeOrder(PortfolioId portfolioId) { return orderDetails -> { val orderId = OrderId.newId(); return portfolioRepository .get(portfolioId) .placeOrder(orderId, orderDetails) .thenApply(done -> orderId); }; }
Example #23
Source File: BrokerServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, Optional<OrderSummary>> getOrderSummary(OrderId orderId) { return notUsed -> orderRepository .get(orderId) .getSummary(); }
Example #24
Source File: HelloServiceImpl.java From lagom-example with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, String> hello(String id) { return request -> { // Look up the hello world entity for the given ID. PersistentEntityRef<HelloCommand> ref = persistentEntityRegistry.refFor(HelloEntity.class, id); // Ask the entity the Hello command. return ref.ask(new Hello(id, Optional.empty())); }; }
Example #25
Source File: WireTransferServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@Override public ServiceCall<Transfer, TransferId> transferFunds() { TransferId transferId = TransferId.newId(); return transfer -> transferRepository .get(transferId) .ask(TransferCommand.TransferFunds.builder() .source(transfer.getSourceAccount()) .destination(transfer.getDestinationAccount()) .amount(transfer.getFunds()) .build() ) .thenApply(done -> transferId); }
Example #26
Source File: RegistrationServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
/** * Get all persisted Cargo services call * Websockets capable * * @return * @deprecated */ public ServiceCall<NotUsed, NotUsed, Source<Cargo, ?>> getAllRegistrationsOld() { log.info("Select all cargo ."); return (id, req) -> { Source<Cargo, ?> result = db.select( "SELECT cargoId, name, description, owner, destination FROM cargo;").map(row -> Cargo.of(row.getString("cargoId"), row.getString("name"), row.getString("description"), row.getString("owner"), row.getString("destination"))); return CompletableFuture.completedFuture(result); }; }
Example #27
Source File: WireTransferServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, Source<String, ?>> transferStream() { return request -> { final PubSubRef<String> topic = pubSub.refFor(TopicId.of(String.class, "transfer")); return CompletableFuture.completedFuture(topic.subscriber()); }; }
Example #28
Source File: ShippingServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
@Override public ServiceCall<String, Leg, Done> addLeg() { return (id, request) -> { CompletionStage<Cargo> response = registrationService.getRegistration().invoke(request.getCargoId(), NotUsed.getInstance()); PersistentEntityRef<ShippingCommand> itinerary = persistentEntityRegistry.refFor(ItineraryEntity.class, id); return itinerary.ask(AddLeg.of(request)); }; }
Example #29
Source File: RegistrationServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
/** * Get live registrations service call * * @return */ @Override public ServiceCall<NotUsed, NotUsed, Source<Cargo, ?>> getLiveRegistrations() { return (id, req) -> { PubSubRef<Cargo> topic = topics.refFor(TopicId.of(Cargo.class, "topic")); return CompletableFuture.completedFuture(topic.subscriber()); }; }
Example #30
Source File: ShippingServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, Itinerary, Done> createItinerary() { return (id, request) -> { // Look up the itinerary for the given ID. PersistentEntityRef<ShippingCommand> itinerary = persistentEntityRegistry.refFor(ItineraryEntity.class, request.getId()); // Tell the entity to use the greeting message specified. return itinerary.ask(CreateItinerary.of(request)); }; }