Search in sources :

Example 6 with Source

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

the class AttachmentContentWrapperTest method testUpdateNonMetadataTouchesAllFields.

public void testUpdateNonMetadataTouchesAllFields() throws Exception {
    AttachmentContent source;
    source = new AttachmentContent();
    source.setFilename("a");
    source.setType("b");
    source.setContentType("v");
    source.setPartsCount("1");
    // TODO this is not required !
    source.setRemoteUrl("uskt");
    AttachmentContentWrapper attachmentContentWrapper = new AttachmentContentWrapper();
    attachmentContentWrapper.updateNonMetadata(source);
    assertTFields(source, attachmentContentWrapper, AttachmentContentWrapper.class, AttachmentContent._Fields.class);
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 7 with Source

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

the class AttachmentHandlerTest method testAttachmentUsageCountWithFilter.

@Test
public void testAttachmentUsageCountWithFilter() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    AttachmentUsage usage3 = createUsage("p2", "r2", "a21", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage4 = createUsage("p3", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage5 = createUsage("p4", "r1", "a11");
    AttachmentUsage usage6 = createUsage("p5", "r3", "a31");
    handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5, usage6));
    Map<Source, Set<String>> queryFor = ImmutableMap.of(Source.releaseId("r1"), ImmutableSet.of("a11", "a12"), Source.releaseId("r3"), ImmutableSet.of("a31"));
    Map<Map<Source, String>, Integer> counts = handler.getAttachmentUsageCount(queryFor, UsageData.licenseInfo(new LicenseInfoUsage()));
    Map<Map<Source, String>, Integer> expected = ImmutableMap.of(ImmutableMap.of(Source.releaseId("r1"), "a11"), 2);
    for (Entry<Map<Source, String>, Integer> entry : expected.entrySet()) {
        Assert.assertThat(counts.get(entry.getKey()), is(entry.getValue()));
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Source(org.eclipse.sw360.datahandler.thrift.Source)

Example 8 with Source

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

the class DocxGenerator method fillReleaseDetailList.

private void fillReleaseDetailList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, boolean includeObligations) throws TException {
    addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true);
    setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):");
    addNewLines(document, 0);
    for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) {
        addReleaseTitle(document, parsingResult);
        if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) {
            addCopyrights(document, parsingResult);
            addLicenses(document, parsingResult, includeObligations);
        } else {
            XWPFRun errorRun = document.createParagraph().createRun();
            String errorText = nullToEmptyString(parsingResult.getMessage());
            String filename = getFilename(parsingResult);
            addFormattedText(errorRun, String.format("Error reading license information: %s", errorText), FONT_SIZE, false, ALERT_COLOR);
            addFormattedText(errorRun, String.format("Source file: %s", filename), FONT_SIZE, false, ALERT_COLOR);
        }
        addNewLines(document, 1);
    }
    addPageBreak(document);
}
Also used : XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 9 with Source

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

Aggregations

AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Map (java.util.Map)2 Set (java.util.Set)2 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)2 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 ReleaseLink (org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 com.google.common.collect (com.google.common.collect)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONException (com.liferay.portal.kernel.json.JSONException)1 JSONFactoryUtil (com.liferay.portal.kernel.json.JSONFactoryUtil)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1