diff --git a/src/main/java/uk/ac/sanger/sccp/stan/repo/WorkRepo.java b/src/main/java/uk/ac/sanger/sccp/stan/repo/WorkRepo.java index ebc7c746..a076db17 100644 --- a/src/main/java/uk/ac/sanger/sccp/stan/repo/WorkRepo.java +++ b/src/main/java/uk/ac/sanger/sccp/stan/repo/WorkRepo.java @@ -11,6 +11,9 @@ import java.util.function.Function; import static java.util.stream.Collectors.toMap; +import static java.util.stream.Collectors.toSet; +import static uk.ac.sanger.sccp.utils.BasicUtils.inMap; +import static uk.ac.sanger.sccp.utils.BasicUtils.stream; public interface WorkRepo extends CrudRepository { Optional findByWorkNumber(String workNumber); @@ -146,6 +149,32 @@ default Map findWorkNumbersForReleaseIds(Collection re @Query(value="select * from work_sample ws join work on (ws.work_id=work.id) where ws.sample_id=(?1) and ws.slot_id = (?2)", nativeQuery = true) Set findWorkForSampleIdAndSlotId(Integer sampleId, Integer slotId); + @Query(value="select slot_id, sample_id, work_id from work_sample ws where ws.slot_id in (?1)", nativeQuery = true) + List slotSampleWorkIdsForSlotIds(Collection slotIds); + + /** + * Loads works linked to the given slot ids. + * @param slotIds slot ids to look for works + * @return a map from slot/sample ids to the set of linked works + */ + default Map> slotSampleWorksForSlotIds(Collection slotIds) { + List rows = slotIds.isEmpty() ? List.of() : slotSampleWorkIdsForSlotIds(slotIds); + if (rows.isEmpty()) { + return Map.of(); + } + Set workIds = rows.stream() + .map(arr -> (Integer) arr[2]) + .collect(toSet()); + Map workMap = stream(findAllById(workIds)) + .collect(inMap(Work::getId)); + Map> map = new HashMap<>(); + for (Object[] row: rows) { + SlotIdSampleId key = new SlotIdSampleId((Integer) row[0], (Integer) row[1]); + map.computeIfAbsent(key, k -> new HashSet<>()).add(workMap.get((Integer) row[2])); + } + return map; + } + default Set getSetByWorkNumberIn(Collection workNumbers) throws EntityNotFoundException { return RepoUtils.getSetByField(this::findAllByWorkNumberIn, workNumbers, Work::getWorkNumber, "Unknown work number{s}: ", String::toUpperCase); diff --git a/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelData.java b/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelData.java index bc1c7e6a..bbd51241 100644 --- a/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelData.java +++ b/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelData.java @@ -4,6 +4,8 @@ import java.util.*; +import static uk.ac.sanger.sccp.utils.BasicUtils.nullToEmpty; + /** * A collection of information that may be printed onto a labware label. * @author dr6 @@ -13,16 +15,22 @@ public class LabwareLabelData { private final String externalBarcode; private final String medium; private final String date; - private final List contents; + private final Map extraFields; public LabwareLabelData(String barcode, String externalBarcode, String medium, String date, - List contents) { + List contents, Map extraFields) { this.barcode = barcode; this.externalBarcode = externalBarcode; this.medium = medium; this.date = date; - this.contents = List.copyOf(contents); + this.contents = nullToEmpty(contents); + this.extraFields = nullToEmpty(extraFields); + } + + public LabwareLabelData(String barcode, String externalBarcode, String medium, String date, + List contents) { + this(barcode, externalBarcode, medium, date, contents, null); } public String getBarcode() { @@ -45,6 +53,10 @@ public List getContents() { return this.contents; } + public Map getExtraFields() { + return this.extraFields; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -54,7 +66,9 @@ public boolean equals(Object o) { && Objects.equals(this.externalBarcode, that.externalBarcode) && Objects.equals(this.medium, that.medium) && Objects.equals(this.date, that.date) - && Objects.equals(this.contents, that.contents)); + && Objects.equals(this.contents, that.contents) + && Objects.equals(this.extraFields, that.extraFields) + ); } @Override @@ -70,6 +84,7 @@ public String toString() { .add("medium", medium) .add("date", date) .add("contents", contents) + .add("extraFields", extraFields) .omitNullValues() .reprStringValues() .toString(); @@ -81,6 +96,7 @@ public Map getFields() { fields.put("medium", getMedium()); fields.put("date", getDate()); fields.put("external", getExternalBarcode()); + fields.putAll(getExtraFields()); int index = 0; for (LabelContent content : contents) { addField(fields, "donor", index, content.donorName()); diff --git a/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelDataService.java b/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelDataService.java index ef1e6a0d..44938076 100644 --- a/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelDataService.java +++ b/src/main/java/uk/ac/sanger/sccp/stan/service/label/LabwareLabelDataService.java @@ -14,6 +14,7 @@ import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; +import static uk.ac.sanger.sccp.utils.BasicUtils.reverseIter; /** * Service for creating LabwareLabelData from labware. @@ -96,6 +97,53 @@ public LabwareLabelData toLabelData(Labware labware, List content, return new LabwareLabelData(labware.getBarcode(), labware.getExternalBarcode(), medium, dateString, content); } + /** + * Label data for labware that has a label per slot + * @param lw the labware being labelled + * @param workNumbers the work number linked to each slot/sample combination + * @param lp the lp number linked to the labware, if any + * @return label data for the labware + */ + public List getSplitLabelData(Labware lw, Map workNumbers, String lp) { + List datas = new ArrayList<>(lw.getSlots().size()); + // Iterate the slots in reverse order + for (Slot slot : reverseIter(lw.getSlots())) { + if (!slot.getSamples().isEmpty()) { + Sample sample = slot.getSamples().getFirst(); + String workNumber = workNumbers.get(new SlotIdSampleId(slot, sample)); + Tissue tissue = sample.getTissue(); + LabelContent lc = new LabelContent(tissue.getDonor().getDonorName(), tissue.getExternalName(), + null, sample.getBioState().toString()); + Map extra = filteredMap("lp", lp, "work", workNumber, + "address", slot.getAddress().toString()); + datas.add(new LabwareLabelData(lw.getBarcode(), lw.getExternalBarcode(), null, null, + List.of(lc), extra)); + } + } + return datas; + } + + /** + * Returns a map containing the given keys and values, omitted null keys and null values + * @param data alternating keys and values + * @return a map containing the data, excluding null keys and values + * @param type of data array given (base type of K and V) + * @param key type + * @param value type + */ + @SuppressWarnings("unchecked") + static Map filteredMap(B... data) { + Map map = new HashMap<>(data.length/2); + for (int i = 0; i < data.length; i+=2) { + K key = (K) data[i]; + V value = (V) data[i+1]; + if (key!=null && value!=null) { + map.put(key, value); + } + } + return map; + } + /** * Label data where we list the tissue for each row. * @param labware the labware the label describes diff --git a/src/main/java/uk/ac/sanger/sccp/stan/service/label/print/LabelPrintService.java b/src/main/java/uk/ac/sanger/sccp/stan/service/label/print/LabelPrintService.java index 25b67e1f..f8319fec 100644 --- a/src/main/java/uk/ac/sanger/sccp/stan/service/label/print/LabelPrintService.java +++ b/src/main/java/uk/ac/sanger/sccp/stan/service/label/print/LabelPrintService.java @@ -1,20 +1,24 @@ package uk.ac.sanger.sccp.stan.service.label.print; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import uk.ac.sanger.sccp.stan.model.*; import uk.ac.sanger.sccp.stan.repo.*; +import uk.ac.sanger.sccp.stan.service.LabwareNoteService; import uk.ac.sanger.sccp.stan.service.LabwareService; import uk.ac.sanger.sccp.stan.service.label.*; +import uk.ac.sanger.sccp.stan.service.work.WorkService; +import uk.ac.sanger.sccp.utils.UCMap; import javax.persistence.EntityNotFoundException; import java.io.IOException; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.function.Function; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; +import static java.util.stream.Collectors.*; +import static uk.ac.sanger.sccp.utils.BasicUtils.nullOrEmpty; +import static uk.ac.sanger.sccp.utils.UCMap.toUCMap; /** * Service to perform and record labware label printing @@ -29,11 +33,13 @@ public class LabelPrintService { private final LabwarePrintRepo labwarePrintRepo; private final LabelTypeRepo labelTypeRepo; private final LabwareService labwareService; + private final LabwareNoteService noteService; + private final WorkService workService; @Autowired public LabelPrintService(LabwareLabelDataService labwareLabelDataService, PrintClientFactory printClientFactory, LabwareRepo labwareRepo, PrinterRepo printerRepo, LabwarePrintRepo labwarePrintRepo, - LabelTypeRepo labelTypeRepo, LabwareService labwareService) { + LabelTypeRepo labelTypeRepo, LabwareService labwareService, LabwareNoteService noteService, WorkService workService) { this.labwareLabelDataService = labwareLabelDataService; this.printClientFactory = printClientFactory; this.labwareRepo = labwareRepo; @@ -41,6 +47,8 @@ public LabelPrintService(LabwareLabelDataService labwareLabelDataService, PrintC this.labwarePrintRepo = labwarePrintRepo; this.labelTypeRepo = labelTypeRepo; this.labwareService = labwareService; + this.noteService = noteService; + this.workService = workService; } public void printLabwareBarcodes(User user, String printerName, List barcodes) throws IOException { @@ -66,20 +74,46 @@ public void printLabware(User user, String printerName, List labware) t throw new IllegalArgumentException("Cannot perform a print request incorporating multiple different label types."); } LabelType labelType = labelTypes.iterator().next(); - final Function labelFunction; - if (labelType.getName().equalsIgnoreCase("adh")) { - labelFunction = labwareLabelDataService::getRowBasedLabelData; + List labelData; + if (labelType.getName().equalsIgnoreCase("strip")) { + // NB if we try and label empty strip tubes from planned actions, it won't work + labelData = stripLabwareLabelData(labware); } else { - labelFunction = labwareLabelDataService::getLabelData; + final Function labelFunction; + if (labelType.getName().equalsIgnoreCase("adh")) { + labelFunction = labwareLabelDataService::getRowBasedLabelData; + } else { + labelFunction = labwareLabelDataService::getLabelData; + } + labelData = labware.stream() + .map(labelFunction) + .toList(); } - List labelData = labware.stream() - .map(labelFunction) - .collect(toList()); LabelPrintRequest request = new LabelPrintRequest(labelType, labelData); print(printer, request); recordPrint(printer, user, labware); } + /** + * Loads the strip label data for the given labware. + * Strip tube labware has multiple labels for each item of labware. + * @param labware the labware being labelled + * @return the label data for all the labware + */ + @NotNull + List stripLabwareLabelData(List labware) { + UCMap lpNumbers = noteService.findNoteValuesForLabware(labware, "lp number").entrySet().stream() + .filter(e -> !nullOrEmpty(e.getValue())) + .collect(toUCMap(Map.Entry::getKey, e -> e.getValue().iterator().next())); + Map> slotWorks = workService.loadWorksForSlotsIn(labware); + Map slotWorkNumbers = slotWorks.entrySet().stream() + .filter(e -> !nullOrEmpty(e.getValue())) + .collect(toMap(Map.Entry::getKey, e -> e.getValue().iterator().next().getWorkNumber())); + return labware.stream() + .flatMap(lw -> labwareLabelDataService.getSplitLabelData(lw, slotWorkNumbers, lpNumbers.get(lw.getBarcode())).stream()) + .toList(); + } + public void print(Printer printer, LabelPrintRequest request) throws IOException { PrintClient printClient = printClientFactory.getClient(printer.getService()); printClient.print(printer.getName(), request); diff --git a/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkService.java b/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkService.java index e473af96..d2c0157b 100644 --- a/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkService.java +++ b/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkService.java @@ -6,8 +6,7 @@ import uk.ac.sanger.sccp.stan.request.WorkWithComment; import uk.ac.sanger.sccp.utils.UCMap; -import java.util.Collection; -import java.util.List; +import java.util.*; import java.util.stream.Stream; /** @@ -222,6 +221,13 @@ Work createWork(User user, String prefix, String workTypeName, String workReques */ List getWorksCreatedBy(User user); + /** + * Loads works linked to the slots in the given labware + * @param labware labware + * @return map of slot/sample ids to works + */ + Map> loadWorksForSlotsIn(Collection labware); + /** * struct-like container for a work and an operation */ diff --git a/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkServiceImp.java b/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkServiceImp.java index d8565c27..5c6eff3b 100644 --- a/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkServiceImp.java +++ b/src/main/java/uk/ac/sanger/sccp/stan/service/work/WorkServiceImp.java @@ -507,6 +507,17 @@ public List getWorksCreatedBy(User user) { .collect(toList()); } + @Override + public Map> loadWorksForSlotsIn(Collection labware) { + return loadWorksForSlots(labware.stream() + .flatMap(lw -> lw.getSlots().stream())); + } + + public Map> loadWorksForSlots(Stream slots) { + List slotIds = slots.map(Slot::getId).toList(); + return workRepo.slotSampleWorksForSlotIds(slotIds); + } + public void fillInComments(Collection wcs, Map workEvents) { for (WorkWithComment wc : wcs) { Work work = wc.getWork(); diff --git a/src/main/resources/sprint.properties b/src/main/resources/sprint.properties index 17026728..3366b317 100644 --- a/src/main/resources/sprint.properties +++ b/src/main/resources/sprint.properties @@ -3,6 +3,7 @@ sprint.host = http://sprint.psd.sanger.ac.uk/graphql sprint.template_dir = sprint sprint.templates = {\ + 'strip' : 'strip.json',\ 'adh' : 'adh.json',\ 'slide@3' : 'slide3.json',\ 'slide@6' : 'slide6.json',\ diff --git a/src/main/resources/sprint/strip.json b/src/main/resources/sprint/strip.json new file mode 100644 index 00000000..7ab6bbbc --- /dev/null +++ b/src/main/resources/sprint/strip.json @@ -0,0 +1,61 @@ +{ + "labelSize": { + "width": 39, + "height": 8, + "displacement": 8 + }, + "barcodeFields": [ + { + "x": 8, + "y": 1, + "value": "#barcode#", + "barcodeType": "datamatrix", + "cellWidth": 0.25 + }, + { + "x": 32, + "y": 1, + "value": "#barcode#", + "barcodeType": "datamatrix", + "cellWidth": 0.25 + } + ], + "textFields": [ + { + "x": 20, + "y": 2, + "value": "#work#", + "fontSize": 1.7 + }, + { + "x": 27, + "y": 2, + "value": "#lp#", + "fontSize": 1.7 + }, + { + "x": 12, + "y": 4, + "value": "#address#", + "fontSize": 1.8 + }, + { + "x": 20, + "y": 4, + "value": "#state[0]#", + "fontSize": 1.8 + }, + { + "x": 20, + "y": 6, + "value": "#tissue[0]#", + "fontSize": 1.5 + }, + { + "x": 8, + "y": 7, + "value": "#barcode#", + "fontSize": 1.5 + } + ] +} diff --git a/src/test/java/uk/ac/sanger/sccp/stan/repo/TestWorkRepo.java b/src/test/java/uk/ac/sanger/sccp/stan/repo/TestWorkRepo.java index 657bff75..8253ebfa 100644 --- a/src/test/java/uk/ac/sanger/sccp/stan/repo/TestWorkRepo.java +++ b/src/test/java/uk/ac/sanger/sccp/stan/repo/TestWorkRepo.java @@ -323,6 +323,15 @@ public void testFindWorkForSampleIdAndSlotId() { assertThat(workIds).containsExactlyInAnyOrder(work1.getId(), work2.getId()); workIds = workRepo.findWorkIdsForLabwareId(labware[1].getId()); assertThat(workIds).containsExactly(work2.getId()); + + List slotIds = labware[0].getSlots().stream() + .map(Slot::getId) + .toList(); + + Map> slotWorks = workRepo.slotSampleWorksForSlotIds(slotIds); + assertThat(slotWorks).hasSize(1); + assertThat(slotWorks.get(new SlotIdSampleId(labware[0].getFirstSlot(), samples[0]))) + .containsExactlyInAnyOrder(work1, work2); } @Transactional diff --git a/src/test/java/uk/ac/sanger/sccp/stan/service/label/TestLabwareLabelDataService.java b/src/test/java/uk/ac/sanger/sccp/stan/service/label/TestLabwareLabelDataService.java index a35212d0..b4a6bcdc 100644 --- a/src/test/java/uk/ac/sanger/sccp/stan/service/label/TestLabwareLabelDataService.java +++ b/src/test/java/uk/ac/sanger/sccp/stan/service/label/TestLabwareLabelDataService.java @@ -501,6 +501,33 @@ public void testGetDividedLabelData_valid(boolean sameMedium) { assertEquals(expectedContents, ld.getContents()); } + @ParameterizedTest + @ValueSource(booleans={false,true}) + public void testGetSplitLabelData(boolean hasLp) { + String lp = (hasLp ? "LP1" : null); + LabwareType lt = EntityFactory.makeLabwareType(3,1); + Sample[] samples = EntityFactory.makeSamples(2); + Tissue tissue = samples[0].getTissue(); + Donor donor = tissue.getDonor(); + Labware lw = EntityFactory.makeLabware(lt, samples); + String state = samples[0].getBioState().getName(); + Map slotWork = Map.of( + new SlotIdSampleId(lw.getFirstSlot(), samples[0]), "SGP1", + new SlotIdSampleId(lw.getFirstSlot(), samples[1]), "SGP2" + ); + List expectedLds = List.of( + new LabwareLabelData(lw.getBarcode(), lw.getExternalBarcode(), null, null, + List.of(new LabelContent(donor.getDonorName(), tissue.getExternalName(), null, state)), + hasLp ? Map.of("lp", "LP1", "address", "B1") + : Map.of("address", "B1")), + new LabwareLabelData(lw.getBarcode(), lw.getExternalBarcode(), null, null, + List.of(new LabelContent(donor.getDonorName(), tissue.getExternalName(), null, state)), + hasLp ? Map.of("lp", "LP1", "address", "A1", "work", "SGP1") + : Map.of("address", "A1", "work", "SGP1")) + ); + assertThat(service.getSplitLabelData(lw, slotWork, lp)).containsExactlyElementsOf(expectedLds); + } + @ParameterizedTest @EnumSource(LifeStage.class) public void testGetTissueDesc(LifeStage lifeStage) { diff --git a/src/test/java/uk/ac/sanger/sccp/stan/service/label/print/TestLabelPrintService.java b/src/test/java/uk/ac/sanger/sccp/stan/service/label/print/TestLabelPrintService.java index 9b7e7ca3..89b84a41 100644 --- a/src/test/java/uk/ac/sanger/sccp/stan/service/label/print/TestLabelPrintService.java +++ b/src/test/java/uk/ac/sanger/sccp/stan/service/label/print/TestLabelPrintService.java @@ -5,13 +5,16 @@ import uk.ac.sanger.sccp.stan.EntityFactory; import uk.ac.sanger.sccp.stan.model.*; import uk.ac.sanger.sccp.stan.repo.*; +import uk.ac.sanger.sccp.stan.service.LabwareNoteService; import uk.ac.sanger.sccp.stan.service.LabwareService; import uk.ac.sanger.sccp.stan.service.label.*; import uk.ac.sanger.sccp.stan.service.label.LabwareLabelData.LabelContent; +import uk.ac.sanger.sccp.stan.service.work.WorkService; +import uk.ac.sanger.sccp.utils.UCMap; import java.io.IOException; import java.time.LocalDateTime; -import java.util.List; +import java.util.*; import java.util.stream.IntStream; import static java.util.stream.Collectors.toList; @@ -31,8 +34,9 @@ public class TestLabelPrintService { private PrinterRepo mockPrinterRepo; private LabwarePrintRepo mockLabwarePrintRepo; private LabelTypeRepo mockLabelTypeRepo; - private LabwareService mockLabwareService; + private LabwareNoteService mockNoteService; + private WorkService mockWorkService; private LabelPrintService labelPrintService; private User user; @@ -48,9 +52,11 @@ void setup() { mockLabwarePrintRepo = mock(LabwarePrintRepo.class); mockLabelTypeRepo = mock(LabelTypeRepo.class); mockLabwareService = mock(LabwareService.class); + mockNoteService = mock(LabwareNoteService.class); + mockWorkService = mock(WorkService.class); labelPrintService = spy(new LabelPrintService(mockLabwareLabelDataService, mockPrintClientFactory, mockLabwareRepo, - mockPrinterRepo, mockLabwarePrintRepo, mockLabelTypeRepo, mockLabwareService)); + mockPrinterRepo, mockLabwarePrintRepo, mockLabelTypeRepo, mockLabwareService, mockNoteService, mockWorkService)); user = EntityFactory.getUser(); printer = EntityFactory.getPrinter(); LabwareType lt = EntityFactory.getTubeType(); @@ -110,7 +116,7 @@ public void testPrintLabwareWithRowBasedLabel() throws IOException { ); LabelPrintRequest expectedRequest = new LabelPrintRequest(lw.getLabwareType().getLabelType(), labelData); - when(mockLabwareLabelDataService.getRowBasedLabelData(lw)).thenReturn(labelData.get(0)); + when(mockLabwareLabelDataService.getRowBasedLabelData(lw)).thenReturn(labelData.getFirst()); when(mockLabwareService.calculateLabelType(lw)).thenReturn(lw.getLabwareType().getLabelType()); doNothing().when(labelPrintService).print(any(), any()); doReturn(List.of()).when(labelPrintService).recordPrint(any(), any(), any()); @@ -141,6 +147,60 @@ public void testPrintLabwareErrors() throws IOException { .hasMessage("Cannot perform a print request incorporating multiple different label types."); } + private List setupStripTubes() { + LabelType lbl = new LabelType(50, "strip"); + LabwareType lt = EntityFactory.makeLabwareType(3, 1, "strip tube"); + lt.setLabelType(lbl); + Sample[] samples = EntityFactory.makeSamples(2); + Labware lw1 = EntityFactory.makeLabware(lt, samples[0], samples[1]); + Labware lw2 = EntityFactory.makeLabware(lt, samples[1]); + List lws = List.of(lw1, lw2); + Map> workMap = Map.of(new SlotIdSampleId(lw1.getFirstSlot(), samples[0]), + Set.of(EntityFactory.makeWork("SGP1"))); + when(mockWorkService.loadWorksForSlotsIn(any())).thenReturn(workMap); + UCMap> lpMap = new UCMap<>(1); + lpMap.put(lw1.getBarcode(), Set.of("LP1")); + when(mockNoteService.findNoteValuesForLabware(anyCollection(), any())).thenReturn(lpMap); + when(mockLabwareService.calculateLabelType(any())).then(invocation -> { + Labware lw = invocation.getArgument(0); + return lw.getLabwareType().getLabelType(); + }); + return lws; + } + + @Test + public void testPrintStripLabels() throws IOException { + when(mockPrinterRepo.getByName(printer.getName())).thenReturn(printer); + List lws = setupStripTubes(); + LabelType lbl = lws.getFirst().getLabwareType().getLabelType(); + doNothing().when(labelPrintService).print(any(), any()); + doReturn(List.of()).when(labelPrintService).recordPrint(any(), any(), any()); + + LabwareLabelData ld1 = new LabwareLabelData("LLD1", null, null, null, null); + LabwareLabelData ld2 = new LabwareLabelData("LLD2", null, null, null, null); + when(mockLabwareLabelDataService.getSplitLabelData(same(lws.get(0)), any(), any())).thenReturn(List.of(ld1)); + when(mockLabwareLabelDataService.getSplitLabelData(same(lws.get(1)), any(), any())).thenReturn(List.of(ld2)); + + labelPrintService.printLabware(user, printer.getName(), lws); + LabelPrintRequest expectedRequest = new LabelPrintRequest(lbl, List.of(ld1, ld2)); + verify(labelPrintService).print(printer, expectedRequest); + verify(labelPrintService).recordPrint(printer, user, lws); + verify(mockWorkService).loadWorksForSlotsIn(lws); + verify(mockNoteService).findNoteValuesForLabware(lws, "lp number"); + verify(labelPrintService).stripLabwareLabelData(lws); + } + + @Test + public void testStripLabwareLabelData() { + List lws = setupStripTubes(); + LabwareLabelData ld1 = new LabwareLabelData("LLD1", null, null, null, null); + LabwareLabelData ld2 = new LabwareLabelData("LLD2", null, null, null, null); + when(mockLabwareLabelDataService.getSplitLabelData(same(lws.get(0)), any(), any())).thenReturn(List.of(ld1)); + when(mockLabwareLabelDataService.getSplitLabelData(same(lws.get(1)), any(), any())).thenReturn(List.of(ld2)); + List lds = labelPrintService.stripLabwareLabelData(lws); + assertThat(lds).containsExactly(ld1, ld2); + } + @Test public void testPrint() throws IOException { //noinspection unchecked diff --git a/src/test/java/uk/ac/sanger/sccp/stan/service/work/TestWorkService.java b/src/test/java/uk/ac/sanger/sccp/stan/service/work/TestWorkService.java index f4f48e8c..220c4421 100644 --- a/src/test/java/uk/ac/sanger/sccp/stan/service/work/TestWorkService.java +++ b/src/test/java/uk/ac/sanger/sccp/stan/service/work/TestWorkService.java @@ -1138,6 +1138,19 @@ public void testSuggestLabwareForWork(boolean forRelease) { workService.suggestLabwareForWorkNumber(work.getWorkNumber(), forRelease)); } + @Test + public void testLoadWorksForSlotsIn() { + Sample sample = EntityFactory.getSample(); + LabwareType lt = EntityFactory.makeLabwareType(3,1); + Labware lw = EntityFactory.makeLabware(lt, sample); + Map> slotWorks = Map.of(new SlotIdSampleId(lw.getFirstSlot(), sample), + Set.of(EntityFactory.makeWork("SGP1"))); + when(mockWorkRepo.slotSampleWorksForSlotIds(any())).thenReturn(slotWorks); + assertSame(slotWorks, workService.loadWorksForSlotsIn(List.of(lw))); + List slotIds = lw.getSlots().stream().map(Slot::getId).toList(); + verify(mockWorkRepo).slotSampleWorksForSlotIds(slotIds); + } + private Operation makeOp(OperationType opType, int opId, Labware srcLw, Labware dstLw) { List actions = new ArrayList<>(); int acId = 100*opId;