Search in sources :

Example 6 with Obligation

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();
        }
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) CSVRecord(org.apache.commons.csv.CSVRecord) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 7 with Obligation

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());
        }
    }
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Aggregations

Obligation (org.eclipse.sw360.datahandler.thrift.licenses.Obligation)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 TException (org.apache.thrift.TException)2 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)2 License (org.eclipse.sw360.datahandler.thrift.licenses.License)2 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)2 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)2 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 PortletResponseUtil (com.liferay.portal.kernel.portlet.PortletResponseUtil)1 SessionMessages (com.liferay.portal.kernel.servlet.SessionMessages)1 IOException (java.io.IOException)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 javax.portlet (javax.portlet)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 EnumUtils (org.apache.commons.lang.enums.EnumUtils)1