Search in sources :

Example 41 with Attachment

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

the class FossologyFileHandlerTest method spyGetFilledSourceAttachment.

private void spyGetFilledSourceAttachment(FilledAttachment filledAttachment) throws TException {
    final Attachment attachment = filledAttachment.getAttachment();
    doReturn(ImmutableSet.of(attachment)).when(fossologyFileHandler).getSourceAttachment(releaseId, user, componentService);
    doReturn(filledAttachment).when(fossologyFileHandler).fillAttachment(attachment);
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)

Example 42 with Attachment

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

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

the class FossologyFileHandler method fillAttachment.

protected FilledAttachment fillAttachment(Attachment attachment) throws SW360Exception {
    String attachmentContentId = attachment.getAttachmentContentId();
    try {
        AttachmentContent attachmentContent = attachmentConnector.getAttachmentContent(attachmentContentId);
        assertNotNull(attachmentContent);
        return new FilledAttachment().setAttachment(attachment).setAttachmentContent(attachmentContent);
    } catch (SW360Exception e) {
        log.error("cannot retrieve attachment " + attachmentContentId, e);
        throw e;
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 44 with Attachment

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

the class CommonUtils method getNewAttachment.

@NotNull
public static Attachment getNewAttachment(User user, String attachmentContentId, String fileName) {
    Attachment attachment = new Attachment();
    attachment.setCreatedBy(user.getEmail());
    attachment.setCreatedOn(SW360Utils.getCreatedOn());
    attachment.setCreatedComment("");
    attachment.setCreatedTeam(user.getDepartment());
    attachment.setFilename(fileName);
    attachment.setAttachmentContentId(attachmentContentId);
    attachment.setAttachmentType(AttachmentType.DOCUMENT);
    attachment.setCheckStatus(CheckStatus.NOTCHECKED);
    attachment.setCheckedComment("");
    attachment.setSha1("");
    return attachment;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with Attachment

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

the class Moderator method updateAttachments.

protected Set<Attachment> updateAttachments(Set<Attachment> attachments, Set<Attachment> attachmentAdditions, Set<Attachment> attachmentDeletions) {
    if (attachments == null) {
        attachments = new HashSet<>();
    }
    Map<String, Attachment> attachmentMap = Maps.uniqueIndex(attachments, Attachment::getAttachmentContentId);
    if (attachmentAdditions != null) {
        for (Attachment update : attachmentAdditions) {
            String id = update.getAttachmentContentId();
            if (attachmentMap.containsKey(id)) {
                Attachment actual = attachmentMap.get(id);
                for (Attachment._Fields field : Attachment._Fields.values()) {
                    if (update.isSet(field)) {
                        actual.setFieldValue(field, update.getFieldValue(field));
                    }
                }
            } else {
                attachments.add(update);
            }
        }
    }
    Map<String, Attachment> additionsMap = attachmentAdditions != null ? Maps.uniqueIndex(attachmentAdditions, Attachment::getAttachmentContentId) : new HashMap<>();
    if (attachmentDeletions != null) {
        for (Attachment delete : attachmentDeletions) {
            if (!additionsMap.containsKey(delete.getAttachmentContentId())) {
                attachments.remove(delete);
            }
        }
    }
    return attachments;
}
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