]> source.dussan.org Git - archiva.git/commitdiff
[MRM-216]
authorMaria Odea B. Ching <oching@apache.org>
Fri, 14 Mar 2008 01:59:49 +0000 (01:59 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Fri, 14 Mar 2008 01:59:49 +0000 (01:59 +0000)
-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/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/UploadAction-validation.xml [new file with mode: 0644]
archiva-web/archiva-webapp/src/main/resources/xwork.xml
archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/upload.jsp

index f5afc57aac9165c1434f37242f609fd810a94dd0..045a3203fd95078599da0158e066ce46f5a2cf81 100644 (file)
@@ -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 <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 @@ 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<String>( 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 (file)
index 0000000..b56cf37
--- /dev/null
@@ -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
index 18226da13e553f345ce722300b0af6f1d8f8c66a..24933e253f6822a3af47c0b45a0574f8e73d9999 100644 (file)
       <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>
index 9089991dcf716d5c2d3eba1fde55f15b5cd92c66..c22bccc9733f45594b1c306ea846d38289510d9f 100644 (file)
 <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>