From: Olivier Lamy Date: Sat, 31 Mar 2012 15:35:32 +0000 (+0000) Subject: take of NPE, add rest method to cleanup uploaded files in session X-Git-Tag: archiva-1.4-M3~891 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=62a08312f9d4085167b052eaa0c043e449d4772c;p=archiva.git take of NPE, add rest method to cleanup uploaded files in session git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307830 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index 7b92f4865..49c9bdbb1 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -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 ); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java index 094b56c92..d485d22b5 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java @@ -187,6 +187,17 @@ public class DefaultFileUploadService return Boolean.FALSE; } + public Boolean clearUploadedFiles() + throws ArchivaRestServiceException + { + List fileMetadatas = getSessionFileMetadatas(); + for ( FileMetadata fileMetadata : fileMetadatas ) + { + deleteFile( fileMetadata.getServerFileName() ); + } + return Boolean.TRUE; + } + public List getSessionFileMetadatas() throws ArchivaRestServiceException { diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java index fce8c26fa..61abd8883 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java @@ -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; + } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js index a268467b4..8e9a96ac6 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js @@ -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