Search in sources :

Example 86 with CSVRecord

use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.

the class ConvertRecord method convertTodos.

public static List<Todo> convertTodos(List<CSVRecord> records) {
    List<Todo> list = new ArrayList<>(records.size());
    for (CSVRecord record : records) {
        if (record.size() < 2)
            break;
        String id = record.get(0);
        String text = record.get(1);
        Todo todo = new Todo().setTodoId(Integer.parseInt(id)).setText(text);
        // Parse boolean values
        String developmentString = record.get(2);
        if (!"NULL".equals(developmentString)) {
            boolean development = parseBoolean(developmentString);
            todo.setDevelopment(development);
        }
        String distributionString = record.get(3);
        if (!"NULL".equals(distributionString)) {
            boolean distribution = parseBoolean(distributionString);
            todo.setDistribution(distribution);
        }
        if (record.size() >= 5) {
            Optional.ofNullable(record.get(4)).filter(json -> !"NULL".equals(json)).map(json -> (Map<String, String>) gson.fromJson(json, new TypeToken<Map<String, String>>() {
            }.getType())).ifPresent(todo::setExternalIds);
        }
        list.add(todo);
    }
    return list;
}
Also used : java.util(java.util) Function(com.google.common.base.Function) TypeToken(com.google.gson.reflect.TypeToken) User(org.eclipse.sw360.datahandler.thrift.users.User) CSVRecord(org.apache.commons.csv.CSVRecord) TException(org.apache.thrift.TException) GsonBuilder(com.google.gson.GsonBuilder) Strings(com.google.common.base.Strings) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) Logger(org.apache.log4j.Logger) Gson(com.google.gson.Gson) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) org.eclipse.sw360.datahandler.thrift.licenses(org.eclipse.sw360.datahandler.thrift.licenses) NotNull(org.jetbrains.annotations.NotNull) com.google.common.collect(com.google.common.collect) CommonUtils.isNullEmptyOrWhitespace(org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 87 with CSVRecord

use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.

the class ConvertRecord method convertLicenseTypes.

public static List<LicenseType> convertLicenseTypes(List<CSVRecord> records) {
    List<LicenseType> list = new ArrayList<>(records.size());
    for (CSVRecord record : records) {
        if (record.size() < 2)
            break;
        int id = Integer.parseInt(record.get(0));
        String text = record.get(1);
        LicenseType type = new LicenseType().setLicenseTypeId(id).setLicenseType(text);
        list.add(type);
    }
    return list;
}
Also used : CSVRecord(org.apache.commons.csv.CSVRecord)

Example 88 with CSVRecord

use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.

the class ConvertRecord method convertRiskCategories.

public static List<RiskCategory> convertRiskCategories(List<CSVRecord> records) {
    ArrayList<RiskCategory> list = new ArrayList<>(records.size());
    for (CSVRecord record : records) {
        if (record.size() < 2)
            break;
        int id = Integer.parseInt(record.get(0));
        String text = record.get(1);
        RiskCategory category = new RiskCategory().setRiskCategoryId(id).setText(text);
        list.add(category);
    }
    return list;
}
Also used : CSVRecord(org.apache.commons.csv.CSVRecord)

Example 89 with CSVRecord

use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.

the class ComponentAndAttachmentAwareDBTest method getCompAttachmentCSVRecordsFromTestFile.

protected static FluentIterable<ComponentAttachmentCSVRecord> getCompAttachmentCSVRecordsFromTestFile(String fileName) throws IOException {
    InputStream testStream = spy(ComponentImportUtilsTest.class.getResourceAsStream(fileName));
    List<CSVRecord> testRecords = ImportCSV.readAsCSVRecords(testStream);
    verify(testStream).close();
    return convertCSVRecordsToComponentAttachmentCSVRecords(testRecords);
}
Also used : InputStream(java.io.InputStream) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 90 with CSVRecord

use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.

the class TypeMappings method getCustomPropertiesWithValuesByIdAndWriteMissingToDatabase.

public static Map<Integer, PropertyWithValue> getCustomPropertiesWithValuesByIdAndWriteMissingToDatabase(LicenseService.Iface licenseClient, InputStream inputStream, User user) throws TException {
    List<CSVRecord> records = ImportCSV.readAsCSVRecords(inputStream);
    Optional<CustomProperties> dbCustomProperties = CommonUtils.wrapThriftOptionalReplacement(licenseClient.getCustomProperties(SW360Constants.TYPE_TODO));
    CustomProperties customProperties;
    if (!dbCustomProperties.isPresent()) {
        customProperties = new CustomProperties().setDocumentType(SW360Constants.TYPE_TODO);
    } else {
        customProperties = dbCustomProperties.get();
    }
    Map<String, Set<String>> propertyToValuesToAdd = ConvertRecord.convertCustomProperties(records);
    customProperties.setPropertyToValues(CommonUtils.mergeMapIntoMap(propertyToValuesToAdd, customProperties.getPropertyToValues()));
    licenseClient.updateCustomProperties(customProperties, user);
    Map<Integer, PropertyWithValue> propertiesWithValuesById = ConvertRecord.convertCustomPropertiesById(records);
    return propertiesWithValuesById;
}
Also used : CSVRecord(org.apache.commons.csv.CSVRecord) PropertyWithValue(org.eclipse.sw360.commonIO.ConvertRecord.PropertyWithValue) CustomProperties(org.eclipse.sw360.datahandler.thrift.CustomProperties)

Aggregations

CSVRecord (org.apache.commons.csv.CSVRecord)127 CSVParser (org.apache.commons.csv.CSVParser)71 IOException (java.io.IOException)40 CSVFormat (org.apache.commons.csv.CSVFormat)40 ArrayList (java.util.ArrayList)36 Reader (java.io.Reader)24 StringReader (java.io.StringReader)22 InputStreamReader (java.io.InputStreamReader)18 FileReader (java.io.FileReader)16 Test (org.junit.Test)14 Path (java.nio.file.Path)13 HashMap (java.util.HashMap)11 File (java.io.File)10 PreparedStatement (java.sql.PreparedStatement)10 InputStream (java.io.InputStream)9 ResultSet (java.sql.ResultSet)9 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)9 CSVCommonsLoader (org.apache.phoenix.util.CSVCommonsLoader)9 BufferedReader (java.io.BufferedReader)8 Map (java.util.Map)7