diff options
author | Maria Odea B. Ching <oching@apache.org> | 2008-05-05 06:24:29 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2008-05-05 06:24:29 +0000 |
commit | e85deb992edb367717e1519ba4efb1ce9f025ad8 (patch) | |
tree | 4c0082330efed421083e15f3ea85ee97a7a3c5d5 | |
parent | e5de45d6b3ec7de0879dbaf7e9d3052ed9a7c698 (diff) | |
download | archiva-e85deb992edb367717e1519ba4efb1ce9f025ad8.tar.gz archiva-e85deb992edb367717e1519ba4efb1ce9f025ad8.zip |
[MRM-773]
-set limit date of artifacts to be included in the feed (new artifacts in repo)
-created test for ArtifactsByRepositoryConstraint
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@653303 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 144 insertions, 7 deletions
diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraint.java index 7a570a80b..0e64a84c2 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraint.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.database.constraints; * under the License. */ +import java.util.Date; + import org.apache.maven.archiva.database.Constraint; /** @@ -41,13 +43,15 @@ public class ArtifactsByRepositoryConstraint declParams = new String[] { "String repoId" }; params = new Object[] { repoId }; } - - public ArtifactsByRepositoryConstraint( String repoId, String sortColumn ) + + public ArtifactsByRepositoryConstraint( String repoId, Date whenGathered, String sortColumn ) { - this( repoId ); + whereClause = "repositoryId == repoId && whenGathered >= whenGathered"; + declParams = new String[] { "String repoId", "Date whenGathered" }; + params = new Object[] { repoId, whenGathered }; this.sortColumn = sortColumn; } - + public String getSortColumn() { return sortColumn; 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 new file mode 100644 index 000000000..e9a82931a --- /dev/null +++ b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByRepositoryConstraintTest.java @@ -0,0 +1,127 @@ +package org.apache.maven.archiva.database.constraints; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; +import org.apache.maven.archiva.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArtifactDAO; +import org.apache.maven.archiva.model.ArchivaArtifact; + +/** + * ArtifactsByRepositoryConstraintTest + * + * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> + * @version + */ +public class ArtifactsByRepositoryConstraintTest + extends AbstractArchivaDatabaseTestCase +{ + private ArtifactDAO artifactDao; + + public void setUp() + throws Exception + { + super.setUp(); + + ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" ); + artifactDao = dao.getArtifactDAO(); + } + + private ArchivaArtifact createArtifact( String groupId, String artifactId, String version ) + { + ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, null, "jar" ); + artifact.getModel().setLastModified( new Date() ); + artifact.getModel().setRepositoryId( "test-repo" ); + + return artifact; + } + + public void testQueryAllArtifactsInRepo() + throws Exception + { + Date whenGathered = Calendar.getInstance().getTime(); + whenGathered.setTime( 123456789 ); + + ArchivaArtifact artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.1" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-two", "1.0.2" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "2.0" ); + artifact.getModel().setRepositoryId( "different-repo" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + assertConstraint( "Artifacts By Repository", 3, new ArtifactsByRepositoryConstraint( "test-repo" ) ); + } + + public void testQueryArtifactsInRepoWithWhenGathered() + throws Exception + { + Date whenGathered = Calendar.getInstance().getTime(); + + ArchivaArtifact artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.1" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.2" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "2.0" ); + artifact.getModel().setRepositoryId( "different-repo" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-two", "1.1-SNAPSHOT" ); + artifact.getModel().setWhenGathered( whenGathered ); + 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" ) ); + } + + private void assertConstraint( String msg, int count, ArtifactsByRepositoryConstraint constraint ) + throws Exception + { + List results = artifactDao.queryArtifacts( constraint ); + assertNotNull( msg + ": Not Null", results ); + assertEquals( msg + ": Results.size", count, results.size() ); + } +} 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 776042796..1ca0a33c0 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 @@ -19,11 +19,13 @@ package org.apache.archiva.rss.processor; * under the License. */ +import java.util.Calendar; import java.util.List; import java.util.Map; import org.apache.archiva.rss.RssFeedEntry; import org.apache.archiva.rss.RssFeedGenerator; +import org.apache.commons.lang.time.DateUtils; import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.Constraint; @@ -46,6 +48,8 @@ import com.sun.syndication.feed.synd.SyndFeed; public class NewArtifactsRssFeedProcessor extends AbstractArtifactsRssFeedProcessor { + public static int numberOfDaysBeforeNow = 100; + private String title = "New Artifacts in Repository "; private String desc = "These are the new artifacts found in the repository "; @@ -83,7 +87,10 @@ public class NewArtifactsRssFeedProcessor { try { - Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, "whenGathered" ); + 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 ); List<RssFeedEntry> entries = processData( artifacts, true ); 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 cce0d1606..359c21efe 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 @@ -30,6 +30,7 @@ import org.apache.archiva.rss.RssFeedGenerator; import org.apache.archiva.rss.stubs.ArtifactDAOStub; import org.apache.maven.archiva.model.ArchivaArtifact; import org.codehaus.plexus.spring.PlexusInSpringTestCase; + import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; @@ -64,9 +65,7 @@ public class NewArtifactsRssFeedProcessorTest throws Exception { List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>(); - Date whenGathered = Calendar.getInstance().getTime(); - whenGathered.setTime( 123456789 ); ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar" ); artifact.getModel().setRepositoryId( "test-repo" ); |