Java Code Examples for io.vlingo.common.Completes#withSuccess()

The following examples show how to use io.vlingo.common.Completes#withSuccess() . 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: InMemoryStreamReader.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Completes<EntityStream<T>> streamFor(final String streamName, final int fromStreamVersion) {
  int version = fromStreamVersion;
  State<T> snapshot = snapshotsView.get(streamName);
  if (snapshot != null) {
    if (snapshot.dataVersion > version) {
      version = snapshot.dataVersion;
    } else {
      snapshot = null; // reading from beyond snapshot
    }
  }
  final List<BaseEntry<T>> entries = new ArrayList<>();
  final Map<Integer,Integer> versionIndexes = streamIndexesView.get(streamName);
  if (versionIndexes != null) {
    Integer journalIndex = versionIndexes.get(version);

    while (journalIndex != null) {
      final BaseEntry<T> entry = journalView.get(journalIndex);
      entries.add(entry);
      journalIndex = versionIndexes.get(++version);
    }
  }
  return Completes.withSuccess(new EntityStream<>(streamName, version - 1, entries, snapshot));
}
 
Example 2
Source File: ProductResource.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
public Completes<Response> defineWith(final ProductDefinition productDefinition) {
    try {
      final Tuple2<ProductId, Product> product =
              Product.defineWith(
                stage,
                Tenant.fromExisting(productDefinition.tenantId),
                ProductOwner.fromExisting(productDefinition.tenantId, productDefinition.ownerId),
                productDefinition.name,
                productDefinition.description,
                productDefinition.hasDiscussion);
      
        return Completes.withSuccess(Response.of(Created, JsonSerialization.serialized(product._1)));
    } catch (Throwable t) {
        this.stage.world().defaultLogger().error("Failed to create the product", t);
        return Completes.withSuccess(Response.of(InternalServerError));
    }
}
 
Example 3
Source File: OrderResource.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Completes<ObjectResponse<String>> create(final OrderCreateRequest request) {
    final Address orderAddress = addressFactory.uniquePrefixedWith("order-");
    Map<ProductId, Integer> quantityByProductId = new HashMap<>();
    request.quantityByIdOfProduct.forEach((key, value) -> quantityByProductId.put(new ProductId(key), value));


    Order orderActor = stage.actorFor(
            Order.class,
            Definition.has(OrderActor.class,
                    Definition.parameters(orderAddress.idString())),
            orderAddress);

    orderActor.initOrderForUserProducts(request.userId, quantityByProductId);
    return Completes.withSuccess(
            ObjectResponse.of(Created,
                    headers(of(Location, urlLocation(orderAddress.idString()))),
                    ""));
}
 
Example 4
Source File: InMemoryJournalReader.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Completes<String> seekTo(final String id) {
  final String currentId;

  switch (id) {
  case Beginning:
    rewind();
    currentId = readCurrentId();
    break;
  case End:
    end();
    currentId = readCurrentId();
    break;
  case Query:
    currentId = readCurrentId();
    break;
  default:
    to(id);
    currentId = readCurrentId();
    break;
  }

  return Completes.withSuccess(currentId);
}
 
Example 5
Source File: RequestHandlerTest.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void objectResponseMappedToContentType() {
  final Name name = new Name("first", "last");
  final RequestObjectHandlerFake handler = new RequestObjectHandlerFake(Method.GET,
    "/hello",
    () -> Completes.withSuccess(ObjectResponse.of(Ok, name))
  );

  Response response = handler.execute(Request.method(Method.GET), null, logger).await();
  String nameAsJson = JsonSerialization.serialized(name);
  assertResponsesAreEquals(
    Response.of(Ok,
                ResponseHeader.headers(ResponseHeader.ContentType, ContentMediaType.Json().toString()),
                nameAsJson),
    response);
}
 
Example 6
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public <ET extends Entry<?>> Completes<JournalReader<ET>> journalReader(final String name) {
  JournalReader<?> reader = journalReaders.get(name);
  if (reader == null) {
    reader = new InMemoryJournalReader(journal, name);
    journalReaders.put(name, reader);
  }
  return Completes.withSuccess((JournalReader<ET>) reader);
}
 
Example 7
Source File: UserResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> register(final UserData userData) {
  final Address userAddress = addressFactory.uniquePrefixedWith("u-");

  final User.UserState userState =
    User.from(
      userAddress.idString(),
      Name.from(userData.nameData.given, userData.nameData.family),
      Contact.from(userData.contactData.emailAddress, userData.contactData.telephoneNumber),
      Security.from(userData.publicSecurityToken));

  stage.actorFor(User.class, Definition.has(UserEntity.class, Definition.parameters(userState)), userAddress);

  return Completes.withSuccess(Response.of(Created, headers(of(Location, userLocation(userState.id))), serialized(UserData.from(userState))));
}
 
Example 8
Source File: ProfileResourceFluent.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> query(final String userId) {
  final Profile.State profileState = repository.profileOf(userId);
  if (profileState.doesNotExist()) {
    return Completes.withSuccess(Response.of(NotFound, profileLocation(userId)));
  } else {
    return Completes.withSuccess(Response.of(Ok, serialized(ProfileData.from(profileState))));
  }
}
 
Example 9
Source File: UserResourceFluent.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> register(final UserData userData) {
  final Address userAddress = ServerBootstrap.instance.world.addressFactory().uniquePrefixedWith("u-"); // stage().world().addressFactory().uniquePrefixedWith("u-");
  final User.State userState =
          User.from(
                  userAddress.idString(),
                  Name.from(userData.nameData.given, userData.nameData.family),
                  Contact.from(userData.contactData.emailAddress, userData.contactData.telephoneNumber));

  stage.actorFor(User.class, Definition.has(UserActor.class, Definition.parameters(userState)), userAddress);

  repository.save(userState);

  return Completes.withSuccess(Response.of(Created, headers(of(Location, userLocation(userState.id))), serialized(UserData.from(userState))));
}
 
Example 10
Source File: FluentTestResource.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> queryRes(final String resId) {
  final Data data = entities.get(resId);

  return Completes.withSuccess(data == null ?
          Response.of(NotFound) :
          Response.of(Ok, serialized(data)));
}
 
Example 11
Source File: CartResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<ObjectResponse<String>> create(final UserId userId) {
    final Address cartAddress = addressFactory.uniquePrefixedWith("cart-");
    final Cart cartActor = stage.actorFor(
            Cart.class,
            Definition.has(CartActor.class, Definition.parameters(cartAddress.idString())),
            cartAddress);

    cartActor.createEmptyCartFor(userId);

    final Headers<ResponseHeader> headers = headers(of(Location, urlLocation(cartAddress.idString())));
    return Completes.withSuccess(ObjectResponse.of(Created, headers, ""));
}
 
Example 12
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Completes<StreamReader<T>> streamReader(final String name) {
  StreamReader<T> reader = streamReaders.get(name);
  if (reader == null) {
    reader = new InMemoryStreamReader(journal, streamIndexes, snapshots, name);
    streamReaders.put(name, reader);
  }
  return Completes.withSuccess(reader);
}
 
Example 13
Source File: OrganizationResource.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Answer the eventual {@code Response} to the GET query of a given Organization.
 * @param OrganizationId the String id of the Organization to query
 * @return {@code Completes<Response>}
 */
public Completes<Response> queryOrganization(final String OrganizationId) {
  world.defaultLogger().debug(getClass().getSimpleName() + ": queryOrganization(\"" + OrganizationId + "\")");
  
  return Completes.withSuccess(Response.of(Ok, OrganizationId));
}
 
Example 14
Source File: AdminResource.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Demonstrate that we can garbage collect
 * @return {@code Completes<Response>}
 */
public Completes<Response> gc() {

  return Completes.withSuccess(Response.of(Ok, String.format("Performed GC %s\n","gc")));
}
 
Example 15
Source File: StateStream.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Completes<Boolean> isSlow() {
  return Completes.withSuccess(false);
}
 
Example 16
Source File: InMemoryJournalReader.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Completes<Long> size() {
  return Completes.withSuccess((long) journalView.size());
}
 
Example 17
Source File: AdminResource.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
/**
  * Demonstrate that we can stop a server.
  * @return {@code Completes<Response>}
  */
 public Completes<Response> close(Integer port) {
//   Bootstrap.bootstrap.server.stop();
   servers.stopServer(port);
   return Completes.withSuccess(Response.of(Ok, String.format("Server on port %s stopping\n",port)));
 }
 
Example 18
Source File: AdminResource.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Demonstrate that we can make a new server.
 * @return {@code Completes<Response>}
 */
public Completes<Response> open(Integer port) {
  servers.produceOrganizationServerAndAddToCache(world,port);
  return Completes.withSuccess(Response.of(Ok, String.format("Opening a web server on port %s\n",port)));
}
 
Example 19
Source File: InMemoryJournalReader.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Completes<String> name() {
  return Completes.withSuccess(name);
}
 
Example 20
Source File: OrganizationResource.java    From vlingo-examples with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer the eventual {@code Response} of defining a new Organization.
 * @return {@code Completes<Response>}
 */
public Completes<Response> info() {

  world.defaultLogger().debug(getClass().getSimpleName() + ": info(): " + port);

  return Completes.withSuccess(Response.of(Ok, String.format("port=%s\n",port)));
}