}
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();