ModuleResource extends AbstractResource { @POST @Produces(MediaType.TEXT_HTML) public Response postModule(@Auth final DbCredential credential, final Module module) { if (!credential.getRoles().contains(AvailableRoles.DEPENDENCY_NOTIFIER)) { throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build()); } if(LOG.isInfoEnabled()) { LOG.info(String.format("Got a post Module request [%s]", module == null ? "NULL" : module.getName())); } DataValidator.validate(module); final DbModule dbModule = getModelMapper().getDbModule(module); final DbOrganization organization = getOrganizationHandler().getMatchingOrganization(dbModule); if (organization != null) { dbModule.setOrganization(organization.getName()); } getModuleHandler().store(dbModule); final ArtifactHandler artifactHandler = getArtifactHandler(); final Set<Artifact> artifacts = DataUtils.getAllArtifacts(module); for (final Artifact artifact : artifacts) { artifactHandler.store(getModelMapper().getDbArtifact(artifact)); } for (final Dependency dep : DataUtils.getAllDependencies(module)) { final DbArtifact dbDependency = getModelMapper().getDbArtifact(dep.getTarget()); artifactHandler.storeIfNew(dbDependency); } return Response.ok().status(HttpStatus.CREATED_201).build(); } ModuleResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST @Produces(MediaType.TEXT_HTML) Response postModule(@Auth final DbCredential credential, final Module module); @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 getVersionsRedirection(@PathParam("name") final String name, @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}" + ServerAPI.GET_VERSIONS) Response getVersions(@PathParam("name") final String name, @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}") Response get(@PathParam("name") final String name, @PathParam("version") final String version); @DELETE @Path("/{name}/{version}") Response delete(@Auth final DbCredential credential, @PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_ORGANIZATION) Response getOrganization(@PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_ANCESTORS) Response getAncestors(@PathParam("name") final String name,
                                 @PathParam("version") final String version,
                                 @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_DEPENDENCIES) Response getDependencies(@PathParam("name") final String name,
                                    @PathParam("version") final String version,
                                    @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_DEPENDENCIES + ServerAPI.GET_REPORT) Response getDependencyReport(@PathParam("name") final String name,
                                        @PathParam("version") final String version,
                                        @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.GET_LICENSES) Response getLicenses(@PathParam("name") final String name, @PathParam("version") final String version); @POST @Path("/{name}/{version}" + ServerAPI.PROMOTION) Response promote(@Auth final DbCredential credential, @PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}/{version}" + ServerAPI.PROMOTION + ServerAPI.GET_FEASIBLE) Response canBePromoted(@PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces({MediaType.APPLICATION_JSON}) @Path("/{name}/{version}" + ServerAPI.PROMOTION + ServerAPI.GET_REPORT) Response getPromotionStatusReport(@PathParam("name") final String name,
                                             @PathParam("version") final String version,
                                             @QueryParam(ServerAPI.EXCLUDE_SNAPSHOT_PARAM) boolean excludeSnapshot); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}/{version}" + ServerAPI.PROMOTION) Response isPromoted(@PathParam("name") final String name, @PathParam("version") final String version); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{name}/{version}" + ServerAPI.GET_BUILD_INFO) Response getBuildInfo(@PathParam("name") final String name, @PathParam("version") final String version); @POST @Path("/{name}/{version}" + ServerAPI.GET_BUILD_INFO) Response updateBuildInfo(@PathParam("name") final String name, @PathParam("version") final String version, final Map<String, String> buildInfo); @GET @Produces(MediaType.APPLICATION_JSON) @Path(ServerAPI.GET_ALL) Response getAllModules(@Context final UriInfo uriInfo);  }
@Test public void postModule() throws UnknownHostException, AuthenticationException { final Module module = DataModelFactory.createModule("module", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact(GrapesTestUtils.CORPORATE_GROUPID_4TEST, "artifactId", "version", "classifier", "type", "extension"); module.addArtifact(artifact); client().addFilter(new HTTPBasicAuthFilter(GrapesTestUtils.USER_4TEST, GrapesTestUtils.PASSWORD_4TEST)); final WebResource resource = client().resource("/" + ServerAPI.MODULE_RESOURCE); final ClientResponse response = resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, module); assertNotNull(response); assertEquals(HttpStatus.CREATED_201, response.getStatus()); final ArgumentCaptor<DbModule> captor = ArgumentCaptor.forClass(DbModule.class); verify(repositoryHandler, times(1)).store(captor.capture()); verify(repositoryHandler, times(1)).store((DbArtifact) anyObject()); assertEquals(GrapesTestUtils.ORGANIZATION_NAME_4TEST, captor.getValue().getOrganization()); }