package gr.iti.mklab.sfc.filters;

import gr.iti.mklab.framework.common.domain.Item;
import gr.iti.mklab.framework.common.domain.config.Configuration;

import org.apache.logging.log4j.LogManager;

/**
 * 
 * @author Manos Schinas - manosetro@iti.gr
 *
 * This filter discard items that have many hashtags as possible spam.
 * 	
 */
public class TagsItemFilter extends ItemFilter {

	private int maxTags = 4;
	
	public TagsItemFilter(Configuration configuration) {
		super(configuration);
		String lenStr =configuration.getParameter("maxTags", "4");
		this.maxTags  = Integer.parseInt(lenStr);
		
		LogManager.getLogger(TagsItemFilter.class).info("Initialized. Max Number of Tags: " + maxTags);
	}
	
	@Override
	public synchronized boolean accept(Item item) {
		if(item == null) {
			incrementDiscarded();
			return false;
		}
		
		String[] tags = item.getTags();
		if(tags == null) {
			incrementAccepted();
			return true;
		}
		
		if(tags.length >= maxTags) {
			incrementDiscarded();
			return false;
		}
		
		incrementAccepted();
		return true;
	}

	@Override
	public String name() {
		return "TagsItemFilter";
	}
	
}

@@ -145,16 +145,90 @@
 ation;%0A%0A
+import java.util.Arrays;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 import o
@@ -264,16 +264,17 @@
 nager;%0A%0A
+%0A
 /**%0A * %0A
@@ -477,17 +477,82 @@
 s = 4;%0A%09
+private Set%3CString%3E sourcesToInclude = new HashSet%3CString%3E();%0A%09%09%09
 %0A
-
 %09public 
@@ -729,16 +729,218 @@
 tr);%0A%09%09%0A
+%09%09String sources = configuration.getParameter(%22sources%22);%0A%09%09if(sources != null && !sources.equals(%22%22)) %7B%0A%09%09%09String%5B%5D parts = sources.split(%22,%22);%0A%09%09%09sourcesToInclude.addAll(Arrays.asList(parts));%0A%09%09%7D%0A%09%09%0A
 %09%09LogMan
@@ -1094,16 +1094,20 @@
 item) %7B%0A
+%09%09%09%0A
 %09%09if(ite
@@ -1136,32 +1136,32 @@
 entDiscarded();%0A
-
 %09%09%09return false;
@@ -1164,24 +1164,124 @@
 lse;%0A%09%09%7D%0A%09%09%0A
+%09%09if(!sourcesToInclude.contains(item.getSource())) %7B%0A%09%09%09incrementAccepted();%0A%09%09%09return true;%0A%09%09%7D%0A%09%09%0A
 %09%09String%5B%5D t

Update tags filter