ArtifactResource extends AbstractResource { @GET @Produces(MediaType.APPLICATION_JSON) @Path("/isPromoted") public Response isPromoted(@QueryParam("user") final String user, @QueryParam("stage") final int stage, @QueryParam("name") final String filename, @QueryParam("sha256") final String sha256, @QueryParam("type") final String type, @QueryParam("location") final String location) { LOG.info("Got a get artifact promotion request"); final ArtifactQuery query = new ArtifactQuery(user, stage, filename, sha256, type, location); DataValidator.validate(query); if(LOG.isInfoEnabled()) { LOG.info(String.format("Artifact validation request. Details [%s]", query.toString())); } final GrapesServerConfig cfg = getConfig(); final List<String> validatedTypes = cfg.getExternalValidatedTypes(); if(!validatedTypes.contains(type)) { return Response.ok(buildArtifactNotSupportedResponse(validatedTypes)).status(HttpStatus.UNPROCESSABLE_ENTITY_422).build(); } final DbArtifact dbArtifact = getArtifactHandler().getArtifactUsingSHA256(sha256); if(dbArtifact == null) { final String jiraLink = buildArtifactNotificationJiraLink(query); sender.send(cfg.getArtifactNotificationRecipients(), buildArtifactValidationSubject(filename), buildArtifactValidationBody(query, "N/A")); return Response.ok(buildArtifactNotKnown(query, jiraLink)).status(HttpStatus.NOT_FOUND_404).build(); } final ArtifactPromotionStatus promotionStatus = new ArtifactPromotionStatus(); promotionStatus.setPromoted(dbArtifact.isPromoted()); if(dbArtifact.isPromoted()){ promotionStatus.setMessage(Messages.get(ARTIFACT_VALIDATION_IS_PROMOTED)); return Response.ok(promotionStatus).build(); } else { final String jenkinsJobInfo = getArtifactHandler().getModuleJenkinsJobInfo(dbArtifact); promotionStatus.setMessage(buildArtifactNotPromotedYetResponse(query, jenkinsJobInfo.isEmpty() ? "<i>(Link to Jenkins job not found)</i>" : jenkinsJobInfo)); } return Response.ok(promotionStatus).build(); } ArtifactResource(final RepositoryHandler repoHandler, final GrapesServerConfig dmConfig); @POST Response postArtifact(@Auth final DbCredential credential, final Artifact artifact); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_GAVCS) Response getGavcs(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path(ServerAPI.GET_GROUPIDS) Response getGroupIds(@Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_VERSIONS) Response getVersions(@PathParam("gavc") final String gavc); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{gavc}" + ServerAPI.GET_LAST_VERSION) Response getLastVersion(@PathParam("gavc") final String gavc); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}") Response get(@PathParam("gavc") final String gavc); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/isPromoted") Response isPromoted(@QueryParam("user") final String user,
                               @QueryParam("stage") final int stage,
                               @QueryParam("name") final String filename,
                               @QueryParam("sha256") final String sha256,
                               @QueryParam("type") final String type,
                               @QueryParam("location") final String location); @POST @Path("/{gavc}" + ServerAPI.GET_DOWNLOAD_URL) Response updateDownloadUrl(@Auth final DbCredential credential, @PathParam("gavc") final String gavc, @QueryParam(ServerAPI.URL_PARAM) final String downLoadUrl); @POST @Path("/{gavc}" + ServerAPI.GET_PROVIDER) Response updateProvider(@Auth final DbCredential credential, @PathParam("gavc") final String gavc, @QueryParam(ServerAPI.PROVIDER_PARAM) final String provider); @DELETE @Path("/{gavc}") Response delete(@Auth final DbCredential credential, @PathParam("gavc") final String gavc); @POST @Path("/{gavc}" + ServerAPI.SET_DO_NOT_USE) Response postDoNotUse(@Auth final DbCredential credential,
                                 @PathParam("gavc") final String gavc,
                                 @QueryParam(ServerAPI.DO_NOT_USE) final BooleanParam doNotUse,
                                 final String commentText); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{gavc}" + ServerAPI.SET_DO_NOT_USE) Response getDoNotUse(@PathParam("gavc") final String gavc); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_ANCESTORS) Response getAncestors(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @GET @Produces({MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_LICENSES) Response getLicenses(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @POST @Path("/{gavc}" + ServerAPI.GET_LICENSES) Response addLicense(@Auth final DbCredential credential,
                               @PathParam("gavc") final String gavc,
                               @QueryParam(ServerAPI.LICENSE_ID_PARAM) final String licenseId); @DELETE @Path("/{gavc}" + ServerAPI.GET_LICENSES) Response deleteLicense(@Auth final DbCredential credential,
                                  @PathParam("gavc") final String gavc,
                                  @QueryParam(ServerAPI.LICENSE_ID_PARAM) final String licenseString); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_MODULE) Response getModule(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Path("/{gavc}" + ServerAPI.GET_ORGANIZATION) Response getOrganization(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo); @GET @Produces(MediaType.APPLICATION_JSON) @Path(ServerAPI.GET_ALL) Response getAll(@Context final UriInfo uriInfo);  }
@Test public void isPromoted(){ final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("groupId"); artifact.setArtifactId("artifactId"); artifact.setVersion("version"); artifact.setClassifier("classifier"); artifact.setPromoted(true); when(repositoryHandler.getArtifactUsingSHA256("6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c")).thenReturn(artifact); ArtifactQuery artifactQuery = new ArtifactQuery("User", 1, "File1", "6554ed3d1ab007bd81d3d57ee27027510753d905277d5b5b8813e5bd516e821c", "filetype1", ""); MultivaluedMap<String, String> params = makeParams(artifactQuery); Messages.init(templatePath); WebResource resource = client().resource("/" + ServerAPI.ARTIFACT_RESOURCE + "/isPromoted"); ClientResponse response = resource.queryParams(params).type(MediaType.APPLICATION_JSON).get(ClientResponse.class); final ArtifactPromotionStatus promotionStatus = response.getEntity(ArtifactPromotionStatus.class); assertNotNull(response); assertEquals(HttpStatus.OK_200, response.getStatus()); assertTrue(promotionStatus.isPromoted()); assertEquals("Artifact is promoted", promotionStatus.getMessage()); }