Esempio n. 1
0
        /// <summary>
        ///     This method gets the data or current status for a request
        /// </summary>
        /// <param name="dataRequestLogObj"></param>
        /// <returns></returns>
        public static FannieMortgageDetails ReRun(DataRequestLog dataRequestLogObj)
        {
            FannieMortgageDetails mDetails = new FannieMortgageDetails();

            mDetails.BBL                 = dataRequestLogObj.BBL;
            mDetails.requestId           = dataRequestLogObj.RequestId;
            mDetails.externalReferenceId = dataRequestLogObj.ExternalReferenceId;
            mDetails.status              = ((RequestStatus)dataRequestLogObj.RequestStatusTypeId).ToString();

            try
            {
                using (WebDataEntities webDBEntities = new WebDataEntities())
                {
                    if (dataRequestLogObj.RequestStatusTypeId == (int)RequestStatus.Success)
                    {
                        Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters);
                        //check if data available
                        WebDataDB.FannieMortgage mortgageObj = webDBEntities.FannieMortgages.FirstOrDefault(i => i.BBL == parameters.BBL);

                        if (mortgageObj != null && DateTime.UtcNow.Subtract(mortgageObj.LastUpdated).Days <= 30)
                        {
                            mDetails.isFannieMortgage = mortgageObj.IsFannie;
                        }
                        else
                        {
                            mDetails.status = RequestStatus.Error.ToString();
                        }
                    }
                }
                return(mDetails);
            }
            catch (Exception e)
            {
                Common.Logs.log().Error(string.Format("Exception encountered processing request log for {0} with externalRefId {1}{2}",
                                                      dataRequestLogObj.BBL, dataRequestLogObj.ExternalReferenceId, Common.Logs.FormatException(e)));
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     This method deals with all the details associated with either returning the Mortgage Servicer details or creating the
        ///     request for getting it scrapped from the web
        /// </summary>
        public static FannieMortgageDetails Get(Parameters inParameters, string externalReferenceId, int priority, string jobId)
        {
            FannieMortgageDetails mDetails = new FannieMortgageDetails();

            mDetails.BBL = inParameters.BBL;
            mDetails.externalReferenceId = externalReferenceId;
            mDetails.status = RequestStatus.Pending.ToString();

            string parameters = ParametersToJSON(inParameters);

            using (WebDataEntities webDBEntities = new WebDataEntities())
            {
                using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction())
                {
                    try
                    {
                        //check if data available
                        WebDataDB.FannieMortgage mortgageObj = webDBEntities.FannieMortgages.FirstOrDefault(i => i.BBL == inParameters.BBL);

                        // record in database and data is not stale
                        if (mortgageObj != null && DateTime.UtcNow.Subtract(mortgageObj.LastUpdated).Days <= 30)
                        {
                            mDetails.isFannieMortgage = mortgageObj.IsFannie;
                            mDetails.status           = RequestStatus.Success.ToString();

                            DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, inParameters.BBL, RequestTypeId, externalReferenceId, jobId, parameters);
                        }
                        else
                        {   //check if pending request in queue
                            DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, inParameters.BBL, RequestTypeId, parameters);

                            if (dataRequestLogObj == null) //No Pending Request Create New Request
                            {
                                string requestStr = "";    //RequestData.XXXX(inParameters);

                                Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId);

                                dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, inParameters.BBL, RequestTypeId, requestObj.RequestId,
                                                                                               externalReferenceId, jobId, parameters);

                                mDetails.status    = RequestStatus.Pending.ToString();
                                mDetails.requestId = requestObj.RequestId;
                            }
                            else //Pending request in queue
                            {
                                mDetails.status = RequestStatus.Pending.ToString();
                                //Send the RequestId for the pending request back
                                mDetails.requestId = dataRequestLogObj.RequestId;
                                dataRequestLogObj  = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, inParameters.BBL, RequestTypeId,
                                                                                                dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, parameters);
                            }
                        }
                        webDBEntitiestransaction.Commit();
                    }
                    catch (Exception e)
                    {
                        webDBEntitiestransaction.Rollback();
                        mDetails.status = RequestStatus.Error.ToString();
                        DAL.DataRequestLog.InsertForFailure(inParameters.BBL, RequestTypeId, externalReferenceId, jobId, parameters);
                        Common.Logs.log().Error(string.Format("Exception encountered processing {0} with externalRefId {1}{2}",
                                                              inParameters.BBL, externalReferenceId, Common.Logs.FormatException(e)));
                    }
                }
            }
            return(mDetails);
        }