Search in sources :

Example 1 with Obligation

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

the class CompareTodos method renderTodoRow.

private static void renderTodoRow(StringBuilder display, Todo todo) {
    display.append("<tr>");
    for (Todo._Fields field : RELEVANT_FIELDS) {
        FieldMetaData fieldMetaData = Todo.metaDataMap.get(field);
        Object fieldValue = todo.getFieldValue(field);
        if (field.equals(Todo._Fields.OBLIGATIONS) && fieldValue != null) {
            fieldValue = ((List<Obligation>) fieldValue).stream().map(Obligation::getName).collect(Collectors.toList());
        }
        display.append(String.format("<td>%s</td>", getDisplayString(fieldMetaData.valueMetaData.type, fieldValue)));
    }
    display.append("</tr>");
}
Also used : Todo(org.eclipse.sw360.datahandler.thrift.licenses.Todo) FieldMetaData(org.apache.thrift.meta_data.FieldMetaData) Obligation(org.eclipse.sw360.datahandler.thrift.licenses.Obligation)

Example 2 with Obligation

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

the class LicensesPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    String id = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
    if (id != null) {
        try {
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            License moderationLicense = client.getByIDWithOwnModerationRequests(id, user.getDepartment(), user);
            List<Todo> allTodos = nullToEmptyList(moderationLicense.getTodos());
            List<Todo> addedTodos = allTodos.stream().filter(CommonUtils::isTemporaryTodo).collect(Collectors.toList());
            List<Todo> currentTodos = allTodos.stream().filter(t -> !CommonUtils.isTemporaryTodo(t)).collect(Collectors.toList());
            request.setAttribute(ADDED_TODOS_FROM_MODERATION_REQUEST, addedTodos);
            request.setAttribute(DB_TODOS_FROM_MODERATION_REQUEST, currentTodos);
            request.setAttribute(MODERATION_LICENSE_DETAIL, moderationLicense);
            License dbLicense = client.getByID(id, user.getDepartment());
            request.setAttribute(KEY_LICENSE_DETAIL, dbLicense);
            List<Obligation> obligations = client.getObligations();
            request.setAttribute(KEY_OBLIGATION_LIST, obligations);
            addLicenseBreadcrumb(request, response, moderationLicense);
        } catch (TException e) {
            log.error("Error fetching license details from backend", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
        }
    }
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) TMP_TODO_ID_PREFIX(org.eclipse.sw360.datahandler.common.CommonUtils.TMP_TODO_ID_PREFIX) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Function(java.util.function.Function) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Strings(com.google.common.base.Strings) Logger(org.apache.log4j.Logger) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) javax.portlet(javax.portlet) org.eclipse.sw360.datahandler.thrift.licenses(org.eclipse.sw360.datahandler.thrift.licenses) Sw360Portlet(org.eclipse.sw360.portal.portlets.Sw360Portlet) ImmutableSet(com.google.common.collect.ImmutableSet) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) IOException(java.io.IOException) CommonUtils.nullToEmptyList(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ErrorMessages(org.eclipse.sw360.portal.common.ErrorMessages) EnumUtils(org.apache.commons.lang.enums.EnumUtils) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) LicenseExporter(org.eclipse.sw360.exporter.LicenseExporter) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 3 with Obligation

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

the class TestLicenseClient method main.

public static void main(String[] args) throws TException, IOException {
    THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/licenses/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    LicenseService.Iface client = new LicenseService.Client(protocol);
    List<License> licenses = client.getLicenseSummary();
    List<Obligation> obligations = client.getObligations();
    System.out.println("Fetched " + licenses.size() + " licenses from license service");
    System.out.println("Fetched " + obligations.size() + " obligations from license service");
    // final List<License> licenseList = client.getDetailedLicenseSummaryForExport("");
    final List<License> licenseList = client.getDetailedLicenseSummary("", ImmutableList.of("AFL-2.1", "Artistic-1.0"));
    System.out.println(licenseList.toString());
}
Also used : Obligation(org.eclipse.sw360.datahandler.thrift.licenses.Obligation) TProtocol(org.apache.thrift.protocol.TProtocol) LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) License(org.eclipse.sw360.datahandler.thrift.licenses.License) THttpClient(org.apache.thrift.transport.THttpClient) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Example 4 with Obligation

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

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

the class ModerationPortlet method renderLicenseModeration.

public void renderLicenseModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
    License actual_license = null;
    User requestingUser = UserCacheHolder.getUserFromEmail(moderationRequest.getRequestingUser());
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        actual_license = client.getByID(moderationRequest.getDocumentId(), requestingUser.getDepartment());
        request.setAttribute(KEY_LICENSE_DETAIL, actual_license);
        List<Obligation> obligations = client.getObligations();
        request.setAttribute(KEY_OBLIGATION_LIST, obligations);
    } catch (TException e) {
        log.error("Could not retrieve license", e);
    }
    if (actual_license == null) {
        renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
        return;
    }
    include("/html/moderation/licenses/merge.jsp", request, response);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Obligation(org.eclipse.sw360.datahandler.thrift.licenses.Obligation) LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) License(org.eclipse.sw360.datahandler.thrift.licenses.License)

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