/** * Construct and submit a new rule to the engine. * * @param isInterchange * @param bean * @return on success, return the id of the newly added rule * @throws WebApplicationException when a rule is not found or the */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response submitThresholdRule( @HeaderParam(X_VISION_INTERCHANGE_HEADER) final boolean isInterchange, final ThresholdRuleBean bean) { try { final VismoRule rule = factory.buildFrom(bean); rule.submit(); update.notifyInsertion(isInterchange, rule.id(), bean); return submittedSuccessfully(rule); } catch (final ThresholdRuleValidationError e) { return badSpecification(e.getMessage()); } }
/** * @param isInterchange * @param name * @param period * @return on success, return the id of the newly added rule */ @Path("{name}/{period}") @POST @Produces(MediaType.TEXT_PLAIN) public Response submitDefaultRule( @HeaderParam(X_VISION_INTERCHANGE_HEADER) final boolean isInterchange, @PathParam("name") final String name, @PathParam("period") final long period) { final DefaultRuleBean bean = new DefaultRuleBean(name, period); final VismoRule rule = factory.buildFrom(bean); if (rule == null) return badSpecification("unknown rule name: " + name); rule.submit(); update.notifyInsertion(isInterchange, rule.id(), bean); return submittedSuccessfully(rule); }
/** * @param rule * @return the {@link Response} object. */ private static Response submittedSuccessfully(final VismoRule rule) { return Response.created(URI.create("/" + rule.id())).entity(rule.id()).build(); }