]> source.dussan.org Git - archiva.git/commitdiff
cleanup logic to upload artifacts groupId,artifactId,version,packaging can be changed...
authorOlivier Lamy <olamy@apache.org>
Mon, 2 Apr 2012 07:17:50 +0000 (07:17 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 2 Apr 2012 07:17:50 +0000 (07:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1308255 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/DefaultFileUploadService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/api/FileUploadService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js

index 07253e372ce40af730244858d0549ae6865a3ca1..56af9bf14b72048224b0a14bf8068ca61ee00013 100644 (file)
@@ -207,7 +207,8 @@ public class DefaultFileUploadService
         return fileMetadatas == null ? Collections.<FileMetadata>emptyList() : fileMetadatas;
     }
 
-    public Boolean save( String repositoryId, final String groupId, final String artifactId, final boolean generatePom )
+    public Boolean save( String repositoryId, final String groupId, final String artifactId, String version,
+                         String packaging, final boolean generatePom )
         throws ArchivaRestServiceException
     {
         List<FileMetadata> fileMetadatas =
@@ -231,7 +232,8 @@ public class DefaultFileUploadService
         {
             FileMetadata fileMetadata = iterator.next();
             log.debug( "fileToAdd: {}", fileMetadata );
-            saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated );
+            saveFile( repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version,
+                      packaging );
             pomGenerated = true;
         }
 
@@ -248,13 +250,14 @@ public class DefaultFileUploadService
         {
             FileMetadata fileMetadata = iterator.next();
             log.debug( "fileToAdd: {}", fileMetadata );
-            savePomFile( repositoryId, fileMetadata );
+            savePomFile( repositoryId, fileMetadata, groupId, artifactId, version, packaging );
         }
 
         return Boolean.TRUE;
     }
 
-    protected void savePomFile( String repositoryId, FileMetadata fileMetadata )
+    protected void savePomFile( String repositoryId, FileMetadata fileMetadata, String groupId, String artifactId,
+                                String version, String packaging )
         throws ArchivaRestServiceException
     {
 
@@ -266,11 +269,11 @@ public class DefaultFileUploadService
             ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId );
 
             ArtifactReference artifactReference = new ArtifactReference();
-            artifactReference.setArtifactId( fileMetadata.getArtifactId() );
-            artifactReference.setGroupId( fileMetadata.getGroupId() );
-            artifactReference.setVersion( fileMetadata.getVersion() );
+            artifactReference.setArtifactId( artifactId );
+            artifactReference.setGroupId( groupId );
+            artifactReference.setVersion( version );
             artifactReference.setClassifier( fileMetadata.getClassifier() );
-            artifactReference.setType( fileMetadata.getPackaging() );
+            artifactReference.setType( packaging );
 
             ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
 
@@ -309,7 +312,8 @@ public class DefaultFileUploadService
         }
     }
 
-    protected void saveFile( String repositoryId, FileMetadata fileMetadata, boolean generatePom )
+    protected void saveFile( String repositoryId, FileMetadata fileMetadata, boolean generatePom, String groupId,
+                             String artifactId, String version, String packaging )
         throws ArchivaRestServiceException
     {
         try
@@ -318,11 +322,11 @@ public class DefaultFileUploadService
             ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId );
 
             ArtifactReference artifactReference = new ArtifactReference();
-            artifactReference.setArtifactId( fileMetadata.getArtifactId() );
-            artifactReference.setGroupId( fileMetadata.getGroupId() );
-            artifactReference.setVersion( fileMetadata.getVersion() );
+            artifactReference.setArtifactId( artifactId );
+            artifactReference.setGroupId( groupId );
+            artifactReference.setVersion( version );
             artifactReference.setClassifier( fileMetadata.getClassifier() );
-            artifactReference.setType( fileMetadata.getPackaging() );
+            artifactReference.setType( packaging );
 
             ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
 
@@ -342,7 +346,7 @@ public class DefaultFileUploadService
             File versionMetadataFile = new File( targetPath, MetadataTools.MAVEN_METADATA );
             ArchivaRepositoryMetadata versionMetadata = getMetadata( versionMetadataFile );
 
-            if ( VersionUtil.isSnapshot( fileMetadata.getVersion() ) )
+            if ( VersionUtil.isSnapshot( version ) )
             {
                 TimeZone timezone = TimeZone.getTimeZone( "UTC" );
                 DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
@@ -364,7 +368,7 @@ public class DefaultFileUploadService
             }
 
             String filename = artifactPath.substring( lastIndex + 1 );
-            if ( VersionUtil.isSnapshot( fileMetadata.getVersion() ) )
+            if ( VersionUtil.isSnapshot( version ) )
             {
                 filename = filename.replaceAll( "SNAPSHOT", timestamp + "-" + newBuildNumber );
             }
@@ -375,8 +379,7 @@ public class DefaultFileUploadService
             try
             {
                 File targetFile = new File( targetPath, filename );
-                if ( targetFile.exists() && !VersionUtil.isSnapshot( fileMetadata.getVersion() )
-                    && repoConfig.isBlockRedeployments() )
+                if ( targetFile.exists() && !VersionUtil.isSnapshot( version ) && repoConfig.isBlockRedeployments() )
                 {
                     throw new ArchivaRestServiceException(
                         "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.",
@@ -407,7 +410,8 @@ public class DefaultFileUploadService
 
                 try
                 {
-                    File generatedPomFile = createPom( targetPath, pomFilename, fileMetadata );
+                    File generatedPomFile =
+                        createPom( targetPath, pomFilename, fileMetadata, groupId, artifactId, version, packaging );
                     triggerAuditEvent( repoConfig.getId(), path + "/" + pomFilename, AuditEvent.UPLOAD_FILE );
                     if ( fixChecksums )
                     {
@@ -427,12 +431,13 @@ public class DefaultFileUploadService
             if ( !archivaAdministration.getKnownContentConsumers().contains( "metadata-updater" ) )
             {
                 updateProjectMetadata( targetPath.getAbsolutePath(), lastUpdatedTimestamp, timestamp, newBuildNumber,
-                                       fixChecksums, fileMetadata );
+                                       fixChecksums, fileMetadata, groupId, artifactId, version, packaging );
 
-                if ( VersionUtil.isSnapshot( fileMetadata.getVersion() ) )
+                if ( VersionUtil.isSnapshot( version ) )
                 {
                     updateVersionMetadata( versionMetadata, versionMetadataFile, lastUpdatedTimestamp, timestamp,
-                                           newBuildNumber, fixChecksums, fileMetadata );
+                                           newBuildNumber, fixChecksums, fileMetadata, groupId, artifactId, version,
+                                           packaging );
                 }
             }
         }
@@ -471,15 +476,16 @@ public class DefaultFileUploadService
         return metadata;
     }
 
-    private File createPom( File targetPath, String filename, FileMetadata fileMetadata )
+    private File createPom( File targetPath, String filename, FileMetadata fileMetadata, String groupId,
+                            String artifactId, String version, String packaging )
         throws IOException
     {
         Model projectModel = new Model();
         projectModel.setModelVersion( "4.0.0" );
-        projectModel.setGroupId( fileMetadata.getGroupId() );
-        projectModel.setArtifactId( fileMetadata.getArtifactId() );
-        projectModel.setVersion( fileMetadata.getVersion() );
-        projectModel.setPackaging( fileMetadata.getPackaging() );
+        projectModel.setGroupId( groupId );
+        projectModel.setArtifactId( artifactId );
+        projectModel.setVersion( version );
+        projectModel.setPackaging( packaging );
 
         File pomFile = new File( targetPath, filename );
         MavenXpp3Writer writer = new MavenXpp3Writer();
@@ -547,11 +553,12 @@ public class DefaultFileUploadService
      * Update artifact level metadata. If it does not exist, create the metadata and fix checksums if necessary.
      */
     private void updateProjectMetadata( String targetPath, Date lastUpdatedTimestamp, String timestamp, int buildNumber,
-                                        boolean fixChecksums, FileMetadata fileMetadata )
+                                        boolean fixChecksums, FileMetadata fileMetadata, String groupId,
+                                        String artifactId, String version, String packaging )
         throws RepositoryMetadataException
     {
         List<String> availableVersions = new ArrayList<String>();
-        String latestVersion = fileMetadata.getVersion();
+        String latestVersion = version;
 
         File projectDir = new File( targetPath ).getParentFile();
         File projectMetadataFile = new File( projectDir, MetadataTools.MAVEN_METADATA );
@@ -564,36 +571,36 @@ public class DefaultFileUploadService
 
             Collections.sort( availableVersions, VersionComparator.getInstance() );
 
-            if ( !availableVersions.contains( fileMetadata.getVersion() ) )
+            if ( !availableVersions.contains( version ) )
             {
-                availableVersions.add( fileMetadata.getVersion() );
+                availableVersions.add( version );
             }
 
             latestVersion = availableVersions.get( availableVersions.size() - 1 );
         }
         else
         {
-            availableVersions.add( fileMetadata.getVersion() );
+            availableVersions.add( version );
 
-            projectMetadata.setGroupId( fileMetadata.getGroupId() );
-            projectMetadata.setArtifactId( fileMetadata.getArtifactId() );
+            projectMetadata.setGroupId( groupId );
+            projectMetadata.setArtifactId( artifactId );
         }
 
         if ( projectMetadata.getGroupId() == null )
         {
-            projectMetadata.setGroupId( fileMetadata.getGroupId() );
+            projectMetadata.setGroupId( groupId );
         }
 
         if ( projectMetadata.getArtifactId() == null )
         {
-            projectMetadata.setArtifactId( fileMetadata.getArtifactId() );
+            projectMetadata.setArtifactId( artifactId );
         }
 
         projectMetadata.setLatestVersion( latestVersion );
         projectMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
         projectMetadata.setAvailableVersions( availableVersions );
 
-        if ( !VersionUtil.isSnapshot( fileMetadata.getVersion() ) )
+        if ( !VersionUtil.isSnapshot( version ) )
         {
             projectMetadata.setReleasedVersion( latestVersion );
         }
@@ -612,14 +619,15 @@ public class DefaultFileUploadService
      */
     private void updateVersionMetadata( ArchivaRepositoryMetadata metadata, File metadataFile,
                                         Date lastUpdatedTimestamp, String timestamp, int buildNumber,
-                                        boolean fixChecksums, FileMetadata fileMetadata )
+                                        boolean fixChecksums, FileMetadata fileMetadata, String groupId,
+                                        String artifactId, String version, String packaging )
         throws RepositoryMetadataException
     {
         if ( !metadataFile.exists() )
         {
-            metadata.setGroupId( fileMetadata.getGroupId() );
-            metadata.setArtifactId( fileMetadata.getArtifactId() );
-            metadata.setVersion( fileMetadata.getVersion() );
+            metadata.setGroupId( groupId );
+            metadata.setArtifactId( artifactId );
+            metadata.setVersion( version );
         }
 
         if ( metadata.getSnapshotVersion() == null )
index 61abd8883b1c1f13bc2acf57959bfad8957078a6..a61cb3478a308bf5d30ab1bcd7e042c049427919 100644 (file)
@@ -67,12 +67,13 @@ public interface FileUploadService
     List<FileMetadata> getSessionFileMetadatas()
         throws ArchivaRestServiceException;
 
-    @Path( "save/{repositoryId}/{groupId}/{artifactId}" )
+    @Path( "save/{repositoryId}/{groupId}/{artifactId}/{version}/{packaging}" )
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD )
     Boolean save( @PathParam( "repositoryId" ) String repositoryId, @PathParam( "groupId" ) String groupId,
-                  @PathParam( "artifactId" ) String artifactId, @QueryParam( "generatePom" ) boolean generatePom )
+                  @PathParam( "artifactId" ) String artifactId, @PathParam( "version" ) String version,
+                  @PathParam( "packaging" ) String packaging, @QueryParam( "generatePom" ) boolean generatePom )
         throws ArchivaRestServiceException;
 
 
index 699d3ea7c94338652563f26970cb34fa1e5dfc67..0d6a7893e617cb2f712fab8e5639885415bd6192 100644 (file)
@@ -43,14 +43,6 @@ public class FileMetadata
 
     private String errorKey;
 
-    private String groupId;
-
-    private String artifactId;
-
-    private String version;
-
-    private String packaging;
-
     private String classifier;
 
     private boolean pomFile;
@@ -134,46 +126,6 @@ public class FileMetadata
         this.errorKey = errorKey;
     }
 
-    public String getGroupId()
-    {
-        return groupId;
-    }
-
-    public void setGroupId( String groupId )
-    {
-        this.groupId = groupId;
-    }
-
-    public String getArtifactId()
-    {
-        return artifactId;
-    }
-
-    public void setArtifactId( String artifactId )
-    {
-        this.artifactId = artifactId;
-    }
-
-    public String getVersion()
-    {
-        return version;
-    }
-
-    public void setVersion( String version )
-    {
-        this.version = version;
-    }
-
-    public String getPackaging()
-    {
-        return packaging;
-    }
-
-    public void setPackaging( String packaging )
-    {
-        this.packaging = packaging;
-    }
-
     public String getClassifier()
     {
         return classifier;
@@ -245,10 +197,6 @@ public class FileMetadata
         sb.append( ", deleteUrl='" ).append( deleteUrl ).append( '\'' );
         sb.append( ", deleteType='" ).append( deleteType ).append( '\'' );
         sb.append( ", errorKey='" ).append( errorKey ).append( '\'' );
-        sb.append( ", groupId='" ).append( groupId ).append( '\'' );
-        sb.append( ", artifactId='" ).append( artifactId ).append( '\'' );
-        sb.append( ", version='" ).append( version ).append( '\'' );
-        sb.append( ", packaging='" ).append( packaging ).append( '\'' );
         sb.append( ", classifier='" ).append( classifier ).append( '\'' );
         sb.append( ", pomFile=" ).append( pomFile );
         sb.append( '}' );
index 44f486cd513a30e022c0f061b2e9287b6a6770ac..5ef5b34fdf431a14b42bac3ef21ca296e75ffd93 100644 (file)
@@ -47,6 +47,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
         return;
       }
       var url="restServices/archivaUiServices/fileUploadService/save/"+this.repositoryId()+"/"+this.groupId()+"/"+this.artifactId();
+      url+="/"+this.version()+"/"+this.packaging();
       if (this.generatePom()){
         url+="?generatePom=true";
       }
@@ -89,21 +90,8 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
                   }
                 });
                 $('#fileupload').fileupload({
-                    add: function (e, data) {
-                      if(!mainContent.find("#fileupload" ).valid()){
-                        return;
-                      }
-                      data.formData = {
-                        groupId: artifactUploadViewModel.groupId(),
-                        artifactId: artifactUploadViewModel.artifactId(),
-                        version: artifactUploadViewModel.version(),
-                        packaging: artifactUploadViewModel.packaging()
-                      };
-                      $.blueimpUI.fileupload.prototype.options.add.call(this, e, data);
-                    },
                     submit: function (e, data) {
                       var $this = $(this);
-
                       $this.fileupload('send', data);
                       artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile));
                       return false;