Skip to content

Commit

Permalink
feat(rest): Add size parameter to clearing request.
Browse files Browse the repository at this point in the history
Signed-off-by: Akshit Joshi <[email protected]>
  • Loading branch information
akshitjoshii committed Oct 30, 2024
1 parent c167bcc commit 5010d20
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ private ThriftEnumUtils() {
ClearingRequestType.HIGH, "High ISR"
);

private static final ImmutableMap<ClearingRequestSize, String> 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<UserAccess, String> MAP_USER_ACCESS_STRING = ImmutableMap.<UserAccess, String>builder()
.put(UserAccess.READ, "Read")
.put(UserAccess.READ_WRITE, "Read and Write")
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions libraries/datahandler/src/main/thrift/moderation.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
**/
Expand Down
4 changes: 3 additions & 1 deletion libraries/datahandler/src/main/thrift/projects.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -247,7 +248,8 @@ struct ClearingRequest {
17: optional i64 modifiedOn,
18: optional list<i64> reOpenOn,
19: optional ClearingPriority priority,
20: optional ClearingType clearingType
20: optional ClearingType clearingType,
21: optional ClearingSize clearingSize
}

struct ProjectDTO{
Expand Down
8 changes: 8 additions & 0 deletions libraries/datahandler/src/main/thrift/sw360.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private HalResource<ClearingRequest> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +90,7 @@ public Set<ClearingRequest> 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.");
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -130,6 +128,9 @@ public class RestControllerHelper<T> {
@NonNull
private final Sw360ObligationService obligationService;

@NonNull
private final Sw360ClearingRequestService clearingRequestService;

@NonNull
private final ResourceComparatorGenerator<T> resourceComparatorGenerator = new ResourceComparatorGenerator<>();

Expand All @@ -147,6 +148,12 @@ public class RestControllerHelper<T> {
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<ClearingRequestSize, Integer> 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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1582,4 +1590,18 @@ public void addEmbeddedReleaseDetails(HalResource<ClearingRequest> 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);
}
}

0 comments on commit 5010d20

Please sign in to comment.