Package org.salamanca.commands.cuota

Source Code of org.salamanca.commands.cuota.InsertarCuota

package org.salamanca.commands.cuota;

import org.salamanca.commands.ICommand;
import org.salamanca.domain.CuotaBasica;
import org.salamanca.domain.Curso;
import javax.jdo.PersistenceManager;
import org.salamanca.broker.BrokerServer;
import org.salamanca.commands.MessageException;
import java.util.Date;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class InsertarCuota implements ICommand {
    CuotaBasica cuota = null;
    Curso curso = null;

    public InsertarCuota(CuotaBasica cuota, Curso curso) {
        this.cuota = cuota;
        this.curso = curso;
    }

    /**
     * execute
     */
    public void execute() throws MessageException {



        if (cuota.getConcepto().trim().length() == 0) {
            throw new MessageException(
                    "EL concepto de la cuota no puede estar vacio");
        }

        if (cuota.getFechaVencimiento().before(new Date())) {
            throw new MessageException(
                    "La fecha de vencimiento no puede ser anterior"+
                  " a la fecha actual del sistema");
        }
        if (cuota.getImporte()<0) {
    throw new MessageException(
            "No se permiten valores negativos en la cuota");
}

        PersistenceManager pm = BrokerServer.instance().getPMF().
                                getPersistenceManager();
        pm.currentTransaction().begin();

        Curso cursoPM = (Curso) pm.getObjectById(javax.jdo.JDOHelper.
                                                 getObjectId(curso),true);
        pm.makePersistent(cuota);
        cursoPM.addCuotaBasica(cuota);
        pm.currentTransaction().commit();

    }


//v.size() == 0 ||
    /**
     * getCommandName
     *
     * @return String
     */
    public String getCommandName() {
        return this.getClass().getName();
    }

    /**
     * getBarDelimitedParameters
     *
     * @return String
     */
    public String getBarDelimitedParameters() {
        return curso.getNombre() + "|" + cuota.getFechaVencimiento() + "|" +
                cuota.getConcepto() + "|" + cuota.getImporte() + "|" +
                cuota.isPagoExtra();
    }

}
TOP

Related Classes of org.salamanca.commands.cuota.InsertarCuota

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.