@POST @Path ("{subscription}/replay") @RequiresPermissions ("databus|poll|{subscription}") @Timed (name = "bv.emodb.databus.DatabusResource1.replay", absolute = true) @ApiOperation (value = "Replay operation.", notes = "Returns a Map.", response = Map.class ) public Map<String, Object> replay(@PathParam ("subscription") String subscription, @QueryParam ("since") DateTimeParam sinceParam, @Authenticated Subject subject) { checkArgument(!Strings.isNullOrEmpty(subscription), "subscription is required"); Date since = (sinceParam == null) ? null : sinceParam.get().toDate(); // Make sure since is within Replay TTL checkArgument(since == null || new DateTime(since).plus(DatabusChannelConfiguration.REPLAY_TTL).isAfterNow(), "Since timestamp is outside the replay TTL. Use null 'since' if you want to replay all events."); String id = _databus.replayAsyncSince(subject, subscription, since); return ImmutableMap.<String, Object>of("id", id); }
@PUT @Path("request/{id}") @RequiresPermissions("stash|request|{id}") public SuccessResponse requestStash(@PathParam("id") String id, @QueryParam("date") DateTimeParam timeParam, @Authenticated Subject subject) { final DateTime time = timeParam != null ? timeParam.get() : null; final String requestedBy = subject.getId(); _stashRequestManager.requestStashOnOrAfter(id, time, requestedBy); return SuccessResponse.instance(); }
@GET @Path("request/{id}") @RequiresPermissions("stash|request|{id}") public Date getStashRequest(@PathParam("id") String id, @QueryParam("date") DateTimeParam timeParam, @Authenticated Subject subject) { final DateTime time = timeParam != null ? timeParam.get() : null; final String requestedBy = subject.getId(); return _stashRequestManager.getRequestsForStash(id, time).stream() .filter(request -> request.getRequestedBy().equals(requestedBy)) .map(StashRequest::getRequestTime) .findFirst() .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND)); }
@DELETE @Path("request/{id}") @RequiresPermissions("stash|request|{id}") public SuccessResponse undoRequestStash(@PathParam("id") String id, @QueryParam("date") DateTimeParam timeParam, @Authenticated Subject subject) { final DateTime time = timeParam != null ? timeParam.get() : null; final String requestedBy = subject.getId(); _stashRequestManager.undoRequestForStashOnOrAfter(id, time, requestedBy); return SuccessResponse.instance(); }
@GET @Path("/date") @Produces(MediaType.TEXT_PLAIN) public String receiveDate(@QueryParam("date") Optional<DateTimeParam> dateTimeParam) { if (dateTimeParam.isPresent()) { final DateTimeParam actualDateTimeParam = dateTimeParam.get(); LOGGER.info("Received a date: {}", actualDateTimeParam); return actualDateTimeParam.get().toString(); } else { LOGGER.warn("No received date"); return null; } }