continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jzurb...@apache.org
Subject svn commit: r794266 - in /continuum/branches/continuum-1.3.x: continuum-core/src/main/java/org/apache/maven/continuum/builddefinition/ continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/ continuum-webapp/src/main/java/org/apache/ma...
Date Wed, 15 Jul 2009 13:35:45 GMT
Author: jzurbano
Date: Wed Jul 15 13:35:45 2009
New Revision: 794266

URL: http://svn.apache.org/viewvc?rev=794266&view=rev
Log:
[CONTINUUM-1755] - Duplicate build definition template name is allowed

Modified:
    continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionService.java
    continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
    continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.java
    continuum/branches/continuum-1.3.x/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.properties

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionService.java?rev=794266&r1=794265&r2=794266&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionService.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/main/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionService.java
Wed Jul 15 13:35:45 2009
@@ -489,15 +489,20 @@
     {
         try
         {
-            BuildDefinitionTemplate stored = getBuildDefinitionTemplate( buildDefinitionTemplate.getId()
);
-            stored.setName( buildDefinitionTemplate.getName() );
-            stored.setBuildDefinitions( buildDefinitionTemplate.getBuildDefinitions() );
-            return buildDefinitionTemplateDao.updateBuildDefinitionTemplate( stored );
+        	if ( !hasDuplicateTemplateName( buildDefinitionTemplate ) )
+        	{
+	            BuildDefinitionTemplate stored = getBuildDefinitionTemplate( buildDefinitionTemplate.getId()
);
+	            stored.setName( buildDefinitionTemplate.getName() );
+	            stored.setBuildDefinitions( buildDefinitionTemplate.getBuildDefinitions() );
+	            return buildDefinitionTemplateDao.updateBuildDefinitionTemplate( stored );
+        	}
         }
         catch ( ContinuumStoreException e )
         {
             throw new BuildDefinitionServiceException( e.getMessage(), e );
         }
+        
+        return null;
     }
 
     public BuildDefinitionTemplate addBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate
)
@@ -505,12 +510,17 @@
     {
         try
         {
-            return buildDefinitionTemplateDao.addBuildDefinitionTemplate( buildDefinitionTemplate
);
+        	if ( !hasDuplicateTemplateName( buildDefinitionTemplate ) )
+        	{
+        	    return buildDefinitionTemplateDao.addBuildDefinitionTemplate( buildDefinitionTemplate
);
+        	}
         }
         catch ( ContinuumStoreException e )
         {
             throw new BuildDefinitionServiceException( e.getMessage(), e );
         }
+        
+        return null;
     }
 
     public BuildDefinitionTemplate addBuildDefinitionInTemplate( BuildDefinitionTemplate
buildDefinitionTemplate,
@@ -645,4 +655,22 @@
             throw new BuildDefinitionServiceException( e.getMessage(), e );
         }
     }
+    
+    private boolean hasDuplicateTemplateName( BuildDefinitionTemplate buildDefinitionTemplate
)
+        throws BuildDefinitionServiceException
+    {
+        boolean isDuplicate = false;
+        List<BuildDefinitionTemplate> allBuildDefinitionTemplate = this.getAllBuildDefinitionTemplate();
+    
+        for ( BuildDefinitionTemplate template : allBuildDefinitionTemplate )
+        {
+            String name = buildDefinitionTemplate.getName();
+            if ( ( template.getId() != buildDefinitionTemplate.getId() ) && ( template.getName().equals(
name ) ) )
+            {
+                isDuplicate = true;
+                break;
+            }
+        }
+        return isDuplicate;
+    }
 }

Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java?rev=794266&r1=794265&r2=794266&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
Wed Jul 15 13:35:45 2009
@@ -144,12 +144,12 @@
         throws Exception
     {
         BuildDefinitionTemplate template = new BuildDefinitionTemplate();
-        template.setName( "test" );
+        template.setName( "testTemplate" );
 
         template = getBuildDefinitionService().addBuildDefinitionTemplate( template );
         template = getBuildDefinitionService().getBuildDefinitionTemplate( template.getId()
);
         assertNotNull( template );
-        assertEquals( "test", template.getName() );
+        assertEquals( "testTemplate", template.getName() );
         List<BuildDefinition> all = getBuildDefinitionService().getAllBuildDefinitions();
         assertEquals( 5, all.size() );
         BuildDefinition bd =
@@ -168,4 +168,14 @@
         assertEquals( 5, all.size() );
 
     }
+    
+    public void testAddDuplicateBuildDefinitionTemplate()
+	    throws Exception
+	{
+	    BuildDefinitionTemplate template = new BuildDefinitionTemplate();
+	    template.setName( "test" );
+	    
+	    template = getBuildDefinitionService().addBuildDefinitionTemplate( template );
+	    assertNull( template );
+	}
 }

Modified: continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.java?rev=794266&r1=794265&r2=794266&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.java
Wed Jul 15 13:35:45 2009
@@ -138,6 +138,8 @@
     {
         List<BuildDefinition> selectedBuildDefinitions = getBuildDefinitionsFromSelectedBuildDefinitions();
         
+        BuildDefinitionTemplate result;
+        
         AuditLog event = new AuditLog( buildDefinitionTemplate.getName(), AuditLogConstants.ADD_TEMPLATE
);
         event.setCategory( AuditLogConstants.TEMPLATE );
         event.setCurrentUser( getPrincipal() );
@@ -145,15 +147,24 @@
         if ( this.buildDefinitionTemplate.getId() > 0 )
         {
             buildDefinitionTemplate.setBuildDefinitions( selectedBuildDefinitions );
-            this.getContinuum().getBuildDefinitionService().updateBuildDefinitionTemplate(
buildDefinitionTemplate );
+            result = this.getContinuum().getBuildDefinitionService().updateBuildDefinitionTemplate(
buildDefinitionTemplate );
             event.setAction( AuditLogConstants.MODIFY_TEMPLATE );
-            event.log();
         }
         else
         {
             buildDefinitionTemplate.setBuildDefinitions( selectedBuildDefinitions );
             this.buildDefinitionTemplate =
                 this.getContinuum().getBuildDefinitionService().addBuildDefinitionTemplate(
buildDefinitionTemplate );
+            result = this.buildDefinitionTemplate;
+        }
+        
+        if ( result == null )
+        {
+            addActionError( getText( "buildDefintionTemplate.name.exists" ) );
+            return INPUT;
+        }
+        else
+        {
             event.log();
         }
 

Modified: continuum/branches/continuum-1.3.x/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.properties
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.properties?rev=794266&r1=794265&r2=794266&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.properties
(original)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/main/resources/org/apache/maven/continuum/web/action/admin/BuildDefinitionTemplateAction.properties
Wed Jul 15 13:35:45 2009
@@ -16,6 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 #
+buildDefintionTemplate.name.exists = Name already exists
 buildDefintionTemplate.name.required = Name is required
 buildDefintion.buildFile.required = BuildFile is required
-buildDefintion.description.required = Description is required
\ No newline at end of file
+buildDefintion.description.required = Description is required



Mime
View raw message