]> source.dussan.org Git - archiva.git/commitdiff
fix concurrent access when uploading files in parallel
authorOlivier Lamy <olamy@apache.org>
Mon, 2 Apr 2012 07:20:23 +0000 (07:20 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 2 Apr 2012 07:20:23 +0000 (07:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1308258 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties
archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js

index cf8e23b87e80c80645a5f3bbddc80c5900a901d0..327512da742468c7c035f3fc516f34ec5ef2985e 100644 (file)
@@ -398,5 +398,7 @@ fileupload.packaging=Packaging
 fileupload.generatePom=Generate Maven POM
 fileupload.repositoryId=Repository Id
 fileupload.save=Save Files
+fileupload.upload.required=You must upload your files first.
+fileupload.artifacts.saved=Artifacts uploaded and saved on Server side.
 
 
index 411eef67d7a9b23e1ae2ed971d396eda58731ebd..f9ca3d0d185825cc47df58fc5b81dbc22ec2293f 100644 (file)
@@ -81,6 +81,7 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.TimeZone;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * @author Olivier Lamy
@@ -123,13 +124,6 @@ public class DefaultFileUploadService
 
         try
         {
-            String groupId = getStringValue( multipartBody, "groupId" );
-
-            String artifactId = getStringValue( multipartBody, "artifactId" );
-
-            String version = getStringValue( multipartBody, "version" );
-
-            String packaging = getStringValue( multipartBody, "packaging" );
 
             String classifier = getStringValue( multipartBody, "classifier" );
             boolean pomFile = BooleanUtils.toBoolean( getStringValue( multipartBody, "pomFile" ) );
@@ -148,17 +142,12 @@ public class DefaultFileUploadService
             fileMetadata.setDeleteUrl( tmpFile.getName() );
             fileMetadata.setPomFile( pomFile );
 
-            log.info( "uploading file:{}", fileMetadata );
+            log.info( "uploading file: {}", fileMetadata );
 
-            List<FileMetadata> fileMetadatas =
-                (List<FileMetadata>) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY );
+            List<FileMetadata> fileMetadatas = getSessionFilesList();
 
-            if ( fileMetadatas == null )
-            {
-                fileMetadatas = new ArrayList<FileMetadata>( 1 );
-            }
             fileMetadatas.add( fileMetadata );
-            httpServletRequest.getSession().setAttribute( FILES_SESSION_KEY, fileMetadatas );
+
             return fileMetadata;
         }
         catch ( IOException e )
@@ -169,6 +158,23 @@ public class DefaultFileUploadService
 
     }
 
+    /**
+     * FIXME must be per session synchronized not globally
+     *
+     * @return
+     */
+    protected synchronized List<FileMetadata> getSessionFilesList()
+    {
+        List<FileMetadata> fileMetadatas =
+            (List<FileMetadata>) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY );
+        if ( fileMetadatas == null )
+        {
+            fileMetadatas = new CopyOnWriteArrayList<FileMetadata>();
+            httpServletRequest.getSession().setAttribute( FILES_SESSION_KEY, fileMetadatas );
+        }
+        return fileMetadatas;
+    }
+
     public Boolean deleteFile( String fileName )
         throws ArchivaRestServiceException
     {
@@ -206,8 +212,7 @@ public class DefaultFileUploadService
                          String packaging, final boolean generatePom )
         throws ArchivaRestServiceException
     {
-        List<FileMetadata> fileMetadatas =
-            (List<FileMetadata>) httpServletRequest.getSession().getAttribute( FILES_SESSION_KEY );
+        List<FileMetadata> fileMetadatas = getSessionFilesList();
         if ( fileMetadatas == null || fileMetadatas.isEmpty() )
         {
             return Boolean.FALSE;
@@ -230,6 +235,7 @@ public class DefaultFileUploadService
             saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version,
                       packaging );
             pomGenerated = true;
+            deleteFile( fileMetadata.getServerFileName() );
         }
 
         filesToAdd = Iterables.filter( fileMetadatas, new Predicate<FileMetadata>()
@@ -246,6 +252,7 @@ public class DefaultFileUploadService
             FileMetadata fileMetadata = iterator.next();
             log.debug( "fileToAdd: {}", fileMetadata );
             savePomFile( repositoryId, fileMetadata, groupId, artifactId, version, packaging );
+            deleteFile( fileMetadata.getServerFileName() );
         }
 
         return Boolean.TRUE;
index 53e5880aeee1ad4f5a76426baebe47db502470ee..a7abf0fe7d0dc4de30939be4363559c761f5cff6 100644 (file)
@@ -55,7 +55,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
           type: "GET",
           dataType: 'json',
           success: function(data) {
-
+            displaySuccessMessage($.i18n.prop("fileupload.artifacts.saved"));
           },
           error: function(data) {
             var res = $.parseJSON(data.responseText);