@Test public void postLicense() throws AuthenticationException, UnknownHostException{ client().addFilter(new HTTPBasicAuthFilter(GrapesTestUtils.USER_4TEST, GrapesTestUtils.PASSWORD_4TEST)); WebResource resource = client().resource("/" + ServerAPI.LICENSE_RESOURCE); ClientResponse response = resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, DataModelFactory.createLicense("shorName", "shortLongName", "BlaBla", "sdfsd", "www.somewhere.org")); assertNotNull(response); assertEquals(HttpStatus.CREATED_201, response.getStatus()); }
@POST public Response postLicense(@Auth final DbCredential credential, final License license){ if(!credential.getRoles().contains(AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a post license request."); DataValidator.validate(license); final DbLicense dbLicense = getModelMapper().getDbLicense(license); getLicenseHandler().store(dbLicense); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok().status(HttpStatus.CREATED_201).build(); }
LicenseResource extends AbstractResource { @POST public Response postLicense(@Auth final DbCredential credential, final License license){ if(!credential.getRoles().contains(AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a post license request."); DataValidator.validate(license); final DbLicense dbLicense = getModelMapper().getDbLicense(license); getLicenseHandler().store(dbLicense); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok().status(HttpStatus.CREATED_201).build(); } }
LicenseResource extends AbstractResource { @POST public Response postLicense(@Auth final DbCredential credential, final License license){ if(!credential.getRoles().contains(AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a post license request."); DataValidator.validate(license); final DbLicense dbLicense = getModelMapper().getDbLicense(license); getLicenseHandler().store(dbLicense); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok().status(HttpStatus.CREATED_201).build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); }
LicenseResource extends AbstractResource { @POST public Response postLicense(@Auth final DbCredential credential, final License license){ if(!credential.getRoles().contains(AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a post license request."); DataValidator.validate(license); final DbLicense dbLicense = getModelMapper().getDbLicense(license); getLicenseHandler().store(dbLicense); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok().status(HttpStatus.CREATED_201).build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postLicense(@Auth final DbCredential credential, final License license); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved); }
LicenseResource extends AbstractResource { @POST public Response postLicense(@Auth final DbCredential credential, final License license){ if(!credential.getRoles().contains(AvailableRoles.DATA_UPDATER)){ throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } LOG.info("Got a post license request."); DataValidator.validate(license); final DbLicense dbLicense = getModelMapper().getDbLicense(license); getLicenseHandler().store(dbLicense); cacheUtils.clear(CacheName.PROMOTION_REPORTS); return Response.ok().status(HttpStatus.CREATED_201).build(); } LicenseResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postLicense(@Auth final DbCredential credential, final License license); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_NAMES) Response getNames(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response get(@PathParam("name") final String name); @DELETE @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name); @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}") Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved);  }