use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.
the class ConvertRecord method convertRelationalTable.
public static Map<String, Set<Integer>> convertRelationalTable(List<CSVRecord> records) {
Map<String, Set<Integer>> map = new HashMap<>(records.size());
for (CSVRecord record : records) {
if (record.size() < 2)
break;
String mainId = record.get(0);
int otherId = Integer.parseInt(record.get(1));
if (map.containsKey(mainId)) {
map.get(mainId).add(otherId);
} else {
Set<Integer> ids = new HashSet<>();
ids.add(otherId);
map.put(mainId, ids);
}
}
return map;
}
use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.
the class ConvertRecord method convertObligation.
public static List<Obligation> convertObligation(List<CSVRecord> records) {
List<Obligation> list = new ArrayList<>(records.size());
for (CSVRecord record : records) {
if (record.size() < 2)
break;
String id = record.get(0);
String name = record.get(1);
Obligation obligation = new Obligation().setObligationId(Integer.parseInt(id)).setName(name);
list.add(obligation);
}
return list;
}
use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.
the class ConvertRecord method convertCustomProperties.
public static Map<String, Set<String>> convertCustomProperties(List<CSVRecord> records) {
Map<String, Set<String>> resultProperties = new HashMap<>();
for (CSVRecord record : records) {
if (!isValidPropertyRecord(record)) {
break;
}
String property = record.get(1).trim();
String value = record.get(2).trim();
addPropertyAndValueToMap(property, value, resultProperties);
}
return resultProperties;
}
use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.
the class ConvertRecord method convertCustomPropertiesById.
public static Map<Integer, PropertyWithValue> convertCustomPropertiesById(List<CSVRecord> records) {
Map<Integer, PropertyWithValue> resultPropertiesById = new HashMap<>();
for (CSVRecord record : records) {
if (!isValidPropertyRecord(record)) {
break;
}
Integer id = Integer.parseInt(record.get(0));
String property = record.get(1).trim();
String value = record.get(2).trim();
resultPropertiesById.put(id, new PropertyWithValue(property, value));
}
return resultPropertiesById;
}
use of org.apache.commons.csv.CSVRecord in project sw360portal by sw360.
the class ConvertRecord method fillLicenses.
public static List<License> fillLicenses(List<CSVRecord> records, Map<Integer, LicenseType> licenseTypeMap, Map<Integer, Todo> todoMap, Map<Integer, Risk> riskMap, Map<String, Set<Integer>> licenseTodo, Map<String, Set<Integer>> licenseRisk) {
List<License> licenses = new ArrayList<>(records.size());
for (CSVRecord record : records) {
if (record.size() < 7)
break;
String identifier = record.get(0);
String fullname = record.get(1);
License license = new License().setId(identifier).setFullname(fullname);
String typeString = record.get(2);
if (!Strings.isNullOrEmpty(typeString) && !"NULL".equals(typeString)) {
Integer typeId = Integer.parseInt(typeString);
LicenseType licenseType = licenseTypeMap.get(typeId);
license.setLicenseType(licenseType);
}
String gplv2CompatString = record.get(3);
if (!Strings.isNullOrEmpty(gplv2CompatString) && !"NULL".equals(gplv2CompatString)) {
Ternary gplv2Compat = ThriftEnumUtils.stringToEnum(gplv2CompatString, Ternary.class);
license.setGPLv2Compat(gplv2Compat);
}
String gplv3CompatString = record.get(4);
if (!Strings.isNullOrEmpty(gplv3CompatString) && !"NULL".equals(gplv3CompatString)) {
Ternary gplv3Compat = ThriftEnumUtils.stringToEnum(gplv3CompatString, Ternary.class);
license.setGPLv3Compat(gplv3Compat);
}
String reviewdate = record.get(5);
license.setReviewdate(ConvertUtil.parseDate(reviewdate));
String text = record.get(6);
license.setText(text);
if (record.size() > 7) {
String externalLink = record.get(7);
license.setExternalLicenseLink(externalLink);
}
if (record.size() > 8) {
Optional.ofNullable(record.get(8)).map(json -> gson.fromJson(json, new TypeToken<Map<String, String>>() {
}.getType())).map(o -> (Map<String, String>) o).ifPresent(license::setExternalIds);
}
// Add all risks
Set<Integer> riskIds = licenseRisk.get(identifier);
if (riskIds != null) {
for (int riskId : riskIds) {
Risk risk = riskMap.get(riskId);
if (risk != null) {
license.addToRiskDatabaseIds(risk.getId());
}
}
}
// Add all todos
Set<Integer> todoIds = licenseTodo.get(identifier);
if (todoIds != null) {
for (int todoId : todoIds) {
Todo todo = todoMap.get(todoId);
if (todo != null) {
license.addToTodoDatabaseIds(todo.getId());
}
}
}
licenses.add(license);
}
return licenses;
}
Aggregations