// Path: SDI-core/src/main/java/ch/sdi/core/exc/SdiException.java
// public class SdiException extends Exception
// {
//     private static final long serialVersionUID = 1L;
// 
//     public static final int EXIT_CODE_NO_ERROR = 0;
//     public static final int EXIT_CODE_UNKNOWN_ERROR = 1;
//     public static final int EXIT_CODE_PARSE_ERROR = 2;
//     public static final int EXIT_CODE_CONFIG_ERROR = 3;
//     public static final int EXIT_CODE_MAIL_ERROR = 4;
//     public static final int EXIT_CODE_IMPORT_ERROR = 5;
//     public static final int EXIT_CODE_FTP_ERROR = 6;
//     public static final int EXIT_CODE_SSH_ERROR = 7;
// 
//     private int myExitCode;
// 
//     /**
//      * Constructor
//      *
//      */
//     public SdiException( int aExitCode )
//     {
//         super();
//     }
// 
//     /**
//      * Constructor
//      *
//      * @param aMessage
//      */
//     public SdiException( String aMessage, int aExitCode )
//     {
//         super( aMessage );
//         myExitCode = aExitCode;
//     }
// 
//     /**
//      * Constructor
//      *
//      * @param aCause
//      */
//     public SdiException( Throwable aCause, int aExitCode )
//     {
//         super( aCause );
//         myExitCode = aExitCode;
//     }
// 
//     /**
//      * Constructor
//      *
//      * @param aMessage
//      * @param aCause
//      */
//     public SdiException( String aMessage, Throwable aCause, int aExitCode )
//     {
//         super( aMessage, aCause );
//         myExitCode = aExitCode;
//     }
// 
// 
//     /**
//      * @return exitCode
//      */
//     public int getExitCode()
//     {
//         return myExitCode;
//     }
// 
//     /**
//      * @param aThrowable
//      * @return
//      */
//     public static SdiException toSdiException( Throwable aThrowable )
//     {
//         return toSdiException( aThrowable, SdiException.EXIT_CODE_UNKNOWN_ERROR );
//     }
// 
//     /**
//      * @param aThrowable
//      * @return
//      */
//     public static SdiException toSdiException( Throwable aThrowable, int aErrorCode )
//     {
//         SdiException newEx;
//         if ( aThrowable instanceof SdiException )
//         {
//             newEx = (SdiException) aThrowable;
//         }
//         else
//         {
//             newEx = new SdiException( "Throwable caught ", aThrowable, aErrorCode );
//         } // if..else t instanceof SdiException
// 
//         return newEx;
//     }
// 
//     @Override
//     public String toString()
//     {
//         String result = super.toString();
// 
//         result += "; ExitCode: " + myExitCode;
// 
//         return result;
//     }
// 
// 
// }


import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import ch.sdi.core.annotations.SdiFilter;
import ch.sdi.core.exc.SdiException;
/**
 * Copyright (c) 2015 by the original author or authors.
 *
 * This code is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


package ch.sdi.core.impl.data.filter;





/**
 * Factory for instantiating the configured CollectFilters
 *
 * <p>
 *
 * @version 1.0 (30.01.2015)
 * @author  Heri
 */
@Component
public class FilterFactory
{

    /** logger for this class */
    private Logger myLog = LogManager.getLogger( FilterFactory.class );


    @Autowired
    private ApplicationContext myAppCtxt;

    /**
     * Instantiates the filter described by the given param.
     * <p>
     * The param is expected to be:
     * <pre>
     *     &lt;filterName>:&lt;fieldname>[:additionalParams]
     * </pre>
     * The number of additional parameters is dependant of the particular filter type.
     * <p>
     * @param aParams
     * @return the initialized filter
     * @throws SdiException on any problem
     */
    public CollectFilter<?> getFilter( String aParams ) throws SdiException
    {
        if ( !StringUtils.hasText( aParams ) )
        {
            throw new SdiException( "Given param is empty!",
                                    SdiException.EXIT_CODE_CONFIG_ERROR );

        }

        String[] values = aParams.split( ":", 3 );

        if ( values.length < 2 )
        {
// Path: SDI-core/src/main/java/ch/sdi/core/exc/SdiException.java
// public class SdiException extends Exception
// {
//     private static final long serialVersionUID = 1L;
// 
//     public static final int EXIT_CODE_NO_ERROR = 0;
//     public static final int EXIT_CODE_UNKNOWN_ERROR = 1;
//     public static final int EXIT_CODE_PARSE_ERROR = 2;
//     public static final int EXIT_CODE_CONFIG_ERROR = 3;
//     public static final int EXIT_CODE_MAIL_ERROR = 4;
//     public static final int EXIT_CODE_IMPORT_ERROR = 5;
//     public static final int EXIT_CODE_FTP_ERROR = 6;
//     public static final int EXIT_CODE_SSH_ERROR = 7;
// 
//     private int myExitCode;
// 
//     /**
//      * Constructor
//      *
//      */
//     public SdiException( int aExitCode )
//     {
//         super();
//     }
// 
//     /**
//      * Constructor
//      *
//      * @param aMessage
//      */
//     public SdiException( String aMessage, int aExitCode )
//     {
//         super( aMessage );
//         myExitCode = aExitCode;
//     }
// 
//     /**
//      * Constructor
//      *
//      * @param aCause
//      */
//     public SdiException( Throwable aCause, int aExitCode )
//     {
//         super( aCause );
//         myExitCode = aExitCode;
//     }
// 
//     /**
//      * Constructor
//      *
//      * @param aMessage
//      * @param aCause
//      */
//     public SdiException( String aMessage, Throwable aCause, int aExitCode )
//     {
//         super( aMessage, aCause );
//         myExitCode = aExitCode;
//     }
// 
// 
//     /**
//      * @return exitCode
//      */
//     public int getExitCode()
//     {
//         return myExitCode;
//     }
// 
//     /**
//      * @param aThrowable
//      * @return
//      */
//     public static SdiException toSdiException( Throwable aThrowable )
//     {
//         return toSdiException( aThrowable, SdiException.EXIT_CODE_UNKNOWN_ERROR );
//     }
// 
//     /**
//      * @param aThrowable
//      * @return
//      */
//     public static SdiException toSdiException( Throwable aThrowable, int aErrorCode )
//     {
//         SdiException newEx;
//         if ( aThrowable instanceof SdiException )
//         {
//             newEx = (SdiException) aThrowable;
//         }
//         else
//         {
//             newEx = new SdiException( "Throwable caught ", aThrowable, aErrorCode );
//         } // if..else t instanceof SdiException
// 
//         return newEx;
//     }
// 
//     @Override
//     public String toString()
//     {
//         String result = super.toString();
// 
//         result += "; ExitCode: " + myExitCode;
// 
//         return result;
//     }
// 
// 
// }


// Path: SDI-core/src/main/java/ch/sdi/core/impl/data/filter/FilterFactory.java
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import ch.sdi.core.annotations.SdiFilter;
import ch.sdi.core.exc.SdiException;

/**
 * Copyright (c) 2015 by the original author or authors.
 *
 * This code is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


package ch.sdi.core.impl.data.filter;





/**
 * Factory for instantiating the configured CollectFilters
 *
 * <p>
 *
 * @version 1.0 (30.01.2015)
 * @author  Heri
 */
@Component
public class FilterFactory
{

    /** logger for this class */
    private Logger myLog = LogManager.getLogger( FilterFactory.class );


    @Autowired
    private ApplicationContext myAppCtxt;

    /**
     * Instantiates the filter described by the given param.
     * <p>
     * The param is expected to be:
     * <pre>
     *     &lt;filterName>:&lt;fieldname>[:additionalParams]
     * </pre>
     * The number of additional parameters is dependant of the particular filter type.
     * <p>
     * @param aParams
     * @return the initialized filter
     * @throws SdiException on any problem
     */
    public CollectFilter<?> getFilter( String aParams ) throws SdiException
    {
        if ( !StringUtils.hasText( aParams ) )
        {
            throw new SdiException( "Given param is empty!",
                                    SdiException.EXIT_CODE_CONFIG_ERROR );

        }

        String[] values = aParams.split( ":", 3 );

        if ( values.length < 2 )
        {
            throw new SdiException( "Given param does not contain at least 2 parts: " + aParams,