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.MetadataRepository;
26 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
27 import org.apache.archiva.rss.RssFeedEntry;
28 import org.apache.archiva.rss.RssFeedGenerator;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.stereotype.Service;
33 import javax.inject.Inject;
34 import java.util.ArrayList;
35 import java.util.Calendar;
36 import java.util.Date;
37 import java.util.List;
39 import java.util.TimeZone;
42 * Retrieve and process all artifacts of a repository from the database and generate a rss feed.
43 * The artifacts will be grouped by the date when the artifacts were gathered.
44 * Each group will appear as one entry in the feed.
47 @Service("rssFeedProcessor#new-artifacts")
48 public class NewArtifactsRssFeedProcessor
49 extends AbstractArtifactsRssFeedProcessor
51 private int numberOfDaysBeforeNow = 30;
53 private static final String title = "New Artifacts in Repository ";
55 private static final String desc = "These are the new artifacts found in the repository ";
61 private RssFeedGenerator generator;
63 private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class );
65 private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
68 * Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
69 * new versions of artifact.
71 public SyndFeed process( Map<String, String> reqParams, MetadataRepository metadataRepository )
74 log.debug( "Process new artifacts into rss feeds." );
76 String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
79 return processNewArtifactsInRepo( repoId, metadataRepository );
85 private SyndFeed processNewArtifactsInRepo( String repoId, MetadataRepository metadataRepository )
88 Calendar greaterThanThisDate = Calendar.getInstance( GMT_TIME_ZONE );
89 greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) );
90 greaterThanThisDate.clear( Calendar.MILLISECOND );
92 List<ArtifactMetadata> artifacts;
95 artifacts = metadataRepository.getArtifactsByDateRange( repoId, greaterThanThisDate.getTime(), null );
97 catch ( MetadataRepositoryException e )
99 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
104 RssFeedEntry entry = null;
105 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
106 String description = "";
108 for ( ArtifactMetadata artifact : artifacts )
110 long whenGathered = artifact.getWhenGathered().getTime();
112 String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
113 if ( tmp != whenGathered )
117 entry.setDescription( description );
118 entries.add( entry );
122 String repoId1 = artifact.getRepositoryId();
123 entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date(
125 entry.setPublishedDate( artifact.getWhenGathered() );
126 description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
130 description = description + id + " | ";
133 if ( idx == ( artifacts.size() - 1 ) )
135 entry.setDescription( description );
136 entries.add( entry );
143 return generator.generateFeed( getTitle() + "\'" + repoId + "\'",
144 "New artifacts found in repository " + "\'" + repoId + "\'" +
145 " during repository scan.", entries );
148 public String getTitle()
153 public String getDescription()
158 public RssFeedGenerator getGenerator()
163 public void setGenerator( RssFeedGenerator generator )
165 this.generator = generator;
168 public int getNumberOfDaysBeforeNow()
170 return numberOfDaysBeforeNow;
173 public void setNumberOfDaysBeforeNow( int numberOfDaysBeforeNow )
175 this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;