Search in sources :

Example 1 with LicenseType

use of org.eclipse.sw360.datahandler.thrift.licenses.LicenseType in project sw360portal by sw360.

the class LicenseTypeSummary method summary.

@Override
protected LicenseType summary(SummaryType type, LicenseType document) {
    // Copy required details
    LicenseType copy = new LicenseType();
    switch(type) {
        case EXPORT_SUMMARY:
            copyField(document, copy, _Fields.LICENSE_TYPE);
            copyField(document, copy, _Fields.LICENSE_TYPE_ID);
            copyField(document, copy, _Fields.ID);
        default:
    }
    return copy;
}
Also used : LicenseType(org.eclipse.sw360.datahandler.thrift.licenses.LicenseType)

Example 2 with LicenseType

use of org.eclipse.sw360.datahandler.thrift.licenses.LicenseType 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 3 with LicenseType

use of org.eclipse.sw360.datahandler.thrift.licenses.LicenseType in project sw360portal by sw360.

the class LicenseHandlerTest method createTestEntries.

public void createTestEntries() throws MalformedURLException {
    // List of test objects
    licenses = new HashMap<>();
    todos = new HashMap<>();
    obligations = new HashMap<>();
    License license1 = new License();
    license1.setId("Apache 1.1");
    license1.setFullname("The Apache Software License, Version 1.1");
    license1.setLicenseType(new LicenseType().setLicenseTypeId(3).setType("Red - copyleft effect"));
    license1.addToRisks(new Risk().setRiskId(123123).setText("If Siemens uses this contractor pattern a long text follows here for reading and display... this might be long.").setCategory(new RiskCategory().setRiskCategoryId(32).setText("Beige")));
    license1.addToRisks(new Risk().setRiskId(1223).setText("Apache 1.1 is noy so risky").setCategory(new RiskCategory().setRiskCategoryId(3123).setText("Green")));
    license1.setReviewdate("10.10.2010");
    license1.addToTodoDatabaseIds("T1");
    license1.addToTodoDatabaseIds("T2");
    license1.addToTodoDatabaseIds("T5");
    licenses.put(license1.id, license1);
    License license2 = new License();
    license2.setId("Apache 2.0");
    license2.setFullname("The Apache Software License, Version 2.0");
    license2.setReviewdate("12.12.2012");
    license2.addToTodoDatabaseIds("T3");
    license2.addToTodoDatabaseIds("T4");
    licenses.put(license2.id, license2);
    Todo todo1 = new Todo().setId("T1").setText("You must include the acknowledgement as part of the documentation for the end user. An example looks as following:  This product includes software developed by the Apache Software Foundation (http://www.apache.org/).");
    todo1.addToObligationDatabaseIds("O1");
    todo1.addToObligationDatabaseIds("O2");
    Todo todo2 = new Todo().setId("T2").setText("You must not names listed in in the license at paragraph 4 (for example Apache and Apache Software Foundation) neither in the documentation nor for ads or marketing.");
    todo2.addToObligationDatabaseIds("O3");
    Todo todo3 = new Todo().setId("T3").setText("Then you must add the following sentence in the header of any modified/added file: 'Code modifications by Siemens AG are under Siemens license conditions'");
    Todo todo4 = new Todo().setId("T4").setText("You must include a prominent notice in the header of all modified files in the following form: © Siemens AG, [year]");
    todo4.addToObligationDatabaseIds("O1");
    todo4.addToObligationDatabaseIds("O4");
    Todo todo5 = new Todo().setId("T5").setText("With the Apache License 2.0,no copyleft effect for proprietary code exists. For proprietary Siemens modifications you can choose the license (meaning applying the Apache 2.0 license or any other license)");
    todo5.addToObligationDatabaseIds("O4");
    todos.put("T1", todo1);
    todos.put("T2", todo2);
    todos.put("T3", todo3);
    todos.put("T4", todo4);
    todos.put("T5", todo5);
    obligations.put("O1", new Obligation().setId("O1").setName("Provide acknowledgements in documentation"));
    obligations.put("O2", new Obligation().setId("O2").setName("Advertising materials are restricted subject to limitations"));
    obligations.put("O3", new Obligation().setId("O3").setName("Documentation that represent additional requirements in case of modifications (for example notice file with author's name)"));
    obligations.put("O4", new Obligation().setId("O4").setName("Apache Copyleft effect"));
    DatabaseConnector db = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Add obligations to database
    for (Obligation obligation : obligations.values()) {
        db.add(obligation);
    }
    // Add todos to database
    for (Todo todo : todos.values()) {
        db.add(todo);
    }
    // Finally, add the licenses to the database
    for (License license : licenses.values()) {
        db.add(license);
    }
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)

Example 4 with LicenseType

use of org.eclipse.sw360.datahandler.thrift.licenses.LicenseType 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)

Example 5 with LicenseType

use of org.eclipse.sw360.datahandler.thrift.licenses.LicenseType 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)

Aggregations

CSVRecord (org.apache.commons.csv.CSVRecord)2 TException (org.apache.thrift.TException)2 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)2 User (org.eclipse.sw360.datahandler.thrift.users.User)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 Logger (org.apache.log4j.Logger)1 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 CommonUtils.isNullEmptyOrWhitespace (org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace)1 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)1 ThriftEnumUtils (org.eclipse.sw360.datahandler.common.ThriftEnumUtils)1 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)1 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)1 org.eclipse.sw360.datahandler.thrift.licenses (org.eclipse.sw360.datahandler.thrift.licenses)1 LicenseType (org.eclipse.sw360.datahandler.thrift.licenses.LicenseType)1