|
| 1 | +package life.qbic.projectmanagement.infrastructure.api.template; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.Optional; |
| 5 | +import java.util.Set; |
| 6 | +import java.util.stream.Collectors; |
| 7 | +import life.qbic.projectmanagement.infrastructure.api.template.ExampleProvider.Helper; |
| 8 | + |
| 9 | +/** |
| 10 | + * <b>Sample Register Columns</b> |
| 11 | + * |
| 12 | + * <p>Enumeration of the columns shown in the file used for sample registration |
| 13 | + * in the context of sample batch file based upload. Provides the name of the header column, the |
| 14 | + * column index and if the column should be set to readOnly in the generated sheet |
| 15 | + * </p> |
| 16 | + */ |
| 17 | +public enum RegisterColumn implements Column { |
| 18 | + |
| 19 | + SAMPLE_NAME("Sample Name", 0, false, true), |
| 20 | + ANALYSIS("Analysis to be performed", 1, false, true), |
| 21 | + BIOLOGICAL_REPLICATE("Biological Replicate", 2, false, false), |
| 22 | + CONDITION("Condition", 3, false, true), |
| 23 | + SPECIES("Species", 4, false, true), |
| 24 | + SPECIMEN("Specimen", 5, false, true), |
| 25 | + ANALYTE("Analyte", 6, false, true), |
| 26 | + COMMENT("Comment", 7, false, false); |
| 27 | + |
| 28 | + private static final ExampleProvider exampleProvider = column -> { |
| 29 | + if (column instanceof RegisterColumn registerColumn) { |
| 30 | + return switch (registerColumn) { |
| 31 | + case SAMPLE_NAME -> new Helper("Free text, e.g. RNA Sample 1, RNA Sample 2", |
| 32 | + "A visual aid to simplify navigation for the person managing the metadata."); |
| 33 | + case ANALYSIS -> new Helper("Enumeration, Select a value from the dropdown", |
| 34 | + "The test performed on samples for the purpose of finding and measuring chemical substances."); |
| 35 | + case BIOLOGICAL_REPLICATE -> new Helper("Free text, e.g. patient1, patient2, Mouse1", """ |
| 36 | + Different samples measured accross multiple conditions. |
| 37 | + Tip: You can use this column to identifiy whether the samples belong to the same source."""); |
| 38 | + case CONDITION -> new Helper("Enumeration, Select a value from the dropdown", """ |
| 39 | + A distinct value or condition of the independent variable at which the dependent variable is measured in order to carry out statistical analysis. |
| 40 | + Note: The values in the dropdown are the predefined values from the experimental design."""); |
| 41 | + case SPECIES -> new Helper("Enumeration, Select a value from the dropdown", """ |
| 42 | + Scientific name of the organism(s) from which the biological material is derived. E.g. Homo sapiens, Mus musculus. |
| 43 | + Note: The values in the dropdown are the predefined values from the experimental design."""); |
| 44 | + case ANALYTE -> new Helper("Enumeration, Select a value from the dropdown", """ |
| 45 | + The chemical substance extracted from the biological material that is identified and measured. |
| 46 | + Note: The values in the dropdown are the predefined values from the experimental design."""); |
| 47 | + case SPECIMEN -> new Helper("Enumeration, Select a value from the dropdown", """ |
| 48 | + Name of the biological material from which the analytes would be extracted. |
| 49 | + Note: The values in the dropdown are the predefined values from the experimental design."""); |
| 50 | + case COMMENT -> new Helper("Free text", "Notes about the sample. (Max 500 characters)"); |
| 51 | + }; |
| 52 | + } |
| 53 | + throw new IllegalArgumentException( |
| 54 | + "Column not of class " + RegisterColumn.class.getName() + " but is " |
| 55 | + + column.getClass().getName()); |
| 56 | + }; |
| 57 | + |
| 58 | + private final String headerName; |
| 59 | + private final int columnIndex; |
| 60 | + private final boolean readOnly; |
| 61 | + private final boolean mandatory; |
| 62 | + |
| 63 | + public static int maxColumnIndex() { |
| 64 | + return Arrays.stream(values()) |
| 65 | + .mapToInt(RegisterColumn::index) |
| 66 | + .max().orElse(0); |
| 67 | + } |
| 68 | + |
| 69 | + public static Set<String> headerNames() { |
| 70 | + return Arrays.stream(values()).map(RegisterColumn::headerName).collect(Collectors.toSet()); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param headerName the name in the header |
| 75 | + * @param columnIndex the index of the column this property is in |
| 76 | + * @param readOnly is the property read only |
| 77 | + * @param mandatory |
| 78 | + */ |
| 79 | + RegisterColumn(String headerName, int columnIndex, boolean readOnly, boolean mandatory) { |
| 80 | + this.headerName = headerName; |
| 81 | + this.columnIndex = columnIndex; |
| 82 | + this.readOnly = readOnly; |
| 83 | + this.mandatory = mandatory; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public String headerName() { |
| 88 | + return headerName; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public int index() { |
| 93 | + return columnIndex; |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public boolean isReadOnly() { |
| 98 | + return readOnly; |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public boolean isMandatory() { |
| 103 | + return mandatory; |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public Optional<Helper> getFillHelp() { |
| 108 | + return Optional.of(exampleProvider.getHelper(this)); |
| 109 | + } |
| 110 | +} |
0 commit comments