]> source.dussan.org Git - archiva.git/commitdiff
take of NPE, add rest method to cleanup uploaded files in session
authorOlivier Lamy <olamy@apache.org>
Sat, 31 Mar 2012 15:35:32 +0000 (15:35 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 31 Mar 2012 15:35:32 +0000 (15:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307830 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
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/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js

index 7b92f4865f76f8ed3d5dec45a2543a930b87893c..49c9bdbb14c8719c7f9e13cf1f3ef3006fa181f9 100644 (file)
@@ -147,7 +147,7 @@ public abstract class AbstractRestService
 
     protected void triggerAuditEvent( String repositoryId, String filePath, String action )
     {
-        AuditEvent auditEvent = new AuditEvent();
+        AuditEvent auditEvent = new AuditEvent( action, repositoryId );
         auditEvent.setAction( action );
         auditEvent.setRepositoryId( repositoryId );
         auditEvent.setResource( filePath );
index 094b56c92b5cc8ffa6ad02f63adc7324563f9ded..d485d22b5fe32bac3e92dbee33c3b5de27d2bbea 100644 (file)
@@ -187,6 +187,17 @@ public class DefaultFileUploadService
         return Boolean.FALSE;
     }
 
+    public Boolean clearUploadedFiles()
+        throws ArchivaRestServiceException
+    {
+        List<FileMetadata> fileMetadatas = getSessionFileMetadatas();
+        for ( FileMetadata fileMetadata : fileMetadatas )
+        {
+            deleteFile( fileMetadata.getServerFileName() );
+        }
+        return Boolean.TRUE;
+    }
+
     public List<FileMetadata> getSessionFileMetadatas()
         throws ArchivaRestServiceException
     {
index fce8c26fa8149d93e90d5f1c03734458434e866b..61abd8883b1c1f13bc2acf57959bfad8957078a6 100644 (file)
@@ -75,4 +75,12 @@ public interface FileUploadService
                   @PathParam( "artifactId" ) String artifactId, @QueryParam( "generatePom" ) boolean generatePom )
         throws ArchivaRestServiceException;
 
+
+    @Path( "clearUploadedFiles" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD )
+    Boolean clearUploadedFiles()
+        throws ArchivaRestServiceException;
+
 }
index a268467b4599f6b1ccb2568bb1661459233910ba..8e9a96ac644523aad5f7e77cd5e26f8ef5d1f125 100644 (file)
@@ -38,7 +38,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
     this.artifactUploads=[];
 
     saveArtifacts=function(){
-
+      clearUserMessages();
       if(!$("#main-content #fileupload" ).valid()){
         return;
       }
@@ -55,6 +55,10 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
           dataType: 'json',
           success: function(data) {
 
+          },
+          error: function(data) {
+            var res = $.parseJSON(data.responseText);
+            displayRestError(res);
           }
         }
       );
@@ -66,46 +70,53 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
   displayUploadArtifact=function(){
     var mainContent=$("#main-content");
     mainContent.html(mediumSpinnerImg());
-    mainContent.html($("#file-upload-screen" ).html());
-    $.ajax("restServices/archivaServices/browseService/userRepositories", {
+
+
+    $.ajax("restServices/archivaUiServices/fileUploadService/clearUploadedFiles", {
         type: "GET",
         dataType: 'json',
         success: function(data) {
-          var artifactUploadViewModel=new ArtifactUploadViewModel(data);
-          ko.applyBindings(artifactUploadViewModel,mainContent.find("#file-upload-main" ).get(0));
-          var validator =  $("#main-content #fileupload" ).validate({
-            showErrors: function(validator, errorMap, errorList) {
-             customShowError("#main-content #fileupload",validator,errorMap,errorMap);
-            }
-          });
-          $('#fileupload').fileupload({
-              add: function (e, data) {
-                data.formData = {
-                  groupId: artifactUploadViewModel.groupId(),
-                  artifactId: artifactUploadViewModel.artifactId(),
-                  version: artifactUploadViewModel.version(),
-                  packaging: artifactUploadViewModel.packaging()
-                };
-                $.blueimpUI.fileupload.prototype.options.add.call(this, e, data);
-              },
-              submit: function (e, data) {
-                var $this = $(this);
+          mainContent.html($("#file-upload-screen" ).html());
+          $.ajax("restServices/archivaServices/browseService/userRepositories", {
+              type: "GET",
+              dataType: 'json',
+              success: function(data) {
+                var artifactUploadViewModel=new ArtifactUploadViewModel(data);
+                ko.applyBindings(artifactUploadViewModel,mainContent.find("#file-upload-main" ).get(0));
+                var validator =  $("#main-content #fileupload" ).validate({
+                  showErrors: function(validator, errorMap, errorList) {
+                   customShowError("#main-content #fileupload",validator,errorMap,errorMap);
+                  }
+                });
+                $('#fileupload').fileupload({
+                    add: function (e, data) {
+                      data.formData = {
+                        groupId: artifactUploadViewModel.groupId(),
+                        artifactId: artifactUploadViewModel.artifactId(),
+                        version: artifactUploadViewModel.version(),
+                        packaging: artifactUploadViewModel.packaging()
+                      };
+                      $.blueimpUI.fileupload.prototype.options.add.call(this, e, data);
+                    },
+                    submit: function (e, data) {
+                      var $this = $(this);
 
-                $this.fileupload('send', data);
-                artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile));
-                return false;
+                      $this.fileupload('send', data);
+                      artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile));
+                      return false;
+                    }
+                  }
+                );
+                $('#fileupload').bind('fileuploadsubmit', function (e, data) {
+                  var pomFile = data.context.find('#pomFile' ).attr("checked");
+                  var classifier = data.context.find('#classifier' ).val();
+                  data.formData.pomFile = pomFile;
+                  data.formData.classifier = classifier;
+                });
               }
-            }
-          );
-          $('#fileupload').bind('fileuploadsubmit', function (e, data) {
-            var pomFile = data.context.find('#pomFile' ).attr("checked");
-            var classifier = data.context.find('#classifier' ).val();
-            data.formData.pomFile = pomFile;
-            data.formData.classifier = classifier;
           });
-        }
+      }
     });
-
   }
 
 });
\ No newline at end of file