Package com.zesped.util

Source Code of com.zesped.util.AsyncAccountCreator

package com.zesped.util;

import com.knowgate.misc.Gadgets;
import com.zesped.DAO;
import com.zesped.Log;
import com.zesped.model.CustomerAccount;
import com.zesped.model.Employee;
import com.zesped.model.TaxPayer;
import com.zesped.model.User;

import es.ipsa.atril.sec.authentication.AtrilSession;

public class AsyncAccountCreator extends Thread {

  private User oUsr;
  public AsyncAccountCreator(User u) {
    oUsr = u;
  }

  public void run() {
    AtrilSession oSes = null;
    try {
      oSes = DAO.getAdminSession("AsyncAccountCreator");
      final String sTemporaryBusinessName = Gadgets.generateUUID();     
      CustomerAccount oCac = CustomerAccount.create(oSes, oUsr, sTemporaryBusinessName);
      oSes.commit();
      TaxPayer oTxp = TaxPayer.create(oSes, oCac, sTemporaryBusinessName, "", oUsr.getFirstName()+" "+oUsr.getLastName(), oUsr.getEmail(), true, DAO.getVolumesMountBase());
      oSes.commit();
      Employee oEmp = new Employee(oSes, oTxp.employees(oSes));
      oEmp.setActive(true);
      oEmp.setUuid(oUsr.getNickName());
      oEmp.setName(oUsr.getFirstName()+" "+oUsr.getLastName());
      oEmp.save(oSes);
      oSes.commit();
      oSes.disconnect();
      oSes.close();
      oSes=null;
    } catch (Exception xcpt) {
      Log.out.error("AsyncAccountCreator.run() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
    } finally {
      if (oSes!=null) {
        if (oSes.isConnected()) oSes.disconnect();
        if (oSes.isOpen()) oSes.close();
      }
    }
  }
}
TOP

Related Classes of com.zesped.util.AsyncAccountCreator

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.