Search in sources :

Example 1 with RssFeedEntry

use of org.apache.archiva.rss.RssFeedEntry in project archiva by apache.

the class NewArtifactsRssFeedProcessor method processNewArtifactsInRepo.

private SyndFeed processNewArtifactsInRepo(String repoId, MetadataRepository metadataRepository) throws FeedException {
    Calendar greaterThanThisDate = Calendar.getInstance(GMT_TIME_ZONE);
    greaterThanThisDate.add(Calendar.DATE, -(getNumberOfDaysBeforeNow()));
    greaterThanThisDate.clear(Calendar.MILLISECOND);
    List<ArtifactMetadata> artifacts;
    try {
        artifacts = metadataRepository.getArtifactsByDateRange(repoId, greaterThanThisDate.getTime(), null);
    } catch (MetadataRepositoryException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    }
    long tmp = 0;
    RssFeedEntry entry = null;
    List<RssFeedEntry> entries = new ArrayList<>();
    String description = "";
    int idx = 0;
    for (ArtifactMetadata artifact : artifacts) {
        long whenGathered = artifact.getWhenGathered().getTime();
        String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
        if (tmp != whenGathered) {
            if (entry != null) {
                entry.setDescription(description);
                entries.add(entry);
                entry = null;
            }
            String repoId1 = artifact.getRepositoryId();
            entry = new RssFeedEntry(this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date(whenGathered));
            entry.setPublishedDate(artifact.getWhenGathered());
            description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
        } else {
            description = description + id + " | ";
        }
        if (idx == (artifacts.size() - 1)) {
            entry.setDescription(description);
            entries.add(entry);
        }
        tmp = whenGathered;
        idx++;
    }
    return generator.generateFeed(getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Calendar(java.util.Calendar) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date)

Example 2 with RssFeedEntry

use of org.apache.archiva.rss.RssFeedEntry in project archiva by apache.

the class NewVersionsOfArtifactRssFeedProcessor method processNewVersionsOfArtifact.

private SyndFeed processNewVersionsOfArtifact(String groupId, String artifactId, MetadataRepository metadataRepository) throws FeedException {
    List<ArtifactMetadata> artifacts = new ArrayList<>();
    try {
        for (String repoId : metadataRepository.getRepositories()) {
            Collection<String> versions = metadataRepository.getProjectVersions(repoId, groupId, artifactId);
            for (String version : versions) {
                artifacts.addAll(metadataRepository.getArtifacts(repoId, groupId, artifactId, version));
            }
        }
    } catch (MetadataRepositoryException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    } catch (MetadataResolutionException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    }
    long tmp = 0;
    RssFeedEntry entry = null;
    List<RssFeedEntry> entries = new ArrayList<>();
    String description = "";
    int idx = 0;
    for (ArtifactMetadata artifact : artifacts) {
        long whenGathered = artifact.getWhenGathered().getTime();
        if (tmp != whenGathered) {
            if (entry != null) {
                entry.setDescription(description);
                entries.add(entry);
                entry = null;
            }
            entry = new RssFeedEntry(this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date(whenGathered));
            entry.setPublishedDate(artifact.getWhenGathered());
            description = this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + " | ";
        } else {
            description = description + artifact.getId() + " | ";
        }
        if (idx == (artifacts.size() - 1)) {
            entry.setDescription(description);
            entries.add(entry);
        }
        tmp = whenGathered;
        idx++;
    }
    String key = groupId + ":" + artifactId;
    return generator.generateFeed(getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key + "\' found during repository scan.", entries);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Date(java.util.Date) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

FeedException (com.sun.syndication.io.FeedException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)2 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)2 RssFeedEntry (org.apache.archiva.rss.RssFeedEntry)2 Calendar (java.util.Calendar)1 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)1