diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java index d45c0ebce6..0ace28bbfd 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java @@ -1311,4 +1311,28 @@ public void addEmbeddedCotsDetails(HalResource halResource, Release release) { addEmbeddedFields("sw360:cotsDetail", cotsDetailsHalResource, halResource); } } + + public void addEmbeddedProjectResponsible(HalResource halResource, String projectResponsible) { + User sw360User = getUserByEmail(projectResponsible); + if(sw360User!=null) + addEmbeddedUser(halResource, sw360User, "projectResponsible"); + } + + public void addEmbeddedSecurityResponsibles (HalResource halResource, Set securityResponsibles) { + for (String securityResponsible : securityResponsibles) { + User sw360User = getUserByEmail(securityResponsible); + if(sw360User!=null) + addEmbeddedUser(halResource, sw360User, "securityResponsibles"); + } + } + + public void addEmbeddedClearingTeam(HalResource userHalResource, String clearingTeam, String resource) { + User sw360User = getUserByEmail(clearingTeam); + if(sw360User!=null) + addEmbeddedUser(userHalResource, sw360User, resource); + } + + public void addEmbeddedLicenseInfoHeaderText(HalResource halResource, String licenseInfoHeaderText, String relation) { + halResource.addEmbeddedResource(relation, licenseInfoHeaderText); + } } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java index 57b91446fb..cace8388a5 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java @@ -1870,12 +1870,49 @@ public ResponseEntity> getAdministration( sw360Project.setReleaseIdToUsage(null); sw360Project.setLinkedProjects(null); HalResource userHalResource = createHalProject(sw360Project, sw360User); + setAdditionalFieldsToHalResource(sw360Project,userHalResource); sw360Project.unsetLinkedProjects(); sw360Project.unsetReleaseIdToUsage(); + sw360Project.unsetModifiedBy(); + sw360Project.unsetProjectOwner(); return new ResponseEntity<>(userHalResource, HttpStatus.OK); } + private void setAdditionalFieldsToHalResource(Project sw360Project, HalResource userHalResource) throws TException { + try { + String licenseInfoHeaderText = sw360Project.getLicenseInfoHeaderText(); + if(licenseInfoHeaderText == null) { + licenseInfoHeaderText=""; + } + restControllerHelper.addEmbeddedLicenseInfoHeaderText(userHalResource, licenseInfoHeaderText, "licenseInfoHeaderText"); + + 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(){{add("");}}); + } + Set 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 createHalProjectDTO(Project sw360Project, User sw360User) throws TException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java index 7ae210ddfc..8c5fcde3d9 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java @@ -1959,8 +1959,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."), @@ -1968,6 +1966,9 @@ public void should_document_create_summary_administration() throws Exception { fieldWithPath("phaseOutSince").description("The project phase-out date"), fieldWithPath("clearingRequestId").description("Clearing Request id associated with project."), fieldWithPath("licenseInfoHeaderText").description("Display licenseInfoHeaderText info"), + fieldWithPath("securityResponsibles").description("The securityResponsibles display"), + fieldWithPath("projectResponsible").description("The projectResponsible display"), + subsectionWithPath("_embedded.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"),