use of org.eclipse.sw360.datahandler.thrift.Ternary in project sw360portal by sw360.
the class LicensesPortlet method updateLicenseFromRequest.
private License updateLicenseFromRequest(License license, ActionRequest request) {
String text = request.getParameter(License._Fields.TEXT.name());
String fullname = request.getParameter(License._Fields.FULLNAME.name());
String shortname = request.getParameter(License._Fields.SHORTNAME.name());
Ternary gpl2compatibility = Ternary.findByValue(Integer.parseInt(request.getParameter(License._Fields.GPLV2_COMPAT.toString())));
Ternary gpl3compatibility = Ternary.findByValue(Integer.parseInt(request.getParameter(License._Fields.GPLV3_COMPAT.toString())));
String licenseTypeString = request.getParameter(License._Fields.LICENSE_TYPE.toString() + LicenseType._Fields.LICENSE_TYPE.toString());
license.setText(CommonUtils.nullToEmptyString(text));
license.setFullname(CommonUtils.nullToEmptyString(fullname));
license.setShortname((CommonUtils.nullToEmptyString(shortname)));
license.setGPLv2Compat(gpl2compatibility);
license.setGPLv3Compat(gpl3compatibility);
try {
Optional<String> licenseTypeDatabaseId = getDatabaseIdFromLicenseType(licenseTypeString);
if (licenseTypeDatabaseId.isPresent()) {
license.setLicenseTypeDatabaseId(licenseTypeDatabaseId.get());
final LicenseType licenseType = thriftClients.makeLicenseClient().getLicenseTypeById(license.getLicenseTypeDatabaseId());
license.setLicenseType(licenseType);
} else {
license.unsetLicenseTypeDatabaseId();
}
} catch (TException e) {
log.error("Could not set licenseTypeDatabaseId:" + e);
license.unsetLicenseTypeDatabaseId();
}
return license;
}
use of org.eclipse.sw360.datahandler.thrift.Ternary 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