package de.metalmatze.krautreporter.services;

import android.content.Context;

import com.activeandroid.ActiveAndroid;
import com.activeandroid.query.Select;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;

import de.metalmatze.krautreporter.KrautreporterRssParser;
import de.metalmatze.krautreporter.models.ArticleModel;

public class ArticleService {

    private static final String RSS_FILE = "krautreporter.rss";

    protected Context context;

    public ArticleService(Context applicationContext) {

        this.context = applicationContext;
    }

    public List<ArticleModel> all()
    {
        return new Select().from(ArticleModel.class).orderBy("date DESC").execute();
    }

    public void update()
    {
        BufferedInputStream inputStream = null;
        try {
            inputStream = new BufferedInputStream(this.context.getAssets().open(RSS_FILE));
            List<ArticleModel> articleModelList = new KrautreporterRssParser.KrautreporterRssParserTask().execute(inputStream).get();

            ActiveAndroid.beginTransaction();
            try {
                for (ArticleModel articleModel : articleModelList)
                {
                    articleModel.save();
                }
                ActiveAndroid.setTransactionSuccessful();
            }
            finally {
                ActiveAndroid.endTransaction();
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

}

@@ -766,32 +766,173 @@
 ecute();%0A    %7D%0A%0A
+    public ArticleModel find(long id)%0A    %7B%0A        return new Select().from(ArticleModel.class).where(%22id = ?%22, id).executeSingle();%0A    %7D%0A%0A
     public void 

Create public ArticleModel find(long id) in ArticleService