/// <summary> /// This method gets the data or current status for a request /// </summary> /// <param name="dataRequestLogObj"></param> /// <returns></returns> public static MortgageDocumentResult ReRun(DataRequestLog dataRequestLogObj) { MortgageDocumentResult resultObj = new MortgageDocumentResult(); resultObj.BBL = dataRequestLogObj.BBL; resultObj.requestId = dataRequestLogObj.RequestId; resultObj.externalReferenceId = dataRequestLogObj.ExternalReferenceId; resultObj.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.Mortgage mortgageDocumentObj = webDBEntities.Mortgages.FirstOrDefault(i => i.BBL == parameters.BBL && i.MortgageDocumentURI == parameters.URI); if (mortgageDocumentObj != null && DateTime.UtcNow.Subtract(mortgageDocumentObj.LastUpdated).Days <= 30) { resultObj.mortgageDetails = mortgageDocumentObj; } else { resultObj.status = RequestStatus.Error.ToString(); } } } return(resultObj); } 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); } }
/// <summary> /// This method deals with all the details associated with either returning the details in the Mortgage Document or creating the /// request for getting the data from the web /// </summary> /// <param name="propertyBBL"></param> /// <param name="externalReferenceId"></param> /// <param name="documentURI"></param> /// <param name="jobId"></param> /// <param name="priority"></param> /// <returns></returns> public static MortgageDocumentResult GetDetails(string propertyBBL, string documentURI, string externalReferenceId, int priority, string jobId) { MortgageDocumentResult mortgageDocumentResultObj = new MortgageDocumentResult(); mortgageDocumentResultObj.BBL = propertyBBL; mortgageDocumentResultObj.mortgageDocumentURI = documentURI; mortgageDocumentResultObj.externalReferenceId = externalReferenceId; mortgageDocumentResultObj.status = RequestStatus.Pending.ToString(); string jsonBillParams = ParametersToJSON(propertyBBL, documentURI); using (WebDataEntities webDBEntities = new WebDataEntities()) { using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction()) { try { //check if data available var mortgageDocumentObj = webDBEntities.Mortgages.FirstOrDefault(i => i.BBL == propertyBBL && i.MortgageDocumentURI == documentURI); // record in database and data is not stale if (mortgageDocumentObj != null && DateTime.UtcNow.Subtract(mortgageDocumentObj.LastUpdated).Days <= 30) { mortgageDocumentResultObj.mortgageDetails = mortgageDocumentObj; mortgageDocumentResultObj.status = RequestStatus.Success.ToString(); DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, propertyBBL, RequestTypeId, externalReferenceId, jobId, jsonBillParams); } else { //check if pending request in queue DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, propertyBBL, RequestTypeId, jsonBillParams); if (dataRequestLogObj == null) //No Pending Request Create New Request { string requestStr = RequestResponseBuilder.RequestObjects.RequestData.CreateRequestDataForMortgage(documentURI); Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId); dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, requestObj.RequestId, externalReferenceId, jobId, jsonBillParams); mortgageDocumentResultObj.status = RequestStatus.Pending.ToString(); mortgageDocumentResultObj.requestId = requestObj.RequestId; } else //Pending request in queue { mortgageDocumentResultObj.status = RequestStatus.Pending.ToString(); //Send the RequestId for the pending request back mortgageDocumentResultObj.requestId = dataRequestLogObj.RequestId; dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, jsonBillParams); } } webDBEntitiestransaction.Commit(); } catch (Exception e) { webDBEntitiestransaction.Rollback(); mortgageDocumentResultObj.status = RequestStatus.Error.ToString(); DAL.DataRequestLog.InsertForFailure(propertyBBL, RequestTypeId, externalReferenceId, jobId, jsonBillParams); Common.Logs.log().Error(string.Format("Exception encountered processing {0} with externalRefId {1}{2}", propertyBBL, externalReferenceId, Common.Logs.FormatException(e))); } } } return(mortgageDocumentResultObj); }