This project has retired. For details please refer to its
Attic page.
NewVersionsOfArtifactRssFeedProcessor xref
1 package org.apache.archiva.rss.processor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
33
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;
39 import java.util.Map;
40
41
42
43
44
45
46
47 @Service("rssFeedProcessor#new-versions")
48 public class NewVersionsOfArtifactRssFeedProcessor
49 extends AbstractArtifactsRssFeedProcessor
50 {
51 private Logger log = LoggerFactory.getLogger( NewVersionsOfArtifactRssFeedProcessor.class );
52
53 private static final String title = "New Versions of Artifact ";
54
55 private static final String desc = "These are the new versions of artifact ";
56
57 @Inject
58 private RssFeedGenerator generator;
59
60
61
62
63 @Override
64 public SyndFeed process( Map<String, String> reqParams, MetadataRepository metadataRepository )
65 throws FeedException
66 {
67 String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
68 String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
69
70 if ( groupId != null && artifactId != null )
71 {
72 return processNewVersionsOfArtifact( groupId, artifactId, metadataRepository );
73 }
74
75 return null;
76 }
77
78 private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId,
79 MetadataRepository metadataRepository )
80 throws FeedException
81 {
82 List<ArtifactMetadata> artifacts = new ArrayList<>();
83 try
84 {
85 for ( String repoId : metadataRepository.getRepositories() )
86 {
87 Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
88 for ( String version : versions )
89 {
90 artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
91 }
92 }
93 }
94 catch ( MetadataRepositoryException e )
95 {
96 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
97 e );
98 }
99 catch ( MetadataResolutionException e )
100 {
101 throw new FeedException( "Unable to construct feed, metadata could not be retrieved: " + e.getMessage(),
102 e );
103 }
104
105 long tmp = 0;
106 RssFeedEntry entry = null;
107 List<RssFeedEntry> entries = new ArrayList<>();
108 String description = "";
109 int idx = 0;
110 for ( ArtifactMetadata artifact : artifacts )
111 {
112 long whenGathered = artifact.getWhenGathered().getTime();
113
114 if ( tmp != whenGathered )
115 {
116 if ( entry != null )
117 {
118 entry.setDescription( description );
119 entries.add( entry );
120 entry = null;
121 }
122
123 entry = new RssFeedEntry(
124 this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
125 entry.setPublishedDate( artifact.getWhenGathered() );
126 description =
127 this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
128 " | ";
129 }
130 else
131 {
132 description = description + artifact.getId() + " | ";
133 }
134
135 if ( idx == ( artifacts.size() - 1 ) )
136 {
137 entry.setDescription( description );
138 entries.add( entry );
139 }
140
141 tmp = whenGathered;
142 idx++;
143 }
144
145 String key = groupId + ":" + artifactId;
146
147 return generator.generateFeed( getTitle() + "\'" + key + "\'",
148 "New versions of artifact " + "\'" + key + "\' found during repository scan.",
149 entries );
150 }
151
152 @Override
153 public String getTitle()
154 {
155 return title;
156 }
157
158 @Override
159 public String getDescription()
160 {
161 return desc;
162 }
163
164 public RssFeedGenerator getGenerator()
165 {
166 return generator;
167 }
168
169 public void setGenerator( RssFeedGenerator generator )
170 {
171 this.generator = generator;
172 }
173 }