mirror of https://github.com/apache/archiva.git
[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
This commit is contained in:
parent
e5de45d6b3
commit
e85deb992e
|
@ -19,6 +19,8 @@ package org.apache.maven.archiva.database.constraints;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.apache.maven.archiva.database.Constraint;
|
import org.apache.maven.archiva.database.Constraint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,13 +43,15 @@ public class ArtifactsByRepositoryConstraint
|
||||||
declParams = new String[] { "String repoId" };
|
declParams = new String[] { "String repoId" };
|
||||||
params = new Object[] { 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;
|
this.sortColumn = sortColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSortColumn()
|
public String getSortColumn()
|
||||||
{
|
{
|
||||||
return sortColumn;
|
return sortColumn;
|
||||||
|
|
|
@ -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() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,11 +19,13 @@ package org.apache.archiva.rss.processor;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.archiva.rss.RssFeedEntry;
|
import org.apache.archiva.rss.RssFeedEntry;
|
||||||
import org.apache.archiva.rss.RssFeedGenerator;
|
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.ArchivaDatabaseException;
|
||||||
import org.apache.maven.archiva.database.ArtifactDAO;
|
import org.apache.maven.archiva.database.ArtifactDAO;
|
||||||
import org.apache.maven.archiva.database.Constraint;
|
import org.apache.maven.archiva.database.Constraint;
|
||||||
|
@ -46,6 +48,8 @@ import com.sun.syndication.feed.synd.SyndFeed;
|
||||||
public class NewArtifactsRssFeedProcessor
|
public class NewArtifactsRssFeedProcessor
|
||||||
extends AbstractArtifactsRssFeedProcessor
|
extends AbstractArtifactsRssFeedProcessor
|
||||||
{
|
{
|
||||||
|
public static int numberOfDaysBeforeNow = 100;
|
||||||
|
|
||||||
private String title = "New Artifacts in Repository ";
|
private String title = "New Artifacts in Repository ";
|
||||||
|
|
||||||
private String desc = "These are the new artifacts found in the repository ";
|
private String desc = "These are the new artifacts found in the repository ";
|
||||||
|
@ -83,7 +87,10 @@ public class NewArtifactsRssFeedProcessor
|
||||||
{
|
{
|
||||||
try
|
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<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo );
|
||||||
|
|
||||||
List<RssFeedEntry> entries = processData( artifacts, true );
|
List<RssFeedEntry> entries = processData( artifacts, true );
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.archiva.rss.RssFeedGenerator;
|
||||||
import org.apache.archiva.rss.stubs.ArtifactDAOStub;
|
import org.apache.archiva.rss.stubs.ArtifactDAOStub;
|
||||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||||
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
||||||
|
|
||||||
import com.sun.syndication.feed.synd.SyndEntry;
|
import com.sun.syndication.feed.synd.SyndEntry;
|
||||||
import com.sun.syndication.feed.synd.SyndFeed;
|
import com.sun.syndication.feed.synd.SyndFeed;
|
||||||
|
|
||||||
|
@ -64,9 +65,7 @@ public class NewArtifactsRssFeedProcessorTest
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
|
List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
|
||||||
|
|
||||||
Date whenGathered = Calendar.getInstance().getTime();
|
Date whenGathered = Calendar.getInstance().getTime();
|
||||||
whenGathered.setTime( 123456789 );
|
|
||||||
|
|
||||||
ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar" );
|
ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar" );
|
||||||
artifact.getModel().setRepositoryId( "test-repo" );
|
artifact.getModel().setRepositoryId( "test-repo" );
|
||||||
|
|
Loading…
Reference in New Issue