package eu.dnetlib.r2d2.neo4j;

import javax.annotation.Resource;

import com.google.common.collect.Iterables;

import eu.dnetlib.r2d2.neo4j.dao.ItemDao;
import eu.dnetlib.r2d2.neo4j.dao.ProfileDao;
import eu.dnetlib.r2d2.neo4j.domain.Neo4jItem;
import eu.dnetlib.r2d2.neo4j.domain.Neo4jProfile;

public class InterceptedBean {

	@Resource private ProfileDao profileDao = null;
	
	@Resource private ItemDao itemDao = null;
	
	private Neo4jProfile user = null;
	private String profileId = "123";
	private String itemId = "124";
	
	
	public void first() {
		user = profileDao.newBean(profileId);
		
		user.setName("Vaggelis Evaggelopoulos");
		user.setMail("vaggellis@vaggelis.gr");
		
		Neo4jItem item = itemDao.newBean(itemId);
		
		item.setDescription("descriptiiiiiiion");
		item.setItemUrl("http://www.olympiacos.org/uploads/Gallery/9_2008_1/realcms475200832200893125111.jpg");
		item.setIconUrl("http://www.olympiacos.org/uploads/Gallery/9_2008_1/realcms369030178200893131515.jpg");
		
		profileDao.addItemAuthor(item.getId(), profileId);
	}
	
	public void firstAndAHalf() {
		user = profileDao.getBean(profileId);
		
		user.setAvatarUrl("http://cdn-www.cracked.com/phpimages/article/0/0/1/25001.jpg?v=1");
		user.setName("Unknown old man");
	}
	
	public void second() {
		user = profileDao.getBean(profileId);
		
		if (Iterables.size(profileDao.getItemAuthors(itemId)) == 0)
			throw new RuntimeException("BOOO!");
		
		profileDao.removeItemAuthor(itemId, profileId);
		
		if (Iterables.size(profileDao.getItemAuthors(itemId)) != 0)
			throw new RuntimeException("BOOO!");
		
		itemDao.deleteBean(itemId);
	}
	
	public void third() {
		profileDao.deleteBean(profileId);
		
		if (itemDao.getBean(itemId) != null)
			throw new RuntimeException("BOOO!");
		
		if (profileDao.getBean(profileId) != null)
			throw new RuntimeException("BOOO!");
	}
}