Search in sources :

Example 6 with Todo

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

the class LicenseDatabaseHandler method updateLicenseFromInputLicense.

private License updateLicenseFromInputLicense(License license, License inputLicense, String businessUnit, User user) {
    if (inputLicense.isSetTodos()) {
        for (Todo todo : inputLicense.getTodos()) {
            if (isTemporaryTodo(todo)) {
                todo.unsetId();
                try {
                    String todoDatabaseId = addTodo(todo, user);
                    license.addToTodoDatabaseIds(todoDatabaseId);
                } catch (SW360Exception e) {
                    log.error("Error adding todo to database.");
                }
            } else if (todo.isSetId()) {
                Todo dbTodo = todoRepository.get(todo.id);
                if (todo.whitelist.contains(businessUnit) && !dbTodo.whitelist.contains(businessUnit)) {
                    dbTodo.addToWhitelist(businessUnit);
                    todoRepository.update(dbTodo);
                }
                if (!todo.whitelist.contains(businessUnit) && dbTodo.whitelist.contains(businessUnit)) {
                    dbTodo.whitelist.remove(businessUnit);
                    todoRepository.update(dbTodo);
                }
            }
        }
    }
    license.setText(inputLicense.getText());
    license.setFullname(inputLicense.getFullname());
    // only a new license gets its id from the shortname. Id of an existing license isn't supposed to be changed anyway
    if (!license.isSetId())
        license.setId(inputLicense.getShortname());
    license.unsetShortname();
    license.setLicenseTypeDatabaseId(inputLicense.getLicenseTypeDatabaseId());
    license.unsetLicenseType();
    license.setGPLv2Compat(Optional.ofNullable(inputLicense.getGPLv2Compat()).orElse(Ternary.UNDEFINED));
    license.setGPLv3Compat(Optional.ofNullable(inputLicense.getGPLv3Compat()).orElse(Ternary.UNDEFINED));
    license.setExternalLicenseLink(inputLicense.getExternalLicenseLink());
    return license;
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Example 7 with Todo

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

the class LicenseDatabaseHandler method getTodoById.

public Todo getTodoById(String id) {
    final Todo todo = todoRepository.get(id);
    fillTodo(todo);
    return todo;
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Example 8 with Todo

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

the class LicenseDatabaseHandler method getLicenseForOrganisationWithOwnModerationRequests.

public License getLicenseForOrganisationWithOwnModerationRequests(String id, String organisation, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    License license = getLicenseForOrganisation(id, organisation);
    DocumentState documentState;
    if (moderationRequestsForDocumentId.isEmpty()) {
        documentState = CommonUtils.getOriginalDocumentState();
    } else {
        final String email = user.getEmail();
        Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
        if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
            ModerationRequest moderationRequest = moderationRequestOptional.get();
            license = moderator.updateLicenseFromModerationRequest(license, moderationRequest.getLicenseAdditions(), moderationRequest.getLicenseDeletions(), organisation);
            for (Todo todo : license.getTodos()) {
                // remove other organisations from whitelist of todo
                todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
            }
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    license.setPermissions(makePermission(license, user).getPermissionMap());
    license.setDocumentState(documentState);
    return license;
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 9 with Todo

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

the class FossologyFileHandler method sendToFossology.

public RequestStatus sendToFossology(String releaseId, User user, String clearingTeam) throws TException {
    Release release;
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    release = getReleaseAndUnlockIt(releaseId, user, componentClient);
    Set<Attachment> sourceAttachments = getSourceAttachment(releaseId, user, componentClient);
    if (sourceAttachments.size() != 1) {
        log.error("release " + releaseId + " does not have a single source attachment");
        // TODO return a summary and better fitting status
        return RequestStatus.FAILURE;
    }
    final Attachment attachment = getFirst(sourceAttachments);
    final FilledAttachment filledAttachment = fillAttachment(attachment);
    if (!release.isSetFossologyId()) {
        /* send the attachment as a new upload */
        AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
        return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient);
    } else {
        if (!checkSourceAttachment(release, filledAttachment)) {
            // TODO summary
            return RequestStatus.FAILURE;
        } else {
            /* duplicate the old upload making it visible for clearingTeam */
            return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient);
        }
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 10 with Todo

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

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)7 TException (org.apache.thrift.TException)6 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)6 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 Strings (com.google.common.base.Strings)3 java.util (java.util)3 CSVRecord (org.apache.commons.csv.CSVRecord)3 Logger (org.apache.log4j.Logger)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 ThriftEnumUtils (org.eclipse.sw360.datahandler.common.ThriftEnumUtils)3 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 org.eclipse.sw360.datahandler.thrift.licenses (org.eclipse.sw360.datahandler.thrift.licenses)3 Todo (org.eclipse.sw360.datahandler.thrift.licenses.Todo)3 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)3 NotNull (org.jetbrains.annotations.NotNull)3 Function (com.google.common.base.Function)2 com.google.common.collect (com.google.common.collect)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2