From f40410bae72aae4a7eabb9e5e225048f2179438b Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Fri, 14 Mar 2008 01:59:49 +0000 Subject: [PATCH] [MRM-216] -added form validation and other validation in the action class git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@636953 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/web/action/UploadAction.java | 46 +++++++++---------- .../web/action/UploadAction-validation.xml | 45 ++++++++++++++++++ .../src/main/resources/xwork.xml | 5 +- .../src/main/webapp/WEB-INF/jsp/upload.jsp | 6 ++- 4 files changed, 75 insertions(+), 27 deletions(-) create mode 100644 archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index f5afc57aa..045a3203f 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -55,13 +55,11 @@ import java.util.Collections; import java.util.List; /** - * Upload an artifact using Jakarta file upload in webwork. If set by the user - * a pom will also be generated. Metadata will also be updated if one exists, - * otherwise it would be created. + * Upload an artifact using Jakarta file upload in webwork. If set by the user a pom will also be generated. Metadata + * will also be updated if one exists, otherwise it would be created. * * @author Wendy Smoak * @author Maria Odea Ching - * * @plexus.component role="com.opensymphony.xwork.Action" role-hint="uploadAction" */ public class UploadAction @@ -117,7 +115,7 @@ public class UploadAction * Flag whether to generate a pom for the artifact or not. */ private boolean generatePom; - + /** * List of managed repositories to deploy to. */ @@ -249,9 +247,8 @@ public class UploadAction new ArrayList( configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() ); } - public String upload() + public String input() { - // TODO form validation return INPUT; } @@ -311,7 +308,10 @@ public class UploadAction } updateMetadata( getMetadata( targetPath.getAbsolutePath() ) ); - + + addActionMessage( "Artifact \'" + groupId + ":" + artifactId + ":" + version + + "\' was successfully deployed to repository \'" + repositoryId + "\'!" ); + return SUCCESS; } catch ( RepositoryNotFoundException re ) @@ -395,19 +395,20 @@ public class UploadAction { availableVersions.add( version ); } - + String latestVersion = availableVersions.get( availableVersions.size() - 1 ); metadata.setLatestVersion( latestVersion ); metadata.setAvailableVersions( availableVersions ); metadata.setLastUpdatedTimestamp( Calendar.getInstance().getTime() ); - - if( !VersionUtil.isSnapshot( version ) ) + + if ( !VersionUtil.isSnapshot( version ) ) { metadata.setReleasedVersion( latestVersion ); - } + } // TODO: - // what about the metadata checksums? re-calculate or - // just leave it to the consumers to fix it? + // what about the metadata checksums? re-calculate or + // just leave it to the consumers to fix it? or just delete it + // and let the consumers create a new checksum file? } else { @@ -418,16 +419,16 @@ public class UploadAction metadata.setLatestVersion( version ); metadata.setLastUpdatedTimestamp( Calendar.getInstance().getTime() ); metadata.setAvailableVersions( availableVersions ); - - if( !VersionUtil.isSnapshot( version ) ) + + if ( !VersionUtil.isSnapshot( version ) ) { metadata.setReleasedVersion( version ); } - } - + } + RepositoryMetadataWriter.write( metadata, metadataFile ); } - + public void validate() { try @@ -438,18 +439,15 @@ public class UploadAction addActionError( "User is not authorized to upload in repository " + repositoryId ); } - // TODO fix validation - /* if ( file == null || file.length() == 0 ) { addActionError( "Please add a file to upload." ); } - + if ( !VersionUtil.isVersion( version ) ) { addActionError( "Invalid version." ); - } - */ + } } catch ( PrincipalNotFoundException pe ) { diff --git a/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml new file mode 100644 index 000000000..b56cf3757 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml @@ -0,0 +1,45 @@ + + + + + + + + + You must enter a groupId. + + + + + You must enter an artifactId. + + + + + You must enter a version. + + + + + You must enter a packaging. + + + \ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 18226da13..24933e253 100644 --- a/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -154,9 +154,10 @@ /WEB-INF/jsp/findArtifact.jsp - + /WEB-INF/jsp/upload.jsp - /WEB-INF/jsp/upload.jsp + /WEB-INF/jsp/upload.jsp + upload diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp index 9089991dc..c22bccc97 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp @@ -32,7 +32,11 @@

Upload Artifact

- + + + + + <%@ include file="/WEB-INF/jsp/include/uploadForm.jspf" %> -- 2.39.5