diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java index 33ab04e61f..4cb222176e 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java @@ -249,6 +249,11 @@ public AddDocumentRequestSummary createClearingRequest(ClearingRequest clearingR if (!(ProjectClearingState.CLOSED.equals(project.getClearingState()) || Visibility.PRIVATE.equals(project.getVisbility()))) { clearingRequest.setProjectBU(project.getBusinessUnit()); + Project projectWithInfo = fillClearingStateSummaryIncludingSubprojectsForSingleProject(project, user); + int initialOpenReleases = SW360Utils.getOpenReleaseCount(projectWithInfo.releaseClearingStateSummary); + ClearingRequestSize initialSize = SW360Utils.determineCRSize(initialOpenReleases); + clearingRequest.setClearingSize(initialSize); + log.info(initialOpenReleases + " open releases found for project: " + project.getId() + "and initial size is: " + initialSize); String crId = moderator.createClearingRequest(clearingRequest, user); if (CommonUtils.isNotNullEmptyOrWhitespace(crId)) { project.setClearingRequestId(crId); diff --git a/backend/moderation/src/main/java/org/eclipse/sw360/moderation/ModerationHandler.java b/backend/moderation/src/main/java/org/eclipse/sw360/moderation/ModerationHandler.java index 07cf1bcdf1..9da9e70804 100644 --- a/backend/moderation/src/main/java/org/eclipse/sw360/moderation/ModerationHandler.java +++ b/backend/moderation/src/main/java/org/eclipse/sw360/moderation/ModerationHandler.java @@ -13,12 +13,7 @@ import org.apache.thrift.TException; import org.eclipse.sw360.datahandler.common.DatabaseSettings; import org.eclipse.sw360.datahandler.db.ModerationSearchHandler; -import org.eclipse.sw360.datahandler.thrift.Comment; -import org.eclipse.sw360.datahandler.thrift.ModerationState; -import org.eclipse.sw360.datahandler.thrift.PaginationData; -import org.eclipse.sw360.datahandler.thrift.RemoveModeratorRequestStatus; -import org.eclipse.sw360.datahandler.thrift.RequestStatus; -import org.eclipse.sw360.datahandler.thrift.SW360Exception; +import org.eclipse.sw360.datahandler.thrift.*; import org.eclipse.sw360.datahandler.thrift.components.Component; import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.licenses.License; @@ -358,6 +353,14 @@ public void updateClearingRequestForChangeInProjectBU(String crId, String busine handler.updateClearingRequestForChangeInProjectBU(crId, businessUnit, user); } + @Override + public void updateClearingRequestForChangeInClearingSize(String crId, ClearingRequestSize size) throws TException { + assertId(crId); + assertNotNull(size); + + handler.updateClearingRequestForChangeInClearingSize(crId, size); + } + @Override public RequestStatus addCommentToClearingRequest(String id, Comment comment, User user) throws TException { assertId(id); diff --git a/backend/moderation/src/main/java/org/eclipse/sw360/moderation/db/ModerationDatabaseHandler.java b/backend/moderation/src/main/java/org/eclipse/sw360/moderation/db/ModerationDatabaseHandler.java index b3954722c4..56307a3fa1 100644 --- a/backend/moderation/src/main/java/org/eclipse/sw360/moderation/db/ModerationDatabaseHandler.java +++ b/backend/moderation/src/main/java/org/eclipse/sw360/moderation/db/ModerationDatabaseHandler.java @@ -30,6 +30,7 @@ import org.eclipse.sw360.datahandler.permissions.PermissionUtils; import org.eclipse.sw360.datahandler.thrift.ClearingRequestEmailTemplate; import org.eclipse.sw360.datahandler.thrift.ClearingRequestState; +import org.eclipse.sw360.datahandler.thrift.ClearingRequestSize; import org.eclipse.sw360.datahandler.thrift.Comment; import org.eclipse.sw360.datahandler.thrift.ModerationState; import org.eclipse.sw360.datahandler.thrift.PaginationData; @@ -320,6 +321,15 @@ public void updateClearingRequestForChangeInProjectBU(String crId, String busine log.error("Failed to update CR-ID: %s with error: %s", crId, e.getMessage()); } } + public void updateClearingRequestForChangeInClearingSize(String crId, ClearingRequestSize size) { + try{ + ClearingRequest clearingRequest = clearingRequestRepository.get(crId); + clearingRequest.setClearingSize(size); + clearingRequestRepository.update(clearingRequest); + } catch (Exception e) { + log.error("Failed to update CR-ID: %s with error: %s", crId, e.getMessage()); + } + } public RequestStatus addCommentToClearingRequest(String id, Comment comment, User user) { try { diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Utils.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Utils.java index 291385696d..614082da85 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Utils.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Utils.java @@ -744,6 +744,20 @@ public static String convertEpochTimeToDate(long timestamp) { return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } + public static ClearingRequestSize determineCRSize(int totalReleaseCount) { + if (totalReleaseCount >= 0 && totalReleaseCount <= 20) { + return ClearingRequestSize.VERY_SMALL; + } else if (totalReleaseCount >= 21 && totalReleaseCount <= 50) { + return ClearingRequestSize.SMALL; + } else if (totalReleaseCount > 50 && totalReleaseCount <= 75) { + return ClearingRequestSize.MEDIUM; + } else if (totalReleaseCount > 75 && totalReleaseCount <= 150) { + return ClearingRequestSize.LARGE; + } else { + return ClearingRequestSize.VERY_LARGE; + } + } + /** * Assumes that the process exists. */ diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftEnumUtils.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftEnumUtils.java index f18a6b948a..08e995e19d 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftEnumUtils.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftEnumUtils.java @@ -363,6 +363,15 @@ private ThriftEnumUtils() { ClearingRequestType.HIGH, "High ISR" ); + private static final ImmutableMap MAP_CLEARING_REQUEST_SIZE_STRING = ImmutableMap.of( + ClearingRequestSize.VERY_SMALL, "Very Small", + ClearingRequestSize.SMALL, "Small", + ClearingRequestSize.MEDIUM, "Medium", + ClearingRequestSize.LARGE, "Large", + ClearingRequestSize.VERY_LARGE, "Very Large" + ); + + private static final ImmutableMap MAP_USER_ACCESS_STRING = ImmutableMap.builder() .put(UserAccess.READ, "Read") .put(UserAccess.READ_WRITE, "Read and Write") @@ -456,6 +465,7 @@ private ThriftEnumUtils() { .put(PackageManager.class, MAP_PACKAGE_MANAGER_STRING) .put(CycloneDxComponentType.class, MAP_CYCLONE_DX_COMPONENT_TYPE_STRING) .put(ClearingRequestType.class, MAP_CLEARING_REQUEST_TYPE_STRING) + .put(ClearingRequestSize.class, MAP_CLEARING_REQUEST_SIZE_STRING) .build(); public static String enumToString(TEnum value) { diff --git a/libraries/datahandler/src/main/thrift/moderation.thrift b/libraries/datahandler/src/main/thrift/moderation.thrift index e6c6c02094..3e1b1d87bb 100644 --- a/libraries/datahandler/src/main/thrift/moderation.thrift +++ b/libraries/datahandler/src/main/thrift/moderation.thrift @@ -34,6 +34,7 @@ typedef licenses.License License typedef licenses.Obligation Obligation typedef components.ComponentType ComponentType typedef projects.ClearingRequest ClearingRequest +typedef sw360.ClearingRequestSize ClearingSize typedef spdxdocument.SPDXDocument SPDXDocument typedef documentcreationinformation.DocumentCreationInformation DocumentCreationInformation typedef packageinformation.PackageInformation PackageInformation @@ -314,6 +315,11 @@ service ModerationService { **/ oneway void updateClearingRequestForChangeInProjectBU(1: string crId, 2: string businessUnit, 3: User user); + /** + * update clearing request if project's BU is changed + **/ + oneway void updateClearingRequestForChangeInClearingSize(1: string crId, 2: ClearingSize size); + /** * get clearing request by Id for view/read **/ diff --git a/libraries/datahandler/src/main/thrift/projects.thrift b/libraries/datahandler/src/main/thrift/projects.thrift index 1c9920d319..56cc7df3b0 100644 --- a/libraries/datahandler/src/main/thrift/projects.thrift +++ b/libraries/datahandler/src/main/thrift/projects.thrift @@ -30,6 +30,7 @@ typedef sw360.SW360Exception SW360Exception typedef sw360.ClearingRequestState ClearingState typedef sw360.ClearingRequestPriority ClearingPriority typedef sw360.ClearingRequestType ClearingType +typedef sw360.ClearingRequestSize ClearingSize typedef sw360.Comment Comment typedef sw360.PaginationData PaginationData typedef components.Release Release @@ -247,7 +248,8 @@ struct ClearingRequest { 17: optional i64 modifiedOn, 18: optional list reOpenOn, 19: optional ClearingPriority priority, - 20: optional ClearingType clearingType + 20: optional ClearingType clearingType, + 21: optional ClearingSize clearingSize } struct ProjectDTO{ diff --git a/libraries/datahandler/src/main/thrift/sw360.thrift b/libraries/datahandler/src/main/thrift/sw360.thrift index af673f577d..752184ad92 100644 --- a/libraries/datahandler/src/main/thrift/sw360.thrift +++ b/libraries/datahandler/src/main/thrift/sw360.thrift @@ -89,6 +89,14 @@ enum ClearingRequestType { HIGH = 1 } +enum ClearingRequestSize{ + VERY_SMALL = 0, + SMALL = 1, + MEDIUM = 2, + LARGE = 3, + VERY_LARGE = 4 +} + enum Visibility { PRIVATE = 0, ME_AND_MODERATORS = 1, diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/ClearingRequestController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/ClearingRequestController.java index 577a24f1e3..819169670d 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/ClearingRequestController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/ClearingRequestController.java @@ -128,6 +128,8 @@ private HalResource createHalClearingRequestWithAllDetails(Clea if (StringUtils.hasText(clearingRequest.projectId)) { Project project = projectService.getProjectForUserById(clearingRequest.getProjectId(), sw360User); Project projectWithClearingInfo = projectService.getClearingInfo(project, sw360User); + ClearingRequest updatedCR = restControllerHelper.updateCRSize(clearingRequest, projectWithClearingInfo, sw360User); + halClearingRequest = new HalResource<>(updatedCR); restControllerHelper.addEmbeddedReleaseDetails(halClearingRequest, projectWithClearingInfo); restControllerHelper.addEmbeddedProject(halClearingRequest, project, true); } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/Sw360ClearingRequestService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/Sw360ClearingRequestService.java index ce743420f9..46a5d166ce 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/Sw360ClearingRequestService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/Sw360ClearingRequestService.java @@ -16,6 +16,7 @@ import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.THttpClient; import org.apache.thrift.transport.TTransportException; +import org.eclipse.sw360.datahandler.thrift.ClearingRequestSize; import org.eclipse.sw360.datahandler.thrift.ClearingRequestState; import org.eclipse.sw360.datahandler.thrift.Comment; import org.eclipse.sw360.datahandler.thrift.RequestStatus; @@ -89,7 +90,7 @@ public Set getMyClearingRequests(User sw360User, ClearingReques } return clearingrequests; } - + public ClearingRequest addCommentToClearingRequest(String crId, Comment comment, User sw360User) throws TException { if (crId == null || crId.isBlank()) { throw new IllegalArgumentException("Clearing request ID cannot be null or empty."); @@ -109,6 +110,11 @@ public ClearingRequest addCommentToClearingRequest(String crId, Comment comment, return getClearingRequestById(crId, sw360User); } - - + public void updateClearingRequestForChangeInClearingSize(String crId, ClearingRequestSize size) throws TException{ + try { + getThriftModerationClient().updateClearingRequestForChangeInClearingSize(crId, size); + } catch (SW360Exception e) { + log.error("Error updating clearing request for change in clearing size: " + e.getMessage()); + } + } } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/JacksonCustomizations.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/JacksonCustomizations.java index 7a5a95be06..72e4498233 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/JacksonCustomizations.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/JacksonCustomizations.java @@ -1862,7 +1862,8 @@ public static abstract class ReferenceDocDataMixin extends ReferenceDocData { "modifiedOn", "commentsSize", "setPriority", - "setClearingType" + "setClearingType", + "setClearingSize" }) @JsonRootName(value = "clearingRequest") public static abstract class ClearingRequestMixin extends ClearingRequest { 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 d3aa27e22e..863eaf020c 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 @@ -28,10 +28,7 @@ import org.eclipse.sw360.datahandler.resourcelists.ResourceClassNotFoundException; import org.eclipse.sw360.datahandler.resourcelists.ResourceComparatorGenerator; import org.eclipse.sw360.datahandler.resourcelists.ResourceListController; -import org.eclipse.sw360.datahandler.thrift.Comment; -import org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship; -import org.eclipse.sw360.datahandler.thrift.Quadratic; -import org.eclipse.sw360.datahandler.thrift.SW360Exception; +import org.eclipse.sw360.datahandler.thrift.*; import org.eclipse.sw360.datahandler.thrift.attachments.Attachment; import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentDTO; import org.eclipse.sw360.datahandler.thrift.attachments.CheckStatus; @@ -53,6 +50,7 @@ import org.eclipse.sw360.datahandler.thrift.vendors.Vendor; import org.eclipse.sw360.datahandler.thrift.vulnerabilities.*; import org.eclipse.sw360.rest.resourceserver.attachment.AttachmentController; +import org.eclipse.sw360.rest.resourceserver.clearingrequest.Sw360ClearingRequestService; import org.eclipse.sw360.rest.resourceserver.component.ComponentController; import org.eclipse.sw360.rest.resourceserver.license.LicenseController; import org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService; @@ -130,6 +128,9 @@ public class RestControllerHelper { @NonNull private final Sw360ObligationService obligationService; + @NonNull + private final Sw360ClearingRequestService clearingRequestService; + @NonNull private final ResourceComparatorGenerator resourceComparatorGenerator = new ResourceComparatorGenerator<>(); @@ -147,6 +148,12 @@ public class RestControllerHelper { private static final double MAX_CVSS = 10; public static final String PAGINATION_PARAM_PAGE_ENTRIES = "page_entries"; private static final String JWT_SUBJECT = "sub"; + public static final HashMap CLEARING_REQUEST_SIZE_MAP = new HashMap<>() {{ + put(ClearingRequestSize.VERY_SMALL, 20); + put(ClearingRequestSize.SMALL, 50); + put(ClearingRequestSize.MEDIUM, 75); + put(ClearingRequestSize.LARGE, 150); + }}; @NonNull private final com.fasterxml.jackson.databind.Module sw360Module; @@ -1377,6 +1384,7 @@ public ClearingRequest convertToEmbeddedClearingRequest(ClearingRequest clearing embeddedClearingRequest.setType(null); embeddedClearingRequest.setClearingType(clearingRequest.getClearingType()); embeddedClearingRequest.setTimestamp(clearingRequest.getTimestamp()); + embeddedClearingRequest.setClearingSize(clearingRequest.getClearingSize()); return embeddedClearingRequest; } @@ -1582,4 +1590,18 @@ public void addEmbeddedReleaseDetails(HalResource halClearingRe halClearingRequest.addEmbeddedResource("openRelease", openReleaseCount); halClearingRequest.addEmbeddedResource("totalRelease", totalReleaseCount); } + + public ClearingRequest updateCRSize(ClearingRequest clearingRequest, Project project, User sw360User) throws TException { + int openReleaseCount = SW360Utils.getOpenReleaseCount(project.getReleaseClearingStateSummary()); + ClearingRequestSize currentSize = SW360Utils.determineCRSize(openReleaseCount); + ClearingRequestSize initialSize = clearingRequest.getClearingSize(); + if(initialSize == null) return clearingRequest; + if(!initialSize.equals(ClearingRequestSize.VERY_LARGE)) { + int limit = CLEARING_REQUEST_SIZE_MAP.get(initialSize); + if(openReleaseCount > limit){ + clearingRequestService.updateClearingRequestForChangeInClearingSize(clearingRequest.getId(), currentSize); + } + } + return clearingRequestService.getClearingRequestById(clearingRequest.getId(), sw360User); + } }