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 16, 2024
1 parent 872c74e commit 7a056d3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,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 @@ -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
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);
restControllerHelper.updateCRSize(clearingRequest, projectWithClearingInfo);
halClearingRequest = new HalResource<>(clearingRequest);
restControllerHelper.addEmbeddedReleaseDetails(halClearingRequest, projectWithClearingInfo);
restControllerHelper.addEmbeddedProject(halClearingRequest, project, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,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 Down Expand Up @@ -147,6 +144,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 +1380,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 +1586,17 @@ public void addEmbeddedReleaseDetails(HalResource<ClearingRequest> halClearingRe
halClearingRequest.addEmbeddedResource("openRelease", openReleaseCount);
halClearingRequest.addEmbeddedResource("totalRelease", totalReleaseCount);
}

public void updateCRSize(ClearingRequest clearingRequest, Project project) {
int openReleaseCount = SW360Utils.getOpenReleaseCount(project.getReleaseClearingStateSummary());
ClearingRequestSize currentSize = SW360Utils.determineCRSize(openReleaseCount);
ClearingRequestSize initialSize = clearingRequest.getClearingSize();
if(initialSize == null) return;
if(!initialSize.equals(ClearingRequestSize.VERY_LARGE)) {
int limit = CLEARING_REQUEST_SIZE_MAP.get(initialSize);
if(openReleaseCount > limit){
clearingRequest.setClearingSize(currentSize);
}
}
}
}

0 comments on commit 7a056d3

Please sign in to comment.