@Test public void testGetOrCreateReleaseFoundByNameAndVersion() { SW360SparseRelease sparseRelease = new SW360SparseRelease(); SW360Release foundRelease = new SW360Release(); SW360Release queryRelease = new SW360Release(); queryRelease.setExternalIds(Collections.singletonMap("id", "42")); foundRelease.setExternalIds(Collections.singletonMap("id2", "47")); queryRelease.setName("theComponent"); queryRelease.setVersion("100.0"); when(releaseClientAdapter.getSparseReleaseByExternalIds(queryRelease.getExternalIds())).thenReturn(Optional.empty()); when(releaseClientAdapter.getSparseReleaseByNameAndVersion(queryRelease.getName(), queryRelease.getVersion())) .thenReturn(Optional.of(sparseRelease)); when(releaseClientAdapter.enrichSparseRelease(sparseRelease)).thenReturn(Optional.of(foundRelease)); assertThat(metaDataUpdater.getOrCreateRelease(queryRelease, false)).isEqualTo(queryRelease); assertThat(queryRelease.getExternalIds()).containsKey("id2"); verify(releaseClientAdapter, never()).updateRelease(any()); }
public SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting) { Optional<SW360SparseRelease> optSparseReleaseByIds = releaseClientAdapter.getSparseReleaseByExternalIds(sw360ReleaseFromArtifact.getExternalIds()); Optional<SW360SparseRelease> optSparseRelease = optSparseReleaseByIds.isPresent() ? optSparseReleaseByIds : releaseClientAdapter.getSparseReleaseByNameAndVersion(sw360ReleaseFromArtifact.getName(), sw360ReleaseFromArtifact.getVersion()); Optional<SW360Release> optRelease = optSparseRelease.flatMap(releaseClientAdapter::enrichSparseRelease) .map(sw360ReleaseFromArtifact::mergeWith); if (optRelease.isPresent()) { SW360Release release = optRelease.get(); return updateExisting ? releaseClientAdapter.updateRelease(release) : release; } return releaseClientAdapter.createRelease(sw360ReleaseFromArtifact); }
SW360MetaDataUpdater { public SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting) { Optional<SW360SparseRelease> optSparseReleaseByIds = releaseClientAdapter.getSparseReleaseByExternalIds(sw360ReleaseFromArtifact.getExternalIds()); Optional<SW360SparseRelease> optSparseRelease = optSparseReleaseByIds.isPresent() ? optSparseReleaseByIds : releaseClientAdapter.getSparseReleaseByNameAndVersion(sw360ReleaseFromArtifact.getName(), sw360ReleaseFromArtifact.getVersion()); Optional<SW360Release> optRelease = optSparseRelease.flatMap(releaseClientAdapter::enrichSparseRelease) .map(sw360ReleaseFromArtifact::mergeWith); if (optRelease.isPresent()) { SW360Release release = optRelease.get(); return updateExisting ? releaseClientAdapter.updateRelease(release) : release; } return releaseClientAdapter.createRelease(sw360ReleaseFromArtifact); } }
SW360MetaDataUpdater { public SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting) { Optional<SW360SparseRelease> optSparseReleaseByIds = releaseClientAdapter.getSparseReleaseByExternalIds(sw360ReleaseFromArtifact.getExternalIds()); Optional<SW360SparseRelease> optSparseRelease = optSparseReleaseByIds.isPresent() ? optSparseReleaseByIds : releaseClientAdapter.getSparseReleaseByNameAndVersion(sw360ReleaseFromArtifact.getName(), sw360ReleaseFromArtifact.getVersion()); Optional<SW360Release> optRelease = optSparseRelease.flatMap(releaseClientAdapter::enrichSparseRelease) .map(sw360ReleaseFromArtifact::mergeWith); if (optRelease.isPresent()) { SW360Release release = optRelease.get(); return updateExisting ? releaseClientAdapter.updateRelease(release) : release; } return releaseClientAdapter.createRelease(sw360ReleaseFromArtifact); } SW360MetaDataUpdater(SW360Connection connection); }
SW360MetaDataUpdater { public SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting) { Optional<SW360SparseRelease> optSparseReleaseByIds = releaseClientAdapter.getSparseReleaseByExternalIds(sw360ReleaseFromArtifact.getExternalIds()); Optional<SW360SparseRelease> optSparseRelease = optSparseReleaseByIds.isPresent() ? optSparseReleaseByIds : releaseClientAdapter.getSparseReleaseByNameAndVersion(sw360ReleaseFromArtifact.getName(), sw360ReleaseFromArtifact.getVersion()); Optional<SW360Release> optRelease = optSparseRelease.flatMap(releaseClientAdapter::enrichSparseRelease) .map(sw360ReleaseFromArtifact::mergeWith); if (optRelease.isPresent()) { SW360Release release = optRelease.get(); return updateExisting ? releaseClientAdapter.updateRelease(release) : release; } return releaseClientAdapter.createRelease(sw360ReleaseFromArtifact); } 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 SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting) { Optional<SW360SparseRelease> optSparseReleaseByIds = releaseClientAdapter.getSparseReleaseByExternalIds(sw360ReleaseFromArtifact.getExternalIds()); Optional<SW360SparseRelease> optSparseRelease = optSparseReleaseByIds.isPresent() ? optSparseReleaseByIds : releaseClientAdapter.getSparseReleaseByNameAndVersion(sw360ReleaseFromArtifact.getName(), sw360ReleaseFromArtifact.getVersion()); Optional<SW360Release> optRelease = optSparseRelease.flatMap(releaseClientAdapter::enrichSparseRelease) .map(sw360ReleaseFromArtifact::mergeWith); if (optRelease.isPresent()) { SW360Release release = optRelease.get(); return updateExisting ? releaseClientAdapter.updateRelease(release) : release; } return releaseClientAdapter.createRelease(sw360ReleaseFromArtifact); } 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);  }