/** * Get User * @return user */ public MUser GetUser() { if (GetAD_User_ID() == 0) { _user = null; } else if (_user == null || _user.GetAD_User_ID() != GetAD_User_ID()) { _user = new MUser(GetCtx(), GetAD_User_ID(), Get_TrxName()); } return(_user); }
/** * Set AD_User_ID from email */ public void SetAD_User_ID() { if (GetAD_User_ID() != 0) { return; } String email = GetEMail(); if (email != null && email.Length > 0) { _user = MUser.Get(GetCtx(), email, Get_TrxName()); if (_user != null) { base.SetAD_User_ID(_user.GetAD_User_ID()); if (GetC_BPartner_ID() == 0) { SetC_BPartner_ID(_user.GetC_BPartner_ID()); } else if (_user.GetC_BPartner_ID() != GetC_BPartner_ID()) { log.Warning("@C_BPartner_ID@ (ID=" + GetC_BPartner_ID() + ") <> @AD_User_ID@ @C_BPartner_ID@ (ID=" + _user.GetC_BPartner_ID() + ")"); } } } }
/// <summary> /// Get User Preference /// </summary> /// <param name="user">user </param> /// <param name="createNew">create new if not found</param> /// <returns>user preference</returns> public static MUserPreference GetOfUser(MUser user, bool createNew) { MUserPreference retValue = null; String sql = "SELECT * FROM AD_UserPreference WHERE AD_User_ID='" + user.GetAD_User_ID() + "'"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql); foreach (DataRow rs in ds.Tables[0].Rows) { retValue = new MUserPreference(user.GetCtx(), rs, null); } ds.Dispose(); } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } if (retValue == null && createNew) { retValue = new MUserPreference(user.GetCtx(), 0, null); retValue.SetClientOrg(user); retValue.SetAD_User_ID(user.GetAD_User_ID()); retValue.Save(); } return(retValue); } // getOfUser
/// <summary> /// Set Created/Updated By /// </summary> /// <param name="email">mail address</param> private void SetCreatedBy(String email) { if (email == null || email.Length == 0) { return; } int AD_User_ID = MUser.GetAD_User_ID(email, GetAD_Client_ID()); Set_ValueNoCheck("CreatedBy", AD_User_ID); SetUpdatedBy(AD_User_ID); GetCtx().SetContext("##AD_User_ID", AD_User_ID.ToString()); SetAD_User_ID(AD_User_ID); }
/// <summary> /// Send Email Now /// </summary> /// <param name="from">optional from user</param> /// <param name="to">to user</param> /// <param name="email">email</param> /// <returns>true if sent</returns> private bool SendEmailNow(MUser from, MUser to, EMail email) { String msg = email.Send(); // X_AD_UserMail um = new X_AD_UserMail(GetCtx(), 0, null); um.SetClientOrg(this); um.SetAD_User_ID(to.GetAD_User_ID()); um.SetSubject(email.GetSubject()); um.SetMailText(email.GetMessageCRLF()); if (email.IsSentOK()) { um.SetMessageID(email.GetMessageID()); } else { um.SetMessageID(email.GetSentMsg()); um.SetIsDelivered(X_AD_UserMail.ISDELIVERED_No); } um.Save(); // if (email.IsSentOK()) { //if (from != null) // log.info("Sent Email: " + email.GetSubject() + " from " + from.GetEMail() + " to " + to.GetEMail()); //else // log.info("Sent Email: " + email.GetSubject() + " to " + to.GetEMail()); return(true); } else { //if (from != null) // log.warning("Could NOT Send Email: " + email.GetSubject() // + " from " + from.GetEMail() // + " to " + to.GetEMail() + ": " + msg // + " (" + GetName() + ")"); //else // log.warning("Could NOT Send Email: " + email.GetSubject() // + " to " + to.GetEMail() + ": " + msg // + " (" + GetName() + ")"); return(false); } }
/** * Create Trial Asset * @param ctx context * @param user user * @param entityType entity type * @return asset or null if no product found */ public static MAsset GetTrial(Ctx ctx, MUser user, String entityType) { if (user == null) { _log.Warning("Cannot create Trial - No User"); return(null); } if (Utility.Util.IsEmpty(entityType)) { _log.Warning("Cannot create Trial - No Entity Type"); return(null); } MProduct product = MProduct.GetTrial(ctx, entityType); if (product == null) { _log.Warning("No Trial for Entity Type=" + entityType); return(null); } // DateTime now = Convert.ToDateTime(CommonFunctions.CurrentTimeMillis()); // MAsset asset = new MAsset(ctx, 0, null); asset.SetClientOrg(user); asset.SetAssetServiceDate(now); asset.SetIsOwned(false); asset.SetIsTrialPhase(true); // MBPartner partner = new MBPartner(ctx, user.GetC_BPartner_ID(), null); String documentNo = "Trial"; // Value String value = partner.GetValue() + "_" + product.GetValue(); if (value.Length > 40 - documentNo.Length) { value = value.Substring(0, 40 - documentNo.Length) + documentNo; } asset.SetValue(value); // Name MProduct.afterSave String name = "Trial " + partner.GetName() + " - " + product.GetName(); if (name.Length > 60) { name = name.Substring(0, 60); } asset.SetName(name); // Description String description = product.GetDescription(); asset.SetDescription(description); // User asset.SetAD_User_ID(user.GetAD_User_ID()); asset.SetC_BPartner_ID(user.GetC_BPartner_ID()); // Product asset.SetM_Product_ID(product.GetM_Product_ID()); asset.SetA_Asset_Group_ID(product.GetA_Asset_Group_ID()); asset.SetQty(new Decimal(product.GetSupportUnits())); // Guarantee & Version asset.SetGuaranteeDate(TimeUtil.AddDays(now, product.GetTrialPhaseDays())); asset.SetVersionNo(product.GetVersionNo()); // return(asset); }
} // sendNoGuaranteeMail /// <summary> /// Deliver Asset /// </summary> /// <param name="A_Asset_ID">asset</param> /// <returns>message - delivery errors start with **</returns> private String DeliverIt(int A_Asset_ID) { log.Fine("A_Asset_ID=" + A_Asset_ID); long start = CommonFunctions.CurrentTimeMillis(); // MAsset asset = new MAsset(GetCtx(), A_Asset_ID, Get_Trx()); if (asset.GetAD_User_ID() == 0) { return("** No Asset User"); } VAdvantage.Model.MUser user = new VAdvantage.Model.MUser(GetCtx(), asset.GetAD_User_ID(), Get_Trx()); if (user.GetEMail() == null || user.GetEMail().Length == 0) { return("** No Asset User Email"); } if (asset.GetProductR_MailText_ID() == 0) { return("** Product Mail Text"); } if (_MailText == null || _MailText.GetR_MailText_ID() != asset.GetProductR_MailText_ID()) { _MailText = new VAdvantage.Model.MMailText(GetCtx(), asset.GetProductR_MailText_ID(), Get_Trx()); } if (_MailText.GetMailHeader() == null || _MailText.GetMailHeader().Length == 0) { return("** No Subject"); } // Create Mail EMail email = _client.CreateEMail(user.GetEMail(), user.GetName(), null, null); if (email == null || !email.IsValid()) { asset.SetHelp(asset.GetHelp() + " - Invalid EMail"); asset.SetIsActive(false); return("** Invalid EMail: " + user.GetEMail() + " - " + email); } if (_client.IsSmtpAuthorization()) { email.CreateAuthenticator(_client.GetRequestUser(), _client.GetRequestUserPW()); } _MailText.SetUser(user); _MailText.SetPO(asset); String message = _MailText.GetMailText(true); if (_MailText.IsHtml() || _AttachAsset) { email.SetMessageHTML(_MailText.GetMailHeader(), message); } else { email.SetSubject(_MailText.GetMailHeader()); email.SetMessageText(message); } if (_AttachAsset) { MProductDownload[] pdls = asset.GetProductDownloads(); if (pdls != null) { foreach (MProductDownload element in pdls) { //URL url = element.getDownloadURL(m_client.getDocumentDir()); Url url = element.GetDownloadURL(_client.GetDocumentDir()); if (url != null) { email.AddAttachment(url.Value); } } } else { log.Warning("No DowloadURL for A_Asset_ID=" + A_Asset_ID); } } String msg = email.Send(); new MUserMail(_MailText, asset.GetAD_User_ID(), email).Save(); if (!EMail.SENT_OK.Equals(msg)) { return("** Not delivered: " + user.GetEMail() + " - " + msg); } MAssetDelivery ad = asset.ConfirmDelivery(email, user.GetAD_User_ID()); ad.Save(); asset.Save(); // log.Fine((CommonFunctions.CurrentTimeMillis() - start) + " ms"); // success return(user.GetEMail() + " - " + asset.GetProductVersionNo()); }