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 com.sun.syndication.feed.synd.SyndFeed;
23 import com.sun.syndication.io.FeedException;
24 import org.apache.archiva.metadata.model.ArtifactMetadata;
25 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
26 import org.apache.archiva.rss.RssFeedEntry;
27 import org.apache.archiva.rss.RssFeedGenerator;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import java.util.ArrayList;
32 import java.util.Calendar;
33 import java.util.Date;
34 import java.util.List;
36 import java.util.TimeZone;
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.
43 * @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-artifacts"
45 public class NewArtifactsRssFeedProcessor
46 extends AbstractArtifactsRssFeedProcessor
48 private int numberOfDaysBeforeNow = 30;
50 private static final String title = "New Artifacts in Repository ";
52 private static final String desc = "These are the new artifacts found in the repository ";
57 private RssFeedGenerator generator;
59 private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class );
61 private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
64 * Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
65 * new versions of artifact.
67 public SyndFeed process( Map<String, String> reqParams )
70 log.debug( "Process new artifacts into rss feeds." );
72 String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
75 return processNewArtifactsInRepo( repoId );
81 private SyndFeed processNewArtifactsInRepo( String repoId )
84 Calendar greaterThanThisDate = Calendar.getInstance( GMT_TIME_ZONE );
85 greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) );
86 greaterThanThisDate.clear( Calendar.MILLISECOND );
88 List<ArtifactMetadata> artifacts = null;
91 artifacts = metadataRepository.getArtifactsByDateRange( repoId, greaterThanThisDate.getTime(), null );
93 catch ( MetadataRepositoryException e )
95 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
100 RssFeedEntry entry = null;
101 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
102 String description = "";
104 for ( ArtifactMetadata artifact : artifacts )
106 long whenGathered = artifact.getWhenGathered().getTime();
108 String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
109 if ( tmp != whenGathered )
113 entry.setDescription( description );
114 entries.add( entry );
118 String repoId1 = artifact.getRepositoryId();
119 entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date(
121 entry.setPublishedDate( artifact.getWhenGathered() );
122 description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
126 description = description + id + " | ";
129 if ( idx == ( artifacts.size() - 1 ) )
131 entry.setDescription( description );
132 entries.add( entry );
139 return generator.generateFeed( getTitle() + "\'" + repoId + "\'",
140 "New artifacts found in repository " + "\'" + repoId + "\'" +
141 " during repository scan.", entries );
144 public String getTitle()
149 public String getDescription()
154 public RssFeedGenerator getGenerator()
159 public void setGenerator( RssFeedGenerator generator )
161 this.generator = generator;
164 public int getNumberOfDaysBeforeNow()
166 return numberOfDaysBeforeNow;
169 public void setNumberOfDaysBeforeNow( int numberOfDaysBeforeNow )
171 this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;