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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations