Package org.salamanca.commands.vale

Source Code of org.salamanca.commands.vale.EliminarVale

package org.salamanca.commands.vale;

import org.salamanca.domain.Vale;
import javax.jdo.PersistenceManager;
import org.salamanca.broker.BrokerServer;
import org.salamanca.commands.MessageException;
import org.salamanca.domain.Persona;
import org.salamanca.commands.ICommand;
import java.util.Date;
import java.util.Calendar;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class EliminarVale  implements ICommand{


  Vale vale;
  /**
   * InsertarVale
   *
   * @param vale Vale
   * @param persona Persona
   */
  public EliminarVale(Vale vale) {
      this.vale = vale;


  }


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


      Date fechaYa = new Date();

       if (vale.getFechaEmision() != null) {
           Calendar calYa = Calendar.getInstance();
           calYa.setTime(fechaYa);
           Calendar calUtil = Calendar.getInstance();
           calUtil.setTime(vale.getFechaEmision());

           if (calYa.get(Calendar.DAY_OF_YEAR) !=
               calUtil.get(Calendar.DAY_OF_YEAR)) {
               throw new MessageException(
                       "Los vales solo se pueden eliminados el mismo dia que fueron emitidos");
           }

        }


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

      pm.currentTransaction().begin();

      Vale valePM = (Vale) pm.getObjectById(javax.jdo.JDOHelper.
              getObjectId(
                      vale), true);


      valePM.getPersona().removeVale(valePM);
      pm.deletePersistent(valePM);

      pm.currentTransaction().commit();

  }

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

  /**
   * getBarDelimitedParameters
   *
   * @return String
   */
  public String getBarDelimitedParameters() {
      return vale.getPersona().getNombre() + "|" + vale.getImporte() + "|" +
              vale.getFechaEmision();
  }



}
TOP

Related Classes of org.salamanca.commands.vale.EliminarVale

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.