Skip to content

Commit

Permalink
feat(rest) : Adding or Modifying fields to project summaryadminastrat…
Browse files Browse the repository at this point in the history
…ion page

Signed-off-by: Keerthi B L <[email protected]>
  • Loading branch information
keerthi-bl committed Nov 2, 2023
1 parent 4666d87 commit 271e4bd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ static abstract class MultiStatusMixin extends MultiStatus {
"createdBy",
"visbility",
"clearingTeam",
"projectOwner",
"homepage",
"wiki",
"documentState",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,4 +1311,26 @@ public void addEmbeddedCotsDetails(HalResource halResource, Release release) {
addEmbeddedFields("sw360:cotsDetail", cotsDetailsHalResource, halResource);
}
}

public void addEmbeddedProjectResponsible(HalResource<Project> halResource, String projectResponsible) {
User sw360User = getUserByEmail(projectResponsible);
if(sw360User!=null) {
addEmbeddedUser(halResource, sw360User, "projectResponsible");
}
}

public void addEmbeddedSecurityResponsibles (HalResource<Project> halResource, Set<String> securityResponsibles) {
for (String securityResponsible : securityResponsibles) {
User sw360User = getUserByEmail(securityResponsible);
if(sw360User!=null) {
addEmbeddedUser(halResource, sw360User, "securityResponsibles");
}
}
}

public void addEmbeddedClearingTeam(HalResource<Project> userHalResource, String clearingTeam, String resource) {
User sw360User = getUserByEmail(clearingTeam);
if(sw360User!=null)
addEmbeddedUser(userHalResource, sw360User, resource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1866,16 +1866,50 @@ public ResponseEntity<EntityModel<Project>> getAdministration(
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
Project sw360Project = projectService.getProjectForUserById(id, sw360User);
Map<String, String> sortedExternalURLs = CommonUtils.getSortedMap(sw360Project.getExternalUrls(), true);
if(sw360Project.getLicenseInfoHeaderText()==null) {
sw360Project.setLicenseInfoHeaderText("");
}
sw360Project.setExternalUrls(sortedExternalURLs);
sw360Project.setReleaseIdToUsage(null);
sw360Project.setLinkedProjects(null);
HalResource<Project> userHalResource = createHalProject(sw360Project, sw360User);
setAdditionalFieldsToHalResource(sw360Project,userHalResource);
sw360Project.unsetLinkedProjects();
sw360Project.unsetReleaseIdToUsage();
sw360Project.unsetProjectResponsible();
sw360Project.unsetSecurityResponsibles();

return new ResponseEntity<>(userHalResource, HttpStatus.OK);
}

private void setAdditionalFieldsToHalResource(Project sw360Project, HalResource<Project> userHalResource) throws TException {
try {
User projectModifier = restControllerHelper.getUserByEmail(sw360Project.getModifiedBy());
if (projectModifier != null) {
restControllerHelper.addEmbeddedUser(userHalResource, projectModifier, "modifiedBy");
}
User projectOwner = restControllerHelper.getUserByEmail(sw360Project.getProjectOwner());
if (projectOwner != null) {
restControllerHelper.addEmbeddedUser(userHalResource, projectOwner, "projectOwner");
}
if (sw360Project.getSecurityResponsibles() == null || sw360Project.getSecurityResponsibles().isEmpty()) {
sw360Project.setSecurityResponsibles(new HashSet<String>(){{add("");}});
}
Set<String> securityResponsibles = sw360Project.getSecurityResponsibles();
restControllerHelper.addEmbeddedSecurityResponsibles(userHalResource, securityResponsibles);

String clearingTeam = sw360Project.getClearingTeam();
if (clearingTeam != null) {
restControllerHelper.addEmbeddedClearingTeam(userHalResource, clearingTeam, "clearingTeam");
}
if (sw360Project.getProjectResponsible() != null) {
restControllerHelper.addEmbeddedProjectResponsible(userHalResource,sw360Project.getProjectResponsible());
}
}catch (Exception e) {
throw new TException(e.getMessage());
}
}

private HalResource<ProjectDTO> createHalProjectDTO(Project sw360Project, User sw360User) throws TException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand Down Expand Up @@ -1959,8 +1960,6 @@ public void should_document_create_summary_administration() throws Exception {
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."),
Expand All @@ -1970,6 +1969,11 @@ public void should_document_create_summary_administration() throws Exception {
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.projectResponsible").description("The project responsible displayed").type(JsonFieldType.OBJECT).optional(),
subsectionWithPath("_embedded.securityResponsibles").description("An array of project securityResponsible will get displayed").type(JsonFieldType.ARRAY).optional(),
subsectionWithPath("_embedded.projectOwner").description("The project owner").type(JsonFieldType.OBJECT).optional(),
subsectionWithPath("_embedded.modifiedBy").description("The user who modified the project").type(JsonFieldType.OBJECT).optional(),
subsectionWithPath("_embedded.leadArchitect").description("The user who leadArchitect of this project").type(JsonFieldType.OBJECT).optional(),
subsectionWithPath("_embedded.sw360:moderators").description("An array of moderators"),
subsectionWithPath("_embedded.sw360:packages").description("An array of linked <<resources-packages, Packages 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 271e4bd

Please sign in to comment.