Search in sources :

Example 21 with Todo

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

Example 22 with Todo

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

the class DocxGenerator method addLicenseObligations.

private void addLicenseObligations(XWPFDocument document, String spdxLicense) throws TException {
    List<License> sw360Licenses = getLicenses();
    XWPFRun todoTitleRun = document.createParagraph().createRun();
    addNewLines(todoTitleRun, 0);
    Set<String> todos = getTodosFromLicenses(spdxLicense, sw360Licenses);
    addFormattedText(todoTitleRun, "Obligations for license " + spdxLicense + ":", FONT_SIZE, true);
    for (String todo : todos) {
        XWPFParagraph copyPara = document.createParagraph();
        copyPara.setSpacingAfter(0);
        XWPFRun todoRun = copyPara.createRun();
        setText(todoRun, todo);
        addNewLines(todoRun, 1);
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) License(org.eclipse.sw360.datahandler.thrift.licenses.License) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 23 with Todo

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

the class ComponentCSVRecord method getRelease.

public Release getRelease(String vendorId, String componentId, List<AttachmentContent> attachments) {
    Release release = new Release();
    // required
    release.setName(releaseName).setVersion(releaseVersion).setComponentId(componentId);
    // optionals
    if (!isNullOrEmpty(vendorId)) {
        release.setVendorId(vendorId);
    }
    if (!isNullOrEmpty(CPEId)) {
        release.setCpeid(CPEId);
    }
    if (!isNullOrEmpty(releaseDate)) {
        release.setReleaseDate(releaseDate);
    }
    if (!isNullOrEmpty(releaseCreatedOn)) {
        release.setCreatedOn(releaseCreatedOn);
    }
    if (!isNullOrEmpty(releaseCreatedBy)) {
        release.setCreatedBy(releaseCreatedBy);
    }
    if (CommonUtils.isValidUrl(releaseDownloadURL)) {
        release.setDownloadurl(releaseDownloadURL);
    }
    if (isSetRepository()) {
        release.setRepository(getRepository());
    }
    if (!isNullOrEmpty(releaseMainlineState)) {
        final MainlineState mainlineState = ThriftEnumUtils.stringToEnum(releaseMainlineState, MainlineState.class);
        if (mainlineState != null)
            release.setMainlineState(mainlineState);
    }
    if (!isNullOrEmpty(releaseClearingState)) {
        final ClearingState clearingState = ThriftEnumUtils.stringToEnum(releaseClearingState, ClearingState.class);
        if (clearingState != null)
            release.setClearingState(clearingState);
    }
    if (!isNullOrEmpty(releaseContributors)) {
        release.setContributors(CommonUtils.splitToSet(releaseContributors));
    }
    if (!isNullOrEmpty(releaseModerators)) {
        release.setModerators(CommonUtils.splitToSet(releaseModerators));
    }
    if (!isNullOrEmpty(releaseSubscribers)) {
        release.setSubscribers(CommonUtils.splitToSet(releaseSubscribers));
    }
    if (!isNullOrEmpty(releaseLanguages)) {
        release.setLanguages(CommonUtils.splitToSet(releaseLanguages));
    }
    if (!isNullOrEmpty(releaseOperatingSystems)) {
        release.setOperatingSystems(CommonUtils.splitToSet(releaseOperatingSystems));
    }
    if (!isNullOrEmpty(releaseMainLicenseIds)) {
        release.setMainLicenseIds(CommonUtils.splitToSet(releaseMainLicenseIds));
    }
    if (isSetClearingInformation()) {
        release.setClearingInformation(getClearingInformation());
    }
    if (isSetEccInformation()) {
        release.setEccInformation(getEccInformation());
    }
    // TODO: There should be only one SOURCE per Release
    if (attachments != null) {
        for (AttachmentContent attachmentContent : attachments) {
            String attachmentContentId = attachmentContent.getId();
            release.addToAttachments(new Attachment().setAttachmentContentId(attachmentContentId).setCreatedOn(SW360Utils.getCreatedOn()).setCreatedBy(releaseCreatedBy).setAttachmentType(AttachmentType.SOURCE).setFilename(attachmentContent.getFilename()));
        }
    }
    return release;
}
Also used : MainlineState(org.eclipse.sw360.datahandler.thrift.MainlineState) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 24 with Todo

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

the class ConvertRecord method convertTodos.

public static List<Todo> convertTodos(List<CSVRecord> records) {
    List<Todo> list = new ArrayList<>(records.size());
    for (CSVRecord record : records) {
        if (record.size() < 2)
            break;
        String id = record.get(0);
        String text = record.get(1);
        Todo todo = new Todo().setTodoId(Integer.parseInt(id)).setText(text);
        // Parse boolean values
        String developmentString = record.get(2);
        if (!"NULL".equals(developmentString)) {
            boolean development = parseBoolean(developmentString);
            todo.setDevelopment(development);
        }
        String distributionString = record.get(3);
        if (!"NULL".equals(distributionString)) {
            boolean distribution = parseBoolean(distributionString);
            todo.setDistribution(distribution);
        }
        if (record.size() >= 5) {
            Optional.ofNullable(record.get(4)).filter(json -> !"NULL".equals(json)).map(json -> (Map<String, String>) gson.fromJson(json, new TypeToken<Map<String, String>>() {
            }.getType())).ifPresent(todo::setExternalIds);
        }
        list.add(todo);
    }
    return list;
}
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) CSVRecord(org.apache.commons.csv.CSVRecord)

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