/*
 * $Id: EnabledFilter.java 988 2008-12-30 08:51:13Z lhoriman $
 * $URL: http://subetha.tigris.org/svn/subetha/branches/resin/core/src/org/subethamail/entity/EnabledFilter.java $
 */

package org.subethamail.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.entity.i.Validator;

/**
 * When a filter is added to a mailing list, one of these entities is
 * created.  It identifies the filter and stores all the filter arguments.
 *
 * @author Jeff Schnitzer
 */
@Entity
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class EnabledFilter implements Serializable, Comparable<EnabledFilter>
{
	private static final long serialVersionUID = 1L;

	/** */
	@Transient private final static Logger log = LoggerFactory.getLogger(EnabledFilter.class);

	/** */
	@Id
	@GeneratedValue
	Long id;

	/** */
	@Column(nullable=false, length=Validator.MAX_FILTER_CLASSNAME)
	String className;

	/** TODO:  consider allowing null to mean global filter */
	@ManyToOne
	@JoinColumn(name="listId", nullable=false)
	MailingList list;

	/** */
	@OneToMany(cascade=CascadeType.ALL, mappedBy="filter")
	@MapKey(name="name")
	@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
	Map<String, FilterArgument> arguments;

	/**
	 */
	public EnabledFilter() {}

	/**
	 */
	public EnabledFilter(MailingList list, String className)
	{
		if (log.isDebugEnabled())
			log.debug("Creating new EnabledFilter");

		this.list = list;
		this.className = className;
		this.arguments = new HashMap<String, FilterArgument>();
	}

	/** */
	public Long getId()		{ return this.id; }

	/** */
	public String getClassName() { return this.className; }

	/** */
	public MailingList getList() { return this.list; }

	/** */
	public Map<String, FilterArgument> getArguments() { return this.arguments; }

	/** Convenience method */
	public void addArgument(FilterArgument arg)
	{
		this.arguments.put(arg.getName(), arg);
	}

	/**
	 * Builds a nice map of the key/values
	 */
	public Map<String, Object> getArgumentMap()
	{
		Map<String, Object> result = new HashMap<String, Object>(this.arguments.size() * 2);

		for (FilterArgument arg: this.arguments.values())
			result.put(arg.getName(), arg.getValue());

		return result;
	}

	/** */
	@Override
	public String toString()
	{
		return this.getClass() + " {id=" + this.id + ", class=" + this.className + "}";
	}

	/**
	 * Natural sort order is based on id?
	 */
	public int compareTo(EnabledFilter other)
	{
		return this.id.compareTo(other.getId());
	}
}


@@ -298,16 +298,49 @@
 il.Map;%0D
+%0Aimport java.util.logging.Level;%0D
 %0A%0D%0Aimpor
@@ -663,42 +663,39 @@
 y;%0D%0A
+%0D%0A
 import 
-javax.persistence.Transient
+lombok.extern.java.Log
 ;%0D%0A%0D
@@ -800,67 +800,8 @@
 y;%0D%0A
-import org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory;%0D%0A
 impo
@@ -1093,16 +1093,22 @@
 IONAL)%0D%0A
+@Log%0D%0A
 public c
@@ -1238,112 +1238,8 @@
 %0D%0A%0D%0A
-%09/** */%0D%0A%09@Transient private final static Logger log = LoggerFactory.getLogger(EnabledFilter.class);%0D%0A%0D%0A
 %09/**
@@ -1826,49 +1826,31 @@
 %7B%0D%0A%09
-%09if (log.isDebugEnabled())%0D%0A%09%09%09log.debug(
+    log.log(Level.FINE,
 %22Cre

switch logging framework