Skip to content

Commit

Permalink
Fix(package): Fix issues api for package
Browse files Browse the repository at this point in the history
- Cannot unlink orphan packages from the project
- Cannot link a package to a release without any package
- Handle message when package with same purl already exists

Signed-off-by: tuannn2 <tuan2.nguyennhu@toshiba.co.jp>
  • Loading branch information
tuannn2 committed Jan 9, 2024
1 parent 89a75f8 commit 88a1202
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public AddDocumentRequestSummary addPackage(Package pkg, User user) throws SW360

if (duplicatePackagesByPurl.size() > 0) {
final AddDocumentRequestSummary addDocumentRequestSummary = new AddDocumentRequestSummary()
.setRequestStatus(AddDocumentRequestStatus.DUPLICATE);
.setRequestStatus(AddDocumentRequestStatus.DUPLICATE)
.setMessage(SW360Constants.DUPLICATE_PACKAGE_BY_PURL);
if(duplicatePackagesByPurl.size() == 1){
addDocumentRequestSummary.setId(duplicatePackagesByPurl.get(0).getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,9 @@ private boolean isLinkedReleasesUpdateFromLinkedPackagesFailed(Project updatedPr
PackageService.Iface packageClient = new ThriftClients().makePackageClient();
List<Package> removedPackages = packageClient.getPackageWithReleaseByPackageIds(unlinkedPacakgeIds);

Map<String, Set<String>> releaseIdToPackageIdsMap = removedPackages.stream().map(Package::getRelease)
Map<String, Set<String>> releaseIdToPackageIdsMap = removedPackages.stream()
.filter(packageFilter -> packageFilter.getRelease() != null)
.map(Package::getRelease)
.filter(rel -> CommonUtils.isNotEmpty(rel.getPackageIds()))
.map(rel -> new AbstractMap.SimpleEntry<>(rel.getId(), rel.getPackageIds()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldVal, newVal) -> newVal));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SW360Constants {
public static final String NULL_STRING = "null";
public static final String PACKAGE_URL = "package-url";
public static final String PURL_ID = "purl.id";
public static final String DUPLICATE_PACKAGE_BY_PURL = "duplicatePackagesByPurl";
public static final String XML_FILE_EXTENSION = "xml";
public static final String JSON_FILE_EXTENSION = "json";
public static final String PROJECT_IDS = "projectIds";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.SW360Constants;
import org.eclipse.sw360.datahandler.couchdb.lucene.LuceneAwareDatabaseConnector;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary;
Expand Down Expand Up @@ -54,6 +55,9 @@ public Package createPackage(Package pkg, User sw360User) throws TException {
pkg.setId(documentRequestSummary.getId());
pkg.setCreatedBy(sw360User.getEmail());
return pkg;
} else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.DUPLICATE
&& documentRequestSummary.getMessage().equals(SW360Constants.DUPLICATE_PACKAGE_BY_PURL) ) {
throw new DataIntegrityViolationException("sw360 package with same purl '" + pkg.getPurl() + "' already exists.");
} else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.DUPLICATE) {
throw new DataIntegrityViolationException("sw360 package with same name and version '" + pkg.getName() + "' already exists.");
} else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.INVALID_INPUT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,9 +1275,11 @@ private RequestStatus linkOrUnlinkPackages(String id, Set<String> packagesInRequ
throws URISyntaxException, TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
Release release = releaseService.getReleaseForUserById(id, sw360User);
Set<String> packageIds = new HashSet<>();
Set<String> packageIds;
packageIds = release.getPackageIds();

if (CommonUtils.isNullOrEmptyCollection(packageIds)) {
packageIds = new HashSet<>();
}
if (link) {
packageIds.addAll(packagesInRequestBody);
} else {
Expand Down

0 comments on commit 88a1202

Please sign in to comment.