continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r654966 - in /continuum/trunk: ./ continuum-api/src/main/java/org/apache/maven/continuum/installation/ continuum-api/src/main/java/org/apache/maven/continuum/profile/ continuum-core/src/main/java/org/apache/maven/continuum/installation/ con...
Date Fri, 09 May 2008 22:37:51 GMT
Author: olamy
Date: Fri May  9 15:37:50 2008
New Revision: 654966

URL: http://svn.apache.org/viewvc?rev=654966&view=rev
Log:
[CONTINUUM-1746] Duplicate Profile names are accepted


Added:
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
  (with props)
Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java
    continuum/trunk/continuum-webapp/pom.xml
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
    continuum/trunk/pom.xml

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
Fri May  9 15:37:50 2008
@@ -24,6 +24,7 @@
 import org.apache.maven.continuum.execution.ExecutorConfigurator;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
 
 /**
  * @author <a href="mailto:olamy@codehaus.org">olamy</a>
@@ -45,7 +46,7 @@
     String ENVVAR_TYPE = "envvar";
 
     public Installation add( Installation installation, boolean automaticProfile )
-        throws InstallationException;
+        throws InstallationException, AlreadyExistsProfileException;
     
     public Installation add( Installation installation )
         throws InstallationException;

Added: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java?rev=654966&view=auto
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
(added)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
Fri May  9 15:37:50 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.maven.continuum.profile;
+
+import org.apache.maven.continuum.ContinuumException;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 9 mai 2008
+ * @version $Id$
+ * @since 1.2
+ */
+public class AlreadyExistsProfileException
+    extends ContinuumException
+{
+
+    /**
+     * @param message
+     */
+    public AlreadyExistsProfileException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public AlreadyExistsProfileException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}

Propchange: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/AlreadyExistsProfileException.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri May  9 15:37:50 2008
@@ -0,0 +1 @@
+URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java
Fri May  9 15:37:50 2008
@@ -39,8 +39,13 @@
     public void deleteProfile( int profileId )
         throws ProfileException;
 
+    /**
+     * @param profile
+     * @throws ProfileException
+     * @throws AlreadyExistsProfileException if a profile with the same name already exists
+     */
     public void updateProfile( Profile profile )
-        throws ProfileException;
+        throws ProfileException, AlreadyExistsProfileException;
 
     /**
      * <b>Add an empty profile without builder, jdk and envVars</b>
@@ -48,9 +53,10 @@
      * @param profile
      * @return
      * @throws ProfileException
+     * @throws AlreadyExistsProfileException if a profile with the same name already exists
      */
     public Profile addProfile( Profile profile )
-        throws ProfileException;
+        throws ProfileException, AlreadyExistsProfileException;
 
     public List<Profile> getAllProfiles()
         throws ProfileException;

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
Fri May  9 15:37:50 2008
@@ -22,6 +22,7 @@
 import org.apache.maven.continuum.execution.ExecutorConfigurator;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
 import org.apache.maven.continuum.profile.ProfileException;
 import org.apache.maven.continuum.profile.ProfileService;
 import org.apache.maven.continuum.store.ContinuumStore;
@@ -94,12 +95,19 @@
     public Installation add( Installation installation )
         throws InstallationException
     {
-        return this.add( installation, false );
-
+        try
+        {
+            return this.add( installation, false );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // normally cannot happend here but anyway we throw the exception
+            throw new InstallationException( e.getMessage(), e );
+        }
     }
 
     public Installation add( Installation installation, boolean automaticProfile )
-        throws InstallationException
+        throws InstallationException, AlreadyExistsProfileException
     {
 
         // TODO must be done in the same transaction

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java
Fri May  9 15:37:50 2008
@@ -19,13 +19,14 @@
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.continuum.installation.InstallationException;
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
 import org.apache.maven.continuum.store.ContinuumStore;
 import org.apache.maven.continuum.store.ContinuumStoreException;
-import org.codehaus.plexus.util.StringUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -50,8 +51,16 @@
      * @see org.apache.maven.continuum.profile.ProfileService#updateProfile(org.apache.maven.continuum.model.system.Profile)
      */
     public void updateProfile( Profile profile )
-        throws ProfileException
+        throws ProfileException, AlreadyExistsProfileException
     {
+        
+        // already exists check should be done in the same transaction
+        // but we assume we don't have a huge load and a lot of concurrent access ;-)
+        if ( alreadyExistsProfileName( profile ) )
+        {
+            throw new AlreadyExistsProfileException( "profile with name " + profile.getName()
+ " already exists" );
+        }        
+        
         try
         {
             Profile stored = getProfile( profile.getId() );
@@ -69,20 +78,55 @@
             throw new ProfileException( e.getMessage(), e );
         }
     }
+    
+    public void updateProfileCheckDuplicateName( Profile profile, boolean checkDuplicateName
)
+        throws ProfileException, AlreadyExistsProfileException
+    {
+        if ( checkDuplicateName )
+        {
+            // already exists check should be done in the same transaction
+            // but we assume we don't have a huge load and a lot of concurrent access ;-)
+            if ( alreadyExistsProfileName( profile ) )
+            {
+                throw new AlreadyExistsProfileException( "profile with name " + profile.getName()
+ " already exists" );
+            }
+        }
+        try
+        {
+            Profile stored = getProfile( profile.getId() );
+            stored.setActive( profile.isActive() );
+            stored.setBuilder( profile.getBuilder() );
+            stored.setBuildWithoutChanges( profile.isBuildWithoutChanges() );
+            stored.setDescription( profile.getDescription() );
+            stored.setJdk( profile.getJdk() );
+            stored.setName( profile.getName() );
+            stored.setEnvironmentVariables( profile.getEnvironmentVariables() );
+            store.updateProfile( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }    
 
     /**
      * @see org.apache.maven.continuum.profile.ProfileService#addProfile(org.apache.maven.continuum.model.system.Profile)
      */
     public Profile addProfile( Profile profile )
-        throws ProfileException
+        throws ProfileException, AlreadyExistsProfileException
     {
-        // TODO check if one with the same name already here
+        // already exists check should be done in the same transaction
+        // but we assume we don't have a huge load and a lot of concurrent access ;-)
+        if ( alreadyExistsProfileName( profile ) )
+        {
+            throw new AlreadyExistsProfileException( "profile with name " + profile.getName()
+ " already exists" );
+        }
         profile.setBuilder( null );
         profile.setJdk( null );
         profile.setEnvironmentVariables( null );
         return store.addProfile( profile );
     }
-
+    
     /**
      * @see org.apache.maven.continuum.profile.ProfileService#deleteProfile(int)
      */
@@ -224,8 +268,35 @@
             }
             stored.setEnvironmentVariables( newEnvVars );
         }
-        updateProfile( stored );
-        
+        try
+        {
+            updateProfileCheckDuplicateName( stored, false );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // normally cannot happend here but anyway we throw the exception
+            throw new ProfileException( e.getMessage(), e );
+        }        
     }
 
+
+    /**
+     * @param profile
+     * @return true if profile with same name (<b>case sensitive) exists
+     * @throws ProfileException
+     */
+    private boolean alreadyExistsProfileName( Profile profile )
+        throws ProfileException
+    {
+        List<Profile> allProfiles = getAllProfiles();
+        for ( Profile prof : allProfiles )
+        {
+            if ( StringUtils.equals( prof.getName(), profile.getName() ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }    
+    
 }

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java
Fri May  9 15:37:50 2008
@@ -4,6 +4,8 @@
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.List;
 
@@ -34,6 +36,7 @@
 public class DefaultProfileServiceTest
     extends AbstractContinuumTest
 {
+    
     Installation jdk1;
 
     String jdk1Name = "jdk1";
@@ -140,11 +143,39 @@
         throws Exception
     {
         Profile defaultProfile = new Profile();
-        defaultProfile.setName( "default profile" );
+        String name = "default profile";
+        defaultProfile.setName( name );
         Profile getted = getProfileService().addProfile( defaultProfile );
         assertNotNull( getProfileService().getProfile( getted.getId() ) );
+        assertEquals( name, getProfileService().getProfile( getted.getId() ).getName() );
+        assertEquals( 3, getProfileService().getAllProfiles().size() );
     }
 
+    public void testAddDuplicateProfile()
+        throws Exception
+    {
+        Profile defaultProfile = new Profile();
+        String name = "default profile";
+        defaultProfile.setName( name );
+        Profile getted = getProfileService().addProfile( defaultProfile );
+        assertNotNull( getProfileService().getProfile( getted.getId() ) );
+        assertEquals( name, getProfileService().getProfile( getted.getId() ).getName() );
+        assertEquals( 3, getProfileService().getAllProfiles().size() );
+
+        defaultProfile = new Profile();
+        defaultProfile.setName( name );
+        try
+        {
+            getted = getProfileService().addProfile( defaultProfile );
+            fail( "no AlreadyExistsProfileException with an already exist name " );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // we must be here
+        }
+        assertEquals( 3, getProfileService().getAllProfiles().size() );
+    }    
+    
     public void testDeleteProfile()
         throws Exception
     {
@@ -166,7 +197,7 @@
         assertEquals( 2, all.size() );
     }
 
-    public void updateProfile()
+    public void testupdateProfile()
         throws Exception
     {
         Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
@@ -179,6 +210,27 @@
         assertNotNull( getted );
         assertEquals( newName, getted.getName() );
     }
+    
+    public void testupdateProfileDuplicateName()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertEquals( jdk1mvn205Name, profile.getName() );
+        profile.setName( jdk2mvn206Name );
+
+        try
+        {
+            getProfileService().updateProfile( profile );
+            fail( "no AlreadyExistsProfileException with duplicate name" );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // we must be here
+        }
+        Profile getted = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNotNull( getted );
+        assertEquals( jdk1mvn205Name, getted.getName() );
+    }    
 
     public void testsetJdkInProfile()
         throws Exception

Modified: continuum/trunk/continuum-webapp/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/pom.xml?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/pom.xml (original)
+++ continuum/trunk/continuum-webapp/pom.xml Fri May  9 15:37:50 2008
@@ -186,7 +186,7 @@
       <plugin>
         <groupId>org.mortbay.jetty</groupId>
         <artifactId>maven-jetty-plugin</artifactId>
-        <version>6.1.0</version>
+        <version>6.1.9</version>
         <configuration>
           <scanIntervalSeconds>10</scanIntervalSeconds>
           <contextPath>/</contextPath>

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java
Fri May  9 15:37:50 2008
@@ -22,10 +22,12 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.ResourceBundle;
 
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
 import org.apache.maven.continuum.profile.ProfileService;
 import org.apache.maven.continuum.security.ContinuumRoleConstants;
 import org.apache.maven.continuum.web.action.ContinuumActionSupport;
@@ -117,22 +119,30 @@
     public String save()
         throws Exception
     {
-        Profile stored = profileService.getProfile( profile.getId() );
-        if ( stored == null )
+        try
         {
-            this.profile = profileService.addProfile( profile );
-            this.allInstallations = installationService.getAllInstallations();
-            return "editProfile";
+            Profile stored = profileService.getProfile( profile.getId() );
+            if ( stored == null )
+            {
+                this.profile = profileService.addProfile( profile );
+                this.allInstallations = installationService.getAllInstallations();
+                return "editProfile";
+            }
+            else
+            {
+                // olamy : the only this to change here is the profile
+                // but in the UI maybe some installations has been we retrieve it
+                // and only set the name related to CONTINUUM-1361
+                String name = profile.getName();
+                profile = profileService.getProfile( profile.getId() );
+                profile.setName( name );
+                profileService.updateProfile( profile );
+            }
         }
-        else
+        catch ( AlreadyExistsProfileException e )
         {
-            // olamy : the only this to change here is the profile
-            // but in the UI maybe some installations has been we retrieve it
-            // and only set the name related to CONTINUUM-1361
-            String name = profile.getName();
-            profile = profileService.getProfile( profile.getId() );
-            profile.setName( name );
-            profileService.updateProfile( profile );
+            this.addActionError( getResourceBundle().getString( "profile.name.already.exists"
) );
+            return INPUT;
         }
         this.profiles = profileService.getAllProfiles();
         return SUCCESS;

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
Fri May  9 15:37:50 2008
@@ -681,6 +681,7 @@
 profile.jdk.path.label = Jdk path
 profile.jdk.path.message = The JDK Path (JAVA_HOME value)
 profile.no.installations = No installations available
+profile.name.already.exists = A Profile with the same name already exists 
 
 # ----------------------------------------------------------------------
 # Page: Installations List

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
Fri May  9 15:37:50 2008
@@ -682,6 +682,7 @@
 profile.jdk.path.label = Chemin du JDK
 profile.jdk.path.message = Le Chemin du JDK (Valeur de JAVA_HOME)
 profile.no.installations = Aucune installation disponible
+profile.name.already.exists = Un Profile avec le meme nom existe deja
 
 # ----------------------------------------------------------------------
 # Page: Installations List

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
Fri May  9 15:37:50 2008
@@ -395,6 +395,7 @@
 profile.no.installations   = No installations available
 profile.page.title         = Continuum - Build do Perfil
 profile.section.title      = Perfil
+profile.name.already.exists = A Profile with the same name already exists
 
 profilesList.page.title    = Perfis de Build 
 profilesList.section.title = Perfis de Build

Modified: continuum/trunk/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/pom.xml?rev=654966&r1=654965&r2=654966&view=diff
==============================================================================
--- continuum/trunk/pom.xml (original)
+++ continuum/trunk/pom.xml Fri May  9 15:37:50 2008
@@ -726,7 +726,7 @@
       <dependency>
         <groupId>hsqldb</groupId>
         <artifactId>hsqldb</artifactId>
-        <version>1.7.3.3</version>
+        <version>1.8.0.7</version>
       </dependency>
       <dependency>
         <groupId>org.codehaus.plexus</groupId>



Mime
View raw message