Skip to content

Commit

Permalink
[JN-474] Fix a gap in Juniper's comprehension of Pepper's kit status (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
breilly2 authored Sep 29, 2023
1 parent 080a5aa commit c0e364d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private void saveKitStatus(KitRequest kit, String statusJson, Instant pepperStat
// Set Juniper kit status if we can parse the Pepper status
try {
var kitStatus = objectMapper.readValue(statusJson, PepperKitStatus.class);
kit.setStatus(statusFromDSMStatus(kitStatus.getCurrentStatus()));
kit.setStatus(statusFromPepperCurrentStatus(kitStatus.getCurrentStatus()));
} catch (JsonProcessingException e) {
logger.warn(
"Unable to deserialize status JSON for kit %s: %s".formatted(kit.getId(), statusJson.toString()),
Expand All @@ -267,7 +267,7 @@ private void saveKitStatus(KitRequest kit, PepperKitStatus pepperKitStatus, Inst
try {
kit.setDsmStatus(objectMapper.writeValueAsString(pepperKitStatus));
kit.setDsmStatusFetchedAt(pepperStatusFetchedAt);
kit.setStatus(statusFromDSMStatus(pepperKitStatus.getCurrentStatus()));
kit.setStatus(statusFromPepperCurrentStatus(pepperKitStatus.getCurrentStatus()));
dao.update(kit);
} catch (JsonProcessingException e) {
logger.warn(
Expand All @@ -276,15 +276,18 @@ private void saveKitStatus(KitRequest kit, PepperKitStatus pepperKitStatus, Inst
}
}

private KitRequestStatus statusFromDSMStatus(String currentStatus) {
private KitRequestStatus statusFromPepperCurrentStatus(String currentStatus) {
if (currentStatus == null) {
return KitRequestStatus.CREATED;
} else if (PEPPER_COMPLETED_STATUSES.contains(currentStatus)) {
return KitRequestStatus.COMPLETE;
} else if (PEPPER_FAILED_STATUSES.contains(currentStatus)) {
return KitRequestStatus.FAILED;
} else {
return KitRequestStatus.IN_PROGRESS;
var status = PepperKitStatus.Status.fromCurrentStatus(currentStatus);
if (PepperKitStatus.Status.isCompleted(status)) {
return KitRequestStatus.COMPLETE;
} else if (PepperKitStatus.Status.isFailed(status)) {
return KitRequestStatus.FAILED;
} else {
return KitRequestStatus.IN_PROGRESS;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
package bio.terra.pearl.core.service.kit;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.Set;

@Getter @Setter
@SuperBuilder @NoArgsConstructor
@EqualsAndHashCode
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class PepperKitStatus {

public enum Status {
CREATED("kit without label"),
QUEUED("queue"),
SENT("sent"),
RECEIVED("received"),
ERRORED("error"),
DEACTIVATED("deactivated");

Status(String currentStatus) {
this.currentStatus = currentStatus;
}

final String currentStatus;

public static Status fromCurrentStatus(String currentStatus) {
for (Status status : Status.values()) {
if (status.currentStatus.equals(currentStatus.toLowerCase())) {
return status;
}
}
throw new IllegalArgumentException("Unexpected Pepper currentStatus: " + currentStatus);
}

public static boolean isCompleted(Status status) {
return Set.of(Status.RECEIVED, Status.DEACTIVATED).contains(status);
}

public static boolean isFailed(Status status) {
return status == Status.ERRORED;
}

}

private String juniperKitId;
private String currentStatus;
private String dsmShippingLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ public void testSyncAllKitStatusesFromPepper() throws Exception {
*/
var kitStatus1a = PepperKitStatus.builder()
.juniperKitId(kitRequest1a.getId().toString())
.currentStatus("SENT")
.currentStatus(PepperKitStatus.Status.SENT.currentStatus)
.build();
var kitStatus1b = PepperKitStatus.builder()
.juniperKitId(kitRequest1b.getId().toString())
.currentStatus("PROCESSED")
.currentStatus(PepperKitStatus.Status.RECEIVED.currentStatus)
.build();
var kitStatus2 = PepperKitStatus.builder()
.juniperKitId(kitRequest2.getId().toString())
.currentStatus("CONTAMINATED")
.currentStatus(PepperKitStatus.Status.ERRORED.currentStatus)
.errorMessage("Something went wrong")
.errorDate(DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(ZoneId.systemDefault()).format(Instant.now()))
.build();
Expand Down

0 comments on commit c0e364d

Please sign in to comment.