}
@Override
public Feed toFeed(List<Event> events, String path) {
String url = config.getString(ConfigProperties.CANDLEPIN_URL) + path + "/";
Feed feed = new Feed();
feed.setUpdated(new Date());
feed.getAuthors().add(new Person("Red Hat, Inc."));
try {
feed.setId(new URI(url));
}
catch (Exception e) {
// ignore, shouldn't happen
}
if (events == null) {
return feed;
}
// Add the friendly message text
this.addMessageText(events);
for (Event e : events) {
Entry entry = new Entry();
entry.setTitle(e.getTarget().toString() + " " + e.getType().toString());
entry.setPublished(e.getTimestamp());
entry.setUpdated(e.getTimestamp());
entry.getAuthors().add(new Person("Red Hat, Inc."));
URI eventURI = null;
try {
eventURI = new URI(url + e.getId());
}
catch (Exception error) {
// ignore, shouldn't happen
}
entry.setId(eventURI);
entry.getLinks().add(
new Link(
"alternate",
eventURI,
MediaType.APPLICATION_JSON_TYPE));
Content content = new Content();
content.setType(MediaType.APPLICATION_XML_TYPE);
content.setJAXBObject(e);
entry.setContent(content);
entry.setSummary(e.getMessageText());
feed.getEntries().add(entry);
}
// Use the most recent event as the feed's published time. Assumes events do not
// get modified, if they do then the feed published date could be inaccurate.
if (events.size() > 0) {
feed.setUpdated(events.get(0).getTimestamp());
}
return feed;
}