1 package org.apache.archiva.rss.processor;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.Calendar;
23 import java.util.List;
25 import java.util.TimeZone;
27 import com.sun.syndication.feed.synd.SyndFeed;
28 import org.apache.archiva.rss.RssFeedEntry;
29 import org.apache.archiva.rss.RssFeedGenerator;
30 import org.apache.maven.archiva.database.ArchivaDatabaseException;
31 import org.apache.maven.archiva.database.ArtifactDAO;
32 import org.apache.maven.archiva.database.Constraint;
33 import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
34 import org.apache.maven.archiva.model.ArchivaArtifact;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * Retrieve and process all artifacts of a repository from the database and generate a rss feed.
40 * The artifacts will be grouped by the date when the artifacts were gathered.
41 * Each group will appear as one entry in the feed.
44 * @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-artifacts"
46 public class NewArtifactsRssFeedProcessor
47 extends AbstractArtifactsRssFeedProcessor
49 private int numberOfDaysBeforeNow = 30;
51 private static final String title = "New Artifacts in Repository ";
53 private static final String desc = "These are the new artifacts found in the repository ";
58 private RssFeedGenerator generator;
60 private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class );
63 * @plexus.requirement role-hint="jdo"
65 private ArtifactDAO artifactDAO;
67 private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
70 * Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
71 * new versions of artifact.
73 public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
75 log.debug( "Process new artifacts into rss feeds." );
77 String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
80 return processNewArtifactsInRepo( repoId );
86 private SyndFeed processNewArtifactsInRepo( String repoId ) throws ArchivaDatabaseException
89 Calendar greaterThanThisDate = Calendar.getInstance( GMT_TIME_ZONE );
90 greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) );
92 Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, greaterThanThisDate.getTime(), "whenGathered", false );
93 List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo );
95 List<RssFeedEntry> entries = processData( artifacts, true );
97 return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " +
98 "\'" + repoId + "\'" + " during repository scan.", entries );
101 public String getTitle()
106 public String getDescription()
111 public RssFeedGenerator getGenerator()
116 public void setGenerator( RssFeedGenerator generator )
118 this.generator = generator;
121 public ArtifactDAO getArtifactDAO()
126 public void setArtifactDAO( ArtifactDAO artifactDAO )
128 this.artifactDAO = artifactDAO;
131 public int getNumberOfDaysBeforeNow()
133 return numberOfDaysBeforeNow;
136 public void setNumberOfDaysBeforeNow( int numberOfDaysBeforeNow )
138 this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;