@Test public void testUploadAttachmentsConflictFailuresAreAddedToResult() throws IOException { Path uploadPath1 = createTestFile(attachmentPath("conflict.doc"), TEST_FILE_CONTENT + "_other"); Path uploadPath2 = createTestFile(attachmentPath("sources.zip"), TEST_FILE_CONTENT); SW360AttachmentType attachmentType = SW360AttachmentType.SOURCE; Map<Path, SW360AttachmentType> attachments = new HashMap<>(); attachments.put(uploadPath1, attachmentType); attachments.put(uploadPath2, attachmentType); SW360SparseAttachment attachment = createAttachment(uploadPath1.getFileName().toString(), attachmentType); SW360Release release = addAttachment(createRelease(RELEASE_NAME), attachment); AttachmentUploadRequest<SW360Release> expRequest = AttachmentUploadRequest.builder(release) .addAttachment(uploadPath2, attachmentType) .build(); AttachmentUploadResult<SW360Release> expResult = new AttachmentUploadResult<>(createRelease("update")); when(releaseClientAdapter.uploadAttachments(expRequest)) .thenReturn(expResult); AttachmentUploadResult<SW360Release> uploadResult = metaDataUpdater.uploadAttachments(release, attachments, false); assertThat(uploadResult.failedUploads().keySet()) .containsOnly(new AttachmentUploadRequest.Item(uploadPath1, attachmentType)); }
public AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release, Map<Path, SW360AttachmentType> attachments, boolean force) { Set<String> attachmentsToDelete = new HashSet<>(); Map<AttachmentUploadRequest.Item, Throwable> conflictFailures = new HashMap<>(); AttachmentUploadRequest.Builder<SW360Release> builder = AttachmentUploadRequest.builder(sw360Release); for (Map.Entry<Path, SW360AttachmentType> e : attachments.entrySet()) { String fileName = String.valueOf(e.getKey().getFileName()); Optional<SW360SparseAttachment> optAttachment = findAttachmentByFileName(sw360Release, fileName); boolean shouldUpload = optAttachment.map(attachment -> checkUploadCriteria(e.getKey(), attachment, attachmentsToDelete, conflictFailures, force)) .orElse(true); if (shouldUpload) { builder = builder.addAttachment(e.getKey(), e.getValue()); } } deleteConflictingAttachments(sw360Release, attachmentsToDelete); AttachmentUploadRequest<SW360Release> uploadRequest = builder.build(); if (!uploadRequest.getItems().isEmpty()) { AttachmentUploadResult<SW360Release> result = releaseClientAdapter.uploadAttachments(uploadRequest); LOGGER.debug("Result of attachment upload operation: {}", result); if (!result.isSuccess()) { LOGGER.error("Failed to upload attachments: {}", result.failedUploads()); } return appendFailures(result, conflictFailures); } return appendFailures(new AttachmentUploadResult<>(sw360Release), conflictFailures); }
SW360MetaDataUpdater { public AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release, Map<Path, SW360AttachmentType> attachments, boolean force) { Set<String> attachmentsToDelete = new HashSet<>(); Map<AttachmentUploadRequest.Item, Throwable> conflictFailures = new HashMap<>(); AttachmentUploadRequest.Builder<SW360Release> builder = AttachmentUploadRequest.builder(sw360Release); for (Map.Entry<Path, SW360AttachmentType> e : attachments.entrySet()) { String fileName = String.valueOf(e.getKey().getFileName()); Optional<SW360SparseAttachment> optAttachment = findAttachmentByFileName(sw360Release, fileName); boolean shouldUpload = optAttachment.map(attachment -> checkUploadCriteria(e.getKey(), attachment, attachmentsToDelete, conflictFailures, force)) .orElse(true); if (shouldUpload) { builder = builder.addAttachment(e.getKey(), e.getValue()); } } deleteConflictingAttachments(sw360Release, attachmentsToDelete); AttachmentUploadRequest<SW360Release> uploadRequest = builder.build(); if (!uploadRequest.getItems().isEmpty()) { AttachmentUploadResult<SW360Release> result = releaseClientAdapter.uploadAttachments(uploadRequest); LOGGER.debug("Result of attachment upload operation: {}", result); if (!result.isSuccess()) { LOGGER.error("Failed to upload attachments: {}", result.failedUploads()); } return appendFailures(result, conflictFailures); } return appendFailures(new AttachmentUploadResult<>(sw360Release), conflictFailures); } }
SW360MetaDataUpdater { public AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release, Map<Path, SW360AttachmentType> attachments, boolean force) { Set<String> attachmentsToDelete = new HashSet<>(); Map<AttachmentUploadRequest.Item, Throwable> conflictFailures = new HashMap<>(); AttachmentUploadRequest.Builder<SW360Release> builder = AttachmentUploadRequest.builder(sw360Release); for (Map.Entry<Path, SW360AttachmentType> e : attachments.entrySet()) { String fileName = String.valueOf(e.getKey().getFileName()); Optional<SW360SparseAttachment> optAttachment = findAttachmentByFileName(sw360Release, fileName); boolean shouldUpload = optAttachment.map(attachment -> checkUploadCriteria(e.getKey(), attachment, attachmentsToDelete, conflictFailures, force)) .orElse(true); if (shouldUpload) { builder = builder.addAttachment(e.getKey(), e.getValue()); } } deleteConflictingAttachments(sw360Release, attachmentsToDelete); AttachmentUploadRequest<SW360Release> uploadRequest = builder.build(); if (!uploadRequest.getItems().isEmpty()) { AttachmentUploadResult<SW360Release> result = releaseClientAdapter.uploadAttachments(uploadRequest); LOGGER.debug("Result of attachment upload operation: {}", result); if (!result.isSuccess()) { LOGGER.error("Failed to upload attachments: {}", result.failedUploads()); } return appendFailures(result, conflictFailures); } return appendFailures(new AttachmentUploadResult<>(sw360Release), conflictFailures); } SW360MetaDataUpdater(SW360Connection connection); }
SW360MetaDataUpdater { public AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release, Map<Path, SW360AttachmentType> attachments, boolean force) { Set<String> attachmentsToDelete = new HashSet<>(); Map<AttachmentUploadRequest.Item, Throwable> conflictFailures = new HashMap<>(); AttachmentUploadRequest.Builder<SW360Release> builder = AttachmentUploadRequest.builder(sw360Release); for (Map.Entry<Path, SW360AttachmentType> e : attachments.entrySet()) { String fileName = String.valueOf(e.getKey().getFileName()); Optional<SW360SparseAttachment> optAttachment = findAttachmentByFileName(sw360Release, fileName); boolean shouldUpload = optAttachment.map(attachment -> checkUploadCriteria(e.getKey(), attachment, attachmentsToDelete, conflictFailures, force)) .orElse(true); if (shouldUpload) { builder = builder.addAttachment(e.getKey(), e.getValue()); } } deleteConflictingAttachments(sw360Release, attachmentsToDelete); AttachmentUploadRequest<SW360Release> uploadRequest = builder.build(); if (!uploadRequest.getItems().isEmpty()) { AttachmentUploadResult<SW360Release> result = releaseClientAdapter.uploadAttachments(uploadRequest); LOGGER.debug("Result of attachment upload operation: {}", result); if (!result.isSuccess()) { LOGGER.error("Failed to upload attachments: {}", result.failedUploads()); } return appendFailures(result, conflictFailures); } return appendFailures(new AttachmentUploadResult<>(sw360Release), conflictFailures); } SW360MetaDataUpdater(SW360Connection connection); Set<SW360License> getLicenses(Collection<License> licenses); SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting); void createProject(String projectName, String projectVersion, Collection<SW360Release> releases); AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release,
                                                                  Map<Path, SW360AttachmentType> attachments,
                                                                  boolean force); SW360Release deleteSourceAttachments(SW360Release release); SW360Release deleteAttachments(SW360Release release, Predicate<SW360SparseAttachment> filter); }
SW360MetaDataUpdater { public AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release, Map<Path, SW360AttachmentType> attachments, boolean force) { Set<String> attachmentsToDelete = new HashSet<>(); Map<AttachmentUploadRequest.Item, Throwable> conflictFailures = new HashMap<>(); AttachmentUploadRequest.Builder<SW360Release> builder = AttachmentUploadRequest.builder(sw360Release); for (Map.Entry<Path, SW360AttachmentType> e : attachments.entrySet()) { String fileName = String.valueOf(e.getKey().getFileName()); Optional<SW360SparseAttachment> optAttachment = findAttachmentByFileName(sw360Release, fileName); boolean shouldUpload = optAttachment.map(attachment -> checkUploadCriteria(e.getKey(), attachment, attachmentsToDelete, conflictFailures, force)) .orElse(true); if (shouldUpload) { builder = builder.addAttachment(e.getKey(), e.getValue()); } } deleteConflictingAttachments(sw360Release, attachmentsToDelete); AttachmentUploadRequest<SW360Release> uploadRequest = builder.build(); if (!uploadRequest.getItems().isEmpty()) { AttachmentUploadResult<SW360Release> result = releaseClientAdapter.uploadAttachments(uploadRequest); LOGGER.debug("Result of attachment upload operation: {}", result); if (!result.isSuccess()) { LOGGER.error("Failed to upload attachments: {}", result.failedUploads()); } return appendFailures(result, conflictFailures); } return appendFailures(new AttachmentUploadResult<>(sw360Release), conflictFailures); } SW360MetaDataUpdater(SW360Connection connection); Set<SW360License> getLicenses(Collection<License> licenses); SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting); void createProject(String projectName, String projectVersion, Collection<SW360Release> releases); AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release,
                                                                  Map<Path, SW360AttachmentType> attachments,
                                                                  boolean force); SW360Release deleteSourceAttachments(SW360Release release); SW360Release deleteAttachments(SW360Release release, Predicate<SW360SparseAttachment> filter);  }