You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by oc...@apache.org on 2008/03/14 02:59:51 UTC

svn commit: r636953 - in /maven/archiva/trunk/archiva-web/archiva-webapp/src/main: java/org/apache/maven/archiva/web/action/ resources/ resources/org/apache/maven/archiva/web/action/ webapp/WEB-INF/jsp/

Author: oching
Date: Thu Mar 13 18:59:49 2008
New Revision: 636953

URL: http://svn.apache.org/viewvc?rev=636953&view=rev
Log:
[MRM-216]
-added form validation and other validation in the action class

Added:
    maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml
Modified:
    maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
    maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml
    maven/archiva/trunk/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp

Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java?rev=636953&r1=636952&r2=636953&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java Thu Mar 13 18:59:49 2008
@@ -55,13 +55,11 @@
 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 <a href="mailto:wsmoak@apache.org">Wendy Smoak</a>
  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- * 
  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="uploadAction"
  */
 public class UploadAction
@@ -117,7 +115,7 @@
      * 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 @@
             new ArrayList<String>( configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() );
     }
 
-    public String upload()
+    public String input()
     {
-        // TODO form validation
         return INPUT;
     }
 
@@ -311,7 +308,10 @@
             }
 
             updateMetadata( getMetadata( targetPath.getAbsolutePath() ) );
-           
+
+            addActionMessage( "Artifact \'" + groupId + ":" + artifactId + ":" + version +
+                "\' was successfully deployed to repository \'" + repositoryId + "\'!" );
+
             return SUCCESS;
         }
         catch ( RepositoryNotFoundException re )
@@ -395,19 +395,20 @@
             {
                 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 @@
             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 @@
                 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 )
         {

Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml?rev=636953&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml Thu Mar 13 18:59:49 2008
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+    "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+  <field name="groupId">
+    <field-validator type="requiredstring">
+      <message>You must enter a groupId.</message>
+    </field-validator>
+  </field>
+  <field name="artifactId">
+    <field-validator type="requiredstring">
+      <message>You must enter an artifactId.</message>
+    </field-validator>
+  </field>
+  <field name="version">
+    <field-validator type="requiredstring">
+      <message>You must enter a version.</message>
+    </field-validator>
+  </field>   
+  <field name="packaging">
+    <field-validator type="requiredstring">
+      <message>You must enter a packaging.</message>
+    </field-validator>
+  </field>   
+</validators>
\ No newline at end of file

Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml?rev=636953&r1=636952&r2=636953&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml Thu Mar 13 18:59:49 2008
@@ -154,9 +154,10 @@
       <result name="input">/WEB-INF/jsp/findArtifact.jsp</result>
     </action>
 
-	<action name="upload" class="uploadAction" method="upload">      
+	<action name="upload" class="uploadAction" method="input">      
       <result name="input">/WEB-INF/jsp/upload.jsp</result>
-      <result name="success">/WEB-INF/jsp/upload.jsp</result>
+      <result name="error">/WEB-INF/jsp/upload.jsp</result>
+      <result name="success" type="redirect-action">upload</result>
       <interceptor-ref name="configuredPrepareParamsStack"/>
       <interceptor-ref name="fileUpload"/>
     </action>

Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp?rev=636953&r1=636952&r2=636953&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp Thu Mar 13 18:59:49 2008
@@ -32,7 +32,11 @@
 <h1>Upload Artifact</h1>
 
 <div id="contentArea">
-  <ww:form action="upload!doUpload" method="post" enctype="multipart/form-data" validate="false">    
+
+  <ww:actionerror/>
+  <ww:actionmessage/>
+
+  <ww:form action="upload!doUpload" method="post" enctype="multipart/form-data" validate="true">    
     <%@ include file="/WEB-INF/jsp/include/uploadForm.jspf" %>
     <ww:submit/>
   </ww:form>