Search in sources :

Example 1 with Ternary

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;
}
Also used : TException(org.apache.thrift.TException) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary)

Example 2 with Ternary

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;
}
Also used : java.util(java.util) Function(com.google.common.base.Function) TypeToken(com.google.gson.reflect.TypeToken) User(org.eclipse.sw360.datahandler.thrift.users.User) CSVRecord(org.apache.commons.csv.CSVRecord) TException(org.apache.thrift.TException) GsonBuilder(com.google.gson.GsonBuilder) Strings(com.google.common.base.Strings) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) Logger(org.apache.log4j.Logger) Gson(com.google.gson.Gson) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) org.eclipse.sw360.datahandler.thrift.licenses(org.eclipse.sw360.datahandler.thrift.licenses) NotNull(org.jetbrains.annotations.NotNull) com.google.common.collect(com.google.common.collect) CommonUtils.isNullEmptyOrWhitespace(org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) CSVRecord(org.apache.commons.csv.CSVRecord)

Aggregations

TException (org.apache.thrift.TException)2 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)2 Function (com.google.common.base.Function)1 Strings (com.google.common.base.Strings)1 com.google.common.collect (com.google.common.collect)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 java.util (java.util)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 Logger (org.apache.log4j.Logger)1 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 CommonUtils.isNullEmptyOrWhitespace (org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace)1 ThriftEnumUtils (org.eclipse.sw360.datahandler.common.ThriftEnumUtils)1 org.eclipse.sw360.datahandler.thrift.licenses (org.eclipse.sw360.datahandler.thrift.licenses)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1 NotNull (org.jetbrains.annotations.NotNull)1