@Test public void testAddExperiment() { final CreateExperimentRequest request = new CreateExperimentRequest( "new_experiment", 0, "it's new", null, null, false, Lists.newArrayList( new TreatmentDto("control", "the default"), new TreatmentDto("first_case", "the first case"), new TreatmentDto("second_case", "the second case") ), Lists.newArrayList( new AllocateRequest("control", 10), new AllocateRequest("first_case", 20), new AllocateRequest("second_case", 30) ), Lists.<TreatmentOverrideRequest>newArrayList() ); assertNull(experiment("new_experiment")); put(EXPERIMENTS_ENDPOINT) .entity(request) .assertStatus(Status.CREATED); assertNotNull(experiment("new_experiment")); }
@PUT public Response addExperiment(@Valid CreateExperimentRequest request) { final Experiment experiment = experiments .create(request.getName()) .setDescription(request.getDescription()); if (request.getFilter() != null) { experiment.setFilter(FilterExpression.of(request.getFilter())); } if (request.getHashAttributes() != null) { experiment.setHashAttributes(request.getHashAttributes()); } if (request.getSeed() != null) { experiment.setSeed(request.getSeed()); } if (request.getTreatments() != null) { for (final TreatmentDto treatment : request.getTreatments()) { experiment.addTreatment(treatment.getName(), treatment.getDescription()); } } if (request.getAllocations() != null) { for (final AllocateRequest allocation : request.getAllocations()) { experiment.allocate(allocation.getTreatment(), allocation.getSize()); } } if (request.getOverrides() != null) { for (final TreatmentOverrideRequest override : request.getOverrides()) { experiment.addOverride(override.getName(), override.getTreatment(), override.getFilter()); } } if (request.isActive() != null) { if (request.isActive()) { experiment.activate(); } else { experiment.deactivate(); } } experiment.save(); return created(); }
ExperimentsResource extends BaseResource { @PUT public Response addExperiment(@Valid CreateExperimentRequest request) { final Experiment experiment = experiments .create(request.getName()) .setDescription(request.getDescription()); if (request.getFilter() != null) { experiment.setFilter(FilterExpression.of(request.getFilter())); } if (request.getHashAttributes() != null) { experiment.setHashAttributes(request.getHashAttributes()); } if (request.getSeed() != null) { experiment.setSeed(request.getSeed()); } if (request.getTreatments() != null) { for (final TreatmentDto treatment : request.getTreatments()) { experiment.addTreatment(treatment.getName(), treatment.getDescription()); } } if (request.getAllocations() != null) { for (final AllocateRequest allocation : request.getAllocations()) { experiment.allocate(allocation.getTreatment(), allocation.getSize()); } } if (request.getOverrides() != null) { for (final TreatmentOverrideRequest override : request.getOverrides()) { experiment.addOverride(override.getName(), override.getTreatment(), override.getFilter()); } } if (request.isActive() != null) { if (request.isActive()) { experiment.activate(); } else { experiment.deactivate(); } } experiment.save(); return created(); } }
ExperimentsResource extends BaseResource { @PUT public Response addExperiment(@Valid CreateExperimentRequest request) { final Experiment experiment = experiments .create(request.getName()) .setDescription(request.getDescription()); if (request.getFilter() != null) { experiment.setFilter(FilterExpression.of(request.getFilter())); } if (request.getHashAttributes() != null) { experiment.setHashAttributes(request.getHashAttributes()); } if (request.getSeed() != null) { experiment.setSeed(request.getSeed()); } if (request.getTreatments() != null) { for (final TreatmentDto treatment : request.getTreatments()) { experiment.addTreatment(treatment.getName(), treatment.getDescription()); } } if (request.getAllocations() != null) { for (final AllocateRequest allocation : request.getAllocations()) { experiment.allocate(allocation.getTreatment(), allocation.getSize()); } } if (request.getOverrides() != null) { for (final TreatmentOverrideRequest override : request.getOverrides()) { experiment.addOverride(override.getName(), override.getTreatment(), override.getFilter()); } } if (request.isActive() != null) { if (request.isActive()) { experiment.activate(); } else { experiment.deactivate(); } } experiment.save(); return created(); } @Inject  ExperimentsResource(Experiments experiments, Mappers mapper); }
ExperimentsResource extends BaseResource { @PUT public Response addExperiment(@Valid CreateExperimentRequest request) { final Experiment experiment = experiments .create(request.getName()) .setDescription(request.getDescription()); if (request.getFilter() != null) { experiment.setFilter(FilterExpression.of(request.getFilter())); } if (request.getHashAttributes() != null) { experiment.setHashAttributes(request.getHashAttributes()); } if (request.getSeed() != null) { experiment.setSeed(request.getSeed()); } if (request.getTreatments() != null) { for (final TreatmentDto treatment : request.getTreatments()) { experiment.addTreatment(treatment.getName(), treatment.getDescription()); } } if (request.getAllocations() != null) { for (final AllocateRequest allocation : request.getAllocations()) { experiment.allocate(allocation.getTreatment(), allocation.getSize()); } } if (request.getOverrides() != null) { for (final TreatmentOverrideRequest override : request.getOverrides()) { experiment.addOverride(override.getName(), override.getTreatment(), override.getFilter()); } } if (request.isActive() != null) { if (request.isActive()) { experiment.activate(); } else { experiment.deactivate(); } } experiment.save(); return created(); } @Inject  ExperimentsResource(Experiments experiments, Mappers mapper); @GET Iterable<ExperimentDto> getExperiments(@QueryParam("filter") String filterValue,
                                                  @QueryParam("offset") Integer offset,
                                                  @QueryParam("limit") Integer limit,
                                                  @QueryParam("sort") String sort); @PUT Response addExperiment(@Valid CreateExperimentRequest request); @POST @Path("/{experimentName}") void updateExperiment(@PathParam("experimentName") String experimentName,
                                 @Valid UpdateExperimentRequest request); @GET @Path("/{experimentName}") ExperimentDto getExperiment(@PathParam("experimentName") String experimentName); @DELETE @Path("/{experimentName}") void removeExperiment(@PathParam("experimentName") String experimentName); }
ExperimentsResource extends BaseResource { @PUT public Response addExperiment(@Valid CreateExperimentRequest request) { final Experiment experiment = experiments .create(request.getName()) .setDescription(request.getDescription()); if (request.getFilter() != null) { experiment.setFilter(FilterExpression.of(request.getFilter())); } if (request.getHashAttributes() != null) { experiment.setHashAttributes(request.getHashAttributes()); } if (request.getSeed() != null) { experiment.setSeed(request.getSeed()); } if (request.getTreatments() != null) { for (final TreatmentDto treatment : request.getTreatments()) { experiment.addTreatment(treatment.getName(), treatment.getDescription()); } } if (request.getAllocations() != null) { for (final AllocateRequest allocation : request.getAllocations()) { experiment.allocate(allocation.getTreatment(), allocation.getSize()); } } if (request.getOverrides() != null) { for (final TreatmentOverrideRequest override : request.getOverrides()) { experiment.addOverride(override.getName(), override.getTreatment(), override.getFilter()); } } if (request.isActive() != null) { if (request.isActive()) { experiment.activate(); } else { experiment.deactivate(); } } experiment.save(); return created(); } @Inject  ExperimentsResource(Experiments experiments, Mappers mapper); @GET Iterable<ExperimentDto> getExperiments(@QueryParam("filter") String filterValue,
                                                  @QueryParam("offset") Integer offset,
                                                  @QueryParam("limit") Integer limit,
                                                  @QueryParam("sort") String sort); @PUT Response addExperiment(@Valid CreateExperimentRequest request); @POST @Path("/{experimentName}") void updateExperiment(@PathParam("experimentName") String experimentName,
                                 @Valid UpdateExperimentRequest request); @GET @Path("/{experimentName}") ExperimentDto getExperiment(@PathParam("experimentName") String experimentName); @DELETE @Path("/{experimentName}") void removeExperiment(@PathParam("experimentName") String experimentName);  }