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 java.util.Calendar; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import org.apache.archiva.rss.RssFeedEntry; |
27 | |
import org.apache.archiva.rss.RssFeedGenerator; |
28 | |
import org.apache.commons.lang.time.DateUtils; |
29 | |
import org.apache.maven.archiva.database.ArchivaDatabaseException; |
30 | |
import org.apache.maven.archiva.database.ArtifactDAO; |
31 | |
import org.apache.maven.archiva.database.Constraint; |
32 | |
import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint; |
33 | |
import org.apache.maven.archiva.model.ArchivaArtifact; |
34 | |
import org.slf4j.Logger; |
35 | |
import org.slf4j.LoggerFactory; |
36 | |
|
37 | |
import com.sun.syndication.feed.synd.SyndFeed; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class NewArtifactsRssFeedProcessor |
48 | |
extends AbstractArtifactsRssFeedProcessor |
49 | |
{ |
50 | 0 | private int numberOfDaysBeforeNow = 30; |
51 | |
|
52 | |
private static final String title = "New Artifacts in Repository "; |
53 | |
|
54 | |
private static final String desc = "These are the new artifacts found in the repository "; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
private RssFeedGenerator generator; |
60 | |
|
61 | 0 | private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class ); |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private ArtifactDAO artifactDAO; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException |
73 | |
{ |
74 | 0 | log.debug( "Process new artifacts into rss feeds." ); |
75 | |
|
76 | 0 | String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID ); |
77 | 0 | if ( repoId != null ) |
78 | |
{ |
79 | 0 | return processNewArtifactsInRepo( repoId ); |
80 | |
} |
81 | |
|
82 | 0 | return null; |
83 | |
} |
84 | |
|
85 | |
private SyndFeed processNewArtifactsInRepo( String repoId ) throws ArchivaDatabaseException |
86 | |
{ |
87 | |
|
88 | 0 | Calendar greaterThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); |
89 | 0 | greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) ); |
90 | |
|
91 | 0 | Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, greaterThanThisDate.getTime(), "whenGathered", false ); |
92 | 0 | List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo ); |
93 | |
|
94 | 0 | List<RssFeedEntry> entries = processData( artifacts, true ); |
95 | |
|
96 | 0 | return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + |
97 | |
"\'" + repoId + "\'" + " during repository scan.", entries ); |
98 | |
} |
99 | |
|
100 | |
public String getTitle() |
101 | |
{ |
102 | 0 | return title; |
103 | |
} |
104 | |
|
105 | |
public String getDescription() |
106 | |
{ |
107 | 0 | return desc; |
108 | |
} |
109 | |
|
110 | |
public RssFeedGenerator getGenerator() |
111 | |
{ |
112 | 0 | return generator; |
113 | |
} |
114 | |
|
115 | |
public void setGenerator( RssFeedGenerator generator ) |
116 | |
{ |
117 | 0 | this.generator = generator; |
118 | 0 | } |
119 | |
|
120 | |
public ArtifactDAO getArtifactDAO() |
121 | |
{ |
122 | 0 | return artifactDAO; |
123 | |
} |
124 | |
|
125 | |
public void setArtifactDAO( ArtifactDAO artifactDAO ) |
126 | |
{ |
127 | 0 | this.artifactDAO = artifactDAO; |
128 | 0 | } |
129 | |
|
130 | |
public int getNumberOfDaysBeforeNow() |
131 | |
{ |
132 | 0 | return numberOfDaysBeforeNow; |
133 | |
} |
134 | |
|
135 | |
public void setNumberOfDaysBeforeNow( int numberOfDaysBeforeNow ) |
136 | |
{ |
137 | 0 | this.numberOfDaysBeforeNow = numberOfDaysBeforeNow; |
138 | 0 | } |
139 | |
|
140 | |
} |