use of org.eclipse.sw360.commonIO.ConvertRecord.PropertyWithValue in project sw360portal by sw360.
the class TypeMappings method updateTodoMapWithCustomPropertiesAndWriteToDatabase.
@NotNull
public static Map<Integer, Todo> updateTodoMapWithCustomPropertiesAndWriteToDatabase(LicenseService.Iface licenseClient, Map<Integer, Todo> todoMap, Map<Integer, PropertyWithValue> customPropertiesMap, Map<Integer, Set<Integer>> todoPropertiesMap, User user) throws TException {
for (Integer todoId : todoPropertiesMap.keySet()) {
Todo todo = todoMap.get(todoId);
if (!todo.isSetCustomPropertyToValue()) {
todo.setCustomPropertyToValue(new HashMap<>());
}
for (Integer propertyWithValueId : todoPropertiesMap.get(todoId)) {
PropertyWithValue propertyWithValue = customPropertiesMap.get(propertyWithValueId);
todo.getCustomPropertyToValue().put(propertyWithValue.getProperty(), propertyWithValue.getValue());
}
}
if (todoMap.values().size() > 0) {
final List<Todo> addedTodos = licenseClient.addTodos(todoMap.values().stream().collect(Collectors.toList()), user);
if (addedTodos != null) {
final ImmutableMap<Integer, Todo> addedTodoMap = Maps.uniqueIndex(addedTodos, getTodoIdentifier());
todoMap.putAll(addedTodoMap);
}
}
return todoMap;
}
use of org.eclipse.sw360.commonIO.ConvertRecord.PropertyWithValue 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.commonIO.ConvertRecord.PropertyWithValue 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