Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

SW360Updater now catches and logs exceptions during processing. #504

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import org.eclipse.sw360.antenna.sw360.client.adapter.SW360ReleaseClientAdapter;
import org.eclipse.sw360.antenna.sw360.client.rest.resource.attachments.SW360AttachmentType;
import org.eclipse.sw360.antenna.sw360.client.rest.resource.releases.SW360Release;
import org.eclipse.sw360.antenna.sw360.client.utils.SW360ClientException;
import org.eclipse.sw360.antenna.sw360.workflow.generators.SW360UpdaterImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -28,6 +31,8 @@
import static org.eclipse.sw360.antenna.frontend.compliancetool.sw360.ComplianceFeatureUtils.getArtifactsFromCsvFile;

public class SW360Updater {
private static final Logger LOG = LoggerFactory.getLogger(SW360Updater.class);

private final SW360UpdaterImpl updater;
private final SW360Configuration configuration;
private final ClearingReportGenerator generator;
Expand All @@ -46,16 +51,21 @@ public void execute() {
}

private void uploadReleaseWithClearingDocumentFromArtifact(Artifact artifact) {
SW360Release release = updater.artifactToReleaseInSW360(artifact);
SW360ReleaseClientAdapter releaseClientAdapter = configuration.getConnection().getReleaseAdapter();
LOG.info("Processing {}.", artifact);
try {
SW360Release release = updater.artifactToReleaseInSW360(artifact);
SW360ReleaseClientAdapter releaseClientAdapter = configuration.getConnection().getReleaseAdapter();

if (release.getClearingState() != null &&
!release.getClearingState().isEmpty() &&
ArtifactClearingState.ClearingState.valueOf(release.getClearingState()) != ArtifactClearingState.ClearingState.INITIAL) {
Map<Path, SW360AttachmentType> attachmentPathMap =
Collections.singletonMap(getOrGenerateClearingDocument(release, artifact),
SW360AttachmentType.CLEARING_REPORT);
releaseClientAdapter.uploadAttachments(release, attachmentPathMap);
if (release.getClearingState() != null &&
!release.getClearingState().isEmpty() &&
ArtifactClearingState.ClearingState.valueOf(release.getClearingState()) != ArtifactClearingState.ClearingState.INITIAL) {
Map<Path, SW360AttachmentType> attachmentPathMap =
Collections.singletonMap(getOrGenerateClearingDocument(release, artifact),
SW360AttachmentType.CLEARING_REPORT);
releaseClientAdapter.uploadAttachments(release, attachmentPathMap);
}
} catch (SW360ClientException e) {
LOG.error("Failed to process artifact {}.", artifact, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

import org.eclipse.sw360.antenna.frontend.compliancetool.sw360.ComplianceFeatureUtils;
import org.eclipse.sw360.antenna.frontend.compliancetool.sw360.SW360Configuration;
import org.eclipse.sw360.antenna.sw360.client.adapter.SW360ReleaseClientAdapter;
import org.eclipse.sw360.antenna.sw360.client.adapter.SW360Connection;
import org.eclipse.sw360.antenna.sw360.client.adapter.SW360ReleaseClientAdapter;
import org.eclipse.sw360.antenna.sw360.client.rest.resource.attachments.SW360AttachmentType;
import org.eclipse.sw360.antenna.sw360.client.rest.resource.releases.SW360Release;
import org.eclipse.sw360.antenna.sw360.client.utils.SW360ClientException;
import org.eclipse.sw360.antenna.sw360.workflow.generators.SW360UpdaterImpl;
import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
Expand Down Expand Up @@ -50,8 +51,8 @@ public class SW360UpdaterTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();

private SW360Configuration configurationMock = mock(SW360Configuration.class);
private SW360ReleaseClientAdapter releaseClientAdapter = mock(SW360ReleaseClientAdapter.class);
private final SW360Configuration configurationMock = mock(SW360Configuration.class);
private final SW360ReleaseClientAdapter releaseClientAdapter = mock(SW360ReleaseClientAdapter.class);

private final String clearingState;
private final boolean clearingDocAvailable;
Expand Down Expand Up @@ -133,12 +134,11 @@ public void testExecute() throws IOException {
initConnectionConfiguration();

SW360UpdaterImpl updater = mock(SW360UpdaterImpl.class);
when(updater.artifactToReleaseInSW360(any()))
.thenReturn(new SW360Release());
SW360Release release = new SW360Release();
release.setClearingState(clearingState);
when(updater.artifactToReleaseInSW360(any()))
.thenReturn(release);
.thenReturn(release)
.thenThrow(new SW360ClientException("Boo"));

ClearingReportGenerator generator = mock(ClearingReportGenerator.class);
when(generator.createClearingDocument(any(), any()))
Expand All @@ -153,7 +153,7 @@ public void testExecute() throws IOException {
if (expectUpload && !clearingDocAvailable) {
verify(generator).createClearingDocument(release, getTargetDir());
}
verify(updater).artifactToReleaseInSW360(any());
verify(updater, times(2)).artifactToReleaseInSW360(any());
verify(releaseClientAdapter, times(expectUpload ? 1 : 0)).uploadAttachments(any(), eq(testAttachmentMap));
}

Expand All @@ -177,7 +177,9 @@ private Path writeCsvFile() throws IOException {
clearingDocPath = clearingDoc.getPath();
}
String csvContent = String.format("Artifact Id,Group Id,Version,Coordinate Type,Clearing State,Clearing Document%s" +
"test,test,x.x.x,mvn,%s,%s%s", System.lineSeparator(), clearingState, clearingDocPath, System.lineSeparator());
"test,test,x.x.x,mvn,%s,%s%s" +
"error,error,y.y.y,mvn,%s,%s%s", System.lineSeparator(), clearingState, clearingDocPath,
System.lineSeparator(), clearingState, clearingDocPath, System.lineSeparator());
Files.write(tempCsvFile.toPath(), csvContent.getBytes(StandardCharsets.UTF_8));
return tempCsvFile.toPath();
}
Expand Down