@Test public void addReferenceBook() throws IOException { String network = "someNetwork"; Main.getWorkMgr().initNetwork(network, null); ReferenceBookBean book = new ReferenceBookBean(ReferenceBook.builder("book1").build()); try (Response response = getReferenceLibraryTarget(network).post(Entity.entity(book, MediaType.APPLICATION_JSON))) { assertThat(response.getStatus(), equalTo(OK.getStatusCode())); } ReferenceLibrary library = Main.getWorkMgr().getReferenceLibrary(network); assertThat(library.getReferenceBook("book1").isPresent(), equalTo(true)); try (Response response2 = getReferenceLibraryTarget(network).post(Entity.entity(book, MediaType.APPLICATION_JSON))) { assertThat(response2.getStatus(), equalTo(BAD_REQUEST.getStatusCode())); } }
@Deprecated @POST public Response addReferenceBook(ReferenceBookBean referenceBookBean) { _logger.infof("WMS2: addReferenceBook '%s'\n", _network); if (referenceBookBean.name == null) { throw new BadRequestException("ReferenceBook must have a name"); } try { ReferenceLibrary library = Main.getWorkMgr().getReferenceLibrary(_network); if (library.getReferenceBook(referenceBookBean.name).isPresent()) { throw new BadRequestException("Duplicate bookname: " + referenceBookBean.name); } Main.getWorkMgr() .putReferenceLibrary( Main.getWorkMgr() .getReferenceLibrary(_network) .mergeReferenceBooks(ImmutableSortedSet.of(referenceBookBean.toAddressBook())), _network); return Response.ok().build(); } catch (IOException e) { throw new InternalServerErrorException("ReferenceLibrary resource is corrupted"); } }
ReferenceLibraryResource { @Deprecated @POST public Response addReferenceBook(ReferenceBookBean referenceBookBean) { _logger.infof("WMS2: addReferenceBook '%s'\n", _network); if (referenceBookBean.name == null) { throw new BadRequestException("ReferenceBook must have a name"); } try { ReferenceLibrary library = Main.getWorkMgr().getReferenceLibrary(_network); if (library.getReferenceBook(referenceBookBean.name).isPresent()) { throw new BadRequestException("Duplicate bookname: " + referenceBookBean.name); } Main.getWorkMgr() .putReferenceLibrary( Main.getWorkMgr() .getReferenceLibrary(_network) .mergeReferenceBooks(ImmutableSortedSet.of(referenceBookBean.toAddressBook())), _network); return Response.ok().build(); } catch (IOException e) { throw new InternalServerErrorException("ReferenceLibrary resource is corrupted"); } } }
ReferenceLibraryResource { @Deprecated @POST public Response addReferenceBook(ReferenceBookBean referenceBookBean) { _logger.infof("WMS2: addReferenceBook '%s'\n", _network); if (referenceBookBean.name == null) { throw new BadRequestException("ReferenceBook must have a name"); } try { ReferenceLibrary library = Main.getWorkMgr().getReferenceLibrary(_network); if (library.getReferenceBook(referenceBookBean.name).isPresent()) { throw new BadRequestException("Duplicate bookname: " + referenceBookBean.name); } Main.getWorkMgr() .putReferenceLibrary( Main.getWorkMgr() .getReferenceLibrary(_network) .mergeReferenceBooks(ImmutableSortedSet.of(referenceBookBean.toAddressBook())), _network); return Response.ok().build(); } catch (IOException e) { throw new InternalServerErrorException("ReferenceLibrary resource is corrupted"); } } ReferenceLibraryResource(String network); }
ReferenceLibraryResource { @Deprecated @POST public Response addReferenceBook(ReferenceBookBean referenceBookBean) { _logger.infof("WMS2: addReferenceBook '%s'\n", _network); if (referenceBookBean.name == null) { throw new BadRequestException("ReferenceBook must have a name"); } try { ReferenceLibrary library = Main.getWorkMgr().getReferenceLibrary(_network); if (library.getReferenceBook(referenceBookBean.name).isPresent()) { throw new BadRequestException("Duplicate bookname: " + referenceBookBean.name); } Main.getWorkMgr() .putReferenceLibrary( Main.getWorkMgr() .getReferenceLibrary(_network) .mergeReferenceBooks(ImmutableSortedSet.of(referenceBookBean.toAddressBook())), _network); return Response.ok().build(); } catch (IOException e) { throw new InternalServerErrorException("ReferenceLibrary resource is corrupted"); } } ReferenceLibraryResource(String network); @Deprecated @POST Response addReferenceBook(ReferenceBookBean referenceBookBean); @Path("/{book}") ReferenceBookResource getReferenceBookResource(@PathParam("book") String book); @GET ReferenceLibraryBean getReferenceLibrary(); }
ReferenceLibraryResource { @Deprecated @POST public Response addReferenceBook(ReferenceBookBean referenceBookBean) { _logger.infof("WMS2: addReferenceBook '%s'\n", _network); if (referenceBookBean.name == null) { throw new BadRequestException("ReferenceBook must have a name"); } try { ReferenceLibrary library = Main.getWorkMgr().getReferenceLibrary(_network); if (library.getReferenceBook(referenceBookBean.name).isPresent()) { throw new BadRequestException("Duplicate bookname: " + referenceBookBean.name); } Main.getWorkMgr() .putReferenceLibrary( Main.getWorkMgr() .getReferenceLibrary(_network) .mergeReferenceBooks(ImmutableSortedSet.of(referenceBookBean.toAddressBook())), _network); return Response.ok().build(); } catch (IOException e) { throw new InternalServerErrorException("ReferenceLibrary resource is corrupted"); } } ReferenceLibraryResource(String network); @Deprecated @POST Response addReferenceBook(ReferenceBookBean referenceBookBean); @Path("/{book}") ReferenceBookResource getReferenceBookResource(@PathParam("book") String book); @GET ReferenceLibraryBean getReferenceLibrary();  }