Skip to content

Commit

Permalink
fix(rest): Added endpoint url for summary and administration page info
Browse files Browse the repository at this point in the history
Signed-off-by: Nikesh kumar <kumar.nikesh@simens.com>
  • Loading branch information
Nikesh kumar committed Jun 1, 2023
1 parent e1d2cb2 commit af669c0
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 6 deletions.
14 changes: 14 additions & 0 deletions rest/resource-server/src/docs/asciidoc/projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,19 @@ include::{snippets}/should_document_get_attachment_usage_for_project/curl-reques

===== Example response
include::{snippets}/should_document_get_attachment_usage_for_project/http-response.adoc[]
[[resources-project-get-summaryadministraion-project]]
==== Administration and Summary Info

A `GET` request will get summary and administration page of project tab.

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

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

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

[[resources-project-get-project-vulnerabilities]]
==== Listing project vulnerabilities
Expand Down Expand Up @@ -650,3 +663,4 @@ include::{snippets}/should_document_import_sbom/curl-request.adoc[]

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

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static abstract class MultiStatusMixin extends MultiStatus {
"attachments",
"createdBy",
"visbility",
"clearingTeam",
"homepage",
"wiki",
"documentState",
Expand Down Expand Up @@ -192,14 +191,11 @@ static abstract class MultiStatusMixin extends MultiStatus {
"setConsiderReleasesFromExternalList",
"externalUrlsSize",
"setExternalUrls",
"externalUrls",
"setVendor",
"setVendorId",
"setSpdxId",
"setModifiedOn",
"modifiedOn",
"setModifiedBy",
"modifiedBy"
})
static abstract class ProjectMixin extends Project {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ public void addEmbeddedLeadArchitect(HalResource halResource, String leadArchite
User sw360User = getUserByEmail(leadArchitect);
addEmbeddedUser(halResource, sw360User, "leadArchitect");
}

public void addEmbeddedReleases(
HalResource halResource,
Set<String> releases,
Expand Down Expand Up @@ -351,6 +350,23 @@ public HalResource<Vendor> addEmbeddedVendor(String vendorFullName) {
return null;
}

public HalResource<Vendor> addEmbeddedVendorsummaryAdministration(String vendorFullName,String shortName,String url) {
Vendor embeddedVendor = convertToSummaryAdministration(vendorFullName,shortName,url);
HalResource<Vendor> halVendor = new HalResource<>(embeddedVendor);
try {
Vendor vendorByFullName = vendorService.getVendorByFullName(vendorFullName);
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);
}
return null;
}

public void addEmbeddedLicenses(HalResource<Release> halComponent, Set<String> licenseIds) {
for (String licenseId : licenseIds) {
HalResource<License> licenseHalResource = addEmbeddedLicense(licenseId);
Expand Down Expand Up @@ -644,7 +660,14 @@ public Vendor convertToEmbeddedVendor(String fullName) {
embeddedVendor.setType(null);
return embeddedVendor;
}

public Vendor convertToSummaryAdministration(String fullName,String shortName,String url) {
Vendor embeddedVendor = new Vendor();
embeddedVendor.setFullname(fullName);
embeddedVendor.setShortname(shortName);
embeddedVendor.setUrl(url);
embeddedVendor.setType(null);
return embeddedVendor;
}
public Attachment convertToEmbeddedAttachment(Attachment attachment) {
attachment.setCreatedTeam(null);
attachment.setCreatedComment(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,51 @@ public ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectsForUser(
mapOfProjects, isSearchByName, sw360Projects, isNoFilter);
}

@RequestMapping(value = PROJECTS_URL + "/{id}/summaryAdministration", method = RequestMethod.GET)
public ResponseEntity<EntityModel<Project>> getAdministration(
@PathVariable("id") String id) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
Project sw360Project = projectService.getProjectForUserById(id, sw360User);
Map<String, String> sortedExternalURLs = CommonUtils.getSortedMap(sw360Project.getExternalUrls(), true);
sw360Project.setExternalUrls(sortedExternalURLs);
HalResource<Project> userHalResource = createHalSummaryAdministration(sw360Project, sw360User);
sw360Project.unsetLinkedProjects();
sw360Project.unsetReleaseIdToUsage();
return new ResponseEntity<>(userHalResource, HttpStatus.OK);
}

private HalResource<Project> createHalSummaryAdministration(Project sw360Project, User sw360User) throws TException {
HalResource<Project> halProject = new HalResource<>(sw360Project);
User projectCreator = restControllerHelper.getUserByEmail(sw360Project.getCreatedBy());
restControllerHelper.addEmbeddedUser(halProject, projectCreator, "createdBy");

if (sw360Project.getModerators() != null) {
Set<String> moderators = sw360Project.getModerators();
restControllerHelper.addEmbeddedModerators(halProject, moderators);
}

if (sw360Project.getAttachments() != null) {
restControllerHelper.addEmbeddedAttachments(halProject, sw360Project.getAttachments());
}

if(sw360Project.getLeadArchitect() != null) {
restControllerHelper.addEmbeddedLeadArchitect(halProject, sw360Project.getLeadArchitect());
}

if (sw360Project.getContributors() != null) {
Set<String> contributors = sw360Project.getContributors();
restControllerHelper.addEmbeddedContributors(halProject, contributors);
}
if (sw360Project.getVendor() != null) {
Vendor vendor = sw360Project.getVendor();
HalResource<Vendor> vendorHalResource = restControllerHelper.addEmbeddedVendorsummaryAdministration(vendor.getFullname(),vendor.getShortname(),vendor.getUrl());
halProject.addEmbeddedResource("sw360:vendors", vendorHalResource);
sw360Project.setVendor(null);
}

return halProject;
}

@NotNull
private ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectResponse(Pageable pageable,
String projectType, String group, String tag, boolean allDetails, boolean luceneSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void before() throws TException, IOException {
project.setClearingSummary("Lorem Ipsum");
project.setSpecialRisksOSS("Lorem Ipsum");
project.setGeneralRisks3rdParty("Lorem Ipsum");
project.setLicenseInfoHeaderText("Lorem Ipsum");
project.setSpecialRisks3rdParty("Lorem Ipsum");
project.setDeliveryChannels("Lorem Ipsum");
project.setVendor(new Vendor());
Expand All @@ -232,6 +233,10 @@ public void before() throws TException, IOException {
project.setAdditionalData(additionalData);
project.setPhaseOutSince("2020-06-24");
project.setClearingRequestId("CR-1");
Map<String, String> externalURLs1 = new HashMap<>();
externalURLs1.put("homepage", "http://test_wiki_url.com");
externalURLs1.put("wiki", "http://test_wiki_url.com");
project.setExternalUrls(externalURLs1);

projectListByName.add(project);
projectList.add(project);
Expand Down Expand Up @@ -265,6 +270,7 @@ public void before() throws TException, IOException {
project2.setGeneralRisks3rdParty("Lorem Ipsum");
project2.setSpecialRisks3rdParty("Lorem Ipsum");
project2.setDeliveryChannels("Lorem Ipsum");
project2.setLicenseInfoHeaderText("Lorem Ipsum");
project2.setRemarksAdditionalRequirements("Lorem Ipsum");
project2.setVendor(new Vendor());
project2.setSecurityResponsibles(new HashSet<>(Arrays.asList("securityresponsible1@sw360.org", "securityresponsible2@sw360.org")));
Expand Down Expand Up @@ -652,6 +658,7 @@ public void should_document_get_projects_with_all_details() throws Exception {
subsectionWithPath("_embedded.sw360:projects.[]ownerGroup").description("The owner group of the project"),
subsectionWithPath("_embedded.sw360:projects.[]ownerCountry").description("The owner country of the project"),
subsectionWithPath("_embedded.sw360:projects.[]obligationsText").description("The obligations text of the project"),
subsectionWithPath("_embedded.sw360:projects.[]licenseInfoHeaderText").description("The licenseInfoHeaderText text of the project"),
subsectionWithPath("_embedded.sw360:projects.[]clearingSummary").description("The clearing summary text of the project"),
subsectionWithPath("_embedded.sw360:projects.[]specialRisksOSS").description("The special risks OSS text of the project"),
subsectionWithPath("_embedded.sw360:projects.[]generalRisks3rdParty").description("The general risks 3rd party text of the project"),
Expand All @@ -678,6 +685,8 @@ public void should_document_get_projects_with_all_details() throws Exception {
subsectionWithPath("_embedded.sw360:projects.[]_embedded.clearingTeam").description("The clearingTeam of the project").optional(),
subsectionWithPath("_embedded.sw360:projects.[]_embedded.homepage").description("The homepage url of the project").optional(),
subsectionWithPath("_embedded.sw360:projects.[]_embedded.wiki").description("The wiki url of the project").optional(),
subsectionWithPath("_embedded.sw360:projects.[]externalUrls").description("A place to store additional data used by external tools").optional(),
subsectionWithPath("_embedded.sw360:projects.[]clearingTeam").description("A place to store additional data used by external tools").optional(),
subsectionWithPath("_embedded.sw360:projects.[]_embedded.sw360:moderators").description("An array of all project moderators with email").optional(),
subsectionWithPath("_embedded.sw360:projects.[]_embedded.sw360:contributors").description("An array of all project contributors with email").optional(),
subsectionWithPath("_embedded.sw360:projects.[]_embedded.sw360:attachments").description("An array of all project attachments").optional(),
Expand Down Expand Up @@ -737,7 +746,9 @@ public void should_document_get_project() throws Exception {
fieldWithPath("enableVulnerabilitiesDisplay").description("Displaying vulnerabilities flag."),
fieldWithPath("state").description("The project active status, possible values are: " + Arrays.asList(ProjectState.values())),
fieldWithPath("phaseOutSince").description("The project phase-out date"),
fieldWithPath("licenseInfoHeaderText").description("The licenseInfoHeaderText text of the project"),
fieldWithPath("clearingRequestId").description("Clearing Request id associated with project."),
subsectionWithPath("externalUrls").description("A place to store additional data used by external URLs"),
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources"),
subsectionWithPath("_embedded.createdBy").description("The user who created this project"),
subsectionWithPath("_embedded.sw360:projects").description("An array of <<resources-projects, Projects resources>>"),
Expand Down Expand Up @@ -1297,6 +1308,58 @@ public void should_document_create_project() throws Exception {
subsectionWithPath("_embedded.createdBy").description("The user who created this project")
)));
}
@Test
public void should_document_create_summary_administration() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(get("/api/projects/" + project.getId()+ "/summaryAdministration")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
responseFields(
fieldWithPath("name").description("The name of the project"),
fieldWithPath("version").description("The project version"),
fieldWithPath("createdOn").description("The date the project was created"),
fieldWithPath("projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())),
fieldWithPath("domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()),
fieldWithPath("visibility").description("The project visibility, possible values are: " + Arrays.asList(Visibility.values())),
subsectionWithPath("externalIds").description("When projects 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("additionalData").description("A place to store additional data used by external tools"),
fieldWithPath("ownerAccountingUnit").description("The owner accounting unit of the project"),
fieldWithPath("ownerGroup").description("The owner group of the project"),
fieldWithPath("description").description("The project description"),
fieldWithPath("ownerCountry").description("The owner country of the project"),
fieldWithPath("obligationsText").description("The obligations text of the project"),
fieldWithPath("clearingSummary").description("The clearing summary text of the project"),
fieldWithPath("specialRisksOSS").description("The special risks OSS text of the project"),
fieldWithPath("generalRisks3rdParty").description("The general risks 3rd party text of the project"),
fieldWithPath("specialRisks3rdParty").description("The special risks 3rd party text of the project"),
fieldWithPath("deliveryChannels").description("The sales and delivery channels text of the project"),
fieldWithPath("remarksAdditionalRequirements").description("The remark additional requirements text of the project"),
fieldWithPath("tag").description("The project tag"),
fieldWithPath("businessUnit").description("The business unit this project belongs to"),
fieldWithPath("deliveryStart").description("The project delivery start date"),
fieldWithPath("preevaluationDeadline").description("The project preevaluation deadline"),
fieldWithPath("systemTestStart").description("Date of the project system begin phase"),
fieldWithPath("systemTestEnd").description("Date of the project system end phase"),
fieldWithPath("securityResponsibles").description("An array of users responsible for security of the project."),
fieldWithPath("projectResponsible").description("A user who is responsible for the project."),
fieldWithPath("enableSvm").description("Security vulnerability monitoring flag"),
fieldWithPath("considerReleasesFromExternalList").description("Consider list of releases from existing external list"),
fieldWithPath("enableVulnerabilitiesDisplay").description("Displaying vulnerabilities flag."),
fieldWithPath("state").description("The project active status, possible values are: " + Arrays.asList(ProjectState.values())),
fieldWithPath("phaseOutSince").description("The project phase-out date"),
fieldWithPath("clearingRequestId").description("Clearing Request id associated with project."),
fieldWithPath("licenseInfoHeaderText").description("Display licenseInfoHeaderText info"),
subsectionWithPath("externalUrls").description("A place to store additional data used by external URLs"),
subsectionWithPath("_embedded.createdBy").description("The user who created this project"),
subsectionWithPath("_embedded.sw360:moderators").description("An array of moderators"),
subsectionWithPath("_embedded.sw360:vendors").description("An array of all component vendors with full name and link to their <<resources-vendor-get,Vendor resource>>"),
subsectionWithPath("_embedded.sw360:attachments").description("An array of all project attachments and link to their <<resources-attachment-get,Attachment resource>>"),
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources")
)));
}

@Test
public void should_document_create_duplicate_project() throws Exception {
Map<String, Object> projectReqs = new HashMap<>();
Expand Down Expand Up @@ -1441,6 +1504,8 @@ public void should_document_update_project() throws Exception {
fieldWithPath("considerReleasesFromExternalList").description("Consider list of releases from existing external list"),
fieldWithPath("enableVulnerabilitiesDisplay").description("Displaying vulnerabilities flag."),
subsectionWithPath("_embedded.sw360:moderators").description("An array of moderators"),
fieldWithPath("licenseInfoHeaderText").description("The licenseInfoHeaderText text of the project"),
subsectionWithPath("externalUrls").description("A place to store additional data used by external URLs"),
subsectionWithPath("_embedded.sw360:projects").description("An array of <<resources-projects, Projects resources>>"),
subsectionWithPath("_embedded.sw360:releases").description("An array of <<resources-releases, Releases resources>>"),
subsectionWithPath("_embedded.sw360:vendors").description("An array of all component vendors with full name and link to their <<resources-vendor-get,Vendor resource>>"),
Expand Down

0 comments on commit af669c0

Please sign in to comment.