Search in sources :

Example 1 with AttachmentType

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

the class Sw360AttachmentService method uploadAttachment.

public Attachment uploadAttachment(MultipartFile file, Attachment newAttachment, User sw360User) throws IOException, TException {
    // TODO: shouldn't the fileName be taken from newAttachment?
    String fileName = file.getOriginalFilename();
    String contentType = file.getContentType();
    final AttachmentContent attachmentContent = makeAttachmentContent(fileName, contentType);
    final AttachmentConnector attachmentConnector = getConnector();
    Attachment attachment = new AttachmentFrontendUtils().uploadAttachmentContent(attachmentContent, file.getInputStream(), sw360User);
    attachment.setSha1(attachmentConnector.getSha1FromAttachmentContentId(attachmentContent.getId()));
    AttachmentType attachmentType = newAttachment.getAttachmentType();
    if (attachmentType != null) {
        attachment.setAttachmentType(attachmentType);
    }
    CheckStatus checkStatus = newAttachment.getCheckStatus();
    if (checkStatus != null) {
        attachment.setCheckStatus(checkStatus);
    }
    return attachment;
}
Also used : AttachmentFrontendUtils(org.eclipse.sw360.commonIO.AttachmentFrontendUtils) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector)

Example 2 with AttachmentType

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

the class PortletUtilsTest method setAttachmentTypes.

protected static void setAttachmentTypes(PortletRequest request, AttachmentType... types) {
    List<String> stringTypes = Lists.newArrayList();
    for (AttachmentType type : types) {
        stringTypes.add("" + type.getValue());
    }
    Mockito.when(request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.ATTACHMENT_TYPE.toString())).thenReturn(stringTypes.toArray(new String[] {}));
}
Also used : AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType)

Example 3 with AttachmentType

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

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

the class ComponentAttachmentCSVRecord method getAttachment.

public Attachment getAttachment() {
    final Attachment attachment = new Attachment().setAttachmentContentId(attachmentContentId).setFilename(filename);
    if (!isNullOrEmpty(attachmentType)) {
        final AttachmentType attachmentTypeCandidate = ThriftEnumUtils.stringToEnum(attachmentType, AttachmentType.class);
        if (attachmentTypeCandidate != null)
            attachment.setAttachmentType(attachmentTypeCandidate);
    }
    attachment.setCreatedComment(nullToEmpty(comment)).setCreatedOn(nullToEmpty(createdOn)).setCreatedBy(nullToEmpty(createdBy));
    return attachment;
}
Also used : AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Aggregations

AttachmentType (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)2 AttachmentFrontendUtils (org.eclipse.sw360.commonIO.AttachmentFrontendUtils)1 AttachmentConnector (org.eclipse.sw360.datahandler.couchdb.AttachmentConnector)1 Test (org.junit.Test)1