Skip to content

Commit

Permalink
feat(rest): Add additional fields in get clearingrequest endpoints.
Browse files Browse the repository at this point in the history
Signed-off-by: Akshit Joshi <akshit.joshi@siemens-healthineers.com>
  • Loading branch information
akshitjoshii committed Sep 18, 2024
1 parent 79c4670 commit fc00aae
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -733,6 +735,15 @@ public static int getTotalReleaseCount(ReleaseClearingStateSummary clearingSumma
+ clearingSummary.getSentToClearingTool()+ clearingSummary.getApproved();
}

public static int getOpenReleaseCount(ReleaseClearingStateSummary clearingSummary) {
return getTotalReleaseCount(clearingSummary) - (clearingSummary.getApproved() + clearingSummary.getReportAvailable());
}

public static String convertEpochTimeToDate(long timestamp) {
LocalDate date = Instant.ofEpochMilli(timestamp).atZone(ZoneId.of("UTC")).toLocalDate();
return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}

/**
* Assumes that the process exists.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ResponseEntity<EntityModel<ClearingRequest>> getClearingRequestById(
) throws TException, URISyntaxException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
ClearingRequest clearingRequest = sw360ClearingRequestService.getClearingRequestById(docId, sw360User);
HalResource<ClearingRequest> halClearingRequest = createHalClearingRequestWithAllDetails(clearingRequest, sw360User);
HalResource<ClearingRequest> halClearingRequest = createHalClearingRequestWithAllDetails(clearingRequest, sw360User, true);
HttpStatus status = halClearingRequest == null ? HttpStatus.NO_CONTENT : HttpStatus.OK;
return new ResponseEntity<>(halClearingRequest, status);
}
Expand All @@ -118,24 +118,29 @@ public ResponseEntity<EntityModel<ClearingRequest>> getClearingRequestByProjectI
) throws TException, URISyntaxException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
ClearingRequest clearingRequest = sw360ClearingRequestService.getClearingRequestByProjectId(projectId, sw360User);
HalResource<ClearingRequest> halClearingRequest = createHalClearingRequestWithAllDetails(clearingRequest, sw360User);
HalResource<ClearingRequest> halClearingRequest = createHalClearingRequestWithAllDetails(clearingRequest, sw360User, true);
HttpStatus status = halClearingRequest == null ? HttpStatus.NO_CONTENT : HttpStatus.OK;
return new ResponseEntity<>(halClearingRequest, status);
}

private HalResource<ClearingRequest> createHalClearingRequestWithAllDetails(ClearingRequest clearingRequest, User sw360User) throws TException {
private HalResource<ClearingRequest> createHalClearingRequestWithAllDetails(ClearingRequest clearingRequest, User sw360User, boolean isSingleRequest) throws TException {
HalResource<ClearingRequest> halClearingRequest = new HalResource<>(clearingRequest);
if (StringUtils.hasText(clearingRequest.projectId)) {
Project project = projectService.getProjectForUserById(clearingRequest.getProjectId(), sw360User);
Project projectWithClearingInfo = projectService.getClearingInfo(project, sw360User);
restControllerHelper.addEmbeddedReleaseDetails(halClearingRequest, projectWithClearingInfo);
restControllerHelper.addEmbeddedProject(halClearingRequest, project, true);
}
User requestingUser = restControllerHelper.getUserByEmail(clearingRequest.getRequestingUser());
restControllerHelper.addEmbeddedUser(halClearingRequest, requestingUser, "requestingUser");
User clearingTeam = restControllerHelper.getUserByEmail(clearingRequest.getClearingTeam());
restControllerHelper.addEmbeddedUser(halClearingRequest, clearingTeam, "clearingTeam");
if(isSingleRequest){
User clearingTeam = restControllerHelper.getUserByEmail(clearingRequest.getClearingTeam());
restControllerHelper.addEmbeddedUser(halClearingRequest, clearingTeam, "clearingTeam");
}
if(clearingRequest.getClearingState().equals(ClearingRequestState.CLOSED) || clearingRequest.getClearingState().equals(ClearingRequestState.REJECTED)){
restControllerHelper.addEmbeddedTimestampOfDecision(halClearingRequest,clearingRequest.getTimestampOfDecision());
}
restControllerHelper.addEmbeddedDatesClearingRequest(halClearingRequest, clearingRequest, isSingleRequest);
return halClearingRequest;
}

Expand Down Expand Up @@ -170,10 +175,9 @@ public ResponseEntity<CollectionModel<EntityModel<ClearingRequest>>> getMyCleari

List<EntityModel<ClearingRequest>> clearingRequestList = new ArrayList<>();
for (ClearingRequest cr : clearingRequestSet) {
EntityModel<ClearingRequest> embeddedCRresource = null;
ClearingRequest embeddedCR = restControllerHelper.convertToEmbeddedClearingRequest(cr);
embeddedCRresource = EntityModel.of(embeddedCR);
clearingRequestList.add(embeddedCRresource);
HalResource<ClearingRequest> halResource = createHalClearingRequestWithAllDetails(embeddedCR, sw360User, false);
clearingRequestList.add(halResource);
}

CollectionModel<EntityModel<ClearingRequest>> resources = CollectionModel.of(clearingRequestList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentDTO;
import org.eclipse.sw360.datahandler.thrift.attachments.CheckStatus;
import org.eclipse.sw360.datahandler.thrift.attachments.UsageAttachment;
import org.eclipse.sw360.datahandler.thrift.components.Component;
import org.eclipse.sw360.datahandler.thrift.components.ComponentDTO;
import org.eclipse.sw360.datahandler.thrift.components.*;
import org.eclipse.sw360.datahandler.thrift.components.ComponentService;
import org.eclipse.sw360.datahandler.thrift.components.ComponentType;
import org.eclipse.sw360.datahandler.thrift.components.COTSDetails;
import org.eclipse.sw360.datahandler.thrift.licenses.LicenseType;
import org.eclipse.sw360.datahandler.thrift.packages.Package;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.datahandler.thrift.licenses.Obligation;
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest;
Expand Down Expand Up @@ -1378,6 +1375,8 @@ public ClearingRequest convertToEmbeddedClearingRequest(ClearingRequest clearing
embeddedClearingRequest.setProjectBU(clearingRequest.getProjectBU());
embeddedClearingRequest.setProjectId(clearingRequest.getProjectId());
embeddedClearingRequest.setType(null);
embeddedClearingRequest.setClearingType(clearingRequest.getClearingType());
embeddedClearingRequest.setTimestamp(clearingRequest.getTimestamp());
return embeddedClearingRequest;
}

Expand Down Expand Up @@ -1569,4 +1568,18 @@ public VulnerabilitySummary convertToEmbeddedVulnerabilitySumm(VulnerabilitySumm
embeddedProject.setIntReleaseName(sw360Vul.getIntReleaseName());
return embeddedProject;
}
public void addEmbeddedDatesClearingRequest(HalResource<ClearingRequest> halClearingRequest, ClearingRequest clearingRequest, boolean isSingleRequest) {
halClearingRequest.addEmbeddedResource("createdOn", SW360Utils.convertEpochTimeToDate(clearingRequest.getTimestamp()));
if (isSingleRequest) {
halClearingRequest.addEmbeddedResource("lastUpdatedOn", SW360Utils.convertEpochTimeToDate(clearingRequest.getModifiedOn()));
}
}

public void addEmbeddedReleaseDetails(HalResource<ClearingRequest> halClearingRequest, Project project) {
ReleaseClearingStateSummary clearingInfo = project.getReleaseClearingStateSummary();
int openReleaseCount = SW360Utils.getOpenReleaseCount(clearingInfo);
int totalReleaseCount = SW360Utils.getTotalReleaseCount(clearingInfo);
halClearingRequest.addEmbeddedResource("openRelease", openReleaseCount);
halClearingRequest.addEmbeddedResource("totalRelease", totalReleaseCount);
}
}
Loading

0 comments on commit fc00aae

Please sign in to comment.