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;
}
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;
}
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));
}
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();
}
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;
}
Aggregations