From: Maria Odea B. Ching Date: Thu, 26 Jun 2008 11:12:47 +0000 (+0000) Subject: cleanup some of the rss code X-Git-Tag: archiva-r676265~45 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=207111bebcbd3993fa3766805c221b9e55580111;p=archiva.git cleanup some of the rss code git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@671856 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraintTest.java b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraintTest.java index e9a82931a..c503ffcfa 100644 --- a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraintTest.java +++ b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraintTest.java @@ -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 ) diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java index 3bf70827a..2bff45def 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java @@ -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 dataEntries, - String queryString ) + public SyndFeed generateFeed( String title, String description, List 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() ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java index dd73456be..55a7086cb 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java @@ -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 reqParams ); + public abstract SyndFeed process( Map reqParams ) throws ArchivaDatabaseException; protected List processData( List artifacts, boolean isRepoLevel ) { diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java index 1ca0a33c0..3ef5c9182 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java @@ -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 reqParams ) + public SyndFeed process( Map 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 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 artifacts = artifactDAO.queryArtifacts( artifactsByRepo ); - List entries = processData( artifacts, true ); + List 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; + } + } diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java index b9261efa1..78c21480c 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java @@ -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 reqParams ) + public SyndFeed process( Map 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 artifacts = artifactDAO.queryArtifacts( artifactVersions ); - - List 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 artifacts = artifactDAO.queryArtifacts( artifactVersions ); + + List 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() diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java index d02704513..806fe3853 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java @@ -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 reqParams ); + SyndFeed process( Map reqParams ) throws ArchivaDatabaseException; } diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java index f3f1c6e6f..1b8b876b7 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/RssFeedGeneratorTest.java @@ -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() ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java index 6865ac22f..bb01786fb 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java @@ -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" ) ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java index 968b183e1..02c31fb5f 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java @@ -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() ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java index efb78f2c1..267c8137e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java @@ -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() ); + } }