Search in sources :

Example 86 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment 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 87 with Attachment

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

the class ComponentImportUtils method writeAttachmentsToDatabase.

public static RequestSummary writeAttachmentsToDatabase(FluentIterable<ComponentAttachmentCSVRecord> compCSVRecords, User user, ComponentService.Iface componentClient, AttachmentService.Iface attachmentClient) throws TException {
    final List<Component> componentDetailedSummaryForExport = componentClient.getComponentDetailedSummaryForExport();
    final ImmutableMap<String, Component> componentsByName = getComponentsByName(componentDetailedSummaryForExport);
    final Map<String, Release> releasesByIdentifier = getReleasesByIdentifier(componentDetailedSummaryForExport);
    final Set<String> usedAttachmentContentIds = componentClient.getUsedAttachmentContentIds();
    final Set<String> releaseIdentifiersToUpdate = new HashSet<>();
    final Set<String> componentsToUpdate = new HashSet<>();
    final Set<Attachment> attachmentStubsToDelete = new HashSet<>();
    for (ComponentAttachmentCSVRecord compCSVRecord : compCSVRecords) {
        if (compCSVRecord.isSaveableAttachment()) {
            final Attachment attachment = compCSVRecord.getAttachment();
            if (usedAttachmentContentIds.contains(attachment.getAttachmentContentId()))
                continue;
            if (compCSVRecord.isForComponent()) {
                final Component component = componentsByName.get(compCSVRecord.getComponentName());
                if (component != null) {
                    component.addToAttachments(attachment);
                    componentsToUpdate.add(component.getName());
                }
            } else if (compCSVRecord.isForRelease()) {
                final Release release = releasesByIdentifier.get(compCSVRecord.getReleaseIdentifier());
                if (release != null) {
                    attachmentStubsToDelete.addAll(removeAutogeneratedAttachments(attachmentClient, attachment, release));
                    release.addToAttachments(attachment);
                    releaseIdentifiersToUpdate.add(compCSVRecord.getReleaseIdentifier());
                }
            }
        }
    }
    final HashSet<Release> updatedReleases = getUpdatedReleases(releasesByIdentifier, releaseIdentifiersToUpdate);
    final RequestSummary releaseRequestSummary = componentClient.updateReleases(updatedReleases, user);
    final HashSet<Component> updatedComponents = Sets.newHashSet(Maps.filterKeys(componentsByName, new Predicate<String>() {

        @Override
        public boolean apply(String input) {
            return componentsToUpdate.contains(input);
        }
    }).values());
    final RequestSummary componentRequestSummary = componentClient.updateComponents(updatedComponents, user);
    RequestSummary attachmentSummary = null;
    if (!attachmentStubsToDelete.isEmpty()) {
        attachmentSummary = attachmentClient.bulkDelete(Lists.transform(Lists.newArrayList(attachmentStubsToDelete), new Function<Attachment, String>() {

            @Override
            public String apply(Attachment input) {
                return input.getAttachmentContentId();
            }
        }));
    }
    RequestSummary requestSummary = CommonUtils.addRequestSummaries(releaseRequestSummary, "release", componentRequestSummary, "component");
    if (attachmentSummary != null) {
        requestSummary = CommonUtils.addToMessage(requestSummary, attachmentSummary, "attachment deletion");
    }
    return requestSummary;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Component(org.eclipse.sw360.datahandler.thrift.components.Component) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 88 with Attachment

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

the class ComponentAttachmentCSVRecordBuilderTest method testFillAttachment.

@Test
public void testFillAttachment() throws Exception {
    final String attachmentContentID = "asda823123123";
    final String fileName = "My.tar.gz";
    final String comment = "blabla";
    final AttachmentType attachmentType = AttachmentType.CLEARING_REPORT;
    final String createdBy = "Me";
    final String createdOn = "Now";
    final Attachment attachment = new Attachment();
    attachment.setFilename(fileName).setAttachmentContentId(attachmentContentID).setCreatedComment(comment).setAttachmentType(attachmentType).setCreatedBy(createdBy).setCreatedOn(createdOn);
    final ComponentAttachmentCSVRecordBuilder componentAttachmentCSVRecordBuilder = new ComponentAttachmentCSVRecordBuilder();
    componentAttachmentCSVRecordBuilder.fill(attachment);
    final ComponentAttachmentCSVRecord filledRecord = componentAttachmentCSVRecordBuilder.build();
    assertThat(filledRecord.getAttachment(), is(attachment));
}
Also used : AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 89 with Attachment

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

the class ComponentImportUtilsTest method getCreatedAttachmentContentId.

private String getCreatedAttachmentContentId() throws TException {
    List<Release> importedReleases = componentClient.getReleaseSummary(user);
    sortByField(importedReleases, Release._Fields.VERSION);
    sortByField(importedReleases, Release._Fields.NAME);
    final Release release = importedReleases.get(4);
    final Set<Attachment> attachments = release.getAttachments();
    assertThat(attachments.size(), is(1));
    final Attachment theAttachment = getFirst(attachments);
    return theAttachment.getAttachmentContentId();
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 90 with Attachment

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

the class DisplayDownloadAttachmentFileTest method createAttachment.

private Attachment createAttachment(String filename) {
    Attachment attachment = new Attachment();
    attachment.setFilename(filename);
    return attachment;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)65 Test (org.junit.Test)40 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)38 User (org.eclipse.sw360.datahandler.thrift.users.User)27 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)22 InputStream (java.io.InputStream)19 Release (org.eclipse.sw360.datahandler.thrift.components.Release)15 IOException (java.io.IOException)13 PortletRequest (javax.portlet.PortletRequest)11 TestUserCacheHolder (org.eclipse.sw360.portal.TestUserCacheHolder)9 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 TException (org.apache.thrift.TException)8 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)8 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)7 OutputStream (java.io.OutputStream)5 AttachmentInputStream (org.ektorp.AttachmentInputStream)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 Maps (com.google.common.collect.Maps)3