Skip to content

Commit

Permalink
(quince-science#2962) Correctly process missing run types
Browse files Browse the repository at this point in the history
When an instrument has multiple file definitions, and at least one has no run type column, uploading new files with missing run types would fail.
  • Loading branch information
squaregoldfish committed Sep 11, 2024
1 parent b6bae08 commit c06f1c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,11 @@ public RunTypeAssignments getRunTypes() {
* @return The run type values
*/
public List<String> getRunTypeValues() {
List<String> values = null;
List<String> values;

if (null != runTypes) {
if (null == runTypes) {
values = new ArrayList<String>(0);
} else {
values = new ArrayList<String>(runTypes.size());
values.addAll(runTypes.keySet());
}
Expand Down
12 changes: 9 additions & 3 deletions WebApp/src/uk/ac/exeter/QuinCe/web/files/MissingRunType.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package uk.ac.exeter.QuinCe.web.files;

import java.util.List;
import java.util.Set;

import uk.ac.exeter.QuinCe.data.Instrument.FileDefinition;
import uk.ac.exeter.QuinCe.data.Instrument.RunTypes.RunTypeAssignment;

public record MissingRunType(FileDefinition fileDefinition,
RunTypeAssignment runType) {
protected static boolean contains(List<MissingRunType> list,
RunTypeAssignment runType) implements Comparable<MissingRunType> {

protected static boolean contains(Set<MissingRunType> list,
FileDefinition fileDefinition, String runName) {
return list.stream().anyMatch(r -> r.fileDefinition.equals(fileDefinition)
&& r.runType.getRunName().equals(runName));
}

@Override
public int compareTo(MissingRunType o) {
return runType.getRunName().compareTo(o.runType.getRunName());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.ac.exeter.QuinCe.web.files;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.TreeSet;
Expand Down Expand Up @@ -29,7 +28,7 @@ public class MultipleFileUploadBean extends FileUploadBean {
*/
private TreeSet<UploadedDataFile> dataFiles = new TreeSet<UploadedDataFile>();

private List<MissingRunType> unrecognisedRunTypes;
private TreeSet<MissingRunType> unrecognisedRunTypes;

@Override
public void processUploadedFile() {
Expand Down Expand Up @@ -131,7 +130,7 @@ private void unsetDataFiles() {
}

private void buildUnrecognisedRunTypes() {
unrecognisedRunTypes = new ArrayList<MissingRunType>();
unrecognisedRunTypes = new TreeSet<MissingRunType>();

for (UploadedDataFile file : dataFiles) {
for (RunTypeAssignment runType : file.getMissingRunTypes()) {
Expand All @@ -144,7 +143,7 @@ private void buildUnrecognisedRunTypes() {
}
}

public List<MissingRunType> getUnrecognisedRunTypes() {
public TreeSet<MissingRunType> getUnrecognisedRunTypes() {

if (null == unrecognisedRunTypes) {
buildUnrecognisedRunTypes();
Expand Down

0 comments on commit c06f1c5

Please sign in to comment.