archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1401075 - in /archiva/trunk/archiva-modules/archiva-web: archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/ archiva-webapp-js...
Date Mon, 22 Oct 2012 20:52:14 GMT
Author: olamy
Date: Mon Oct 22 20:52:14 2012
New Revision: 1401075

URL: http://svn.apache.org/viewvc?rev=1401075&view=rev
Log:
fix deletion of project version when it's snapshot version, timestamped was not deleted

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java?rev=1401075&r1=1401074&r2=1401075&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
Mon Oct 22 20:52:14 2012
@@ -123,6 +123,19 @@ public interface RepositoriesService
     Boolean deleteArtifact( Artifact artifact )
         throws ArchivaRestServiceException;
 
+    @Path ("projectVersion/{repositoryId}/{namespace}/{projectId}/{version}")
+    @DELETE
+    @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN
})
+    @RedbackAuthorization (noPermission = true)
+    /**
+     * <b>permissions are checked in impl</b>
+     * @since 1.4-M4
+     */
+    Boolean removeProjectVersion( @PathParam ( "repositoryId" ) String repositoryId,
+                                  @PathParam ( "namespace" ) String namespace, @PathParam
( "projectId" ) String projectId,
+                                  @PathParam ( "version" ) String version )
+        throws ArchivaRestServiceException;
+
     @Path ("isAuthorizedToDeleteArtifacts/{repositoryId}")
     @GET
     @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN
})
@@ -141,16 +154,16 @@ public interface RepositoriesService
     Boolean deleteGroupId( @QueryParam ("groupId") String groupId, @QueryParam ("repositoryId")
String repositoryId )
         throws ArchivaRestServiceException;
 
-    @Path ( "project/{repositoryId}/{groupId}/{projectId}" )
+    @Path ("project/{repositoryId}/{groupId}/{projectId}")
     @DELETE
-    @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN
} )
-    @RedbackAuthorization ( noPermission = true )
+    @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN
})
+    @RedbackAuthorization (noPermission = true)
     /**
      * <b>permissions are checked in impl</b>
      * @since 1.4-M4
      */
-    Boolean deleteProject( @PathParam ( "groupId" ) String groupId, @PathParam ( "projectId"
) String projectId,
-                           @PathParam ( "repositoryId" ) String repositoryId )
+    Boolean deleteProject( @PathParam ("groupId") String groupId, @PathParam ("projectId")
String projectId,
+                           @PathParam ("repositoryId") String repositoryId )
         throws ArchivaRestServiceException;
 
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java?rev=1401075&r1=1401074&r2=1401075&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
Mon Oct 22 20:52:14 2012
@@ -600,6 +600,109 @@ public class DefaultRepositoriesService
         }
     }
 
+    public Boolean removeProjectVersion( String repositoryId, String namespace, String projectId,
String version )
+        throws ArchivaRestServiceException
+    {
+        // if not a generic we can use the standard way to delete artifact
+        if ( !VersionUtil.isGenericSnapshot( version ) )
+        {
+            Artifact artifact = new Artifact( namespace, projectId, version );
+            return deleteArtifact( artifact );
+        }
+
+        if ( StringUtils.isEmpty( repositoryId ) )
+        {
+            throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null
);
+        }
+
+        if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
+        {
+            throw new ArchivaRestServiceException( "not authorized to delete artifacts",
403, null );
+        }
+
+        if ( StringUtils.isEmpty( namespace ) )
+        {
+            throw new ArchivaRestServiceException( "groupId cannot be null", 400, null );
+        }
+
+        if ( StringUtils.isEmpty( projectId ) )
+        {
+            throw new ArchivaRestServiceException( "artifactId cannot be null", 400, null
);
+        }
+
+        if ( StringUtils.isEmpty( version ) )
+        {
+            throw new ArchivaRestServiceException( "version cannot be null", 400, null );
+        }
+
+        RepositorySession repositorySession = repositorySessionFactory.createSession();
+
+        try
+        {
+            ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent(
repositoryId );
+
+            VersionedReference ref = new VersionedReference();
+            ref.setArtifactId( projectId );
+            ref.setGroupId( namespace );
+            ref.setVersion( version );
+
+            repository.deleteVersion( ref );
+
+            /*
+            ProjectReference projectReference = new ProjectReference();
+            projectReference.setGroupId( namespace );
+            projectReference.setArtifactId( projectId );
+
+            repository.getVersions(  )
+            */
+
+            ArtifactReference artifactReference = new ArtifactReference();
+            artifactReference.setGroupId( namespace );
+            artifactReference.setArtifactId( projectId );
+            artifactReference.setVersion( version );
+
+            MetadataRepository metadataRepository = repositorySession.getRepository();
+
+            Set<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference
);
+            log.debug( "related: {}", related );
+            for ( ArtifactReference artifactRef : related )
+            {
+                repository.deleteArtifact( artifactRef );
+            }
+
+            Collection<ArtifactMetadata> artifacts =
+                metadataRepository.getArtifacts( repositoryId, namespace, projectId, version
);
+
+            for ( ArtifactMetadata artifactMetadata : artifacts )
+            {
+                metadataRepository.removeArtifact( artifactMetadata, version );
+            }
+
+            metadataRepository.removeProjectVersion( repositoryId, namespace, projectId,
version );
+        }
+        catch ( MetadataRepositoryException e )
+        {
+            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(),
500, e );
+        }
+        catch ( MetadataResolutionException e )
+        {
+            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(),
500, e );
+        }
+        catch ( RepositoryException e )
+        {
+            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(),
500, e );
+        }
+        finally
+        {
+
+            repositorySession.save();
+
+            repositorySession.close();
+        }
+
+        return Boolean.TRUE;
+    }
+
     public Boolean deleteArtifact( Artifact artifact )
         throws ArchivaRestServiceException
     {
@@ -632,7 +735,8 @@ public class DefaultRepositoriesService
 
         // TODO more control on artifact fields
 
-        boolean snapshotVersion = VersionUtil.isSnapshot( artifact.getVersion() );
+        boolean snapshotVersion =
+            VersionUtil.isSnapshot( artifact.getVersion() ) | VersionUtil.isGenericSnapshot(
artifact.getVersion() );
 
         RepositorySession repositorySession = repositorySessionFactory.createSession();
         try

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js?rev=1401075&r1=1401074&r2=1401075&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
Mon Oct 22 20:52:14 2012
@@ -270,17 +270,17 @@ define("archiva.search",["jquery","i18n"
         });
         return;
       }
-      $.log("deleteVersion:"+version+',repoId:'+repoId);
+
       clearUserMessages();
         var artifact = new Artifact(repoId,null,self.groupId,self.artifactId,repoId,version);
         openDialogConfirm(function(){
+          var url = "restServices/archivaServices/repositoriesService/projectVersion/"+repoId;
+          url+="/"+encodeURIComponent(self.groupId)+"/"+encodeURIComponent(self.artifactId);
+          url+="/"+encodeURIComponent(version);
           $("#dialog-confirm-modal-ok").button('loading');
           $.ajax({
-            url:"restServices/archivaServices/repositoriesService/deleteArtifact",
-            type:"POST",
-            dataType:"json",
-            contentType: 'application/json',
-            data: ko.toJSON(artifact),
+            url:url,
+            type:"DELETE",
             success:function(data){
               self.versions.remove(version);
               refreshContent();



Mime
View raw message