archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r590765 - in /maven/archiva/branches/archiva-backend-security/archiva-database/src: main/java/org/apache/maven/archiva/database/browsing/ test/java/org/apache/maven/archiva/database/browsing/
Date Wed, 31 Oct 2007 17:35:29 GMT
Author: joakime
Date: Wed Oct 31 10:35:28 2007
New Revision: 590765

URL: http://svn.apache.org/viewvc?rev=590765&view=rev
Log:
Updates to repository browsing for selected repositories.


Modified:
    maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/BrowsingResults.java
    maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java
    maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/GroupIdFilter.java
    maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsing.java
    maven/archiva/branches/archiva-backend-security/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java

Modified: maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/BrowsingResults.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/BrowsingResults.java?rev=590765&r1=590764&r2=590765&view=diff
==============================================================================
--- maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/BrowsingResults.java
(original)
+++ maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/BrowsingResults.java
Wed Oct 31 10:35:28 2007
@@ -32,14 +32,16 @@
 public class BrowsingResults
 {
     private String selectedGroupId;
-    
+
     private String selectedArtifactId;
 
-    private List groupIds = null;
+    private List<String> selectedRepositoryIds = null;
+
+    private List<String> groupIds = null;
 
-    private List artifacts = null;
+    private List<String> artifacts = null;
 
-    private List versions = null;
+    private List<String> versions = null;
 
     public BrowsingResults()
     {
@@ -50,19 +52,19 @@
     {
         this.selectedGroupId = groupId;
     }
-    
+
     public BrowsingResults( String groupId, String artifactId )
     {
         this.selectedGroupId = groupId;
         this.selectedArtifactId = artifactId;
     }
 
-    public List getArtifacts()
+    public List<String> getArtifacts()
     {
         return artifacts;
     }
 
-    public List getGroupIds()
+    public List<String> getGroupIds()
     {
         return groupIds;
     }
@@ -77,7 +79,7 @@
         return selectedGroupId;
     }
 
-    public List getVersions()
+    public List<String> getVersions()
     {
         return versions;
     }
@@ -97,18 +99,28 @@
         return CollectionUtils.isNotEmpty( versions );
     }
 
-    public void setArtifacts( List artifacts )
+    public void setArtifacts( List<String> artifacts )
     {
         this.artifacts = artifacts;
     }
 
-    public void setGroupIds( List groupIds )
+    public void setGroupIds( List<String> groupIds )
     {
         this.groupIds = groupIds;
     }
 
-    public void setVersions( List versions )
+    public void setVersions( List<String> versions )
     {
         this.versions = versions;
+    }
+
+    public List<String> getSelectedRepositoryIds()
+    {
+        return selectedRepositoryIds;
+    }
+
+    public void setSelectedRepositoryIds( List<String> selectedRepositoryIds )
+    {
+        this.selectedRepositoryIds = selectedRepositoryIds;
     }
 }

Modified: maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java?rev=590765&r1=590764&r2=590765&view=diff
==============================================================================
--- maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java
(original)
+++ maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java
Wed Oct 31 10:35:28 2007
@@ -22,6 +22,8 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.PredicateUtils;
 import org.apache.commons.collections.functors.NotPredicate;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.VersionUtil;
 import org.apache.maven.archiva.database.ArchivaDAO;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
 import org.apache.maven.archiva.database.ObjectNotFoundException;
@@ -32,14 +34,14 @@
 import org.apache.maven.archiva.database.updater.DatabaseUpdater;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.maven.archiva.model.Keys;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.HashMap;
+import java.util.Map.Entry;
 
 /**
  * DefaultRepositoryBrowsing
@@ -62,23 +64,26 @@
      */
     private DatabaseUpdater dbUpdater;
 
-    public BrowsingResults getRoot()
+    public BrowsingResults getRoot( String principle, List<String> observableRepositoryIds
)
     {
-        List groups = dao.query( new UniqueGroupIdConstraint() );
+        List<String> groups = dao.query( new UniqueGroupIdConstraint( observableRepositoryIds
) );
 
         BrowsingResults results = new BrowsingResults();
+        results.setSelectedRepositoryIds( observableRepositoryIds );
 
         results.setGroupIds( GroupIdFilter.filterGroups( groups ) );
 
         return results;
     }
 
-    public BrowsingResults selectArtifactId( String groupId, String artifactId )
+    public BrowsingResults selectArtifactId( String principle, List<String> observableRepositoryIds,
String groupId,
+                                             String artifactId )
     {
         // NOTE: No group Id or artifact Id's should be returned here. 
-        List versions = dao.query( new UniqueVersionConstraint( groupId, artifactId ) );
+        List<String> versions = dao.query( new UniqueVersionConstraint( observableRepositoryIds,
groupId, artifactId ) );
 
         BrowsingResults results = new BrowsingResults( groupId, artifactId );
+        results.setSelectedRepositoryIds( observableRepositoryIds );
 
         processSnapshots( versions );
 
@@ -87,10 +92,10 @@
         return results;
     }
 
-    public BrowsingResults selectGroupId( String groupId )
+    public BrowsingResults selectGroupId( String principle, List<String> observableRepositoryIds,
String groupId )
     {
-        List groups = dao.query( new UniqueGroupIdConstraint( groupId ) );
-        List artifacts = dao.query( new UniqueArtifactIdConstraint( groupId ) );
+        List<String> groups = dao.query( new UniqueGroupIdConstraint( observableRepositoryIds,
groupId ) );
+        List<String> artifacts = dao.query( new UniqueArtifactIdConstraint( observableRepositoryIds,
groupId ) );
 
         BrowsingResults results = new BrowsingResults( groupId );
 
@@ -104,10 +109,11 @@
         return results;
     }
 
-    public ArchivaProjectModel selectVersion( String groupId, String artifactId, String version
)
+    public ArchivaProjectModel selectVersion( String principle, List<String> observableRepositoryIds,
String groupId,
+                                              String artifactId, String version )
         throws ObjectNotFoundException, ArchivaDatabaseException
     {
-        ArchivaArtifact pomArtifact = getArtifact( groupId, artifactId, version );
+        ArchivaArtifact pomArtifact = getArtifact( principle, observableRepositoryIds, groupId,
artifactId, version );
 
         ArchivaProjectModel model;
         version = pomArtifact.getVersion();
@@ -123,7 +129,8 @@
         return model;
     }
 
-    private ArchivaArtifact getArtifact( String groupId, String artifactId, String version
)
+    private ArchivaArtifact getArtifact( String principle, List<String> observableRepositoryIds,
String groupId,
+                                         String artifactId, String version )
         throws ObjectNotFoundException, ArchivaDatabaseException
     {
         ArchivaArtifact pomArtifact = null;
@@ -139,18 +146,30 @@
 
         if ( pomArtifact == null )
         {
-            throw new ObjectNotFoundException(
-                "Unable to find artifact [" + groupId + ":" + artifactId + ":" + version
+ "]" );
+            throw new ObjectNotFoundException( "Unable to find artifact [" + Keys.toKey(
groupId, artifactId, version )
+                + "]" );
+        }
+
+        // Allowed to see this?
+        if ( observableRepositoryIds.contains( pomArtifact.getModel().getRepositoryId() )
)
+        {
+            return pomArtifact;
+        }
+        else
+        {
+            throw new ObjectNotFoundException( "Unable to find artifact " + Keys.toKey( groupId,
artifactId, version )
+                + " in observable repository [" + StringUtils.join( observableRepositoryIds.iterator(),
", " )
+                + "] for user " + principle );
         }
-        return pomArtifact;
     }
 
-    public List getUsedBy( String groupId, String artifactId, String version )
+    public List<ArchivaProjectModel> getUsedBy( String principle, List<String>
observableRepositoryIds, String groupId,
+                                                String artifactId, String version )
         throws ArchivaDatabaseException
     {
-        ProjectsByArtifactUsageConstraint constraint =
-            new ProjectsByArtifactUsageConstraint( groupId, artifactId, version );
-        List results = dao.getProjectModelDAO().queryProjectModels( constraint );
+        ProjectsByArtifactUsageConstraint constraint = new ProjectsByArtifactUsageConstraint(
groupId, artifactId,
+                                                                                        
     version );
+        List<ArchivaProjectModel> results = dao.getProjectModelDAO().queryProjectModels(
constraint );
         if ( results == null )
         {
             // defensive. to honor contract as specified. never null.
@@ -178,15 +197,14 @@
      *
      * @param versions
      */
-    private void processSnapshots( List versions )
+    private void processSnapshots( List<String> versions )
     {
-        Map snapshots = new HashMap();
+        Map<String, String> snapshots = new HashMap<String, String>();
 
         getLogger().info( "Processing snapshots." );
 
-        for ( Iterator iter = versions.iterator(); iter.hasNext(); )
+        for ( String version : versions )
         {
-            String version = (String) iter.next();
             if ( VersionUtil.isSnapshot( version ) )
             {
                 String baseVersion = VersionUtil.getBaseVersion( version );
@@ -197,9 +215,9 @@
             }
         }
 
-        for ( Iterator it = ( snapshots.entrySet() ).iterator(); it.hasNext(); )
+        for ( Entry<String, String> entry : snapshots.entrySet() )
         {
-            String baseVersion = (String) ( (Map.Entry) it.next() ).getValue();
+            String baseVersion = entry.getValue();
             if ( !versions.contains( baseVersion ) )
             {
                 versions.add( baseVersion );
@@ -227,14 +245,12 @@
     {
         if ( VersionUtil.isGenericSnapshot( version ) )
         {
-            List versions = dao.query( new UniqueVersionConstraint( groupId, artifactId )
);
+            List<String> versions = dao.query( new UniqueVersionConstraint( groupId,
artifactId ) );
             Collections.sort( versions );
             Collections.reverse( versions );
 
-            for ( Iterator iter = versions.iterator(); iter.hasNext(); )
+            for ( String uniqueVersion : versions )
             {
-                String uniqueVersion = (String) iter.next();
-
                 if ( VersionUtil.getBaseVersion( uniqueVersion ).equals( version ) )
                 {
                     getLogger().info( "Retrieving artifact with version " + uniqueVersion
);
@@ -266,8 +282,8 @@
 
             if ( model == null )
             {
-                throw new ObjectNotFoundException(
-                    "Unable to find project model for [" + groupId + ":" + artifactId + ":"
+ version + "]" );
+                throw new ObjectNotFoundException( "Unable to find project model for ["
+                    + Keys.toKey( groupId, artifactId, version ) + "]" );
             }
 
             return model;

Modified: maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/GroupIdFilter.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/GroupIdFilter.java?rev=590765&r1=590764&r2=590765&view=diff
==============================================================================
--- maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/GroupIdFilter.java
(original)
+++ maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/GroupIdFilter.java
Wed Oct 31 10:35:28 2007
@@ -20,7 +20,6 @@
  */
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
@@ -77,21 +76,19 @@
      * @param groups the list of groupIds.
      * @return
      */
-    public static List filterGroups( List groups )
+    public static List<String> filterGroups( List<String> groups )
     {
         GroupTreeNode tree = buildGroupTree( groups );
         return collateGroups( tree );
     }
 
-    public static GroupTreeNode buildGroupTree( List groups )
+    public static GroupTreeNode buildGroupTree( List<String> groups )
     {
         GroupTreeNode rootNode = new GroupTreeNode();
 
         // build a tree structure
-        for ( Iterator i = groups.iterator(); i.hasNext(); )
+        for ( String groupId : groups )
         {
-            String groupId = (String) i.next();
-
             StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR );
 
             GroupTreeNode node = rootNode;
@@ -108,7 +105,7 @@
                 }
                 else
                 {
-                    node = (GroupTreeNode) node.getChildren().get( part );
+                    node = node.getChildren().get( part );
                 }
             }
         }
@@ -116,16 +113,14 @@
         return rootNode;
     }
 
-    private static List collateGroups( GroupTreeNode rootNode )
+    private static List<String> collateGroups( GroupTreeNode rootNode )
     {
-        List groups = new ArrayList();
-        for ( Iterator i = rootNode.getChildren().values().iterator(); i.hasNext(); )
+        List<String> groups = new ArrayList<String>();
+        for ( GroupTreeNode node : rootNode.getChildren().values() )
         {
-            GroupTreeNode node = (GroupTreeNode) i.next();
-
             while ( node.getChildren().size() == 1 )
             {
-                node = (GroupTreeNode) node.getChildren().values().iterator().next();
+                node = node.getChildren().values().iterator().next();
             }
 
             groups.add( node.getFullName() );
@@ -139,7 +134,7 @@
 
         private final String fullName;
 
-        private final Map children = new TreeMap();
+        private final Map<String, GroupTreeNode> children = new TreeMap<String,
GroupTreeNode>();
 
         GroupTreeNode()
         {
@@ -163,7 +158,7 @@
             return fullName;
         }
 
-        public Map getChildren()
+        public Map<String, GroupTreeNode> getChildren()
         {
             return children;
         }

Modified: maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsing.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsing.java?rev=590765&r1=590764&r2=590765&view=diff
==============================================================================
--- maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsing.java
(original)
+++ maven/archiva/branches/archiva-backend-security/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsing.java
Wed Oct 31 10:35:28 2007
@@ -38,7 +38,7 @@
      * 
      * @return the root browsing results.
      */
-    public BrowsingResults getRoot();
+    public BrowsingResults getRoot( String principle, List<String> observableRepositoryIds
);
 
     /**
      * Get the {@link BrowsingResults} for the selected groupId.
@@ -46,7 +46,7 @@
      * @param groupId the groupId to select.
      * @return the {@link BrowsingResults} for the specified groupId.
      */
-    public BrowsingResults selectGroupId( String groupId );
+    public BrowsingResults selectGroupId( String principle, List<String> observableRepositoryIds,
String groupId );
 
     /**
      * Get the {@link BrowsingResults} for the selected groupId & artifactId.
@@ -55,7 +55,8 @@
      * @param artifactId the artifactId selected
      * @return the {@link BrowsingResults} for the specified groupId / artifactId combo.
      */
-    public BrowsingResults selectArtifactId( String groupId, String artifactId );
+    public BrowsingResults selectArtifactId( String principle, List<String> observableRepositoryIds,
String groupId,
+                                             String artifactId );
 
     /**
      * Get the {@link ArchivaProjectModel} for the selected groupId / artifactId / version
combo.
@@ -67,9 +68,10 @@
      * @throws ObjectNotFoundException if the artifact object or project object isn't found
in the database.
      * @throws ArchivaDatabaseException if there is a fundamental database error.
      */
-    public ArchivaProjectModel selectVersion( String groupId, String artifactId, String version
)
+    public ArchivaProjectModel selectVersion( String principle, List<String> observableRepositoryIds,
String groupId,
+                                              String artifactId, String version )
         throws ObjectNotFoundException, ArchivaDatabaseException;
-    
+
     /**
      * Get the {@link List} of {@link ArchivaProjectModel} that are used by the provided
      * groupId, artifactId, and version specified.
@@ -80,6 +82,7 @@
      * @return the {@link List} of {@link ArchivaProjectModel} objects. (never null, but
can be empty)
      * @throws ArchivaDatabaseException if there is a fundamental database error.
      */
-    public List getUsedBy( String groupId, String artifactId, String version )
+    public List<ArchivaProjectModel> getUsedBy( String principle, List<String>
observableRepositoryIds, String groupId,
+                                                String artifactId, String version )
         throws ArchivaDatabaseException;
 }

Modified: maven/archiva/branches/archiva-backend-security/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-backend-security/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java?rev=590765&r1=590764&r2=590765&view=diff
==============================================================================
--- maven/archiva/branches/archiva-backend-security/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java
(original)
+++ maven/archiva/branches/archiva-backend-security/archiva-database/src/test/java/org/apache/maven/archiva/database/browsing/RepositoryBrowsingTest.java
Wed Oct 31 10:35:28 2007
@@ -24,6 +24,7 @@
 import org.apache.maven.archiva.database.ArtifactDAO;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -36,13 +37,24 @@
 public class RepositoryBrowsingTest
     extends AbstractArchivaDatabaseTestCase
 {
+    private static final List<String> GUEST_REPO_IDS;
+
+    private static final String USER_GUEST = "guest";
+    
+    static
+    {
+        GUEST_REPO_IDS = new ArrayList<String>();
+        GUEST_REPO_IDS.add( "central" );
+        GUEST_REPO_IDS.add( "snapshots" );
+    }
+    
     private ArtifactDAO artifactDao;
 
     public ArchivaArtifact createArtifact( String groupId, String artifactId, String version
)
     {
         ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version,
"", "jar" );
         artifact.getModel().setLastModified( new Date() ); // mandatory field.
-        artifact.getModel().setRepositoryId( "testable_repo" );
+        artifact.getModel().setRepositoryId( "central" );
         return artifact;
     }
 
@@ -97,7 +109,7 @@
         saveTestData();
 
         RepositoryBrowsing browser = lookupBrowser();
-        BrowsingResults results = browser.selectGroupId( "org.apache.maven.test" );
+        BrowsingResults results = browser.selectGroupId( USER_GUEST, GUEST_REPO_IDS, "org.apache.maven.test"
);
         assertNotNull( "Browsing Results should not be null.", results );
 
         String expectedSubGroupIds[] = new String[] { "org.apache.maven.test.foo" };
@@ -110,7 +122,7 @@
         saveTestData();
 
         RepositoryBrowsing browser = lookupBrowser();
-        BrowsingResults results = browser.getRoot();
+        BrowsingResults results = browser.getRoot( USER_GUEST, GUEST_REPO_IDS );
         assertNotNull( "Browsing Results should not be null.", results );
 
         String expectedRootGroupIds[] = new String[] { "commons-lang", "org" };



Mime
View raw message