Skip to content

Commit

Permalink
Merge pull request #2182 from Siemens-Healthineers/fix/rework-on-PR-2154
Browse files Browse the repository at this point in the history
fix(importCDX): Remove view BY_VCS_LOWERCASE and BY_PURL_LOWERCASE

Reviewed by: [email protected]
Tested by: [email protected]
  • Loading branch information
ag4ums authored Nov 15, 2023
2 parents 265fb19 + 5e48f83 commit ad69c47
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ private void setMainLicenses(Component component) {
* Add new release to the database
*/
public AddDocumentRequestSummary addComponent(Component component, String user) throws SW360Exception {
if(isDuplicateUsingVcs(component.getVcs(), true)){
if(isDuplicateUsingVcs(component.getVcs())){
final AddDocumentRequestSummary addDocumentRequestSummary = new AddDocumentRequestSummary()
.setRequestStatus(AddDocumentRequestStatus.DUPLICATE);
Set<String> duplicates = componentRepository.getComponentIdsByVCS(component.getVcs(), true);
Set<String> duplicates = componentRepository.getComponentIdsByVCS(component.getVcs().toLowerCase());
if (duplicates.size() == 1) {
duplicates.forEach(addDocumentRequestSummary::setId);
}
Expand Down Expand Up @@ -593,11 +593,11 @@ private boolean isDuplicate(String componentName, boolean caseInsenstive) {
return duplicates.size()>0;
}

private boolean isDuplicateUsingVcs(String vcsUrl, boolean caseInsenstive){
private boolean isDuplicateUsingVcs(String vcsUrl){
if (isNullEmptyOrWhitespace(vcsUrl)) {
return false;
}
Set<String> duplicates = componentRepository.getComponentIdsByVCS(vcsUrl, caseInsenstive);
Set<String> duplicates = componentRepository.getComponentIdsByVCS(vcsUrl.toLowerCase());
return duplicates.size()>0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,8 @@ public class ComponentRepository extends SummaryAwareRepository<Component> {
" }" +
"}";

private static final String BY_VCS_LOWERCASE = "function(doc) {" +
" if (doc.type == 'component') {" +
" emit(doc.vcs.toLowerCase().trim(), doc._id);" +
" } " +
"}";

private static final String BY_VCS = "function(doc) {" +
" if (doc.type == 'component') {" +
" if (doc.type == 'component' && doc.vcs) {" +
" emit(doc.vcs, doc._id);" +
" } " +
"}";
Expand All @@ -177,8 +171,7 @@ public ComponentRepository(DatabaseConnectorCloudant db, ReleaseRepository relea
views.put("bynamelowercase", createMapReduce(BY_NAME_LOWERCASE, null));
views.put("bymainlicense", createMapReduce(BY_MAIN_LICENSE, null));
views.put("byvendor", createMapReduce(BY_VENDOR, null));
views.put("byVcs", createMapReduce(BY_VCS, null));
views.put("byVcsLowercase", createMapReduce(BY_VCS_LOWERCASE, null));
views.put("byVCS", createMapReduce(BY_VCS, null));
initStandardDesignDocument(views, db);
}

Expand Down Expand Up @@ -229,11 +222,9 @@ public Set<String> getComponentIdsByName(String name, boolean caseInsenstive) {
return queryForIdsAsValue("byname", name);
}

public Set<String> getComponentIdsByVCS(String vcs, boolean caseInsenstive){
if(caseInsenstive) {
return queryForIdsAsValue("byVcsLowercase", vcs.toLowerCase());
}
return queryForIdsAsValue("byVcs", vcs);
public Set<String> getComponentIdsByVCS(String vcs){
Set<String> componentIds = queryForIdsAsValue("byVCS", vcs);
return componentIds;
}

public List<Component> searchComponentByName(String name, boolean caseSensitive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private List<Package> getPackageByPurl(String purl) {
if (purl == null) {
return Collections.emptyList();
}
return packageRepository.searchByPurl(purl, true);
return packageRepository.searchByPurl(purl);
}

private void copyImmutableFields(Package destination, Package source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class PackageRepository extends DatabaseRepositoryCloudantClient<Package>
private static final String BY_RELEASE_ID = "function(doc) { if (doc.type == 'package') { emit(doc.releaseId, doc._id); } }";
private static final String BY_LICENSE_IDS = "function(doc) { if (doc.type == 'package') { if (doc.licenseIds) { emit(doc.licenseIds.join(), doc._id); } else { emit('', doc._id); } } }";
private static final String BY_PURL = "function(doc) { if (doc.type == 'package') { emit(doc.purl.trim(), doc._id) } }";
private static final String BY_PURL_LOWERCASE = "function(doc) { if (doc.type == 'package') { emit(doc.purl.toLowerCase().trim(), doc._id) } }";

public PackageRepository(DatabaseConnectorCloudant db) {
super(db, Package.class);
Expand All @@ -64,7 +63,6 @@ public PackageRepository(DatabaseConnectorCloudant db) {
views.put("byReleaseId", createMapReduce(BY_RELEASE_ID, null));
views.put("byLicenseIds", createMapReduce(BY_LICENSE_IDS, null));
views.put("byPurl", createMapReduce(BY_PURL, null));
views.put("byPurlLowerCase", createMapReduce(BY_PURL_LOWERCASE, null));
initStandardDesignDocument(views, db);
}

Expand Down Expand Up @@ -109,13 +107,9 @@ public List<Package> searchByNameAndVersion(String name, String version, boolean
return releasesMatchingNameAndVersion;
}

public List<Package> searchByPurl(String purl, boolean caseInsenstive) {
List<org.eclipse.sw360.datahandler.thrift.packages.Package> packagesMatchingPurl;
if (caseInsenstive) {
packagesMatchingPurl = new ArrayList<org.eclipse.sw360.datahandler.thrift.packages.Package>(queryView("byPurlLowerCase", purl.toLowerCase()));
} else {
packagesMatchingPurl = new ArrayList<org.eclipse.sw360.datahandler.thrift.packages.Package>(queryView("byPurl", purl));
}
public List<Package> searchByPurl(String purl) {
List<org.eclipse.sw360.datahandler.thrift.packages.Package> packagesMatchingPurl
= new ArrayList<org.eclipse.sw360.datahandler.thrift.packages.Package>(queryView("byPurl", purl));
return packagesMatchingPurl;
}

Expand Down

0 comments on commit ad69c47

Please sign in to comment.