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