forked from DependencyTrack/dependency-track
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the changes suggested by @nscuro
Signed-off-by: Mikael Carneholm <[email protected]>
- Loading branch information
1 parent
54cce6b
commit beba9d2
Showing
8 changed files
with
463 additions
and
173 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/org/dependencytrack/exception/ProjectOperationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.exception; | ||
|
||
import java.util.Map; | ||
|
||
public class ProjectOperationException extends IllegalStateException { | ||
|
||
private final Map<String, String> errorByUUID; | ||
|
||
private ProjectOperationException(final String message, final Map<String, String> errorByUUID) { | ||
super(message); | ||
this.errorByUUID = errorByUUID; | ||
} | ||
|
||
public static ProjectOperationException forDeletion(final Map<String, String> errorByUUID) { | ||
return new ProjectOperationException("One or more projects could not be deleted", errorByUUID); | ||
} | ||
|
||
public Map<String, String> getErrorByUUID() { | ||
return errorByUUID; | ||
} | ||
|
||
} |
390 changes: 269 additions & 121 deletions
390
src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...main/java/org/dependencytrack/resources/v1/exception/ProjectOperationExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.resources.v1.exception; | ||
|
||
import org.dependencytrack.exception.ProjectOperationException; | ||
import org.dependencytrack.resources.v1.problems.ProjectOperationProblemDetails; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
public class ProjectOperationExceptionMapper implements ExceptionMapper<ProjectOperationException> { | ||
|
||
@Override | ||
public Response toResponse(final ProjectOperationException exception) { | ||
final var problemDetails = new ProjectOperationProblemDetails(); | ||
problemDetails.setStatus(400); | ||
problemDetails.setTitle("Project operation failed"); | ||
problemDetails.setDetail(exception.getMessage()); | ||
problemDetails.setErrors(exception.getErrorByUUID()); | ||
return problemDetails.toResponse(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/dependencytrack/resources/v1/problems/ProjectOperationProblemDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.resources.v1.problems; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import java.util.Map; | ||
|
||
public class ProjectOperationProblemDetails extends ProblemDetails { | ||
|
||
@Schema(description = "Errors encountered during the operation, grouped by project UUID") | ||
private Map<String, String> errors; | ||
|
||
public Map<String, String> getErrors() { | ||
return errors; | ||
} | ||
|
||
public void setErrors(final Map<String, String> errors) { | ||
this.errors = errors; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters