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.
67 public SyndFeed process( Map<String, String> reqParams, MetadataRepository metadataRepository )
70 String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
71 String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
73 if ( groupId != null && artifactId != null )
75 return processNewVersionsOfArtifact( groupId, artifactId, metadataRepository );
81 private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId,
82 MetadataRepository metadataRepository )
85 List<ArtifactMetadata> artifacts = new ArrayList<>();
88 for ( String repoId : metadataRepository.getRepositories() )
90 Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
91 for ( String version : versions )
93 artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
97 catch ( MetadataRepositoryException e )
99 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
102 catch ( MetadataResolutionException e )
104 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
109 RssFeedEntry entry = null;
110 List<RssFeedEntry> entries = new ArrayList<>();
111 String description = "";
113 for ( ArtifactMetadata artifact : artifacts )
115 long whenGathered = artifact.getWhenGathered().getTime();
117 if ( tmp != whenGathered )
121 entry.setDescription( description );
122 entries.add( entry );
126 entry = new RssFeedEntry(
127 this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
128 entry.setPublishedDate( artifact.getWhenGathered() );
130 this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
135 description = description + artifact.getId() + " | ";
138 if ( idx == ( artifacts.size() - 1 ) )
140 entry.setDescription( description );
141 entries.add( entry );
148 String key = groupId + ":" + artifactId;
150 return generator.generateFeed( getTitle() + "\'" + key + "\'",
151 "New versions of artifact " + "\'" + key + "\' found during repository scan.",
156 public String getTitle()
162 public String getDescription()
167 public RssFeedGenerator getGenerator()
172 public void setGenerator( RssFeedGenerator generator )
174 this.generator = generator;