Skip to content

Commit

Permalink
Merge branch '5.9.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
hplahar committed Jun 30, 2021
2 parents f37a32b + 569a82d commit 69d4f96
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 112 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.jbei</groupId>
<artifactId>ice</artifactId>
<packaging>war</packaging>
<version>5.9.2</version>
<version>5.9.3</version>
<name>ice</name>
<description>Inventory of Composable Elements (ICE) for Synthetic Biology</description>
<repositories>
Expand Down Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16</version>
<version>42.2.18</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
Expand All @@ -66,7 +66,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.11.8.Final</version>
<version>5.11.9.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
Expand All @@ -76,7 +76,7 @@
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.3.Final</version>
<version>6.2.0.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
Expand All @@ -86,7 +86,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.4.22.Final</version>
<version>5.5.3.Final</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand All @@ -101,7 +101,7 @@
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.2</version>
<version>5.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/DevelopmentServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static void main(String[] args) throws Exception {
PredicatesHandler handler = Handlers.predicates(PredicatedHandlersParser.parse(
"path-prefix('search') or " +
"path-prefix('folders') or " +
"path-prefix('upload') or " +
"path-prefix('download') or " +
"path-prefix('entry') or path-prefix('admin') and regex('/.+') -> rewrite('/')",
ClassLoader.getSystemClassLoader()), servletHandler);
Expand Down
153 changes: 58 additions & 95 deletions src/main/java/org/jbei/ice/lib/bulkupload/BulkCSVUpload.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.jbei.ice.lib.bulkupload;

import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import com.opencsv.CSVReader;
import org.apache.commons.lang3.StringUtils;
import org.jbei.ice.lib.common.logging.Logger;
import org.jbei.ice.lib.dto.StorageLocation;
Expand All @@ -20,7 +17,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.io.InputStreamReader;
import java.util.*;

/**
Expand Down Expand Up @@ -131,7 +128,7 @@ private HashMap<Integer, HeaderValue> processColumnHeaders(String[] headerArray)
HashMap<Integer, HeaderValue> headers = new HashMap<>();

for (int i = 0; i < headerArray.length; i += 1) {
String fieldStr = headerArray[i].trim();
String fieldStr = headerArray[i].replaceAll("[^\\x20-\\x7e]", " ").trim();

// account for asterisk that indicates a header is required
fieldStr = fieldStr.replace(FileBulkUpload.ASTERISK_SYMBOL, "");
Expand Down Expand Up @@ -176,89 +173,63 @@ private HashMap<Integer, HeaderValue> processColumnHeaders(String[] headerArray)
List<PartWithSample> getBulkUploadDataFromFile(InputStream inputStream) throws IOException {
List<PartWithSample> partDataList = new LinkedList<>();

// parse CSV file
try (LineIterator it = IOUtils.lineIterator(inputStream, StandardCharsets.UTF_8)) {
HashMap<Integer, HeaderValue> headers;
CSVParser parser;

//
// process headers
//
if (it.hasNext()) {
String headerString = it.nextLine();
// check the separator char (header will use the same separator)
// to indicate the type of parser to use (tab or comma separated)
if (headerString.contains("\t") && !headerString.contains(",")) {
parser = new CSVParserBuilder().withSeparator('\t').build();
} else {
parser = new CSVParser();
}
HashMap<Integer, HeaderValue> headers = null;
CSVReader reader = new CSVReader(new InputStreamReader(inputStream));
int row = -1;
for (String[] nextLine : reader) {
row += 1;

// get column headers
String[] fieldStrArray = parser.parseLine(headerString);
headers = processColumnHeaders(fieldStrArray);
} else {
throw new IllegalStateException("No headers found in csv file");
if (row == 0) {
// parse headers
headers = processColumnHeaders(nextLine);
continue;
}

//
// process data
//
int index = 0;
while (it.hasNext()) {
String line = it.nextLine().trim();
// parse data
PartData partData = new PartData(addType);
PartSample partSample = null;

// skip any empty lines (holes) in the csv file
if (StringUtils.isBlank(line) || line.replaceAll(",", "").trim().isEmpty())
continue;

// parser != null; process line contents with available headers
String[] valuesArray = parser.parseLine(line);
PartData partData = new PartData(addType);
PartSample partSample = null;
if (subType != null) {
partData.getLinkedParts().add(new PartData(subType));
}

if (subType != null) {
partData.getLinkedParts().add(new PartData(subType));
}
// for each column
for (int i = 0; i < nextLine.length; i += 1) {
HeaderValue headerForColumn = headers.get(i);
String value = nextLine[i].replaceAll("[^\\x20-\\x7e]", " ");

// for each column
for (int i = 0; i < valuesArray.length; i += 1) {
HeaderValue headerForColumn = headers.get(i);
String value = valuesArray[i];

// process sample information
if (headerForColumn.isSampleField()) {
if (partSample == null)
partSample = new PartSample();

setPartSampleData(((SampleHeaderValue) headerForColumn).getSampleField(), partSample, value);
} else if (headerForColumn.isCustomField()) {
// process custom field
setCustomField(value, partData, (EntryHeaderValue) headerForColumn);
} else {
// process existing field
setExistingField(value, partData, (EntryHeaderValue) headerForColumn);
}
}
// process sample information
if (headerForColumn.isSampleField()) {
if (partSample == null)
partSample = new PartSample();

// validate
List<EntryFieldLabel> fields = EntryUtil.validates(partData);
if (!fields.isEmpty()) {
invalidFields.clear();
invalidFields.addAll(fields);
return null;
setPartSampleData(((SampleHeaderValue) headerForColumn).getSampleField(), partSample, value);
} else if (headerForColumn.isCustomField()) {
// process custom field
setCustomField(value, partData, (EntryHeaderValue) headerForColumn);
} else {
// process existing field
setExistingField(value, partData, (EntryHeaderValue) headerForColumn);
}
}

partData.setIndex(index);
PartWithSample partWithSample = new PartWithSample(partSample, partData);
partDataList.add(partWithSample);
index += 1;
// validate
List<EntryFieldLabel> fields = EntryUtil.validates(partData);
if (!fields.isEmpty()) {
invalidFields.clear();
invalidFields.addAll(fields);
return null;
}

partData.setIndex(row);
PartWithSample partWithSample = new PartWithSample(partSample, partData);
partDataList.add(partWithSample);
}

return partDataList;
}

private boolean setCustomField(String value, PartData partData, EntryHeaderValue headerValue) throws IOException {
private void setCustomField(String value, PartData partData, EntryHeaderValue headerValue) throws IOException {
// todo : e.g. {entryField: host} can be existing field or custom field
CustomEntryFieldDAO fieldDAO = DAOFactory.getCustomEntryFieldDAO();
EntryType type;
Expand All @@ -270,28 +241,27 @@ private boolean setCustomField(String value, PartData partData, EntryHeaderValue
}

Optional<CustomEntryFieldModel> optional = fieldDAO.getLabelForType(type, headerValue.getLabel());
if (!optional.isPresent()) {
if (optional.isEmpty()) {
Logger.error("Could not retrieve custom field for \"" + headerValue.getLabel() + "\"");
return false;
return;
}

CustomEntryFieldModel customEntryFieldModel = optional.get();
if (customEntryFieldModel.getFieldType() == FieldType.EXISTING) {
// validate
if (customEntryFieldModel.getRequired() && StringUtils.isEmpty(value)) {
// todo : return error
return false;
return;
}
setExistingField(value, partData, headerValue);
return true;
return;
}

CustomEntryField customEntryField = new CustomEntryField();
customEntryField.setId(customEntryFieldModel.getId());
customEntryField.setValue(value); // todo : check if the value is from a pre-selected list of options
partData.getCustomEntryFields().add(customEntryField);

return true;
}

private void setExistingField(String value, PartData partData, EntryHeaderValue headerValue) throws IOException {
Expand Down Expand Up @@ -340,33 +310,26 @@ private void setExistingField(String value, PartData partData, EntryHeaderValue

private void setPartSampleData(SampleField sampleField, PartSample partSample, String data) {
switch (sampleField) {
case LABEL:
partSample.setLabel(data);
break;

case SHELF:
case LABEL -> partSample.setLabel(data);
case SHELF -> {
StorageLocation storageLocation = new StorageLocation();
storageLocation.setType(SampleType.SHELF);
storageLocation.setDisplay(data);
partSample.setLocation(storageLocation);
break;

case BOX:
}
case BOX -> {
StorageLocation childLocation = new StorageLocation();
childLocation.setDisplay(data);
childLocation.setType(SampleType.BOX_INDEXED);
partSample.getLocation().setChild(childLocation);
break;

case WELL:
}
case WELL -> {
StorageLocation grandChildLocation = new StorageLocation();
grandChildLocation.setType(SampleType.WELL);
grandChildLocation.setDisplay(data);
partSample.getLocation().getChild().setChild(grandChildLocation);
break;

default:
throw new IllegalArgumentException("No handler for sample field " + sampleField);
}
default -> throw new IllegalArgumentException("No handler for sample field " + sampleField);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jbei/ice/lib/config/SiteSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class SiteSettings implements IDataTransferModel {

private String version = "5.9.2";
private String version = "5.9.3";
private String assetName;
private boolean hasLogo;
private boolean hasLoginMessage;
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/scripts/lib/open-vector-editor/main.css

Large diffs are not rendered by default.

Loading

0 comments on commit 69d4f96

Please sign in to comment.