Search in sources :

Example 1 with HistoricalEvent

use of models.HistoricalEvent in project modules.playframework.org by playframework.

the class FeedCreationActor method onReceive.

@Override
public void onReceive(Object o) throws Exception {
    List<HistoricalEvent> historicalEvents = HistoricalEvent.findMostRecent(10);
    File feedDir = Play.application().getFile("public/feeds");
    boolean directoryExists = feedDir.exists();
    if (!directoryExists) {
        directoryExists = feedDir.mkdir();
        Logger.debug(String.format("Create feed directory [%s]", directoryExists ? "OK" : "Failed"));
    }
    if (directoryExists) {
        for (Map.Entry<String, String> entry : feedDetails.entrySet()) {
            createFeed(historicalEvents, entry.getKey(), feedDir, entry.getValue());
        }
    }
}
Also used : HistoricalEvent(models.HistoricalEvent) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with HistoricalEvent

use of models.HistoricalEvent in project modules.playframework.org by playframework.

the class AbstractController method createHistoricalEvent.

public static void createHistoricalEvent(String category, String message) {
    HistoricalEvent historicalEvent = new HistoricalEvent();
    historicalEvent.creationDate = new Date();
    historicalEvent.category = category;
    historicalEvent.message = message;
    ActorSystem actorSystem = Akka.system();
    ActorRef actor = actorSystem.actorOf(new Props(HistoricalEventActor.class));
    actor.tell(historicalEvent);
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) HistoricalEvent(models.HistoricalEvent) Props(akka.actor.Props) Date(java.util.Date) HistoricalEventActor(actors.HistoricalEventActor)

Example 3 with HistoricalEvent

use of models.HistoricalEvent in project modules.playframework.org by playframework.

the class FeedCreationActor method createFeed.

private void createFeed(List<HistoricalEvent> historicalEvents, String feedType, File outputDirectory, String classifier) {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(feedType);
    feed.setTitle("Play! Modules");
    feed.setLink("http://modules.playframework.org");
    feed.setUri("http://modules.playframework.org");
    feed.setPublishedDate(new Date());
    feed.setDescription("The Play! Framework's module repository feed");
    List<SyndEntry> entries = new ArrayList<SyndEntry>(historicalEvents.size());
    for (HistoricalEvent historicalEvent : historicalEvents) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(historicalEvent.category);
        entry.setAuthor("Play framework modules");
        entry.setPublishedDate(historicalEvent.creationDate);
        // todo this will be the url of the module
        entry.setLink("http://modules.playframework.org");
        entry.setUri("mpo-he-" + historicalEvent.id);
        SyndContent description = new SyndContentImpl();
        description.setType("text/plain");
        description.setValue(historicalEvent.message);
        entry.setDescription(description);
        entries.add(entry);
    }
    feed.setEntries(entries);
    Writer writer = null;
    try {
        File outputFile = new File(outputDirectory, String.format("mpo.%s.xml", classifier));
        writer = new FileWriter(outputFile);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);
        writer.close();
    } catch (IOException e) {
        Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
    } catch (FeedException e) {
        Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
    } finally {
        IOUtils.close(writer);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) HistoricalEvent(models.HistoricalEvent) FileWriter(java.io.FileWriter) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

HistoricalEvent (models.HistoricalEvent)3 File (java.io.File)2 Date (java.util.Date)2 HistoricalEventActor (actors.HistoricalEventActor)1 ActorRef (akka.actor.ActorRef)1 ActorSystem (akka.actor.ActorSystem)1 Props (akka.actor.Props)1 SyndContent (com.sun.syndication.feed.synd.SyndContent)1 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)1 FeedException (com.sun.syndication.io.FeedException)1 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1