Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
*/
@Configuration
public class FieldValidation {
@Bean
public Validator<String> sectionValidator() {
Set<CharacterType> charTypes = EnumSet.of(CharacterType.ALPHA, CharacterType.DIGIT);
return new StringValidator("Section", 1, 16, charTypes, false, Pattern.compile("[1-9][0-9]*[a-z]*", Pattern.CASE_INSENSITIVE));
}

@Bean
public Validator<String> cellClassValidator() {
Set<CharacterType> charTypes = EnumSet.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CytassistOverview {
private Integer id;
private String workNumber;
private Integer sampleId;
private Integer section;
private String section;
private String sourceBarcode;
private String sourceSlotAddress;
private String sourceLabwareType;
Expand Down Expand Up @@ -73,11 +73,11 @@ public void setSampleId(Integer sampleId) {
this.sampleId = sampleId;
}

public Integer getSection() {
public String getSection() {
return this.section;
}

public void setSection(Integer section) {
public void setSection(String section) {
this.section = section;
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/uk/ac/sanger/sccp/stan/model/PlanAction.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package uk.ac.sanger.sccp.stan.model;

import com.google.common.base.MoreObjects;

import javax.persistence.*;
import java.util.Objects;

import static uk.ac.sanger.sccp.utils.BasicUtils.describe;

/**
* A planned action inside a planned operation.
* @author dr6
Expand All @@ -26,7 +26,7 @@ public class PlanAction {
private Slot destination;
@ManyToOne
private Sample sample;
private Integer newSection;
private String newSection;
private String sampleThickness;
@ManyToOne
private BioState newBioState;
Expand All @@ -38,7 +38,7 @@ public PlanAction(Integer id, Integer planOperationId, Slot source, Slot destina
}

public PlanAction(Integer id, Integer planOperationId, Slot source, Slot destination, Sample sample,
Integer newSection, String sampleThickness, BioState newBioState) {
String newSection, String sampleThickness, BioState newBioState) {
this.id = id;
this.planOperationId = planOperationId;
this.source = source;
Expand Down Expand Up @@ -89,11 +89,11 @@ public void setSample(Sample sample) {
this.sample = sample;
}

public Integer getNewSection() {
public String getNewSection() {
return this.newSection;
}

public void setNewSection(Integer section) {
public void setNewSection(String section) {
this.newSection = section;
}

Expand Down Expand Up @@ -135,13 +135,13 @@ public int hashCode() {

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
return describe(this)
.add("id", id)
.add("planOperationId", planOperationId)
.add("source", source)
.add("destination", destination)
.add("sample", sample)
.add("newSection", newSection)
.addRepr("newSection", newSection)
.add("sampleThickness", sampleThickness)
.add("newBioState", newBioState)
.toString();
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/uk/ac/sanger/sccp/stan/model/Sample.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package uk.ac.sanger.sccp.stan.model;

import com.google.common.base.MoreObjects;

import javax.persistence.*;
import java.util.Objects;

import static uk.ac.sanger.sccp.utils.BasicUtils.describe;

/**
* A sample is a piece of some tissue that has some particular state and can be located inside slots in labware,
* and used in operations.
Expand All @@ -15,15 +15,15 @@ public class Sample {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Integer section;
private String section;
@ManyToOne
private Tissue tissue;
@ManyToOne
private BioState bioState;

public Sample() {}

public Sample(Integer id, Integer section, Tissue tissue, BioState bioState) {
public Sample(Integer id, String section, Tissue tissue, BioState bioState) {
this.id = id;
this.section = section;
this.tissue = tissue;
Expand All @@ -38,11 +38,11 @@ public void setId(Integer id) {
this.id = id;
}

public Integer getSection() {
public String getSection() {
return this.section;
}

public void setSection(Integer section) {
public void setSection(String section) {
this.section = section;
}

Expand Down Expand Up @@ -80,9 +80,9 @@ public int hashCode() {

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
return describe(this)
.add("id", id)
.add("section", section)
.addRepr("section", section)
.add("tissue", tissue)
.add("bioState", bioState)
.toString();
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/uk/ac/sanger/sccp/stan/repo/PlanActionRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,9 @@
import java.util.OptionalInt;

public interface PlanActionRepo extends CrudRepository<PlanAction, Integer> {
@Query("SELECT MAX(a.newSection) FROM PlanAction a WHERE a.sample.tissue.id=?1")
Integer _findMaxPlannedSectionForTissueId(int tissueId);

@Query("SELECT MAX(a.newSection) FROM PlanAction a WHERE a.source.id=?1")
@Query(value = "SELECT MAX(CAST(a.new_section AS UNSIGNED)) FROM plan_action a WHERE a.source_slot_id=?1", nativeQuery = true)
Integer _findMaxPlannedSectionFromSlotId(int sourceSlotId);

/**
* Finds the maximum section for planned actions for particular tissue
* @param tissueId the id of tissue
* @return the highest section number of any planned action on a sample with that tissue id
*/
default OptionalInt findMaxPlannedSectionForTissueId(int tissueId) {
Integer maxInteger = _findMaxPlannedSectionForTissueId(tissueId);
return (maxInteger==null ? OptionalInt.empty() : OptionalInt.of(maxInteger));
}

/**
* Finds the maximum section for planned actions from a particular slot
* @param sourceSlotId the id of the source slot
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/uk/ac/sanger/sccp/stan/repo/SampleRepo.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
package uk.ac.sanger.sccp.stan.repo;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import uk.ac.sanger.sccp.stan.model.Sample;

import javax.persistence.EntityNotFoundException;
import java.util.*;

public interface SampleRepo extends CrudRepository<Sample, Integer> {
@Query("SELECT MAX(section) FROM Sample WHERE tissue.id=?1")
Integer _findMaxSectionForTissueId(int tissueId);

List<Sample> findAllByIdIn(Collection<Integer> ids);

List<Sample> findAllByTissueIdIn(Collection<Integer> tissueIds);

/**
* Finds the maximum section for particular tissue
*
* @param tissueId the id of tissue
* @return the highest section number of any section with that tissue id
* @deprecated no current use case
*/
default OptionalInt findMaxSectionForTissueId(int tissueId) {
Integer maxInteger = _findMaxSectionForTissueId(tissueId);
return maxInteger == null ? OptionalInt.empty() : OptionalInt.of(maxInteger);
}

/**
* Gets the samples with the given ids
* @param ids the ids to find
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@
public class CancelPlanAction {
private Address destinationAddress;
private Integer sampleId;
private Integer newSection;
private String newSection;

public CancelPlanAction() {}

public CancelPlanAction(Address destinationAddress, Integer sampleId, Integer newSection) {
public CancelPlanAction(Address destinationAddress, Integer sampleId, String newSection) {
this.destinationAddress = destinationAddress;
this.sampleId = sampleId;
this.newSection = newSection;
}

public CancelPlanAction(PlanAction planAction) {
this(planAction.getDestination().getAddress(), planAction.getSample().getId(), planAction.getNewSection());
}

public Address getDestinationAddress() {
return this.destinationAddress;
}
Expand All @@ -43,11 +39,11 @@ public void setSampleId(Integer sampleId) {
this.sampleId = sampleId;
}

public Integer getNewSection() {
public String getNewSection() {
return this.newSection;
}

public void setNewSection(Integer newSection) {
public void setNewSection(String newSection) {
this.newSection = newSection;
}

Expand All @@ -71,7 +67,7 @@ public String toString() {
return BasicUtils.describe("CancelPlanAction")
.add("destinationAddress", destinationAddress)
.add("sampleId", sampleId)
.add("newSection", newSection)
.addRepr("newSection", newSection)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
public class ConfirmSection {
private List<Address> destinationAddresses = List.of();
private Integer sampleId;
private Integer newSection;
private String newSection;
private List<Integer> commentIds = List.of();
private String thickness;

public ConfirmSection() {}

public ConfirmSection(List<Address> destinationAddresses, Integer sampleId, Integer newSection,
public ConfirmSection(List<Address> destinationAddresses, Integer sampleId, String newSection,
List<Integer> commentIds) {
setDestinationAddress(destinationAddresses);
setSampleId(sampleId);
setNewSection(newSection);
setCommentIds(commentIds);
}

public ConfirmSection(Address destinationAddress, Integer sampleId, Integer newSection,
public ConfirmSection(Address destinationAddress, Integer sampleId, String newSection,
List<Integer> commentIds) {
this(destinationAddress==null ? null : List.of(destinationAddress), sampleId, newSection, commentIds);
}

public ConfirmSection(Address destinationAddress, Integer sampleId, Integer newSection) {
public ConfirmSection(Address destinationAddress, Integer sampleId, String newSection) {
this(destinationAddress, sampleId, newSection, null);
}

Expand All @@ -55,11 +55,11 @@ public void setSampleId(Integer sampleId) {
this.sampleId = sampleId;
}

public Integer getNewSection() {
public String getNewSection() {
return this.newSection;
}

public void setNewSection(Integer newSection) {
public void setNewSection(String newSection) {
this.newSection = newSection;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ public String toString() {
return BasicUtils.describe("ConfirmSection")
.add("destinationAddresses", destinationAddresses)
.add("sampleId", sampleId)
.add("newSection", newSection)
.addRepr("newSection", newSection)
.add("commentIds", commentIds)
.addRepr("thickness", thickness)
.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SectionRegisterContent {
private String replicateNumber;
private String fixative;
private String medium;
private Integer sectionNumber;
private String sectionNumber;
private String sectionThickness;
private String region;
private LocalDate dateSectioned;
Expand Down Expand Up @@ -126,11 +126,11 @@ public void setMedium(String medium) {
this.medium = medium;
}

public Integer getSectionNumber() {
public String getSectionNumber() {
return this.sectionNumber;
}

public void setSectionNumber(Integer sectionNumber) {
public void setSectionNumber(String sectionNumber) {
this.sectionNumber = sectionNumber;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import uk.ac.sanger.sccp.stan.request.history.HistoryGraph.Link;
import uk.ac.sanger.sccp.stan.request.history.HistoryGraph.Node;
import uk.ac.sanger.sccp.stan.service.releasefile.Ancestoriser.SlotSample;
import uk.ac.sanger.sccp.utils.BasicUtils;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.*;
import static uk.ac.sanger.sccp.utils.BasicUtils.inMap;
import static uk.ac.sanger.sccp.utils.BasicUtils.nullOrEmpty;

/**
* @author dr6
Expand Down Expand Up @@ -160,10 +163,10 @@ public String describeBio(Collection<Sample> samples) {
return null;
}
String desc = samples.iterator().next().getBioState().getName();
List<Integer> sections = samples.stream()
List<String> sections = samples.stream()
.map(Sample::getSection)
.filter(Objects::nonNull)
.sorted()
.filter(s -> !nullOrEmpty(s))
.sorted(BasicUtils.numberStringComparator())
.distinct()
.toList();
if (!sections.isEmpty()) {
Expand All @@ -177,19 +180,23 @@ public String describeBio(Collection<Sample> samples) {
* @param sections a monotonic sequence of ints
* @return a string describing the given sections
*/
public String summariseSections(List<Integer> sections) {
public String summariseSections(List<String> sections) {
if (sections.isEmpty()) {
return null;
}
if (sections.size()==1) {
return sections.getFirst().toString();
return sections.getFirst();
}
if (sections.size()==2) {
return sections.getFirst().toString()+","+sections.getLast().toString();
}
if (sections.getLast()==sections.getFirst()+sections.size()-1) {
return sections.getFirst()+"-"+sections.getLast();
return sections.getFirst()+","+sections.getLast();
}
try {
int firstNum = Integer.parseInt(sections.getFirst());
if (IntStream.range(1, sections.size())
.allMatch(i -> Integer.toString(i+firstNum).equals(sections.get(i)))) {
return firstNum+"-"+sections.getLast();
}
} catch (NumberFormatException ignored) {}
return sections.stream()
.map(Object::toString)
.collect(joining(","));
Expand Down
Loading
Loading