use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class CLIParserTest method testGetCLIFailsOnMalformedXML.
@Test
public void testGetCLIFailsOnMalformedXML() throws Exception {
Attachment cliAttachment = new Attachment("A1", "a.xml");
when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE.replaceAll("</Content>", "</Broken>"))));
LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
assertLicenseInfoParsingResult(res, LicenseInfoRequestStatus.FAILURE);
assertThat(res.getStatus(), is(LicenseInfoRequestStatus.FAILURE));
assertThat(res.getLicenseInfo(), notNullValue());
assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ProjectHandler method removeAttachmentFromProject.
@Override
public RequestStatus removeAttachmentFromProject(String projectId, User user, String attachmentContentId) throws TException {
Project projectByIdForEdit = getProjectByIdForEdit(projectId, user);
Set<Attachment> attachments = projectByIdForEdit.getAttachments();
Optional<Attachment> attachmentOptional = CommonUtils.getAttachmentOptional(attachmentContentId, attachments);
if (attachmentOptional.isPresent()) {
attachments.remove(attachmentOptional.get());
return updateProject(projectByIdForEdit, user);
} else {
return RequestStatus.SUCCESS;
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ModerationRequestGenerator method dealWithAttachments.
protected void dealWithAttachments(U attachmentField) {
Set<Attachment> actualAttachments = (Set<Attachment>) actualDocument.getFieldValue(attachmentField);
Set<Attachment> updateAttachments = (Set<Attachment>) updateDocument.getFieldValue(attachmentField);
Map<String, Attachment> actualAttachmentMap = Maps.uniqueIndex(actualAttachments, Attachment::getAttachmentContentId);
Set<String> actualAttachmentIds = actualAttachmentMap.keySet();
Map<String, Attachment> updateAttachmentMap = Maps.uniqueIndex(updateAttachments, Attachment::getAttachmentContentId);
Set<String> updateAttachmentIds = updateAttachmentMap.keySet();
Set<Attachment> attachmentAdditions = updateAttachmentMap.values().stream().filter(attachment -> !actualAttachmentIds.contains(attachment.getAttachmentContentId())).collect(Collectors.toSet());
Set<Attachment> attachmentDeletions = actualAttachmentMap.values().stream().filter(attachment -> !updateAttachmentIds.contains(attachment.getAttachmentContentId())).collect(Collectors.toSet());
// determine changes in common attachments
Set<String> commonAttachmentIds = Sets.intersection(actualAttachmentIds, updateAttachmentIds);
for (String id : commonAttachmentIds) {
Attachment actual = actualAttachmentMap.get(id);
Attachment update = updateAttachmentMap.get(id);
if (actual != null && !actual.equals(update)) {
attachmentAdditions.add(getAdditionsFromCommonAttachment(actual, update));
attachmentDeletions.add(getDeletionsFromCommonAttachment(actual, update));
}
}
documentAdditions.setFieldValue(attachmentField, attachmentAdditions);
documentDeletions.setFieldValue(attachmentField, attachmentDeletions);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ComponentController method addAttachmentToComponent.
@RequestMapping(value = COMPONENTS_URL + "/{componentId}/attachments", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
public ResponseEntity<HalResource> addAttachmentToComponent(@PathVariable("componentId") String componentId, OAuth2Authentication oAuth2Authentication, @RequestPart("file") MultipartFile file, @RequestPart("attachment") Attachment newAttachment) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Attachment attachment;
try {
attachment = attachmentService.uploadAttachment(file, newAttachment, sw360User);
} catch (IOException e) {
log.error("failed to upload attachment", e);
throw new RuntimeException("failed to upload attachment", e);
}
final Component component = componentService.getComponentForUserById(componentId, sw360User);
component.addToAttachments(attachment);
componentService.updateComponent(component, sw360User);
final HalResource halRelease = createHalComponent(component, sw360User);
return new ResponseEntity<>(halRelease, HttpStatus.OK);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ProjectController method addAttachmentToProject.
@RequestMapping(value = PROJECTS_URL + "/{projectId}/attachments", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
public ResponseEntity<HalResource> addAttachmentToProject(@PathVariable("projectId") String projectId, OAuth2Authentication oAuth2Authentication, @RequestPart("file") MultipartFile file, @RequestPart("attachment") Attachment newAttachment) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Attachment attachment;
try {
attachment = attachmentService.uploadAttachment(file, newAttachment, sw360User);
} catch (IOException e) {
log.error(e.getMessage());
throw new RuntimeException(e);
}
final Project project = projectService.getProjectForUserById(projectId, sw360User);
project.addToAttachments(attachment);
projectService.updateProject(project, sw360User);
final HalResource<Project> halResource = createHalProject(project, sw360User);
return new ResponseEntity<>(halResource, HttpStatus.OK);
}
Aggregations