Commit c9f36b38 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Uploading AccessionRefs as CSV file

- Support for CSV settings
- Extended API for subsets and datasets
parent 3acdf674
......@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -29,7 +30,13 @@ import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetAccessionRef;
......@@ -48,9 +55,11 @@ import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
......@@ -75,6 +84,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
......@@ -124,6 +134,9 @@ public class DatasetController extends ApiBaseController {
@Autowired
private AccessionService accessionService;
@Autowired
private Validator validator;
/**
* Creates the dataset.
*
......@@ -241,6 +254,52 @@ public class DatasetController extends ApiBaseController {
return datasetService.setAccessionRefs(dataset, accessionRefs);
}
/**
* Set accessions to Dataset from uploaded CSV file.
*
* @param uuid the uuid
* @param version the version
* @param separator the delimiter to use for separating entries in the CSV file
* @param quotechar the character to use for quoted elements in the CSV file
* @param file the CSV file with accessionRefs to be added
* @return updated record
*/
@PostMapping(value = "/upload-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Dataset uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version,
// CSV settings
@RequestParam(required = false, defaultValue = "\t") char separator, @RequestParam(required = false, defaultValue = "\"") char quotechar,
// The file
@RequestPart(name = "file") final MultipartFile file) throws IOException {
// Permit only a CSV file
if (!file.getContentType().equalsIgnoreCase("text/csv")) {
throw new InvalidApiUsageException("Invalid file type: " + file.getContentType() + " is not permitted.");
}
Dataset dataset = datasetService.getDataset(uuid, version);
List<DatasetAccessionRef> accessionRefs = new ArrayList<>();
// Build CSV parser
CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).withQuoteChar(quotechar).withEscapeChar((char) 0)
.withStrictQuotes(false).withIgnoreLeadingWhiteSpace(false).withIgnoreQuotations(true).build();
// Read file bytes as CSV
try (CSVReader reader = new CSVReaderBuilder(CabReader.bomSafeReader(file.getInputStream())).withSkipLines(0).withCSVParser(csvParser).build()) {
Iterator<DatasetAccessionRef> beanReader = CabReader.beanReader(DatasetAccessionRef.class, reader).iterator();
DatasetAccessionRef acceRef = null;
while (beanReader.hasNext() && (acceRef = beanReader.next()) != null) {
Set<ConstraintViolation<DatasetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
}
}
}
dataset = datasetService.setAccessionRefs(dataset, accessionRefs);
dataset = datasetService.rematchDatasetAccessions(dataset);
return dataset;
}
/**
* Rematch accessions.
*
......
......@@ -27,6 +27,9 @@ import java.util.UUID;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReaderBuilder;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
......@@ -295,11 +298,18 @@ public class DiversityTreeController extends ApiBaseController {
*
* @param uuid the uuid
* @param version the version
* @param separator the delimiter to use for separating entries in the CSV file
* @param quotechar the character to use for quoted elements in the CSV file
* @param file the CSV file with accessionRefs to be added
* @return updated record
*/
@PostMapping(value = "/upload-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public DiversityTree uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version, @RequestPart(name = "file") final MultipartFile file) throws IOException {
public DiversityTree uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version,
// CSV settings
@RequestParam(required = false, defaultValue = "\t") char separator, @RequestParam(required = false, defaultValue = "\"") char quotechar,
// The file
@RequestPart(name = "file") final MultipartFile file) throws IOException {
// Permit only a CSV file
if (!file.getContentType().equalsIgnoreCase("text/csv")) {
throw new InvalidApiUsageException("Invalid file type: " + file.getContentType() + " is not permitted.");
......@@ -307,8 +317,12 @@ public class DiversityTreeController extends ApiBaseController {
DiversityTree tree = treeService.get(uuid, version);
List<DiversityTreeAccessionRef> accessionRefs = new ArrayList<>();
// Build CSV parser
CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).withQuoteChar(quotechar).withEscapeChar((char) 0)
.withStrictQuotes(false).withIgnoreLeadingWhiteSpace(false).withIgnoreQuotations(true).build();
// Read file bytes as CSV
try (CSVReader reader = CabReader.openCsvReader(file.getInputStream(), 0)) {
try (CSVReader reader = new CSVReaderBuilder(CabReader.bomSafeReader(file.getInputStream())).withSkipLines(0).withCSVParser(csvParser).build()) {
Iterator<DiversityTreeAccessionRef> beanReader = CabReader.beanReader(DiversityTreeAccessionRef.class, reader).iterator();
DiversityTreeAccessionRef dtAcceRef = null;
while (beanReader.hasNext() && (dtAcceRef = beanReader.next()) != null) {
......
......@@ -20,19 +20,29 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import com.google.common.collect.Sets;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.ShortFilterService.FilterInfo;
import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -63,12 +73,14 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import org.springframework.web.multipart.MultipartFile;
/**
* The Class SubsetController.
......@@ -98,6 +110,9 @@ public class SubsetController extends ApiBaseController {
@Autowired
private AccessionService accessionService;
@Autowired
private Validator validator;
/**
* Register the subset.
*
......@@ -279,7 +294,6 @@ public class SubsetController extends ApiBaseController {
*
* @param uuid the uuid
* @param version the version
* @param accessionIds the accessions UUIDs to be added
* @return the subset
*/
@PostMapping(value = "/set-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
......@@ -290,6 +304,52 @@ public class SubsetController extends ApiBaseController {
return subset;
}
/**
* Set accessions to Subset from uploaded CSV file.
*
* @param uuid the uuid
* @param version the version
* @param separator the delimiter to use for separating entries in the CSV file
* @param quotechar the character to use for quoted elements in the CSV file
* @param file the CSV file with accessionRefs to be added
* @return updated record
*/
@PostMapping(value = "/upload-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Subset uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version,
// CSV settings
@RequestParam(required = false, defaultValue = "\t") char separator, @RequestParam(required = false, defaultValue = "\"") char quotechar,
// The file
@RequestPart(name = "file") final MultipartFile file) throws IOException {
// Permit only a CSV file
if (!file.getContentType().equalsIgnoreCase("text/csv")) {
throw new InvalidApiUsageException("Invalid file type: " + file.getContentType() + " is not permitted.");
}
Subset subset = subsetService.getSubset(uuid, version);
List<SubsetAccessionRef> accessionRefs = new ArrayList<>();
// Build CSV parser
CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).withQuoteChar(quotechar).withEscapeChar((char) 0)
.withStrictQuotes(false).withIgnoreLeadingWhiteSpace(false).withIgnoreQuotations(true).build();
// Read file bytes as CSV
try (CSVReader reader = new CSVReaderBuilder(CabReader.bomSafeReader(file.getInputStream())).withSkipLines(0).withCSVParser(csvParser).build()) {
Iterator<SubsetAccessionRef> beanReader = CabReader.beanReader(SubsetAccessionRef.class, reader).iterator();
SubsetAccessionRef acceRef = null;
while (beanReader.hasNext() && (acceRef = beanReader.next()) != null) {
Set<ConstraintViolation<SubsetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
}
}
}
subset = subsetService.setAccessionRefs(subset, accessionRefs);
subset = subsetService.rematchSubsetAccessions(subset);
return subset;
}
/**
* Rematch accessions.
*
......
......@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -28,9 +29,15 @@ import java.util.UUID;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.Validator;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetAccessionRef;
......@@ -48,9 +55,11 @@ import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.DetailedConstraintViolationException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
......@@ -76,6 +85,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
......@@ -124,10 +134,13 @@ public class DatasetController extends ApiBaseController {
@Autowired
private AccessionService accessionService;
@Autowired
private Validator validator;
/**
* Creates the dataset.
* Creates the datasets.
*
* @param dataset the dataset
* @param datasets the datasets
* @return the dataset
*/
@PostMapping(value = "/create")
......@@ -148,9 +161,9 @@ public class DatasetController extends ApiBaseController {
}
/**
* Update dataset.
* Update datasets.
*
* @param dataset the dataset
* @param datasets the datasets
* @return the dataset
*/
@PreAuthorize("isAuthenticated()")
......@@ -183,9 +196,9 @@ public class DatasetController extends ApiBaseController {
}
/**
* Gets the dataset.
* Gets the datasets.
*
* @param uuid the uuid
* @param uuids the uuids
* @return the dataset
* @throws NotFoundElement the not found element
*/
......@@ -204,15 +217,13 @@ public class DatasetController extends ApiBaseController {
}
/**
* Delete dataset.
* Delete datasets.
*
* @param uuid the uuid
* @param version the version
* @param entities the entities
* @return the dataset
* @throws Exception the exception
*/
@PostMapping("/delete")
public List<OpResponse<Dataset>> deleteDataset(@RequestBody final List<UUIDandVersion> entities) throws Exception {
public List<OpResponse<Dataset>> deleteDataset(@RequestBody final List<UUIDandVersion> entities) {
return entities.stream().map(entity -> {
try {
final Dataset dataset = datasetService.removeDataset(datasetService.getDataset(entity.uuid, entity.version));
......@@ -287,6 +298,52 @@ public class DatasetController extends ApiBaseController {
return datasetService.setAccessionRefs(dataset, accessionRefs);
}
/**
* Set accessions to Dataset from uploaded CSV file.
*
* @param uuid the uuid
* @param version the version
* @param separator the delimiter to use for separating entries in the CSV file
* @param quotechar the character to use for quoted elements in the CSV file
* @param file the CSV file with accessionRefs to be added
* @return updated record
*/
@PostMapping(value = "/upload-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Dataset uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version,
// CSV settings
@RequestParam(required = false, defaultValue = "\t") char separator, @RequestParam(required = false, defaultValue = "\"") char quotechar,
// The file
@RequestPart(name = "file") final MultipartFile file) throws IOException {
// Permit only a CSV file
if (!file.getContentType().equalsIgnoreCase("text/csv")) {
throw new InvalidApiUsageException("Invalid file type: " + file.getContentType() + " is not permitted.");
}
Dataset dataset = datasetService.getDataset(uuid, version);
List<DatasetAccessionRef> accessionRefs = new ArrayList<>();
// Build CSV parser
CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).withQuoteChar(quotechar).withEscapeChar((char) 0)
.withStrictQuotes(false).withIgnoreLeadingWhiteSpace(false).withIgnoreQuotations(true).build();
// Read file bytes as CSV
try (CSVReader reader = new CSVReaderBuilder(CabReader.bomSafeReader(file.getInputStream())).withSkipLines(0).withCSVParser(csvParser).build()) {
Iterator<DatasetAccessionRef> beanReader = CabReader.beanReader(DatasetAccessionRef.class, reader).iterator();
DatasetAccessionRef acceRef = null;
while (beanReader.hasNext() && (acceRef = beanReader.next()) != null) {
Set<ConstraintViolation<DatasetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
}
}
}
dataset = datasetService.setAccessionRefs(dataset, accessionRefs);
dataset = datasetService.rematchDatasetAccessions(dataset);
return dataset;
}
/**
* Rematch accessions.
*
......@@ -454,10 +511,9 @@ public class DatasetController extends ApiBaseController {
}
/**
* Loads dataset by uuid and version and tries to publish it.
* Loads datasets by uuid and version and tries to publish.
*
* @param uuid dataset UUID
* @param version record version
* @param entities the entities
* @return published Dataset (admin-only)
*/
@RequestMapping(value = "/approve", method = RequestMethod.POST)
......@@ -473,10 +529,9 @@ public class DatasetController extends ApiBaseController {
}
/**
* Loads dataset by uuid and version and send to review.
* Loads datasets by uuids and versions and sends to review.
*
* @param uuid dataset UUID
* @param version record version
* @param entities the entities
* @return dataset in review state
*/
@RequestMapping(value = "/for-review", method = RequestMethod.POST)
......@@ -492,10 +547,9 @@ public class DatasetController extends ApiBaseController {
}
/**
* Loads dataset by uuid and version and unpublish it.
* Loads datasets by uuids and versions and unpublishes.
*
* @param uuid dataset UUID
* @param version record version
* @param entities the entities
* @return unpublished dataset
*/
@RequestMapping(value = "/reject", method = RequestMethod.POST)
......
......@@ -30,6 +30,9 @@ import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.Validator;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReaderBuilder;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
......@@ -343,11 +346,18 @@ public class DiversityTreeController extends ApiBaseController {
*
* @param uuid the uuid
* @param version the version
* @param separator the delimiter to use for separating entries in the CSV file
* @param quotechar the character to use for quoted elements in the CSV file
* @param file the CSV file with accessionRefs to be added
* @return updated record
*/
@PostMapping(value = "/upload-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public DiversityTree uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version, @RequestPart(name = "file") final MultipartFile file) throws IOException {
public DiversityTree uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version,
// CSV settings
@RequestParam(required = false, defaultValue = "\t") char separator, @RequestParam(required = false, defaultValue = "\"") char quotechar,
// The file
@RequestPart(name = "file") final MultipartFile file) throws IOException {
// Permit only a CSV file
if (!file.getContentType().equalsIgnoreCase("text/csv")) {
throw new InvalidApiUsageException("Invalid file type: " + file.getContentType() + " is not permitted.");
......@@ -355,8 +365,12 @@ public class DiversityTreeController extends ApiBaseController {
DiversityTree tree = treeService.get(uuid, version);
List<DiversityTreeAccessionRef> accessionRefs = new ArrayList<>();
// Build CSV parser
CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).withQuoteChar(quotechar).withEscapeChar((char) 0)
.withStrictQuotes(false).withIgnoreLeadingWhiteSpace(false).withIgnoreQuotations(true).build();
// Read file bytes as CSV
try (CSVReader reader = CabReader.openCsvReader(file.getInputStream(), 0)) {
try (CSVReader reader = new CSVReaderBuilder(CabReader.bomSafeReader(file.getInputStream())).withSkipLines(0).withCSVParser(csvParser).build()) {
Iterator<DiversityTreeAccessionRef> beanReader = CabReader.beanReader(DiversityTreeAccessionRef.class, reader).iterator();
DiversityTreeAccessionRef dtAcceRef = null;
while (beanReader.hasNext() && (dtAcceRef = beanReader.next()) != null) {
......
......@@ -16,12 +16,15 @@
package org.genesys2.server.api.v2;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import javax.validation.Validator;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -31,12 +34,18 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import io.swagger.annotations.Api;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.DetailedConstraintViolationException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -66,7 +75,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* The Subset API V2 controller.
......@@ -96,6 +107,9 @@ public class SubsetController extends ApiBaseController {
@Autowired
private AccessionService accessionService;
@Autowired
private Validator validator;
/**
* Register subsets.
*
......@@ -335,6 +349,52 @@ public class SubsetController extends ApiBaseController {
return subset;
}
/**
* Set accessions to Subset from uploaded CSV file.
*
* @param uuid the uuid
* @param version the version
* @param separator the delimiter to use for separating entries in the CSV file
* @param quotechar the character to use for quoted elements in the CSV file
* @param file the CSV file with accessionRefs to be added
* @return updated record
*/
@PostMapping(value = "/upload-accessions/{uuid},{version}", produces = { MediaType.APPLICATION_JSON_VALUE })
public Subset uploadAccessions(@PathVariable("uuid") final UUID uuid, @PathVariable("version") final int version,
// CSV settings
@RequestParam(required = false, defaultValue = "\t") char separator, @RequestParam(required = false, defaultValue = "\"") char quotechar,
// The file
@RequestPart(name = "file") final MultipartFile file) throws IOException {
// Permit only a CSV file
if (!file.getContentType().equalsIgnoreCase("text/csv")) {
throw new InvalidApiUsageException("Invalid file type: " + file.getContentType() + " is not permitted.");
}
Subset subset = subsetService.getSubset(uuid, version);
List<SubsetAccessionRef> accessionRefs = new ArrayList<>();
// Build CSV parser
CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).withQuoteChar(quotechar).withEscapeChar((char) 0)
.withStrictQuotes(false).withIgnoreLeadingWhiteSpace(false).withIgnoreQuotations(true).build();
// Read file bytes as CSV
try (CSVReader reader = new CSVReaderBuilder(CabReader.bomSafeReader(file.getInputStream())).withSkipLines(0).withCSVParser(csvParser).build()) {
Iterator<SubsetAccessionRef> beanReader = CabReader.beanReader(SubsetAccessionRef.class, reader).iterator();
SubsetAccessionRef acceRef = null;
while (beanReader.hasNext() && (acceRef = beanReader.next()) != null) {
Set<ConstraintViolation<SubsetAccessionRef>> violations = validator.validate(acceRef);
if (violations == null || violations.isEmpty()) {
accessionRefs.add(acceRef);
}
}
}
subset = subsetService.setAccessionRefs(subset, accessionRefs);
subset = subsetService.rematchSubsetAccessions(subset);
return subset;
}
/**
* Rematch accessions.
*
......
......@@ -37,8 +37,6 @@ import org.genesys2.server.model.impl.AccessionIdentifier3;
import com.fasterxml.jackson.annotation.JsonView;
import net.sf.oval.constraint.MinLength;
/**
* Identifies an accession by it's INSTCODE, ACCENUMB and GENUS. Use of DOI
* remains optional.
......@@ -70,16 +68,14 @@ public abstract class AccessionRef<T> extends BasicModel implements SelfCleaning
/** The acce numb. */