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;
}
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[] {}));
}
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));
}
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;
}
Aggregations