use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class FossologyUploaderTest method testUploadToFossology.
@Test
public void testUploadToFossology() throws Exception {
AttachmentContent attachment = mock(AttachmentContent.class);
when(attachment.getId()).thenReturn("id");
when(attachment.getFilename()).thenReturn("fileName");
String clearingTeam = "cl";
final InputStream inputStream = mock(InputStream.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Object[] arguments = invocation.getArguments();
String command = (String) arguments[0];
InputStream input = (InputStream) arguments[1];
OutputStream outputStream = (OutputStream) arguments[2];
assertThat(input, sameInstance(inputStream));
assertThat(command, is("./uploadFromSW360 -i 'id' -g 'cl' -f 'fileName'"));
outputStream.write("uploadId=60".getBytes());
return 0;
}
}).when(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
final long uploadId = fossologyUploader.uploadToFossology(inputStream, attachment, clearingTeam);
verify(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
assertThat(uploadId, is((long) 60));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class FossologyFileHandlerTest method getMockFilledAttachment.
private static FilledAttachment getMockFilledAttachment(String attachmentContentId) {
final FilledAttachment filledAttachment = mock(FilledAttachment.class);
final Attachment attachment = mock(Attachment.class);
when(filledAttachment.getAttachment()).thenReturn(attachment);
final AttachmentContent attachmentContent = mock(AttachmentContent.class);
when(filledAttachment.getAttachmentContent()).thenReturn(attachmentContent);
when(attachment.getAttachmentContentId()).thenReturn(attachmentContentId);
when(attachmentContent.getId()).thenReturn(attachmentContentId);
return filledAttachment;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class CLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.
@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>")));
assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent 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;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent in project sw360portal by sw360.
the class ComponentImportUtils method getAttachmentContents.
@Nullable
private static List<AttachmentContent> getAttachmentContents(HashMap<String, List<String>> releaseIdentifierToDownloadURL, ImmutableMap<String, AttachmentContent> URLtoAttachment, String releaseIdentifier) {
List<AttachmentContent> attachmentContents = null;
if (releaseIdentifierToDownloadURL.containsKey(releaseIdentifier)) {
final List<String> URLs = releaseIdentifierToDownloadURL.get(releaseIdentifier);
attachmentContents = new ArrayList<>(URLs.size());
for (String url : URLs) {
if (URLtoAttachment.containsKey(url)) {
final AttachmentContent attachmentContent = URLtoAttachment.get(url);
attachmentContents.add(attachmentContent);
}
}
}
return attachmentContents;
}
Aggregations