package eu.socialsensor.sfc.streams.input.FeedsCreatorImpl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import eu.socialsensor.framework.client.dao.SourceDAO;
import eu.socialsensor.framework.client.dao.impl.SourceDAOImpl;
import eu.socialsensor.framework.common.domain.Feed;
import eu.socialsensor.framework.common.domain.Keyword;
import eu.socialsensor.framework.common.domain.Location;
import eu.socialsensor.framework.common.domain.Source;
import eu.socialsensor.framework.common.domain.feeds.KeywordsFeed;
import eu.socialsensor.framework.common.domain.feeds.LocationFeed;
import eu.socialsensor.framework.common.domain.feeds.SourceFeed;
import eu.socialsensor.sfc.streams.StorageConfiguration;
import eu.socialsensor.sfc.streams.StreamsManagerConfiguration;
import eu.socialsensor.sfc.streams.input.FeedsCreator;

public class NewsHoundsFeedCreator implements FeedsCreator{
	
	protected static final String HOST = "mongodb.host";
	protected static final String DB = "mongodb.database";
	protected static final String SOURCES_COLLECTION = "mongodb.sources.collection";
	
	private StreamsManagerConfiguration configFile;
	private StorageConfiguration storageConfig;
	
	private String host = null;
	private String db = null;
	private String newsHoundsCollection = null;
	
	private Date sinceDate = null;
	
	private List<Keyword> extractedKeywords = new ArrayList<Keyword>();
	private List<Source> extractedSources = new ArrayList<Source>();
	private List<Location> extractedLocations = new ArrayList<Location>();
	
	public NewsHoundsFeedCreator(StreamsManagerConfiguration configFile){
		this.configFile = configFile;
		
		storageConfig = configFile.getStorageConfig("Mongodb");
	}
	
	public List<Source> extractFeedInfo(){
		this.host = storageConfig.getParameter(NewsHoundsFeedCreator.HOST);
		this.db = storageConfig.getParameter(NewsHoundsFeedCreator.DB);
		this.newsHoundsCollection = storageConfig.getParameter(NewsHoundsFeedCreator.SOURCES_COLLECTION, "Sources");
	
		if(host == null || db == null || newsHoundsCollection == null){
			System.out.println("News hounds collection needs to be configured correctly");
			return null;
		}
		SourceDAO sourceDao = new SourceDAOImpl("social1.atc.gr", db, newsHoundsCollection);	
		
		List<Source> sources = sourceDao.findTopSources(5000);
		extractedSources.addAll(sources);
		
		return sources;
	}
	
	public List<Feed> createFeeds(){
		List<Feed> feeds = new ArrayList<Feed>();
		
		for(Keyword keyword : extractedKeywords){
			String feedID = UUID.randomUUID().toString();
			KeywordsFeed keywordsFeed = new KeywordsFeed(keyword,sinceDate,feedID,null);
			feeds.add(keywordsFeed);
		}
		
		for(Source source : extractedSources){
			String feedID = UUID.randomUUID().toString();
			SourceFeed sourceFeed = new SourceFeed(source,sinceDate,feedID,null);
			feeds.add(sourceFeed);
		}
		
		for(Location location : extractedLocations){
			String feedID = UUID.randomUUID().toString();
			LocationFeed locationFeed = new LocationFeed(location,sinceDate,feedID);
			feeds.add(locationFeed);
		}
		
		return feeds;
	}

}

@@ -1345,35 +1345,76 @@
 ection = null;%0D%0A
+%09private Source.Type streamType = null;%0D%0A
 %09%0D%0A
-
 %09private Date si
@@ -1813,32 +1813,701 @@
 godb%22);%0D%0A%09%7D%0D%0A%09%0D%0A
+%09public void setTypeOfStream(String streamType)%7B%0D%0A%09%09%0D%0A%09%09if(streamType.equals(%22Twitter%22))%0D%0A%09%09%09this.streamType = Source.Type.Twitter;%0D%0A%09%09else if(streamType.equals(%22Facebook%22))%0D%0A%09%09%09this.streamType = Source.Type.Facebook;%0D%0A%09%09else if(streamType.equals(%22Flickr%22))%0D%0A%09%09%09this.streamType = Source.Type.Flickr;%0D%0A%09%09else if(streamType.equals(%22GooglePlus%22))%0D%0A%09%09%09this.streamType = Source.Type.GooglePlus;%0D%0A%09%09else if(streamType.equals(%22Instagram%22))%0D%0A%09%09%09this.streamType = Source.Type.Instagram;%0D%0A%09%09else if(streamType.equals(%22Tumblr%22))%0D%0A%09%09%09this.streamType = Source.Type.Tumblr;%0D%0A%09%09else if(streamType.equals(%22Youtube%22))%0D%0A%09%09%09this.streamType = Source.Type.Youtube;%0D%0A%09%09%09%0D%0A%09%7D%0D%0A%09%0D%0A%09@Override%0D%0A
 %09public List%3CSou
@@ -3103,16 +3103,27 @@
 ces(5000
+,streamType
 );%0D%0A%09%09ex
@@ -3178,25 +3178,34 @@
 urces;%0D%0A%09%7D%0D%0A
-
 %09
+@Override
 %0D%0A%09public Li

add stream type to newshoundsfeedcreator