Package com.zesped.model

Examples of com.zesped.model.User


    oTxt = oTxtBody;
    oHtm = oHtmBody;
  }
 
  public void run() {
    User oUsr = null;
    String sUid;
    FastStreamReplacer oRpl = new FastStreamReplacer();
      MailSessionHandler oHlr = null;
    HashMap<String,Object> oActivationInfo = new HashMap<String,Object>();

      Log.out.debug("Begin AsyncSendInvitation()");
     
      try {
      oHlr = new MailSessionHandler();
    } catch (IOException ioe) {
      Log.out.error("AsyncSendInvitation new MailSessionHandler() "+ioe.getClass().getName()+" "+ioe.getMessage(), ioe);
    }
     
      AtrilSession oSes = DAO.getAdminSession("AsyncSendInvitation");
      oSes.autoCommit(true);
      Dms oDms = oSes.getDms();
    CustomerAccount oAcc = new CustomerAccount(oDms, sAccId);
     
    for (int t=0; t<aTxprs.length; t++) {
      String sTxpId = aTxprs[t];
        TaxPayer oTxp = new TaxPayer (oDms, sTxpId);

        try {

          sUid = User.forEmail(sEmail);
        oUsr = new User(oSes, sUid);
        try {
          oUsr.allowTaxPayer(oSes, oTxp.id());
        } catch (Exception xcpt) {
          Log.out.error("AsyncSendInvitation User.allowTaxPayer() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
        }

        } catch (ElementNotFoundException enfe) {

        String sPwd = Gadgets.generateRandomId(6, "abcdefghjkmnpqrtuvwxyz", Character.LOWERCASE_LETTER);
        sUid = User.create(oSes, sRec1stName, sRec2ndName, sRecEmail, sPwd, false).id();
        oUsr = new User(oSes, sUid);
        oUsr.canApproveInvoices(bApprove);
        oUsr.canSettleBillNotes(bSettle);
        oUsr.canUsePremiumCaptureServiceFlavor(bPremium);
        oUsr.setRole(oSes, oAcc, Role.user);
        oUsr.save(oSes);     

        try {
          oUsr.allowTaxPayer(oSes, oTxp.id());
        } catch (Exception xcpt) {
          Log.out.error("AsyncSendInvitation User.allowTaxPayer() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
        }
       
        HashMap oMap = FastStreamReplacer.createMap(new String[] {"1","2","3","4","5","6"},
                              new String[] {oUsr.getFirstName(), sSender1stName, sSender2ndName, oTxp.getBusinessName() + (aTxprs.length>1 ? " y a otras " + String.valueOf(aTxprs.length-1) + " más": ""), oUsr.id(), sPwd});
          ByteArrayOutputStream oByOut = new ByteArrayOutputStream();
          PrintStream oPrt = new PrintStream(oByOut);             
          try {
              Log.out.debug("sending email");
          oHlr.sendMessage("Acceso a zesped", "Zesped", "noreply@zesped.com", "noreply@zesped.com",
                           new String[] {sEmail}, RecipientType.TO, oRpl.replace(oTxt, oMap), oRpl.replace(oHtm, oMap),
                           "ISO8859_1", null, null, null, oPrt);
        } catch (Exception xcpt) {
          Log.out.error("AsyncSendInvitation MailSessionHandler.sendMessage() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
        }
          oPrt.close();
          Log.out.info(oByOut.toString());
          try {
          oByOut.close();
        } catch (IOException ignore) { }
        DAO.log(oSes, oUsr.getDocument(), User.class, "SEND INVITATION", AtrilEvent.Level.INFO, sEmail);
      }
        if (bCreateEmp) {
        Employees oEms = oTxp.employees(oSes);
        try {
          oEms.seek(oSes, oUsr.getNickName());
        } catch (InstantiationException xcpt) {
          Log.out.error("AsyncSendInvitation Employees.seek() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
        } catch (IllegalAccessException xcpt) {
          Log.out.error("AsyncSendInvitation Employees.seek() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);     
        } catch (ElementNotFoundException enfe) {
              Log.out.debug("creating employee");
          Employee oEmp = new Employee(oSes, oEms);
            oEmp.setUuid(oUsr.getNickName());
            oEmp.setName(oUsr.getFirstName()+" "+oUsr.getLastName());
            oEmp.setEmployeeId("");
            oEmp.setTaxId("");
            oEmp.setActive(true);
            oEmp.save(oSes);
            if (0==t) oActivationInfo.put("employee_uuid", oUsr.getNickName());
        }
      }           
    } // next

    oActivationInfo.put("nickname", oUsr.getNickName());
    oActivationInfo.put("password", oUsr.getPassword());
    oActivationInfo.put("fullname", oUsr.getFirstName()+" "+oUsr.getLastName());
    oActivationInfo.put("email", oUsr.getEmail());
    oActivationInfo.put("user_docid", oUsr.id());
    oActivationInfo.put("user_uuid", oUsr.getString("user_uuid"));
    oActivationInfo.put("businessname", oAcc.getBusinessName());
    oActivationInfo.put("customer_acount", oAcc.getUuid());
    oActivationInfo.put("customer_account_docid", oAcc.id());
    oActivationInfo.put("taxpayer_docid", aTxprs[0]);
    oActivationInfo.put("can_approve", oUsr.getString("can_approve"));
    oActivationInfo.put("can_settle", oUsr.getString("can_settle"));
    oActivationInfo.put("can_premium", oUsr.getString("can_premium"));
    oActivationInfo.put("role", Role.user);
    oActivationInfo.put("hasorders", new Boolean(oAcc.orders(oSes).count()>0));
     
    try {
      Cache.putEntry(oUsr.id()+"activationinfo", oActivationInfo);
    } catch (Exception xcpt) {
      Log.out.error("AsyncSendInvitation Cache.putEntry() "+xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
    }
   
    oSes.disconnect();
View Full Code Here


  public void setTaxId(String sTaxId) {
    taxId = sTaxId;
  }
 
  public SignUpForm() {
    user = new User();
  }
View Full Code Here

    final boolean bActive = getParam("active","").length()>0;   
    if (getErrorsCount()==0) {
      Log.out.debug("SaveUser.save("+sFormerId+")");
      Log.out.debug("permissions is "+sPerms+" selected TaxPayers are "+sSelected);
      try {
        User oUsr;
        connect();
        CustomerAccount oAcc = new CustomerAccount(getSession().getDms(), getSessionAttribute("customer_account_docid"));
        Log.out.debug("Got customer account "+oAcc.id());
        if (sFormerId.length()>0) {
          oUsr = new User(getSession(), sFormerId);
          LoginInterceptor.expire(oUsr.getNickName(), oUsr.getPassword());
          oUsr.setFirstName(getParam("user.firstName"));
          oUsr.setLastName(getParam("user.lastName"));
          oUsr.setEmail(getParam("user.email"));
          if (bActive) oUsr.activate(); else oUsr.deactivate();
          if (!Role.valueOf(sRole).equals(Role.admin)) {
            oUsr.canApproveInvoices(getParam("approve","").length()>0);
            oUsr.canSettleBillNotes(getParam("settle","").length()>0);
            oUsr.canUsePremiumCaptureServiceFlavor(getParam("premium","").length()>0);
          } else {
            oUsr.canApproveInvoices(true);
            oUsr.canSettleBillNotes(true);
            oUsr.canUsePremiumCaptureServiceFlavor(true);
          }
          oUsr.save(getSession());
          if (!oUsr.getRole(oAcc).equals(Role.valueOf(sRole)))
            oUsr.setRole(getSession(), oAcc, Role.valueOf(sRole));
        } else {
          String sUid = User.create(getSession(), getParam("user.firstName"), getParam("user.lastName"), getParam("user.email"), getParam("user.password"), bActive).id();
          commit();
          oUsr = new User(getSession(), sUid);
          oUsr.canApproveInvoices(getParam("approve","").length()>0);
          oUsr.canSettleBillNotes(getParam("settle","").length()>0);
          oUsr.canUsePremiumCaptureServiceFlavor(getParam("premium","").length()>0);
          oUsr.setRole(getSession(), oAcc, Role.valueOf(sRole));
        }
        if (sTxpr.length()>0) {
          Dms oDms = getSession().getDms();
            TaxPayer oTxp = new TaxPayer(oDms, sTxpr);
          Employees oEms = oTxp.employees(getSession());
          Employee oEmp = new Employee();
          Document e = oEmp.exists(getSession(), "employee_uuid", oUsr.getNickName());
            if (e!=null) {
            Log.out.debug("Employee already exists");
              oEmp.load(getSession(), e.id());
              if (!oEmp.parentId().equals(oEms.id()))
                oEmp.getDocument().parents().replace(oDms.getDocument(oEmp.parentId()), oDms.getDocument(oEms.id()));
            } else {
            Log.out.debug("Employee does not exist");
              oEmp = new Employee(getSession(), oEms);
              oEmp.setUuid(oUsr.getNickName());
            }
            oEmp.setName(oUsr.getFirstName()+" "+oUsr.getLastName());
            oEmp.setEmployeeId(getParam("employee.employeeId"));
            oEmp.setTaxId(getParam("employee.taxId"));
            oEmp.setActive(bActive);
            oEmp.save(getSession());
        }
        oUsr.allowAll(getSession());
        if (sSelected.length()>0) {
          String[] aSelected = sSelected.split("###");
          if (sPerms.equals("allow"))
            for (int t=0; t<aSelected.length; t++)
              oUsr.allowTaxPayer(getSession(), aSelected[t]);
          else if (sPerms.equals("deny"))
            for (int t=0; t<aSelected.length; t++)
              if (!sTxpr.equals(aSelected[t]))
                oUsr.denyTaxPayer(getSession(), aSelected[t]);
          if (sTxpr.length()>0)
            if (Gadgets.search(aSelected, sTxpr)<0)
              oUsr.allowTaxPayer(getSession(), sTxpr);
        }
        disconnect();
          addDataLine("id",oUsr.id());
      } catch (Exception xcpt) {
        Log.out.error("SaveUser.save() "+xcpt.getMessage(), xcpt);
        addError(new SimpleError(xcpt.getMessage()));
      } finally {
        close();
View Full Code Here

TOP

Related Classes of com.zesped.model.User

Copyright © 2018 www.massapicom. 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.