/**
         *  Create Asset Delivery for HTTP Request
         *  @param asset asset
         *  @param request request
         *  @param AD_User_ID BP Contact
         */
        //public MAssetDelivery(MAsset asset,
        //    HttpServletRequest request, int AD_User_ID)
        //{
        //    base(asset.getCtx(), 0, asset.get_TrxName());
        //    setClientOrg(asset);
        //    //	Asset Info
        //    setA_Asset_ID(asset.getA_Asset_ID());
        //    setLot(asset.getLot());
        //    setSerNo(asset.getSerNo());
        //    setVersionNo(asset.getVersionNo());
        //    //
        //    SetMovementDate(new DateTime(System.currentTimeMillis()));
        //    //	Request
        //    setURL(request.getRequestURL().toString());
        //    setReferrer(request.getHeader("Referer"));
        //    setRemote_Addr(request.getRemoteAddr());
        //    setRemote_Host(request.getRemoteHost());
        //    //	Who
        //    setAD_User_ID(AD_User_ID);
        //    //
        //    save();
        //}

        /**
         *  Create Asset Delivery for EMail
         *  @param asset asset
         *  @param email optional email
         *  @param messageID access ID
         *  @param AD_User_ID BP Contact
         */
        public MAssetDelivery(MAsset asset, EMail email, String messageID, int AD_User_ID)
            : base(asset.GetCtx(), 0, asset.Get_TrxName())
        {
            SetClientOrg(asset);
            //	Asset Info
            SetA_Asset_ID(asset.GetA_Asset_ID());
            SetLot(asset.GetLot());
            SetSerNo(asset.GetSerNo());
            SetVersionNo(asset.GetVersionNo());
            //
            SetMovementDate(new DateTime(CommonFunctions.CurrentTimeMillis()));
            //	EMail
            if (email != null)
            {
                SetEMail(email.GetTo().ToString());
                SetMessageID(email.GetMessageID());
            }
            else
            {
                SetMessageID(messageID);
            }
            //	Who
            SetAD_User_ID(AD_User_ID);
            //
            Save();
        }
Beispiel #2
0
        /// <summary>
        /// Get Asset From Shipment.
        /// (Order.reverseCorrect)
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="M_InOutLine_ID">shipment line</param>
        /// <param name="trxName">transaction</param>
        /// <returns>asset or null</returns>
        public static MAsset GetFromShipment(Ctx ctx, int M_InOutLine_ID, Trx trxName)
        {
            MAsset  retValue = null;
            String  sql      = "SELECT * FROM A_Asset WHERE M_InOutLine_ID=" + M_InOutLine_ID;
            DataSet ds       = new DataSet();

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, trxName);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    retValue = new MAsset(ctx, dr, trxName);
                }
                ds = null;
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }

            return(retValue);
        }
Beispiel #3
0
        /**
         *  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);
        }
        }       //	authenticateSubscription

        /// <summary>
        /// Authenticate Product Asset
        /// </summary>
        /// <param name="ldapUser">user</param>
        /// <param name="AD_User_ID">id</param>
        /// <param name="usr">user authentification (email, ...)</param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="AD_Client_ID">client</param>
        /// <param name="remoteHost">remote info</param>
        /// <param name="remoteAddr">remote info</param>
        /// <returns>user with error message set if error</returns>
        private MLdapUser AuthenticateAsset(MLdapUser ldapUser,
                                            int AD_User_ID, String usr, int M_Product_ID,
                                            int AD_Client_ID, String remoteHost, String remoteAddr)
        {
            String error = null;
            String info  = null;

            //	Query 2 - Validate Asset
            MAsset asset = null;
            String sql   = "SELECT * "
                           + "FROM A_Asset "
                           + "WHERE M_Product_ID=@param1"
                           + " AND AD_User_ID=@param2"; //	only specific user

            //	Will have problems with multiple assets
            SqlParameter[] param = new SqlParameter[2];
            IDataReader    idr   = null;

            try
            {
                //pstmt = DataBase.prepareStatement (sql, null);
                //pstmt.setInt (1, M_Product_ID);
                param[0] = new SqlParameter("@param1", M_Product_ID);
                //pstmt.setInt (2, AD_User_ID);
                param[1] = new SqlParameter("@param2", AD_User_ID);
                idr      = DataBase.DB.ExecuteReader(sql, param, null);
                if (idr.Read())
                {
                    asset = new MAsset(GetCtx(), idr, null);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
                error = "System Error (3)";
            }

            //	System Error
            if (error != null)
            {
                _error++;
                ldapUser.SetErrorString(error);
                return(ldapUser);
            }
            int A_Asset_ID = 0;

            if (asset == null)
            {
                error = "@UserNoAsset@ User="******"No Asset - " + usr + " - " + M_Product_ID;
            }
            else if (!asset.IsActive())
            {
                A_Asset_ID = asset.GetA_Asset_ID();
                error      = "@UserNoAsset@ User="******"Asset not active - " + usr;
            }
            else if (!asset.IsActive(true))
            {
                A_Asset_ID = asset.GetA_Asset_ID();
                error      = "@UserNoAsset@ User="******" @GuaranteeDate@=" + asset.GetGuaranteeDate();
                info       = "Expired - " + usr + " - GuaranteeDate=" + asset.GetGuaranteeDate();
            }
            else
            {
                info = "Asset - " + usr;
            }

            if (error != null)  //	should use Language of the User
            {
                LogAccess(AD_Client_ID, AD_User_ID, 0, A_Asset_ID, info, error,
                          remoteHost, remoteAddr);
                ldapUser.SetErrorString(Msg.Translate(GetCtx(), error));
                return(ldapUser);
            }
            //	Done OK
            MLdapAccess log = LogAccess(AD_Client_ID, AD_User_ID, 0, asset.GetA_Asset_ID(), info, null,
                                        remoteHost, remoteAddr);
            MAssetDelivery ad = new MAssetDelivery(asset, null, log.ToString(), AD_User_ID);

            ad.SetRemote_Host(remoteHost);
            ad.SetRemote_Addr(remoteAddr);
            ad.Save();
            return(ldapUser);
        }       //	authenticateAsset