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.metadata.repository.MetadataResolutionException;
28 import org.apache.archiva.rss.RssFeedEntry;
29 import org.apache.archiva.rss.RssFeedGenerator;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.stereotype.Service;
34 import javax.inject.Inject;
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import java.util.Date;
38 import java.util.List;
42 * Retrieve and process new versions of an artifact from the database and
43 * generate a rss feed. The versions will be grouped by the date when the artifact
44 * was gathered. Each group will appear as one entry in the feed.
47 @Service("rssFeedProcessor#new-versions")
48 public class NewVersionsOfArtifactRssFeedProcessor
49 extends AbstractArtifactsRssFeedProcessor
51 private Logger log = LoggerFactory.getLogger( NewVersionsOfArtifactRssFeedProcessor.class );
53 private static final String title = "New Versions of Artifact ";
55 private static final String desc = "These are the new versions of artifact ";
61 private RssFeedGenerator generator;
64 * Process all versions of the artifact which had a rss feed request.
66 public SyndFeed process( Map<String, String> reqParams, MetadataRepository metadataRepository )
69 String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
70 String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
72 if ( groupId != null && artifactId != null )
74 return processNewVersionsOfArtifact( groupId, artifactId, metadataRepository );
80 private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId,
81 MetadataRepository metadataRepository )
84 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
87 for ( String repoId : metadataRepository.getRepositories() )
89 Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
90 for ( String version : versions )
92 artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
96 catch ( MetadataRepositoryException e )
98 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
101 catch ( MetadataResolutionException e )
103 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
108 RssFeedEntry entry = null;
109 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
110 String description = "";
112 for ( ArtifactMetadata artifact : artifacts )
114 long whenGathered = artifact.getWhenGathered().getTime();
116 if ( tmp != whenGathered )
120 entry.setDescription( description );
121 entries.add( entry );
125 entry = new RssFeedEntry(
126 this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
127 entry.setPublishedDate( artifact.getWhenGathered() );
129 this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
134 description = description + artifact.getId() + " | ";
137 if ( idx == ( artifacts.size() - 1 ) )
139 entry.setDescription( description );
140 entries.add( entry );
147 String key = groupId + ":" + artifactId;
149 return generator.generateFeed( getTitle() + "\'" + key + "\'",
150 "New versions of artifact " + "\'" + key + "\' found during repository scan.",
154 public String getTitle()
159 public String getDescription()
164 public RssFeedGenerator getGenerator()
169 public void setGenerator( RssFeedGenerator generator )
171 this.generator = generator;