Skip to content

Commit

Permalink
feat(REST):fetch releases that are in NEW_CLEARING state and have a S…
Browse files Browse the repository at this point in the history
…RC/SRS attachment using parameter isNewClearingWithSourceAvailable

Signed-off-by: afsahsyeda <afsah.syeda@siemens-healthineers.com>
  • Loading branch information
afsahsyeda authored and GMishx committed Nov 6, 2024
1 parent 2621657 commit 33012fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
19 changes: 19 additions & 0 deletions rest/resource-server/src/docs/asciidoc/releases.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ include::{snippets}/should_document_get_releases_by_name/http-response.adoc[]
include::{snippets}/should_document_get_releases_by_name/links.adoc[]


[[resources-releases-list-by-isNewClearingWithSourceAvailable-filter]]
==== Listing releases in new clearing state with a source attachment available

A `GET` request will list all the releases in NEW_CLEARING state that have a source attachment available. +
Please set the request parameter `&isNewClearingWithSourceAvailable=true`.

===== Response structure
include::{snippets}/should_document_get_releases_by_isNewClearingWithSourceAvailable_filter/response-fields.adoc[]

===== Example request
include::{snippets}/should_document_get_releases_by_isNewClearingWithSourceAvailable_filter/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_get_releases_by_isNewClearingWithSourceAvailable_filter/http-response.adoc[]

===== Links
include::{snippets}/should_document_get_releases_by_isNewClearingWithSourceAvailable_filter/links.adoc[]


[[resources-releases-get-by-externalids]]
==== Listing by external ids

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,10 @@
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.LinkedHashMap;
import java.util.Objects;
import java.util.TreeSet;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -67,14 +56,11 @@
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentDTO;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
import org.eclipse.sw360.datahandler.thrift.components.*;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.components.Component;
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcess;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation;
Expand All @@ -92,7 +78,6 @@
import org.eclipse.sw360.rest.resourceserver.vendor.Sw360VendorService;
import org.eclipse.sw360.rest.resourceserver.licenseinfo.Sw360LicenseInfoService;
import org.eclipse.sw360.rest.resourceserver.vulnerability.Sw360VulnerabilityService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.BasePathAwareController;
Expand All @@ -107,7 +92,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -178,6 +162,8 @@ public ResponseEntity<CollectionModel<EntityModel<Release>>> getReleasesForUser(
@RequestParam(value = "name", required = false) String name,
@Parameter(description = "luceneSearch parameter to filter the releases.")
@RequestParam(value = "luceneSearch", required = false) boolean luceneSearch,
@Parameter(description = "fetch releases that are in NEW state and have a SRC/SRS attachment")
@RequestParam(value = "isNewClearingWithSourceAvailable", required = false) boolean isNewClearingWithSourceAvailable,
@Parameter(description = "allDetails of the release")
@RequestParam(value = "allDetails", required = false) boolean allDetails,
HttpServletRequest request
Expand All @@ -193,6 +179,12 @@ public ResponseEntity<CollectionModel<EntityModel<Release>>> getReleasesForUser(
} else {
if (sha1 != null && !sha1.isEmpty()) {
sw360Releases.addAll(searchReleasesBySha1(sha1, sw360User));
} else if (isNewClearingWithSourceAvailable) {
sw360Releases.addAll(releaseService.getReleasesForUser(sw360User));
sw360Releases = sw360Releases.stream()
.filter(release -> release.getClearingState() == ClearingState.NEW_CLEARING && !CommonUtils.isNullOrEmptyCollection(release.getAttachments())
&& release.getAttachments().stream().anyMatch(attachment -> attachment.getAttachmentType() == AttachmentType.SOURCE
|| attachment.getAttachmentType() == AttachmentType.SOURCE_SELF)).collect(Collectors.toList());
} else {
sw360Releases.addAll(releaseService.getReleasesForUser(sw360User));
sw360Releases = sw360Releases.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void before() throws TException, IOException {
release2.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
release2.setComponentId(component.getId());
release2.setComponentType(ComponentType.OSS);
release2.setClearingState(ClearingState.APPROVED);
release2.setClearingState(ClearingState.NEW_CLEARING);
release2.setMainlineState(MainlineState.MAINLINE);
release2.setExternalIds(release2ExternalIds);
release2.setLanguages(new HashSet<>(Arrays.asList("C++", "Java")));
Expand All @@ -323,6 +323,7 @@ public void before() throws TException, IOException {
release2.setClearingInformation(clearingInfo);
release2.setCotsDetails(cotsDetails);
release2.setEccInformation(eccInformation);
release2.setAttachments(ImmutableSet.of(att1));
releaseList.add(release2);

Package package2 = new Package()
Expand Down Expand Up @@ -938,6 +939,21 @@ public void should_document_get_releases_by_externalIds() throws Exception {
)));
}

@Test
public void should_document_get_releases_by_isNewClearingWithSourceAvailable_filter() throws Exception {
mockMvc.perform(get("/api/releases?isNewClearingWithSourceAvailable=" + true)
.header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword)).accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
links(linkWithRel("curies").description("Curies are used for online documentation")),
responseFields(
subsectionWithPath("_embedded.sw360:releases.[]name").description("The name of the release, optional"),
subsectionWithPath("_embedded.sw360:releases.[]version").description("The version of the release"),
subsectionWithPath("_embedded.sw360:releases").description("An array of <<resources-releases, Releases resources>>"),
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources")))
);
}

@Test
public void should_document_trigger_fossology_process() throws Exception {
mockMvc.perform(
Expand Down

0 comments on commit 33012fd

Please sign in to comment.