/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2009 C.Marchand - christophe.marchand@axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS 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 3 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fr.gouv.finances.dgfip.xemelios.batch.imports.utils;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import org.apache.log4j.Logger;

public class ImportVOFull extends ImportVOPK implements java.io.Serializable {
    private static final Logger logger = Logger.getLogger(ImportVOFull.class);

    /**
     * MAPS UTI_LOGIN column.
     */
    protected java.lang.String utiLogin;
    protected boolean isUtiLoginSet = false;
    protected boolean isUtiLoginModified = false;
    /**
     * MAPS FILE_NAME column.
     */
    protected java.lang.String fileName;
    protected boolean isFileNameSet = false;
    protected boolean isFileNameModified = false;
    /**
     * MAPS FILE_TYPE column.
     */
    protected java.lang.String fileType;
    protected boolean isFileTypeSet = false;
    protected boolean isFileTypeModified = false;
    /**
     * MAPS SUBMIT_DATE column.
     */
    protected java.sql.Timestamp submitDate;
    protected boolean isSubmitDateSet = false;
    protected boolean isSubmitDateModified = false;
    /**
     * MAPS END_DATE column.
     */
    protected java.sql.Timestamp endDate;
    protected boolean isEndDateSet = false;
    protected boolean isEndDateModified = false;
    /**
     * MAPS STATUS column.
     */
    protected java.lang.Integer status;
    protected boolean isStatusSet = false;
    protected boolean isStatusModified = false;
    /**
     * MAPS COLLECTIVITE column.
     */
    protected java.lang.String collectivite;
    protected boolean isCollectiviteSet = false;
    protected boolean isCollectiviteModified = false;
    /**
     * MAPS BUDGET column.
     */
    protected java.lang.String budget;
    protected boolean isBudgetSet = false;
    protected boolean isBudgetModified = false;
    /**
     * MAPS COLLECTIVITE_LIB column.
     */
    protected java.lang.String collectiviteLib;
    protected boolean isCollectiviteLibSet = false;
    protected boolean isCollectiviteLibModified = false;
    /**
     * MAPS BUDGET_LIB column.
     */
    protected java.lang.String budgetLib;
    protected boolean isBudgetLibSet = false;
    protected boolean isBudgetLibModified = false;
    /**
     * MAPS ERROR_MESSAGE column.
     */
    protected java.lang.String errorMessage;
    protected boolean isErrorMessageSet = false;
    protected boolean isErrorMessageModified = false;

    /**
     * Default Constructor
     */
    public ImportVOFull() {
        super();
    }

    /**
     * Constructs a new Full object, initializing only PK fileds.
     */
    public ImportVOFull(java.lang.String importId) {
        super(importId);
    }

    public ImportVOFull(ResultSet rs) throws SQLException {
        this();
        int i = 1;
        setInnerUtiLogin(rs.getString(i++));
        setInnerImportId(rs.getString(i++));
        setInnerFileName(rs.getString(i++));
        setInnerFileType(rs.getString(i++));
        try {
            setInnerSubmitDate(rs.getTimestamp(i++));
        } catch(SQLException sqlEx) {
            // mysql jdbc driver throws a SQLException when value is null
        }
        try {
            setInnerEndDate(rs.getTimestamp(i++));
        } catch(SQLException sqlEx) {
            // mysql jdbc driver throws a SQLException when value is null
        }
        int statusTmp = rs.getInt(i++);
        if (!rs.wasNull()) {
            setInnerStatus(new java.lang.Integer(statusTmp));
        }
        setInnerCollectivite(rs.getString(i++));
        setInnerBudget(rs.getString(i++));
        setInnerCollectiviteLib(rs.getString(i++));
        setInnerBudgetLib(rs.getString(i++));
        setInnerErrorMessage(rs.getString(i++));
    }

    public java.lang.String getUtiLogin() {
        return utiLogin;
    }

    public void setUtiLogin(java.lang.String utiLogin) {
        this.utiLogin = utiLogin;
        this.isUtiLoginModified = true;
    }

    protected void setInnerUtiLogin(java.lang.String utiLogin) {
        this.utiLogin = utiLogin;
        this.isUtiLoginSet = true;
    }

    public java.lang.String getStrUtiLogin(java.lang.String returnInCaseOfNull) {
        return utiLogin != null ? utiLogin.toString() : returnInCaseOfNull;
    }

    public java.lang.String getFileName() {
        return fileName;
    }

    public void setFileName(java.lang.String fileName) {
        this.fileName = fileName;
        this.isFileNameModified = true;
    }

    protected void setInnerFileName(java.lang.String fileName) {
        this.fileName = fileName;
        this.isFileNameSet = true;
    }

    public java.lang.String getStrFileName(java.lang.String returnInCaseOfNull) {
        return fileName != null ? fileName.toString() : returnInCaseOfNull;
    }

    public java.lang.String getFileType() {
        return fileType;
    }

    public void setFileType(java.lang.String fileType) {
        this.fileType = fileType;
        this.isFileTypeModified = true;
    }

    protected void setInnerFileType(java.lang.String fileType) {
        this.fileType = fileType;
        this.isFileTypeSet = true;
    }

    public java.lang.String getStrFileType(java.lang.String returnInCaseOfNull) {
        return fileType != null ? fileType.toString() : returnInCaseOfNull;
    }

    public java.sql.Timestamp getSubmitDate() {
        return submitDate;
    }

    public void setSubmitDate(java.sql.Timestamp submitDate) {
        this.submitDate = submitDate;
        this.isSubmitDateModified = true;
    }

    protected void setInnerSubmitDate(java.sql.Timestamp submitDate) {
        this.submitDate = submitDate;
        this.isSubmitDateSet = true;
    }

    public java.lang.String getStrSubmitDate(java.lang.String returnInCaseOfNull) {
        return submitDate != null ? submitDate.toString() : returnInCaseOfNull;
    }

    public java.sql.Timestamp getEndDate() {
        return endDate;
    }

    public void setEndDate(java.sql.Timestamp endDate) {
        this.endDate = endDate;
        this.isEndDateModified = true;
    }

    protected void setInnerEndDate(java.sql.Timestamp endDate) {
        this.endDate = endDate;
        this.isEndDateSet = true;
    }

    public java.lang.String getStrEndDate(java.lang.String returnInCaseOfNull) {
        return endDate != null ? endDate.toString() : returnInCaseOfNull;
    }

    public java.lang.Integer getStatus() {
        return status;
    }

    public void setStatus(java.lang.Integer status) {
        this.status = status;
        this.isStatusModified = true;
        if(status==5 || status==4)
            setEndDate(new Timestamp(System.currentTimeMillis()));

    }

    protected void setInnerStatus(java.lang.Integer status) {
        this.status = status;
        this.isStatusSet = true;
    }

    public java.lang.String getStrStatus(java.lang.String returnInCaseOfNull) {
        return status != null ? status.toString() : returnInCaseOfNull;
    }

    public java.lang.String getCollectivite() {
        return collectivite;
    }

    public void setCollectivite(java.lang.String collectivite) {
        this.collectivite = collectivite;
        this.isCollectiviteModified = true;
    }

    protected void setInnerCollectivite(java.lang.String collectivite) {
        this.collectivite = collectivite;
        this.isCollectiviteSet = true;
    }

    public java.lang.String getStrCollectivite(java.lang.String returnInCaseOfNull) {
        return collectivite != null ? collectivite.toString() : returnInCaseOfNull;
    }

    public java.lang.String getBudget() {
        return budget;
    }

    public void setBudget(java.lang.String budget) {
        this.budget = budget;
        this.isBudgetModified = true;
    }

    protected void setInnerBudget(java.lang.String budget) {
        this.budget = budget;
        this.isBudgetSet = true;
    }

    public java.lang.String getStrBudget(java.lang.String returnInCaseOfNull) {
        return budget != null ? budget.toString() : returnInCaseOfNull;
    }

    public java.lang.String getCollectiviteLib() {
        return collectiviteLib;
    }

    public void setCollectiviteLib(java.lang.String collectiviteLib) {
        this.collectiviteLib = collectiviteLib;
        this.isCollectiviteLibModified = true;
    }

    protected void setInnerCollectiviteLib(java.lang.String collectiviteLib) {
        this.collectiviteLib = collectiviteLib;
        this.isCollectiviteLibSet = true;
    }

    public java.lang.String getStrCollectiviteLib(java.lang.String returnInCaseOfNull) {
        return collectiviteLib != null ? collectiviteLib.toString() : returnInCaseOfNull;
    }

    public java.lang.String getBudgetLib() {
        return budgetLib;
    }

    public void setBudgetLib(java.lang.String budgetLib) {
        this.budgetLib = budgetLib;
        this.isBudgetLibModified = true;
    }

    protected void setInnerBudgetLib(java.lang.String budgetLib) {
        this.budgetLib = budgetLib;
        this.isBudgetLibSet = true;
    }

    public java.lang.String getStrBudgetLib(java.lang.String returnInCaseOfNull) {
        return budgetLib != null ? budgetLib.toString() : returnInCaseOfNull;
    }

    public java.lang.String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(java.lang.String errorMessage) {
        this.errorMessage = errorMessage;
        this.isErrorMessageModified = true;
    }

    protected void setInnerErrorMessage(java.lang.String errorMessage) {
        this.errorMessage = errorMessage;
        this.isErrorMessageSet = true;
    }

    public java.lang.String getStrErrorMessage(java.lang.String returnInCaseOfNull) {
        return errorMessage != null ? errorMessage.toString() : returnInCaseOfNull;
    }

    public void validate() throws IllegalStateException {
        if (utiLogin == null) {
            throw new IllegalStateException("UTI_LOGIN " + VoConstants.NOT_NULL_MSG);
        }
        if (utiLogin != null && utiLogin.length() > UTI_LOGIN_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "UTI_LOGIN" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (importId == null) {
            throw new IllegalStateException("IMPORT_ID " + VoConstants.NOT_NULL_MSG);
        }
        if (importId != null && importId.length() > IMPORT_ID_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "IMPORT_ID" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (fileName == null) {
            throw new IllegalStateException("FILE_NAME " + VoConstants.NOT_NULL_MSG);
        }
        if (fileName != null && fileName.length() > FILE_NAME_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "FILE_NAME" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (fileType == null) {
            throw new IllegalStateException("FILE_TYPE " + VoConstants.NOT_NULL_MSG);
        }
        if (fileType != null && fileType.length() > FILE_TYPE_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "FILE_TYPE" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (status == null) {
            throw new IllegalStateException("STATUS " + VoConstants.NOT_NULL_MSG);
        }
        if (collectivite != null && collectivite.length() > COLLECTIVITE_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "COLLECTIVITE" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (budget != null && budget.length() > BUDGET_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "BUDGET" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (collectiviteLib != null && collectiviteLib.length() > COLLECTIVITE_LIB_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "COLLECTIVITE_LIB" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (budgetLib != null && budgetLib.length() > BUDGET_LIB_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "BUDGET_LIB" + VoConstants.TOO_LONG_MSG_SUFX);
        }
        if (errorMessage != null && errorMessage.length() > ERROR_MESSAGE_LEN) {
            throw new IllegalStateException(VoConstants.TOO_LONG_MSG_PRFX + "ERROR_MESSAGE" + VoConstants.TOO_LONG_MSG_SUFX);
        }
    }
    public void determinateStatus() {
        if(status==5) return;
        boolean correct = true;
        if(collectivite==null || collectivite.length()==0) correct = false;
        if(collectiviteLib==null || collectiviteLib.length()==0) correct = false;
        if(budget==null || budget.length()==0) correct=false;
        if(budgetLib==null || budgetLib.length()==0) correct=false;
        if(fileType==null || fileType.length()==0) correct=false;
        if(correct) setStatus(6);
        else setStatus(2);
    }
}
        
