From f832e697a022643967cdb4874be35f7da2c6cf72 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 29 Mar 2012 22:52:48 +0000 Subject: [PATCH] use MultipartBody as a parameter for the FileUpload service and parse various parameters git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307153 13f79535-47bb-0310-9956-ffa450edef68 --- .../api/DefaultFileUploadService.java | 41 +++++++++++++++++++ .../ui/services/api/FileUploadService.java | 12 +++--- .../webapp/js/archiva/artifacts-management.js | 9 +++- .../archiva/artifacts-management.html | 2 +- 4 files changed, 56 insertions(+), 8 deletions(-) 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 8e4924ce5..37c6dafeb 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 @@ -21,7 +21,10 @@ package org.apache.archiva.webapp.ui.services.api; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.webapp.ui.services.model.FileMetadata; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.SystemUtils; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -70,6 +73,44 @@ public class DefaultFileUploadService } } + public FileMetadata post( MultipartBody multipartBody ) + throws ArchivaRestServiceException + { + + try + { + String groupId = + IOUtils.toString( multipartBody.getAttachment( "groupId" ).getDataHandler().getInputStream() ); + String artifactId = + IOUtils.toString( multipartBody.getAttachment( "artifactId" ).getDataHandler().getInputStream() ); + String version = + IOUtils.toString( multipartBody.getAttachment( "version" ).getDataHandler().getInputStream() ); + String packaging = + IOUtils.toString( multipartBody.getAttachment( "packaging" ).getDataHandler().getInputStream() ); + + boolean generatePom = BooleanUtils.toBoolean( + IOUtils.toString( multipartBody.getAttachment( "generatePom" ).getDataHandler().getInputStream() ) ); + + String classifier = + IOUtils.toString( multipartBody.getAttachment( "classifier" ).getDataHandler().getInputStream() ); + + log.info( "uploading file:" + groupId + ":" + artifactId + ":" + version ); + Attachment file = multipartBody.getAttachment( "files[]" ); + File tmpFile = File.createTempFile( "upload-artifact", "tmp" ); + tmpFile.deleteOnExit(); + IOUtils.copy( file.getDataHandler().getInputStream(), new FileOutputStream( tmpFile ) ); + FileMetadata fileMetadata = new FileMetadata( "thefile", tmpFile.length(), "theurl" ); + fileMetadata.setDeleteUrl( tmpFile.getName() ); + return fileMetadata; + } + catch ( IOException e ) + { + throw new ArchivaRestServiceException( e.getMessage(), + Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() ); + } + + } + public Boolean deleteFile( String fileName ) 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 3b4612781..b3823998f 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 @@ -20,6 +20,7 @@ package org.apache.archiva.webapp.ui.services.api; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.webapp.ui.services.model.FileMetadata; +import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; import org.codehaus.plexus.redback.authorization.RedbackAuthorization; import javax.ws.rs.Consumes; @@ -28,7 +29,6 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; /** @@ -39,15 +39,15 @@ import javax.ws.rs.core.MediaType; public interface FileUploadService { - //@Path( "upload" ) @POST @Consumes( MediaType.MULTIPART_FORM_DATA ) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( noRestriction = true ) - FileMetadata post( @QueryParam( "g" ) String groupId, @QueryParam( "a" ) String artifactId, - @QueryParam( "v" ) String version, @QueryParam( "p" ) String packaging, - @QueryParam( "c" ) String classifier, @QueryParam( "r" ) String repositoryId, - @QueryParam( "generatePom" ) String generatePom ) + //FileMetadata post( @FormParam( "groupId" ) String groupId, @FormParam( "artifactId" ) String artifactId, + // @FormParam( "version" ) String version, @FormParam( "packaging" ) String packaging, + // @FormParam( "classifier" ) String classifier, @FormParam( "repositoryId" ) String repositoryId, + // @FormParam( "generatePom" ) String generatePom ) + FileMetadata post( MultipartBody multipartBody )// @Multipart( value = "files[]", type = "*/*" ) Attachment file ) throws ArchivaRestServiceException; @Path( "{fileName}" ) 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 d74eb9c71..6e76eeb66 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 @@ -27,7 +27,14 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque dataType: 'json', success: function(data) { mainContent.html($("#file-upload-tmpl" ).tmpl({managedRepositories: data})); - $('#fileupload').fileupload(); + $('#fileupload').fileupload({ + add: function (e, data) { + data.timeStamp = $.now(); + $.blueimpUI.fileupload.prototype + .options.add.call(this, e, data); + } + } + ); } }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html index f79bbecd3..719965d76 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html @@ -94,7 +94,7 @@ {% for (var i=0, file; file=o.files[i]; i++) { %} {%=file.name%} - + {%=o.formatFileSize(file.size)%} {% if (file.error) { %}