]> source.dussan.org Git - archiva.git/commitdiff
cleanup some of the rss code
authorMaria Odea B. Ching <oching@apache.org>
Thu, 26 Jun 2008 11:12:47 +0000 (11:12 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Thu, 26 Jun 2008 11:12:47 +0000 (11:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@671856 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraintTest.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java

index e9a82931a9371c12454e7557b2e07c6169461ccb..c503ffcfa147b50cb55310c56f693cbcb0680a09 100644 (file)
@@ -105,16 +105,19 @@ public class ArtifactsByRepositoryConstraintTest
         artifact.getModel().setWhenGathered( whenGathered );
         artifactDao.saveArtifact( artifact );
 
+        Date olderWhenGathered = Calendar.getInstance().getTime();
+        olderWhenGathered.setTime( 123456789 );
+        
         artifact = createArtifact( "org.apache.archiva", "artifact-two", "1.1-SNAPSHOT" );
-        artifact.getModel().setWhenGathered( whenGathered );
+        artifact.getModel().setWhenGathered( olderWhenGathered );
         artifactDao.saveArtifact( artifact );
 
         artifact = createArtifact( "org.apache.archiva", "artifact-three", "2.0-beta-1" );
         artifact.getModel().setWhenGathered( whenGathered );
         artifactDao.saveArtifact( artifact );
 
-        assertConstraint( "Artifacts By Repository and When Gathered", 5,
-                          new ArtifactsByRepositoryConstraint( "test-repo" ) );
+        assertConstraint( "Artifacts By Repository and When Gathered", 4,
+                          new ArtifactsByRepositoryConstraint( "test-repo", whenGathered, "repositoryId" ) );
     }
 
     private void assertConstraint( String msg, int count, ArtifactsByRepositoryConstraint constraint )
index 3bf70827a063d1ef6632ecb5c7333b1c3f6ece78..2bff45def7cf6e19a3739bd27bea6312376b08b5 100644 (file)
@@ -50,15 +50,14 @@ public class RssFeedGenerator
 
     public static String DEFAULT_LANGUAGE = "en-us";
 
-    private String DEFAULT_LINK = "http://localhost:8080/archiva/rss/";
+    //private String DEFAULT_LINK = "http://localhost:8080/archiva/rss/";
 
-    public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries,
-                                  String queryString )
+    public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries )
     {
         SyndFeed feed = new SyndFeedImpl();
 
         feed.setTitle( title );
-        feed.setLink( DEFAULT_LINK + queryString );
+        //feed.setLink( DEFAULT_LINK + queryString );
         feed.setDescription( description );
         feed.setLanguage( DEFAULT_LANGUAGE );
         feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() );
index dd73456be02ca190062097643a47f134c2e909cd..55a7086cb0270363d7b8f5bd7648234b467dc8d3 100644 (file)
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.archiva.rss.RssFeedEntry;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 
 import com.sun.syndication.feed.synd.SyndFeed;
@@ -36,7 +37,7 @@ import com.sun.syndication.feed.synd.SyndFeed;
 public abstract class AbstractArtifactsRssFeedProcessor
     implements RssFeedProcessor
 {
-    public abstract SyndFeed process( Map<String, String> reqParams );
+    public abstract SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
 
     protected List<RssFeedEntry> processData( List<ArchivaArtifact> artifacts, boolean isRepoLevel )
     {
index 1ca0a33c0884dad670a3dfffbe02f125fcc854ea..3ef5c91829789aadd9797985d5c10d2bccec7f41 100644 (file)
@@ -48,11 +48,11 @@ import com.sun.syndication.feed.synd.SyndFeed;
 public class NewArtifactsRssFeedProcessor
     extends AbstractArtifactsRssFeedProcessor
 {
-    public static int numberOfDaysBeforeNow = 100;
+    private int numberOfDaysBeforeNow = 30;
     
-    private String title = "New Artifacts in Repository ";
+    private static final String title = "New Artifacts in Repository ";
 
-    private String desc = "These are the new artifacts found in the repository ";
+    private static final String desc = "These are the new artifacts found in the repository ";
 
     /**
      * @plexus.requirement
@@ -70,7 +70,7 @@ public class NewArtifactsRssFeedProcessor
      * Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
      * new versions of artifact.
      */
-    public SyndFeed process( Map<String, String> reqParams )
+    public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
     {
         log.debug( "Process new artifacts into rss feeds." );
 
@@ -83,27 +83,19 @@ public class NewArtifactsRssFeedProcessor
         return null;
     }
 
-    private SyndFeed processNewArtifactsInRepo( String repoId )
+    private SyndFeed processNewArtifactsInRepo( String repoId ) throws ArchivaDatabaseException
     {
-        try
-        {
-            Calendar greaterThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
-            greaterThanThisDate.add( Calendar.DATE, -numberOfDaysBeforeNow );
-            
-            Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, greaterThanThisDate.getTime(), "whenGathered" );
-            List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo );
+        
+        Calendar greaterThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
+        greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) );
+        
+        Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, greaterThanThisDate.getTime(), "whenGathered" );
+        List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo );
 
-            List<RssFeedEntry> entries = processData( artifacts, true );
+        List<RssFeedEntry> entries = processData( artifacts, true );
 
-            return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " +
-                "\'" + repoId + "\'" + " during repository scan.", entries, "rss_feeds?repoId=" + repoId );
-        }
-        catch ( ArchivaDatabaseException ae )
-        {
-            log.error( ae.getMessage() );
-        }
-
-        return null;
+        return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " +
+            "\'" + repoId + "\'" + " during repository scan.", entries );
     }
 
     public String getTitle()
@@ -135,4 +127,15 @@ public class NewArtifactsRssFeedProcessor
     {
         this.artifactDAO = artifactDAO;
     }
+
+    public int getNumberOfDaysBeforeNow()
+    {
+        return numberOfDaysBeforeNow;
+    }
+
+    public void setNumberOfDaysBeforeNow( int numberOfDaysBeforeNow )
+    {
+        this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;
+    }
+    
 }
index b9261efa16c5ab3742a6b488808cc455ff251215..78c21480cb1d2d410e6dcb46f9906f470aa48234 100644 (file)
@@ -27,7 +27,6 @@ import org.apache.archiva.rss.RssFeedGenerator;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
 import org.apache.maven.archiva.database.ArtifactDAO;
 import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
 import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.slf4j.Logger;
@@ -47,9 +46,9 @@ import com.sun.syndication.feed.synd.SyndFeed;
 public class NewVersionsOfArtifactRssFeedProcessor
     extends AbstractArtifactsRssFeedProcessor
 {
-    private String title = "New Versions of Artifact ";
+    private static final String title = "New Versions of Artifact ";
 
-    private String desc = "These are the new versions of artifact ";
+    private static final String desc = "These are the new versions of artifact ";
 
     /**
      * @plexus.requirement
@@ -66,7 +65,7 @@ public class NewVersionsOfArtifactRssFeedProcessor
     /**
      * Process all versions of the artifact which had a rss feed request.
      */
-    public SyndFeed process( Map<String, String> reqParams )
+    public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
     {
         String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
         String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
@@ -81,30 +80,17 @@ public class NewVersionsOfArtifactRssFeedProcessor
     }
 
     private SyndFeed processNewVersionsOfArtifact( String repoId, String groupId, String artifactId )
+        throws ArchivaDatabaseException
     {
-        try
-        {            
-            Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" );
-            List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions );
-            
-            List<RssFeedEntry> entries = processData( artifacts, false );
-            String key = groupId + ":" + artifactId;
-            return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key +
-                "\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries,
-                                           "rss_feeds?groupId=" + groupId + "&artifactId=" + artifactId );
-        }
-        catch ( ObjectNotFoundException oe )
-        {
-            oe.printStackTrace();
-            log.error( oe.getMessage() );
-        }
-        catch ( ArchivaDatabaseException ae )
-        {
-            ae.printStackTrace();
-            log.error( ae.getMessage() );
-        }
-
-        return null;
+                    
+        Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" );
+        List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions );
+        
+        List<RssFeedEntry> entries = processData( artifacts, false );
+        String key = groupId + ":" + artifactId;
+        
+        return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key +
+            "\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries );
     }
 
     public String getTitle()
index d02704513f6c1bdf97e2dd78cac027207f164fb7..806fe3853768a2448e2e0c8e3b1e6eb34bfc821e 100644 (file)
@@ -21,6 +21,8 @@ package org.apache.archiva.rss.processor;
 
 import java.util.Map;
 
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+
 import com.sun.syndication.feed.synd.SyndFeed;
 
 /**
@@ -37,5 +39,5 @@ public interface RssFeedProcessor
 
     public static final String KEY_ARTIFACT_ID = "artifactId";
 
-    SyndFeed process( Map<String, String> reqParams );
+    SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
 }
index f3f1c6e6f8581302d1b7393c913789bf42148f12..1b8b876b7b335617d18a85b98645989bc1890ec9 100644 (file)
@@ -68,10 +68,10 @@ public class RssFeedGeneratorTest
         entries.add( entry );
 
         SyndFeed feed =
-            generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries, "generated-rss2.0-feed.xml" );
+            generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries );
 
         assertEquals( "Test Feed", feed.getTitle() );
-        assertEquals( "http://localhost:8080/archiva/rss/generated-rss2.0-feed.xml", feed.getLink() );
+        //assertEquals( "http://localhost:8080/archiva/rss/generated-rss2.0-feed.xml", feed.getLink() );
         assertEquals( "The test feed from Archiva.", feed.getDescription() );
         assertEquals( "en-us", feed.getLanguage() );
         assertEquals( entries.get( 2 ).getPublishedDate(), feed.getPublishedDate() );
index 6865ac22fe826405bd7daae9317b1c8037a98386..bb01786fb1054f10bcf827409a630081b1d6e878 100644 (file)
@@ -115,7 +115,7 @@ public class NewArtifactsRssFeedProcessorTest
         SyndFeed feed = newArtifactsProcessor.process( reqParams );
 
         assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
-        assertTrue( feed.getLink().equals( "http://localhost:8080/archiva/rss/rss_feeds?repoId=test-repo" ) );
+        //assertTrue( feed.getLink().equals( "http://localhost:8080/archiva/rss/rss_feeds?repoId=test-repo" ) );
         assertTrue( feed.getDescription().equals(
                                                   "New artifacts found in repository 'test-repo' during repository scan." ) );
         assertTrue( feed.getLanguage().equals( "en-us" ) );
index 968b183e1e3a331d1e4635940717fab8ac29a1e1..02c31fb5f8feb5dd008c782798004018ca4c3210 100644 (file)
@@ -93,8 +93,8 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
         SyndFeed feed = newVersionsProcessor.process( reqParams );
 
         assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
-        assertEquals( "http://localhost:8080/archiva/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two",
-                      feed.getLink() );
+        //assertEquals( "http://localhost:8080/archiva/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two",
+        //              feed.getLink() );
         assertEquals(
                       "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
                       feed.getDescription() );
index efb78f2c18c1e90d809ac64a87c5b69c91441753..267c8137e74c7a00fead1c21f58bc0a719954798 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.archiva.rss.processor.RssFeedProcessor;
 import org.apache.commons.codec.Decoder;
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.binary.Base64;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
 import org.apache.maven.archiva.security.AccessDeniedException;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.security.ArchivaSecurityException;
@@ -163,35 +164,37 @@ public class RssFeedServlet
             SyndFeedOutput output = new SyndFeedOutput();
             output.output( feed, res.getWriter() );
         }
+        catch ( ArchivaDatabaseException e )
+        {
+            log.debug( COULD_NOT_GENERATE_FEED_ERROR, e );
+            res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR );
+        }
         catch ( UserNotFoundException unfe )
         {
-            log.error( COULD_NOT_AUTHENTICATE_USER, unfe );
+            log.debug( COULD_NOT_AUTHENTICATE_USER, unfe );
             res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
         }
         catch ( AccountLockedException acce )
-        {
-            log.error( COULD_NOT_AUTHENTICATE_USER, acce );
+        {            
             res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
         }
         catch ( AuthenticationException authe )
-        {
-            authe.printStackTrace();
-            log.error( COULD_NOT_AUTHENTICATE_USER, authe );
+        {   
+            log.debug( COULD_NOT_AUTHENTICATE_USER, authe );
             res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
         }
         catch ( FeedException ex )
         {
-            log.error( COULD_NOT_GENERATE_FEED_ERROR, ex );
+            log.debug( COULD_NOT_GENERATE_FEED_ERROR, ex );
             res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR );
         }
         catch ( MustChangePasswordException e )
-        {
-            log.error( COULD_NOT_AUTHENTICATE_USER, e );
+        {            
             res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
         }
         catch ( UnauthorizedException e )
         {
-            log.error( e.getMessage() );
+            log.debug( e.getMessage() );
             if ( repoId != null )
             {
                 res.setHeader("WWW-Authenticate", "Basic realm=\"Repository Archiva Managed " + repoId + " Repository" );
@@ -240,7 +243,7 @@ public class RssFeedServlet
                 }
                 catch ( DecoderException ie )
                 {
-                    log.error( "Error decoding username and password.", ie.getMessage() );
+                    log.warn( "Error decoding username and password.", ie.getMessage() );
                 }
 
                 if ( usernamePassword == null || usernamePassword.trim().equals( "" ) )
@@ -278,11 +281,11 @@ public class RssFeedServlet
             }
             catch ( AuthorizationException e )
             {
-                log.error( "Fatal Authorization Subsystem Error." );
+                
             }
             catch ( UnauthorizedException e )
             {
-                log.error( e.getMessage() );
+             
             }
         }