Skip to content

Commit

Permalink
Fix(Rest): Add more information in get components response (support N…
Browse files Browse the repository at this point in the history
…ew GUI)

Signed-off-by: hoangnt2 <[email protected]>
  • Loading branch information
hoangnt2 committed May 30, 2023
1 parent 6f16ffe commit 776c9b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ private Component makeExportSummary(Component document, List<Release> releases)
copyField(document, copy, Component._Fields.CREATED_BY);
copyField(document, copy, Component._Fields.CREATED_ON);
copyField(document, copy, Component._Fields.VENDOR_NAMES);
copyField(document, copy, Component._Fields.MAIN_LICENSE_IDS);
copyField(document, copy, Component._Fields.COMPONENT_TYPE);
copyField(document, copy, Component._Fields.DEFAULT_VENDOR_ID);


for (Release release : releases) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,12 @@ static abstract class UserMixin extends User {

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(value = {
"id",
"revision",
"attachments",
"createdBy",
"subscribers",
"moderators",
"releases",
"mainLicenseIds",
"softwarePlatforms",
"wiki",
"blog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ public Component convertToEmbeddedComponent(Component component) {
embeddedComponent.setName(component.getName());
embeddedComponent.setComponentType(component.getComponentType());
embeddedComponent.setVisbility(component.getVisbility());
embeddedComponent.setMainLicenseIds(component.getMainLicenseIds());
if (CommonUtils.isNotNullEmptyOrWhitespace(component.getDefaultVendorId())) {
Vendor defaultVendor = vendorService.getVendorById(component.getDefaultVendorId());
embeddedComponent.setDefaultVendor(defaultVendor);
}
embeddedComponent.setType(null);
return embeddedComponent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelationDTO;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityState;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
import org.eclipse.sw360.rest.resourceserver.TestHelper;
import org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService;
import org.eclipse.sw360.rest.resourceserver.component.Sw360ComponentService;
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.eclipse.sw360.rest.resourceserver.vulnerability.Sw360VulnerabilityService;
import org.eclipse.sw360.rest.resourceserver.vendor.Sw360VendorService;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -93,6 +95,9 @@ public class ComponentSpecTest extends TestRestDocsSpecBase {
@MockBean
private Sw360VulnerabilityService vulnerabilityServiceMock;

@MockBean
private Sw360VendorService vendorServiceMock;

private Component angularComponent;

private Attachment attachment;
Expand All @@ -105,6 +110,14 @@ public class ComponentSpecTest extends TestRestDocsSpecBase {

@Before
public void before() throws TException, IOException {
Set<String> licenseIds = new HashSet<>();
licenseIds.add("MIT");
licenseIds.add("Apache-2.0");
Vendor vendor = new Vendor();
vendor.setId("vendorId");
vendor.setFullname("vendorFullName");
vendor.setShortname("vendorShortName");
vendor.setUrl("https://vendor.com");
Set<Attachment> attachmentList = new HashSet<>();
List<EntityModel<Attachment>> attachmentResources = new ArrayList<>();
attachment = new Attachment("1231231254", "spring-core-4.3.4.RELEASE.jar");
Expand Down Expand Up @@ -165,6 +178,8 @@ public void before() throws TException, IOException {
angularComponent.setMailinglist("[email protected]");
angularComponent.setAdditionalData(Collections.singletonMap("Key", "Value"));
angularComponent.setHomepage("https://angular.io");
angularComponent.setMainLicenseIds(licenseIds);
angularComponent.setDefaultVendorId("vendorId");
componentList.add(angularComponent);
componentListByName.add(angularComponent);

Expand All @@ -190,6 +205,8 @@ public void before() throws TException, IOException {
springComponent.setOperatingSystems(ImmutableSet.of("Windows", "Linux"));
springComponent.setExternalIds(springComponentExternalIds);
springComponent.setMailinglist("[email protected]");
springComponent.setMainLicenseIds(licenseIds);
springComponent.setDefaultVendorId("vendorId");
componentList.add(springComponent);
usedByComponent.add(springComponent);

Expand Down Expand Up @@ -240,6 +257,8 @@ public void before() throws TException, IOException {
given(this.userServiceMock.getUserByEmail("[email protected]")).willReturn(
new User("[email protected]", "sw360").setId("74427996"));

given(this.vendorServiceMock.getVendorById("vendorId")).willReturn(vendor);

List<Release> releaseList = new ArrayList<>();
Release release = new Release();
release.setId("3765276512");
Expand Down Expand Up @@ -467,7 +486,7 @@ public void should_document_get_components_with_all_details() throws Exception {
linkWithRel("last").description("Link to last page")
),
responseFields(

subsectionWithPath("_embedded.sw360:components.[]id").description("The id of the component"),
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"),
Expand All @@ -479,6 +498,9 @@ public void should_document_get_components_with_all_details() throws Exception {
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.[]mainLicenseIds").description("Main license ids of component"),
subsectionWithPath("_embedded.sw360:components.[]_embedded.defaultVendor").description("Default vendor of component"),
subsectionWithPath("_embedded.sw360:components.[]defaultVendorId").description("Default vendor of component"),

subsectionWithPath("_embedded.sw360:components.[]categories").description("The component categories"),
subsectionWithPath("_embedded.sw360:components.[]languages").description("The language of the component"),
Expand Down Expand Up @@ -638,6 +660,7 @@ public void should_document_get_component() throws Exception {
linkWithRel("self").description("The <<resources-components,Component resource>>")
),
responseFields(
fieldWithPath("id").description("The id of the component"),
fieldWithPath("name").description("The name of the component"),
fieldWithPath("componentType").description("The component type, possible values are: " + Arrays.asList(ComponentType.values())),
fieldWithPath("description").description("The component description"),
Expand All @@ -661,7 +684,10 @@ public void should_document_get_component() throws Exception {
subsectionWithPath("_embedded.sw360:attachments").description("An array of all component attachments and link to their <<resources-attachment-get,Attachment resource>>"),
fieldWithPath("visbility").description("The visibility type of the component"),
fieldWithPath("setVisbility").description("The visibility of the component"),
fieldWithPath("setBusinessUnit").description("Whether or not a business unit is set for the component")
fieldWithPath("setBusinessUnit").description("Whether or not a business unit is set for the component"),
fieldWithPath("mainLicenseIds").description("Main license ids of component"),
subsectionWithPath("_embedded.defaultVendor").description("Default vendor of component"),
fieldWithPath("defaultVendorId").description("Default vendor id of component")
)));
}

Expand Down Expand Up @@ -689,6 +715,7 @@ public void should_document_create_component() throws Exception {
fieldWithPath("homepage").description("The homepage url of the component")
),
responseFields(
fieldWithPath("id").description("The id of the component"),
fieldWithPath("name").description("The name of the component"),
fieldWithPath("componentType").description("The component type, possible values are: " + Arrays.asList(ComponentType.values())),
fieldWithPath("description").description("The component description"),
Expand Down Expand Up @@ -908,6 +935,7 @@ private RestDocumentationResultHandler documentComponentProperties() {
linkWithRel("self").description("The <<resources-components,Component resource>>")
),
responseFields(
fieldWithPath("id").description("The id of the component"),
fieldWithPath("name").description("The name of the component"),
fieldWithPath("componentType").description("The component type, possible values are: " + Arrays.asList(ComponentType.values())),
fieldWithPath("description").description("The component description"),
Expand All @@ -931,7 +959,10 @@ private RestDocumentationResultHandler documentComponentProperties() {
subsectionWithPath("_embedded.sw360:attachments").description("An array of all component attachments and link to their <<resources-attachment-get,Attachment resource>>"),
fieldWithPath("visbility").description("The visibility type of the component"),
fieldWithPath("setVisbility").description("The visibility of the component"),
fieldWithPath("setBusinessUnit").description("Whether or not a business unit is set for the component")
fieldWithPath("setBusinessUnit").description("Whether or not a business unit is set for the component"),
fieldWithPath("mainLicenseIds").description("Main license ids of component"),
subsectionWithPath("_embedded.defaultVendor").description("Default vendor of component"),
fieldWithPath("defaultVendorId").description("Default vendor id of component")
));
}

Expand Down

0 comments on commit 776c9b3

Please sign in to comment.