Search in sources :

Example 1 with ParsedEntryId

use of org.jbei.ice.lib.dto.entry.ParsedEntryId in project ice by JBEI.

the class Entries method validateEntries.

/**
     * @param stream csv file input stream
     */
public List<ParsedEntryId> validateEntries(InputStream stream) throws IOException {
    List<ParsedEntryId> accepted = new ArrayList<>();
    EntryAuthorization authorization = new EntryAuthorization();
    try (CSVReader reader = new CSVReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
        List<String[]> results = reader.readAll();
        for (String[] result : results) {
            if (result[0].isEmpty())
                continue;
            Entry entry = dao.getByPartNumber(result[0]);
            if (entry == null || !authorization.canRead(this.userId, entry)) {
                accepted.add(new ParsedEntryId(result[0], null));
                continue;
            }
            PartData partData = new PartData(EntryType.nameToType(entry.getRecordType()));
            partData.setPartId(entry.getPartNumber());
            partData.setId(entry.getId());
            accepted.add(new ParsedEntryId(result[0], partData));
        }
    }
    return accepted;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData) ParsedEntryId(org.jbei.ice.lib.dto.entry.ParsedEntryId)

Aggregations

CSVReader (com.opencsv.CSVReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 ParsedEntryId (org.jbei.ice.lib.dto.entry.ParsedEntryId)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 Entry (org.jbei.ice.storage.model.Entry)1