Deploydb should gracefully handle error when create artifact is called twice

for the same artifact
  - Fixes #153
This commit is contained in:
Giri Dandu 2015-04-10 15:05:05 -04:00
parent 6cf305a1ad
commit 6878fcb6a5
3 changed files with 25 additions and 0 deletions

View File

@ -199,3 +199,18 @@ Feature: Artifact CREATE APIs
}
"""
Then the response should be 404
@error
Scenario: Creating an existing artifact should fail
Given there is an artifact
When I POST to "/api/artifacts" with:
"""
{
"group" : "com.example.cucumber",
"name" : "cucumber-artifact",
"version" : "1.0.1",
"sourceUrl" : "http://example.com/maven/com.example.cucumber/cucumber-artifact/1.0.1/cucumber-artifact-1.0.1.jar"
}
"""
Then the response should be 409

View File

@ -357,6 +357,11 @@ class WorkFlow {
*/
void triggerArtifactCreated(models.Artifact artifact) {
/* if artifacts already exists, send 409 back */
if (artifactDAO.artifactExists(artifact.group, artifact.name, artifact.version)) {
throw new WebApplicationException(Response.Status.CONFLICT)
}
/* Lookup Service(s) */
List<models.Service> services = this.serviceRegistry.getAll().findAll() { models.Service service ->
service.artifacts.find() { String artifactIdent ->

View File

@ -69,4 +69,9 @@ class ArtifactDAO extends AbstractDAO<Artifact> {
return artifacts
}
boolean artifactExists(String group, String name, String version) {
return criteria().add(Restrictions.eq('group', group))
.add(Restrictions.eq('name', name))
.add(Restrictions.eq('version', version)).uniqueResult() == null ? false: true
}
}