From 93ff501274cbdd29bea79beddaec95ba7a31e7ea Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 28 Mar 2012 11:17:55 +0000 Subject: [PATCH] [MRM-1586] rewrite upload artifact page some progress on uploading ui git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1306261 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/archiva/i18n/default.properties | 3 ++ .../api/DefaultFileUploadService.java | 28 +++++++++++-- .../ui/services/api/FileUploadService.java | 19 ++++++++- .../ui/services/model/FileMetadata.java | 2 + .../src/main/webapp/index.html | 2 +- .../archiva/artifacts-management.html | 42 ++++++++++++++++--- 6 files changed, 83 insertions(+), 13 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index 9f7d49b34..f6206524b 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -377,11 +377,14 @@ appearance-configuration.updated=Appearance has been updated appearance-configuration.updating-error=Error during appearance setting #file upload +fileupload.header=Upload Artifact +fileupload.file.choose=Choose File menu.artifacts.upload=Upload Artifact fileupload.cancel=Cancel Upload fileupload.start=Start Upload fileupload.error=Error Upload fileupload.destroy=Delete Upload +fileupload.delete=Delete Upload fileupload.errors.maxFileSize=File is too big fileupload.errors.minFileSize=File is too small fileupload.errors.acceptFileTypes=Filetype not allowed 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 49f0a5350..8e4924ce5 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,6 +21,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.commons.io.IOUtils; +import org.apache.commons.lang.SystemUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -29,6 +30,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; /** @@ -46,14 +49,19 @@ public class DefaultFileUploadService @Context private HttpServletResponse httpServletResponse; - public FileMetadata post() + public FileMetadata post( String groupId, String artifactId, String version, String packaging, String classifier, + String repositoryId, String generatePom ) throws ArchivaRestServiceException { - log.info( "uploading file" ); + log.info( "uploading file:" + groupId + ":" + artifactId + ":" + version ); try { - byte[] bytes = IOUtils.toByteArray( httpServletRequest.getInputStream() ); - return new FileMetadata( "thefile", bytes.length, "theurl" ); + File file = File.createTempFile( "upload-artifact", "tmp" ); + file.deleteOnExit(); + IOUtils.copy( httpServletRequest.getInputStream(), new FileOutputStream( file ) ); + FileMetadata fileMetadata = new FileMetadata( "thefile", file.length(), "theurl" ); + fileMetadata.setDeleteUrl( file.getName() ); + return fileMetadata; } catch ( IOException e ) { @@ -61,4 +69,16 @@ public class DefaultFileUploadService Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() ); } } + + public Boolean deleteFile( String fileName ) + throws ArchivaRestServiceException + { + File file = new File( SystemUtils.getJavaIoTmpDir(), fileName ); + log.debug( "delete file:{},exists:{}", file.getPath(), file.exists() ); + if ( file.exists() ) + { + return file.delete(); + } + return Boolean.FALSE; + } } 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 1c8cc3d0a..3b4612781 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 @@ -23,8 +23,12 @@ import org.apache.archiva.webapp.ui.services.model.FileMetadata; import org.codehaus.plexus.redback.authorization.RedbackAuthorization; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; 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; /** @@ -35,10 +39,21 @@ import javax.ws.rs.core.MediaType; public interface FileUploadService { - @Path( "upload" ) + //@Path( "upload" ) @POST @Consumes( MediaType.MULTIPART_FORM_DATA ) + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( noRestriction = true ) - FileMetadata post() + 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 ) + throws ArchivaRestServiceException; + + @Path( "{fileName}" ) + @DELETE + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( noRestriction = true ) + Boolean deleteFile( @PathParam( "fileName" ) String fileName ) throws ArchivaRestServiceException; } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java index a5ae89191..5dbeb2515 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java @@ -39,6 +39,8 @@ public class FileMetadata private String deleteType; + private String errorKey; + public FileMetadata() { // no op diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html index 08b495b01..0c4f957aa 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html @@ -1,7 +1,7 @@ - + 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 bc0bc816f..7f91fdeaa 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 @@ -1,23 +1,52 @@