Search in sources :

Example 1 with SampleField

use of org.jbei.ice.lib.dto.bulkupload.SampleField in project ice by JBEI.

the class BulkCSVUpload method processColumnHeaders.

/**
     * @param headerArray list of column header values representing the entry fields
     * @return mapping of col number to the entry type
     * @throws IOException
     */
HashMap<Integer, HeaderValue> processColumnHeaders(String[] headerArray) throws IOException {
    HashMap<Integer, HeaderValue> headers = new HashMap<>();
    for (int i = 0; i < headerArray.length; i += 1) {
        String fieldStr = headerArray[i].trim();
        // account for "*" that indicates a header is required
        if (fieldStr.lastIndexOf("*") != -1)
            fieldStr = fieldStr.substring(0, fieldStr.length() - 1);
        EntryField field = EntryField.fromString(fieldStr);
        if (field != null) {
            // field header maps as is to EntryField which indicates it is not a sub Type
            HeaderValue headerValue = new EntryHeaderValue(false, field);
            headers.put(i, headerValue);
            continue;
        }
        // check if sample field
        SampleField sampleField = SampleField.fromString(fieldStr);
        if (sampleField != null) {
            HeaderValue headerValue = new SampleHeaderValue(sampleField);
            headers.put(i, headerValue);
            continue;
        }
        // check sub Type
        if (subType != null) {
            HeaderValue headerValue = detectSubTypeHeaderValue(subType, fieldStr);
            headers.put(i, headerValue);
            continue;
        }
        // sub data is null, try to detect
        subType = detectSubType(fieldStr);
        if (subType == null) {
            throw new IOException("Unknown field [" + fieldStr + "] for upload [" + addType.getDisplay() + "]");
        }
        HeaderValue headerValue = detectSubTypeHeaderValue(subType, fieldStr);
        headers.put(i, headerValue);
    }
    if (headers.size() != headerArray.length) {
        throw new IOException("Header size and input header array length differ");
    }
    return headers;
}
Also used : HashMap(java.util.HashMap) SampleField(org.jbei.ice.lib.dto.bulkupload.SampleField) IOException(java.io.IOException) EntryField(org.jbei.ice.lib.dto.entry.EntryField)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 SampleField (org.jbei.ice.lib.dto.bulkupload.SampleField)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1