use of org.eclipse.sw360.datahandler.thrift.licenses.Obligation in project sw360portal by sw360.
the class ComponentUploadPortlet method updateLicenses.
@UsedAsLiferayAction
public void updateLicenses(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
final HashMap<String, InputStream> inputMap = new HashMap<>();
User user = UserCacheHolder.getUserFromRequest(request);
try {
fillFilenameInputStreamMap(request, inputMap);
if (ZipTools.isValidLicenseArchive(inputMap)) {
final LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
log.debug("Parsing risk categories ...");
Map<Integer, RiskCategory> riskCategoryMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(RISK_CATEGORY_FILE), RiskCategory.class, Integer.class, user);
log.debug("Parsing risks ...");
Map<Integer, Risk> riskMap = getIntegerRiskMap(licenseClient, riskCategoryMap, inputMap.get(RISK_FILE), user);
log.debug("Parsing obligations ...");
Map<Integer, Obligation> obligationMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(OBLIGATION_FILE), Obligation.class, Integer.class, user);
log.debug("Parsing obligation todos ...");
List<CSVRecord> obligationTodoRecords = readAsCSVRecords(inputMap.get(OBLIGATION_TODO_FILE));
Map<Integer, Set<Integer>> obligationTodoMapping = convertRelationalTableWithIntegerKeys(obligationTodoRecords);
log.debug("Parsing license types ...");
Map<Integer, LicenseType> licenseTypeMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(LICENSETYPE_FILE), LicenseType.class, Integer.class, user);
log.debug("Parsing todos ...");
Map<Integer, Todo> todoMap = getTodoMapAndWriteMissingToDatabase(licenseClient, obligationMap, obligationTodoMapping, inputMap.get(TODO_FILE), user);
if (inputMap.containsKey(CUSTOM_PROPERTIES_FILE)) {
log.debug("Parsing custom properties ...");
Map<Integer, PropertyWithValue> customPropertiesMap = getCustomPropertiesWithValuesByIdAndWriteMissingToDatabase(licenseClient, inputMap.get(CUSTOM_PROPERTIES_FILE), user);
log.debug("Parsing todo custom properties relation ...");
List<CSVRecord> todoPropertiesRecord = readAsCSVRecords(inputMap.get(TODO_CUSTOM_PROPERTIES_FILE));
Map<Integer, Set<Integer>> todoPropertiesMap = convertRelationalTableWithIntegerKeys(todoPropertiesRecord);
todoMap = updateTodoMapWithCustomPropertiesAndWriteToDatabase(licenseClient, todoMap, customPropertiesMap, todoPropertiesMap, user);
}
log.debug("Parsing license todos ...");
List<CSVRecord> licenseTodoRecord = readAsCSVRecords(inputMap.get(LICENSE_TODO_FILE));
Map<String, Set<Integer>> licenseTodoMap = convertRelationalTable(licenseTodoRecord);
log.debug("Parsing license risks ...");
List<CSVRecord> licenseRiskRecord = readAsCSVRecords(inputMap.get(LICENSE_RISK_FILE));
Map<String, Set<Integer>> licenseRiskMap = convertRelationalTable(licenseRiskRecord);
log.debug("Parsing licenses ...");
List<CSVRecord> licenseRecord = readAsCSVRecords(inputMap.get(LICENSE_FILE));
final List<License> licensesToAdd = ConvertRecord.fillLicenses(licenseRecord, licenseTypeMap, todoMap, riskMap, licenseTodoMap, licenseRiskMap);
addLicenses(licenseClient, licensesToAdd, log, user);
} else {
throw new SW360Exception("Invalid file format");
}
} finally {
for (InputStream inputStream : inputMap.values()) {
inputStream.close();
}
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.Obligation in project sw360portal by sw360.
the class LicenseDatabaseHandler method fillTodos.
private void fillTodos(List<Todo> todos) {
Set<String> obligationIdsToFetch = new HashSet<>();
for (Todo todo : todos) {
obligationIdsToFetch.addAll(CommonUtils.nullToEmptySet(todo.getObligationDatabaseIds()));
}
Map<String, Obligation> obligationIdMap = null;
if (!obligationIdsToFetch.isEmpty()) {
obligationIdMap = ThriftUtils.getIdMap(getObligationsByIds(obligationIdsToFetch));
}
if (obligationIdMap == null) {
obligationIdMap = Collections.emptyMap();
}
for (Todo todo : todos) {
if (todo.isSetObligationDatabaseIds()) {
for (String id : todo.getObligationDatabaseIds()) {
final Obligation obligation = obligationIdMap.get(id);
if (obligation != null) {
todo.addToObligations(obligation);
}
}
}
todo.setDevelopmentString(todo.isDevelopment() ? "True" : "False");
todo.setDistributionString(todo.isDistribution() ? "True" : "False");
todo.unsetObligationDatabaseIds();
}
for (Todo todo : todos) {
if (!todo.isSetWhitelist()) {
todo.setWhitelist(Collections.emptySet());
}
}
}
Aggregations