@Test public void testFilterAnswer() throws IOException { String network = "network"; String snapshot = "snapshot"; String question = "question"; AnswerRowsOptions filterOptions = new AnswerRowsOptions( ImmutableSet.of(), ImmutableList.of(), 1, 0, ImmutableList.of(), false); FilterAnswerBean filterAnswer = new FilterAnswerBean(snapshot, null, filterOptions); TableMetadata baseTableMetadata = new TableMetadata( ImmutableList.of(new ColumnMetadata("colName", Schema.STRING, "col description"))); TableAnswerElement baseTableAnswerElement = new TableAnswerElement(baseTableMetadata); baseTableAnswerElement.addRow(Row.of("colName", "value1")); baseTableAnswerElement.addRow(Row.of("colName", "value2")); Answer baseAnswer = new Answer(); baseAnswer.addAnswerElement(baseTableAnswerElement); Main.getWorkMgr().initNetwork(network, null); uploadTestSnapshot(network, snapshot, _folder); setupQuestionAndAnswer(network, snapshot, question, null, baseAnswer); TableViewRow expectedRow = new TableViewRow(0, Row.of("colName", "value1")); TableView expectedTableView = new TableView(filterOptions, ImmutableList.of(expectedRow), baseTableMetadata); expectedTableView.setSummary(new AnswerSummary("", 0, 0, 2)); String expectedTableViewString = BatfishObjectMapper.writeString(expectedTableView); try (Response response = filterAnswerTarget(network, question, snapshot).post(Entity.json(filterAnswer))) { assertThat(response.getStatus(), equalTo(OK.getStatusCode())); Answer actual = response.readEntity(Answer.class); assertThat(actual.getAnswerElements(), iterableWithSize(1)); assertThat( BatfishObjectMapper.writeString(actual.getAnswerElements().get(0)), equalTo(expectedTableViewString)); } }
@POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response filterAnswer(FilterAnswerBean filterAnswerBean) throws IOException { if (!Main.getWorkMgr().checkSnapshotExists(_network, filterAnswerBean.snapshot)) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Snapshot %s not found in network %s", filterAnswerBean.snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer( _network, filterAnswerBean.snapshot, _questionName, filterAnswerBean.referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, filterAnswerBean.snapshot, filterAnswerBean.referenceSnapshot, _analysis)) .build(); } return Response.ok() .entity(Main.getWorkMgr().filterAnswer(ans, filterAnswerBean.filterOptions)) .build(); }
AnswerResource { @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response filterAnswer(FilterAnswerBean filterAnswerBean) throws IOException { if (!Main.getWorkMgr().checkSnapshotExists(_network, filterAnswerBean.snapshot)) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Snapshot %s not found in network %s", filterAnswerBean.snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer( _network, filterAnswerBean.snapshot, _questionName, filterAnswerBean.referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, filterAnswerBean.snapshot, filterAnswerBean.referenceSnapshot, _analysis)) .build(); } return Response.ok() .entity(Main.getWorkMgr().filterAnswer(ans, filterAnswerBean.filterOptions)) .build(); } }
AnswerResource { @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response filterAnswer(FilterAnswerBean filterAnswerBean) throws IOException { if (!Main.getWorkMgr().checkSnapshotExists(_network, filterAnswerBean.snapshot)) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Snapshot %s not found in network %s", filterAnswerBean.snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer( _network, filterAnswerBean.snapshot, _questionName, filterAnswerBean.referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, filterAnswerBean.snapshot, filterAnswerBean.referenceSnapshot, _analysis)) .build(); } return Response.ok() .entity(Main.getWorkMgr().filterAnswer(ans, filterAnswerBean.filterOptions)) .build(); } AnswerResource(String network, @Nullable String analysis, String questionName); }
AnswerResource { @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response filterAnswer(FilterAnswerBean filterAnswerBean) throws IOException { if (!Main.getWorkMgr().checkSnapshotExists(_network, filterAnswerBean.snapshot)) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Snapshot %s not found in network %s", filterAnswerBean.snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer( _network, filterAnswerBean.snapshot, _questionName, filterAnswerBean.referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, filterAnswerBean.snapshot, filterAnswerBean.referenceSnapshot, _analysis)) .build(); } return Response.ok() .entity(Main.getWorkMgr().filterAnswer(ans, filterAnswerBean.filterOptions)) .build(); } AnswerResource(String network, @Nullable String analysis, String questionName); @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response filterAnswer(FilterAnswerBean filterAnswerBean); @GET @Produces(MediaType.APPLICATION_JSON) Response getAnswer(
      @Nullable @QueryParam("snapshot") String snapshot,
      @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot); }
AnswerResource { @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response filterAnswer(FilterAnswerBean filterAnswerBean) throws IOException { if (!Main.getWorkMgr().checkSnapshotExists(_network, filterAnswerBean.snapshot)) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Snapshot %s not found in network %s", filterAnswerBean.snapshot, _network)) .build(); } Answer ans = Main.getWorkMgr() .getAnswer( _network, filterAnswerBean.snapshot, _questionName, filterAnswerBean.referenceSnapshot, _analysis); if (ans == null) { return Response.status(Status.NOT_FOUND) .entity( String.format( "Answer not found for question %s on network: %s, snapshot: %s, referenceSnapshot: %s, analysis: %s", _questionName, _network, filterAnswerBean.snapshot, filterAnswerBean.referenceSnapshot, _analysis)) .build(); } return Response.ok() .entity(Main.getWorkMgr().filterAnswer(ans, filterAnswerBean.filterOptions)) .build(); } AnswerResource(String network, @Nullable String analysis, String questionName); @POST @Path(RSC_FILTER) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response filterAnswer(FilterAnswerBean filterAnswerBean); @GET @Produces(MediaType.APPLICATION_JSON) Response getAnswer(
      @Nullable @QueryParam("snapshot") String snapshot,
      @Nullable @QueryParam("referenceSnapshot") String referenceSnapshot);  }