Package org.salamanca.commands.periodo

Source Code of org.salamanca.commands.periodo.InsertarPeriodo

package org.salamanca.commands.periodo;

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

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class InsertarPeriodo implements ICommand {
    Periodo periodo;
    Alumno alumno;
    /**
     * InsertarPersona
     *
     * @param persona Persona
     */
    public InsertarPeriodo(Alumno alumno, Periodo periodo) {
        this.periodo = periodo;
        this.alumno = alumno;
    }

    /**
     * execute
     */
    public void execute() throws MessageException {
        if (alumno.getVectorPeriodos().size()>=
            alumno.getCurso().getCantidadPeriodos()+1) {//es mas uno porque tambien va el Examen final
            throw new MessageException(
                    "Este curso no permite mas periodos");
        }

        PersistenceManager pm = BrokerServer.instance().getPMF().
                                getPersistenceManager();
        Alumno alumnoPM = (Alumno) pm.getObjectById(javax.jdo.JDOHelper.
                getObjectId(alumno),true);

        pm.currentTransaction().begin();
        pm.makePersistent(periodo);
        alumnoPM.addPeriodo(periodo);
        pm.currentTransaction().commit();

    }

    /**
     * getCommandName
     *
     * @return String
     */
    public String getCommandName() {
        return this.getClass().getName();
    }

    /**
     * getBarDelimitedParameters
     *
     * @return String
     */
    public String getBarDelimitedParameters() {
        return alumno.getVectorPeriodos().size() + "|" +
                alumno.getPersona().getNombre() + "|" +
                alumno.getPersona().getApellido() + "|" +
                periodo.getEscribir() + "|" + periodo.getEscuchar() + "|" +
                periodo.getGramatica() + "|" + periodo.getHablar() +
                "|" + periodo.getLeer() + "|" +
                periodo.getInasistenciasInjustificadas() + "|" +
                periodo.getInasistenciasjustificadas();
    }

}
TOP

Related Classes of org.salamanca.commands.periodo.InsertarPeriodo

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.