io.dropwizard.jersey.params.UUIDParam Java Examples

The following examples show how to use io.dropwizard.jersey.params.UUIDParam. 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: Search.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@POST
@Path("wwrelations/wwdocuments")
public Response receptionSearch(SearchRequestV2_1 searchRequest) {
  Optional<SearchResult> otherSearch = searchStore.getSearchResult(
          UUID.fromString(searchRequest.getOtherSearchId()));

  LOG.info("Using other search ID: {}", searchRequest.getOtherSearchId());

  if (otherSearch.isPresent()) {
    LOG.info("other search is present");
    UUID uuid = searchStore.add(getDescription("wwrelations", otherSearch.get())
            .get().execute(graphWrapper, searchRequest));
    URI uri = createUri(uuid);

    return Response.created(uri).build();
  }

  return Response.status(Response.Status.BAD_REQUEST)
          .entity(new NotFoundMessage(new UUIDParam(searchRequest.getOtherSearchId()))).build();
}
 
Example #2
Source File: Search.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@GET
@Path("{id}")
/*
 * Use UUIDParam instead of UUID, because we want to be explicit to the user of this API the request is not
 * supported. When UUID is used Jersery returns a '404 Not Found' if the request contains a malformed one. The
 * UUIDParam will return a '400 Bad Request' for malformed UUID's.
 * See: http://www.dropwizard.io/0.9.1/dropwizard-jersey/apidocs/io/dropwizard/jersey/params/AbstractParam.html
 * Or: http://codahale.com/what-makes-jersey-interesting-parameter-classes/
 */
public Response get(@PathParam("id") UUIDParam id,
                    @QueryParam("rows") @DefaultValue("10") int rows,
                    @QueryParam("start") @DefaultValue("0") int start) {
  Optional<SearchResult> searchResult = searchStore.getSearchResult(id.get());
  if (searchResult.isPresent()) {
    return Response.ok(searchResponseFactory.createResponse(searchResult.get(), rows, start)).build();
  }

  return Response
    .status(Response.Status.NOT_FOUND)
    .entity(new NotFoundMessage(id))
    .build();
}
 
Example #3
Source File: AccountResource.java    From event-sourcing-cqrs-examples with MIT License 5 votes vote down vote up
@GET
public Response get(@PathParam("id") UUIDParam accountId) {
  Optional<Account> possibleAccount = accountService.loadAccount(accountId.get());
  if (!possibleAccount.isPresent()) {
    return Response.status(NOT_FOUND).build();
  }
  AccountDto accountDto = toDto(possibleAccount.get());
  return Response.ok(accountDto).build();
}
 
Example #4
Source File: WithdrawalsResource.java    From event-sourcing-cqrs-examples with MIT License 5 votes vote down vote up
@POST
public Response post(@PathParam("id") UUIDParam accountId, @Valid WithdrawalDto withdrawalDto)
    throws AccountNotFoundException, OptimisticLockingException {

  WithdrawAccountCommand command = new WithdrawAccountCommand(accountId.get(),
      withdrawalDto.getAmount());
  try {
    accountService.process(command);
  } catch (NonSufficientFundsException e) {
    return Response.status(BAD_REQUEST).build();
  }
  return Response.noContent().build();
}
 
Example #5
Source File: DepositsResource.java    From event-sourcing-cqrs-examples with MIT License 5 votes vote down vote up
@POST
public Response post(@PathParam("id") UUIDParam accountId, @Valid DepositDto depositDto)
    throws AccountNotFoundException, OptimisticLockingException {

  DepositAccountCommand command = new DepositAccountCommand(accountId.get(),
      depositDto.getAmount());
  accountService.process(command);
  return Response.noContent().build();
}
 
Example #6
Source File: ClientResource.java    From event-sourcing-cqrs-examples with MIT License 5 votes vote down vote up
@GET
public Response get(@PathParam("id") UUIDParam clientId) {
  Optional<Client> possibleClient = clientService.loadClient(clientId.get());
  if (!possibleClient.isPresent()) {
    return Response.status(NOT_FOUND).build();
  }
  ClientDto clientDto = toDto(possibleClient.get());
  return Response.ok(clientDto).build();
}
 
Example #7
Source File: ClientResource.java    From event-sourcing-cqrs-examples with MIT License 5 votes vote down vote up
@PUT
public Response put(@PathParam("id") UUIDParam clientId, @Valid @NotNull ClientDto clientDto) {
  UpdateClientCommand command = new UpdateClientCommand(
      clientId.get(), clientDto.getName(), new Email(clientDto.getEmail()));
  clientService.process(command);
  return Response.noContent().build();
}
 
Example #8
Source File: LegacySingleEntityRedirect.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@GET
public Response singleEntity(@PathParam("collection") String collectionName, @PathParam("id") UUIDParam id,
                             @QueryParam("rev") Integer rev) {
  return Response.status(301)
                 .location(uriHelper.fromResourceUri(SingleEntity.makeUrl(collectionName, id.get(), rev)))
                 .build();
}
 
Example #9
Source File: Graph.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@GET
public Response get(@PathParam("collection") String collectionName, @PathParam("id") UUIDParam id,
                    @QueryParam("depth") int depth, @QueryParam("types") List<String> relationNames) {

  try {
    D3Graph result = d3GraphGeneratorService.get(collectionName, id.get(), relationNames, depth);
    return Response.ok(result).build();
  } catch (NotFoundException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(jsnO("message", jsn("not found"))).build();
  }
}
 
Example #10
Source File: ClientAccountsResource.java    From event-sourcing-cqrs-examples with MIT License 4 votes vote down vote up
@GET
public Response get(@PathParam("id") UUIDParam clientId) {
  List<AccountProjection> accounts = accountsRepository.getAccounts(clientId.get());
  return Response.ok(accounts).build();
}
 
Example #11
Source File: OptionalQueryParamResourceTest.java    From dropwizard-java8 with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/uuid")
public String getUUID(@QueryParam("uuid") Optional<UUIDParam> uuid) {
    return uuid.orElse(new UUIDParam("d5672fa8-326b-40f6-bf71-d9dacf44bcdc")).get().toString();
}
 
Example #12
Source File: OptionalCookieParamResourceTest.java    From dropwizard-java8 with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/uuid")
public String getUUID(@CookieParam("uuid") Optional<UUIDParam> uuid) {
    return uuid.orElse(new UUIDParam("d5672fa8-326b-40f6-bf71-d9dacf44bcdc")).get().toString();
}
 
Example #13
Source File: OptionalFormParamResourceTest.java    From dropwizard-java8 with Apache License 2.0 4 votes vote down vote up
@POST
@Path("/uuid")
public String getUUID(@FormParam("uuid") Optional<UUIDParam> uuid) {
    return uuid.orElse(new UUIDParam("d5672fa8-326b-40f6-bf71-d9dacf44bcdc")).get().toString();
}
 
Example #14
Source File: OptionalHeaderParamResourceTest.java    From dropwizard-java8 with Apache License 2.0 4 votes vote down vote up
@GET
@Path("/uuid")
public String getUUID(@HeaderParam("uuid") Optional<UUIDParam> uuid) {
    return uuid.orElse(new UUIDParam("d5672fa8-326b-40f6-bf71-d9dacf44bcdc")).get().toString();
}
 
Example #15
Source File: Search.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public NotFoundMessage(UUIDParam id) {
  message = String.format("No SearchResult with id '%s'", id.get());
}