Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#1936 from muhammadali9699/feat/Compo…
Browse files Browse the repository at this point in the history
…nentsWithalldetailsUpdatedDoc

feat(rest):Components with all details Rest Api doc updated

Tested by: rudra.chopra@siemens.com
Reviewed by: rudra.chopra@siemens.com

Signed-off-by: Nikesh kumar <kumar.nikesh@simens.com>
  • Loading branch information
ag4ums authored and Nikesh kumar committed May 16, 2023
2 parents b321fb2 + c80f759 commit e415e6f
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 7 deletions.
16 changes: 16 additions & 0 deletions rest/resource-server/src/docs/asciidoc/components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ include::{snippets}/should_document_get_components/http-response.adoc[]
===== Links
include::{snippets}/should_document_get_components/links.adoc[]

[[resources-components-list-all-details]]
==== Listing components with all details

A `GET` request will list all of the service's components with all details.

===== Request parameter
include::{snippets}/should_document_get_components_with_all_details/request-parameters.adoc[]

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

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

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

[[resources-recent-components-list]]
==== Listing recent components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ private HalResource<Component> createHalComponent(Component sw360Component, User
restControllerHelper.addEmbeddedAttachments(halComponent, sw360Component.getAttachments());
}

restControllerHelper.addEmbeddedUser(halComponent, componentCreator, "createdBy");
if(null!= componentCreator)
restControllerHelper.addEmbeddedUser(halComponent, componentCreator, "createdBy");

return halComponent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ public void addEmbeddedModerators(HalResource halResource, Set<String> moderator

for (String moderatorEmail : moderators) {
User sw360User = getUserByEmail(moderatorEmail);
addEmbeddedUser(halResource, sw360User, "sw360:moderators");
if(sw360User!=null)
addEmbeddedUser(halResource, sw360User, "sw360:moderators");
}
}

Expand Down Expand Up @@ -338,9 +339,11 @@ public HalResource<Vendor> addEmbeddedVendor(String vendorFullName) {
HalResource<Vendor> halVendor = new HalResource<>(embeddedVendor);
try {
Vendor vendorByFullName = vendorService.getVendorByFullName(vendorFullName);
Link vendorSelfLink = linkTo(UserController.class)
.slash("api" + VendorController.VENDORS_URL + "/" + vendorByFullName.getId()).withSelfRel();
halVendor.add(vendorSelfLink);
if(vendorByFullName != null) {
Link vendorSelfLink = linkTo(UserController.class)
.slash("api" + VendorController.VENDORS_URL + "/" + vendorByFullName.getId()).withSelfRel();
halVendor.add(vendorSelfLink);
}
return halVendor;
} catch (Exception e) {
LOGGER.error("cannot create self link for vendor with full name: " + vendorFullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public ResponseEntity<CollectionModel<EntityModel>> getReleasesForUser(
releaseService.setComponentDependentFieldsInRelease(release, sw360User);
}

sw360Releases = sw360Releases.stream()
sw360Releases = sw360Releases.stream().map(release -> releaseService.setComponentDependentFieldsInRelease(release, sw360User))
.filter(release -> name == null || name.isEmpty() || release.getName().equalsIgnoreCase(name))
.collect(Collectors.toList());
PaginationResult<Release> paginationResult = restControllerHelper.createPaginationResult(request, pageable, sw360Releases, SW360Constants.TYPE_RELEASE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType;
import org.eclipse.sw360.datahandler.thrift.components.ClearingState;
import org.eclipse.sw360.datahandler.thrift.components.ComponentType;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.MainlineState;
import org.eclipse.sw360.datahandler.thrift.Source;
Expand Down Expand Up @@ -166,6 +167,34 @@ public static List<Attachment> getDummyAttachmentsListForTest() {
return attachments;
}

public static Release getDummyReleaseForComponentTypeTest() {
List<Release> releases = new ArrayList<>();

Release release1 = new Release();
release1.setName("Release 1");
release1.setId(release1Id);
release1.setComponentId("component123");
release1.setVersion("1.0.4");
release1.setCpeid("cpe:id-1231");
release1.setMainlineState(MainlineState.MAINLINE);
release1.setClearingState(ClearingState.APPROVED);
release1.setComponentType(ComponentType.OSS);
releases.add(release1);

Release release2 = new Release();
release2.setName("Release 2");
release2.setId(releaseId2);
release2.setComponentId("component456");
release2.setVersion("2.0.0");
release2.setCpeid("cpe:id-4567");
release2.setMainlineState(MainlineState.OPEN);
release2.setClearingState(ClearingState.NEW_CLEARING);
release2.setComponentType(ComponentType.OSS);
releases.add(release2);

return release2;
}

public static List<AttachmentInfo> getDummyAttachmentInfoListForTest() {
Source source1 = new Source(Source._Fields.RELEASE_ID, release1Id);
Source source2 = new Source(Source._Fields.RELEASE_ID, releaseId2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void before() throws TException {
given(this.releaseServiceMock.getReleaseForUserById(eq(TestHelper.getDummyReleaseListForTest().get(0).getId()),eq(user))).willReturn(TestHelper.getDummyReleaseListForTest().get(0));
given(this.releaseServiceMock.getReleasesForUser(any())).willReturn(TestHelper.getDummyReleaseListForTest());
given(this.releaseServiceMock.getReleaseForUserById(eq(TestHelper.getDummyReleaseListForTest().get(1).getId()),eq(user))).willReturn(TestHelper.getDummyReleaseListForTest().get(1));
given(this.releaseServiceMock.setComponentDependentFieldsInRelease(any(), any())).willReturn(TestHelper.getDummyReleaseForComponentTypeTest());

given(this.licenseServiceMock.getLicenseById("Apache-2.0")).willReturn(
new License("Apache 2.0 License")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.common.collect.ImmutableSet;
import org.apache.thrift.TException;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.Visibility;
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType;
Expand Down Expand Up @@ -280,6 +281,75 @@ public void should_document_get_components() throws Exception {
fieldWithPath("page.number").description("Number of the current page")
)));
}

@Test
public void should_document_get_components_with_all_details() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(get("/api/components")
.header("Authorization", "Bearer " + accessToken)
.param("allDetails", "true")
.param("page", "0")
.param("page_entries", "5")
.param("sort", "name,desc")
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
requestParameters(
parameterWithName("allDetails").description("Flag to get components with all details. Possible values are `<true|false>`"),
parameterWithName("page").description("Page of components"),
parameterWithName("page_entries").description("Amount of components per page"),
parameterWithName("sort").description("Defines order of the components")
),
links(
linkWithRel("curies").description("Curies are used for online documentation"),
linkWithRel("first").description("Link to first page"),
linkWithRel("last").description("Link to last page")
),
responseFields(

subsectionWithPath("_embedded.sw360:components.[]name").description("The name of the component"),
subsectionWithPath("_embedded.sw360:components.[]description").description("The component description"),
subsectionWithPath("_embedded.sw360:components.[]createdOn").description("The date the component was created"),
subsectionWithPath("_embedded.sw360:components.[]componentType").description("The component type, possible values are: " + Arrays.asList(ComponentType.values())),
subsectionWithPath("_embedded.sw360:components.[]componentOwner").description("The owner of the component"),
subsectionWithPath("_embedded.sw360:components.[]ownerAccountingUnit").description("The owner accounting unit of the component"),
subsectionWithPath("_embedded.sw360:components.[]ownerGroup").description("The owner group of the component"),
subsectionWithPath("_embedded.sw360:components.[]ownerCountry").description("The owner country of the component"),
subsectionWithPath("_embedded.sw360:components.[]visbility").description("The component visibility, possible values are: " + Arrays.asList(Visibility.values())),
subsectionWithPath("_embedded.sw360:components.[]externalIds").description("When components are imported from other tools, the external ids can be stored here. Store as 'Single String' when single value, or 'Array of String' when multi-values"),
subsectionWithPath("_embedded.sw360:components.[]additionalData").description("A place to store additional data used by external tools").optional(),

subsectionWithPath("_embedded.sw360:components.[]categories").description("The component categories"),
subsectionWithPath("_embedded.sw360:components.[]languages").description("The language of the component"),

subsectionWithPath("_embedded.sw360:components.[]operatingSystems").description("The OS on which the component operates"),
subsectionWithPath("_embedded.sw360:components.[]mailinglist").description("Component mailing lists"),
subsectionWithPath("_embedded.sw360:components.[]setVisbility").description("The visibility of the component"),

subsectionWithPath("_embedded.sw360:components.[]setBusinessUnit").description("The business unit this component belongs to"),
subsectionWithPath("_embedded.sw360:components.[]_links").description("Self <<resources-index-links,Links>> to Component resource").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.sw360:moderators").description("An array of all component moderators with email").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.sw360:releases").description("An array of all releases").optional(),

subsectionWithPath("_embedded.sw360:components.[]homepage").description("The homepage url of the component").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.createdBy.email").description("The email of user who created this Component").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.createdBy.deactivated").description("The user is activated or deactivated").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.createdBy._links").description("Self <<resources-index-links,Links>> to Component resource").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.sw360:attachments.[]filename").description("Attached file name").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.sw360:attachments.[]sha1").description("The attachment sha1 value").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.sw360:attachments.[]_links").description("Self <<resources-index-links,Links>> to Component resource").optional(),
subsectionWithPath("_embedded.sw360:components.[]_embedded.sw360:vendors").description("The vendors list").optional(),

subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources"),
fieldWithPath("page").description("Additional paging information"),
fieldWithPath("page.size").description("Number of components per page"),
fieldWithPath("page.totalElements").description("Total number of all existing components"),
fieldWithPath("page.totalPages").description("Total number of pages"),
fieldWithPath("page.number").description("Number of the current page")

)));
}

@Test
public void should_document_get_mysubscriptions_components() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class ReleaseSpecTest extends TestRestDocsSpecBase {

@MockBean
private Sw360LicenseService licenseServiceMock;
private Release release, release3;
private Release release, release3, release4;
private Attachment attachment;
Component component;
private Project project;
Expand Down Expand Up @@ -246,6 +246,43 @@ public void before() throws TException, IOException {
attachment3.setAttachmentType(AttachmentType.SOURCE);
release3.setAttachments(ImmutableSet.of(attachment3));

List<Release> releaseList2 = new ArrayList<>();
release4 = new Release();
Map<String, String> releaseExternalIds2 = new HashMap<>();
releaseExternalIds2.put("mainline-id-component", "1432");
releaseExternalIds2.put("ws-component-id", "[\"2365\",\"5487923\"]");

release4.setId(releaseId);
owner.setReleaseId(release.getId());
release4.setName("Spring Core 4.3.4");
release4.setCpeid("cpe:/a:pivotal:spring-core:4.3.4:");
release4.setReleaseDate("2016-12-07");
release4.setVersion("4.3.4");
release4.setCreatedOn("2016-12-18");
release4.setCreatedBy("admin@sw360.org");
release4.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
release4.setCreatedBy("admin@sw360.org");
release4.setSourceCodeDownloadurl("http://www.google.com");
release4.setBinaryDownloadurl("http://www.google.com/binaries");
release4.setComponentId(component.getId());
release4.setClearingState(ClearingState.APPROVED);
release4.setMainlineState(MainlineState.SPECIFIC);
release4.setExternalIds(releaseExternalIds);
release4.setComponentType(ComponentType.OSS);
release4.setAdditionalData(Collections.singletonMap("Key", "Value"));
release4.setAttachments(attachments);
release4.setLanguages(new HashSet<>(Arrays.asList("C++", "Java")));
release4.setMainLicenseIds(new HashSet<>(Arrays.asList("GPL-2.0-or-later", "Apache-2.0")));
release4.setOtherLicenseIds(new HashSet<>(Arrays.asList("MIT", "BSD-3-Clause")));
release4.setOperatingSystems(ImmutableSet.of("Windows", "Linux"));
release4.setSoftwarePlatforms(new HashSet<>(Arrays.asList("Java SE", ".NET")));
release4.setContributors(new HashSet<>(Arrays.asList("admin@sw360.org", "jane@sw360.org")));
release4.setVendor(new Vendor("TV", "Test Vendor", "http://testvendor.com"));
release4.setReleaseIdToRelationship(releaseIdToRelationship);
release4.setCotsDetails(cotsDetails);
release4.setClearingInformation(clearingInfo);
releaseList2.add(release4);

Set<Project> projectList = new HashSet<>();
project = new Project();
project.setId("376576");
Expand All @@ -263,6 +300,7 @@ public void before() throws TException, IOException {
given(this.releaseServiceMock.getUsingComponentsForRelease(eq(release.getId()), any())).willReturn(usedByComponent);
given(this.releaseServiceMock.deleteRelease(eq(release.getId()), any())).willReturn(RequestStatus.SUCCESS);
given(this.releaseServiceMock.searchByExternalIds(eq(externalIds), any())).willReturn((new HashSet<>(releaseList)));
given(this.releaseServiceMock.setComponentDependentFieldsInRelease(any(), any())).willReturn(release4);
given(this.releaseServiceMock.convertToEmbeddedWithExternalIds(eq(release))).willReturn(
new Release("Angular", "2.3.0", component.getId())
.setId(releaseId)
Expand Down

0 comments on commit e415e6f

Please sign in to comment.