Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x1263 add priority field to flag #496

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/uk/ac/sanger/sccp/stan/GraphQLDataFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import uk.ac.sanger.sccp.stan.repo.*;
import uk.ac.sanger.sccp.stan.request.*;
import uk.ac.sanger.sccp.stan.request.LabwareRoi.RoiResult;
import uk.ac.sanger.sccp.stan.request.history.History;
import uk.ac.sanger.sccp.stan.request.history.HistoryGraph;
import uk.ac.sanger.sccp.stan.service.*;
import uk.ac.sanger.sccp.stan.service.extract.ExtractResultQueryService;
import uk.ac.sanger.sccp.stan.service.flag.FlagLookupService;
Expand Down Expand Up @@ -214,10 +216,10 @@ public DataFetcher<LabwareFlagged> findLabwareFlagged() {
throw new IllegalArgumentException("No barcode supplied.");
}
Labware lw = labwareRepo.getByBarcode(barcode);
if (requestsField(dfe, "flagged")) {
if (requestsField(dfe, "flagged") || requestsField(dfe, "flagPriority")) {
return flagLookupService.getLabwareFlagged(lw);
}
return new LabwareFlagged(lw, false);
return new LabwareFlagged(lw, null);
};
}

Expand Down
24 changes: 22 additions & 2 deletions src/main/java/uk/ac/sanger/sccp/stan/model/LabwareFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
@Entity
public class LabwareFlag {
public enum Priority implements Comparable<Priority> {
note, flag
}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
Expand All @@ -23,12 +27,17 @@ public class LabwareFlag {
private User user;
private Integer operationId;

public LabwareFlag(Integer id, Labware labware, String description, User user, Integer operationId) {
@Column(columnDefinition = "enum('note', 'flag')")
@Enumerated(EnumType.STRING)
private Priority priority = Priority.flag;

public LabwareFlag(Integer id, Labware labware, String description, User user, Integer operationId, Priority priority) {
this.id = id;
this.labware = labware;
this.description = description;
this.user = user;
this.operationId = operationId;
this.priority = priority;
}

public LabwareFlag() {}
Expand Down Expand Up @@ -77,6 +86,14 @@ public void setOperationId(Integer operationId) {
this.operationId = operationId;
}

public Priority getPriority() {
return this.priority;
}

public void setPriority(Priority priority) {
this.priority = priority;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -86,7 +103,9 @@ public boolean equals(Object o) {
&& Objects.equals(this.labware, that.labware)
&& Objects.equals(this.description, that.description)
&& Objects.equals(this.user, that.user)
&& Objects.equals(this.operationId, that.operationId));
&& Objects.equals(this.operationId, that.operationId)
&& this.priority==that.priority
);
}

@Override
Expand All @@ -102,6 +121,7 @@ public String toString() {
.addRepr("description", description)
.add("user", user==null ? null : user.getUsername())
.add("operationId", operationId)
.add("priority", priority)
.toString();
}
}
20 changes: 17 additions & 3 deletions src/main/java/uk/ac/sanger/sccp/stan/request/FlagDetail.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.ac.sanger.sccp.stan.request;

import uk.ac.sanger.sccp.stan.model.LabwareFlag.Priority;

import java.util.List;
import java.util.Objects;

Expand All @@ -17,10 +19,12 @@ public class FlagDetail {
public static class FlagSummary {
private String barcode;
private String description;
private Priority priority;

public FlagSummary(String barcode, String description) {
public FlagSummary(String barcode, String description, Priority priority) {
this.barcode = barcode;
this.description = description;
this.priority = priority;
}

/**
Expand All @@ -45,13 +49,23 @@ public void setDescription(String description) {
this.description = description;
}

public Priority getPriority() {
return this.priority;
}

public void setPriority(Priority priority) {
this.priority = priority;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FlagSummary that = (FlagSummary) o;
return (Objects.equals(this.barcode, that.barcode)
&& Objects.equals(this.description, that.description));
&& Objects.equals(this.description, that.description)
&& this.priority == that.priority
);
}

@Override
Expand All @@ -61,7 +75,7 @@ public int hashCode() {

@Override
public String toString() {
return String.format("[%s: %s]", barcode, repr(description));
return String.format("[%s: %s: %s]", priority, barcode, repr(description));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.ac.sanger.sccp.stan.request;

import uk.ac.sanger.sccp.stan.model.LabwareFlag.Priority;
import uk.ac.sanger.sccp.utils.BasicUtils;

import java.util.Objects;
Expand All @@ -12,11 +13,13 @@ public class FlagLabwareRequest {
private String barcode;
private String description;
private String workNumber;
private Priority priority;

public FlagLabwareRequest(String barcode, String description, String workNumber) {
public FlagLabwareRequest(String barcode, String description, String workNumber, Priority priority) {
this.barcode = barcode;
this.description = description;
this.workNumber = workNumber;
this.priority = priority;
}

// required for framework
Expand Down Expand Up @@ -53,14 +56,24 @@ public void setWorkNumber(String workNumber) {
this.workNumber = workNumber;
}

public Priority getPriority() {
return this.priority;
}

public void setPriority(Priority priority) {
this.priority = priority;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FlagLabwareRequest that = (FlagLabwareRequest) o;
return (Objects.equals(this.barcode, that.barcode)
&& Objects.equals(this.description, that.description)
&& Objects.equals(this.workNumber, that.workNumber));
&& Objects.equals(this.workNumber, that.workNumber)
&& this.priority == that.priority
);
}

@Override
Expand All @@ -74,6 +87,7 @@ public String toString() {
.add("barcode", barcode)
.add("description", description)
.addIfNotNull("workNumber", workNumber)
.add("priority", priority)
.reprStringValues()
.toString();
}
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/uk/ac/sanger/sccp/stan/request/LabwareFlagged.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.NotNull;
import uk.ac.sanger.sccp.stan.model.*;
import uk.ac.sanger.sccp.stan.model.LabwareFlag.Priority;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -15,11 +16,11 @@
public class LabwareFlagged {
@NotNull
private final Labware labware;
private final boolean flagged;
private final Priority flagPriority;

public LabwareFlagged(Labware labware, boolean flagged) {
public LabwareFlagged(Labware labware, Priority priority) {
this.labware = requireNonNull(labware, "labware is null");
this.flagged = flagged;
this.flagPriority = priority;
}

/**
Expand Down Expand Up @@ -108,15 +109,20 @@ public Labware getLabware() {
* Is there a labware flag applicable to this labware?
*/
public boolean isFlagged() {
return this.flagged;
return this.flagPriority != null;
}

/** The highest priority of flag on the labware, if any */
public Priority getFlagPriority() {
return this.flagPriority;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LabwareFlagged that = (LabwareFlagged) o;
return (this.flagged == that.flagged
return (this.flagPriority == that.flagPriority
&& this.labware.equals(that.labware));
}

Expand All @@ -127,6 +133,6 @@ public int hashCode() {

@Override
public String toString() {
return String.format("LabwareFlagged(%s, %s)", labware.getBarcode(), flagged);
return String.format("LabwareFlagged(%s, %s)", labware.getBarcode(), flagPriority);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uk.ac.sanger.sccp.stan.request.history;

import uk.ac.sanger.sccp.stan.model.LabwareFlag.Priority;

import java.util.List;
import java.util.Objects;

/**
* A flagged labware barcode and its flag priority
* @author dr6
*/
public class FlagBarcodes {
private final Priority priority;
private final List<String> barcodes;

public FlagBarcodes(Priority priority, List<String> barcodes) {
this.priority = priority;
this.barcodes = barcodes;
}

public Priority getPriority() {
return this.priority;
}

public List<String> getBarcodes() {
return this.barcodes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FlagBarcodes that = (FlagBarcodes) o;
return (this.priority == that.priority
&& Objects.equals(this.barcodes, that.barcodes));
}

@Override
public int hashCode() {
return Objects.hash(priority, barcodes);
}

@Override
public String toString() {
return String.format("(%s: %s)", priority, barcodes);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package uk.ac.sanger.sccp.stan.request;
package uk.ac.sanger.sccp.stan.request.history;

import uk.ac.sanger.sccp.stan.model.Labware;
import uk.ac.sanger.sccp.stan.model.Sample;
import uk.ac.sanger.sccp.utils.BasicUtils;
import uk.ac.sanger.sccp.stan.model.*;

import java.util.List;
import java.util.Objects;
import java.util.*;

import static uk.ac.sanger.sccp.utils.BasicUtils.nullToEmpty;
import static uk.ac.sanger.sccp.utils.BasicUtils.*;

/**
* @author dr6
Expand All @@ -16,21 +13,22 @@ public class History {
private List<HistoryEntry> entries;
private List<Sample> samples;
private List<Labware> labware;
private List<String> flaggedBarcodes;
private Map<LabwareFlag.Priority, List<String>> flagPriorityBarcodes;

public History(List<HistoryEntry> entries, List<Sample> samples, List<Labware> labware, List<String> flaggedBarcodes) {
public History(List<HistoryEntry> entries, List<Sample> samples, List<Labware> labware,
Map<LabwareFlag.Priority, List<String>> flagPriorityBarcodes) {
setEntries(entries);
setSamples(samples);
setLabware(labware);
setFlaggedBarcodes(flaggedBarcodes);
setFlagPriorityBarcodes(flagPriorityBarcodes);
}

public History(List<HistoryEntry> entries, List<Sample> samples, List<Labware> labware) {
this(entries, samples, labware, null);
}

public History() {
this(null, null, null);
this(null, null, null, null);
}

public List<HistoryEntry> getEntries() {
Expand All @@ -57,12 +55,25 @@ public void setLabware(List<Labware> labware) {
this.labware = nullToEmpty(labware);
}

public List<String> getFlaggedBarcodes() {
return this.flaggedBarcodes;
public Map<LabwareFlag.Priority, List<String>> getFlagPriorityBarcodes() {
return this.flagPriorityBarcodes;
}

public void setFlaggedBarcodes(List<String> flaggedBarcodes) {
this.flaggedBarcodes = nullToEmpty(flaggedBarcodes);
public void setFlagPriorityBarcodes(Map<LabwareFlag.Priority, List<String>> flagPriorityBarcodes) {
this.flagPriorityBarcodes = nullToEmpty(flagPriorityBarcodes);
}

/**
* Gets flagged barcodes as a list pairing up a priority with a list of barcodes
* @return a list of {@code FlagBarcodes} objects
*/
public List<FlagBarcodes> getFlagBarcodes() {
if (nullOrEmpty(flagPriorityBarcodes)) {
return List.of();
}
return flagPriorityBarcodes.entrySet().stream()
.map(e -> new FlagBarcodes(e.getKey(), e.getValue()))
.toList();
}

@Override
Expand All @@ -73,7 +84,7 @@ public boolean equals(Object o) {
return (Objects.equals(this.entries, that.entries)
&& Objects.equals(this.samples, that.samples)
&& Objects.equals(this.labware, that.labware)
&& Objects.equals(this.flaggedBarcodes, that.flaggedBarcodes));
&& Objects.equals(this.flagPriorityBarcodes, that.flagPriorityBarcodes));
}

@Override
Expand All @@ -83,11 +94,11 @@ public int hashCode() {

@Override
public String toString() {
return BasicUtils.describe("History")
return describe("History")
.add("entries", entries)
.add("samples", samples)
.add("labware", labware)
.add("flaggedBarcodes", flaggedBarcodes)
.add("flagPriorityBarcodes", flagPriorityBarcodes)
.toString();
}
}
Loading
Loading