/// <summary> /// Updates the header from genius. /// </summary> /// <param name="xiapHeader">The xiap header.</param> /// <param name="results">The results.</param> /// <exception cref="System.ServiceModel.FaultException">new FaultCode(Sender)</exception> /// <exception cref="FaultReason"></exception> /// <exception cref="FaultCode">Sender</exception> private void UpdateFromGenius(Header xiapHeader, ProcessResultsCollection results) { try { IUWHeader externalHeader = null; IPolicyService riskService = null; // Create an external policy service to the external service linked on the Header product. // This external service will be Genius. riskService = new PolicyService(xiapHeader.GetProduct().Product.ExternalDataSource); externalHeader = riskService.GetPolicy(xiapHeader.HeaderReference); if (this.ValidateExternalHeader(xiapHeader, externalHeader, results).Count == 0) { // Count is 0, i.e. no errors added to the ProcessResultsCollection 'results' in the Validation of External Header this.UpdateHeader(xiapHeader, externalHeader); // Apply the external policy terms to the GeniusX policy. foreach (IUWTerms externalTerm in externalHeader.ITerms) { this.ProcessTerms(xiapHeader, externalTerm); } // Order the external policy sections by the External Reference, which will be a Genius Reference, // thus the sections will be ordered as they are in the Genius policy. // Then apply each to the GeniusX policy in turn. var sections = externalHeader.ISections.OrderBy(x => x.ExternalReference); foreach (IUWSection externalSection in sections) { this.ProcessSection(xiapHeader, externalSection); } // Finally, update NameInvolvements from the external Genius policy this.UpdateNameInvolvement(xiapHeader, externalHeader); } } catch (Exception e) { if (_logger.IsErrorEnabled) { _logger.Error(e); } throw new FaultException(new FaultReason(e.Message), new FaultCode("Sender")); } }
/// <summary> /// Processes the terms on the external policy, adding each to the GeniusX policy in turn. /// </summary> /// <param name="xiapHeader">The xiap header.</param> /// <param name="externalTerms">The external terms.</param> private void ProcessTerms(Header xiapHeader, IUWTerms externalTerms) { // Get the current terms on the GeniusX policy and the Product Version. Terms terms = xiapHeader.Terms.FirstOrDefault(); long productVersionID = xiapHeader.GetProduct().ProductVersionID; if (terms == null) { // We have no terms on the policy at all, so first get the default terms from the product. using (MetadataEntities metadata = MetadataEntitiesFactory.GetMetadataEntities()) { ProductTerms productTerms = metadata.ProductTerms.Where(a => a.ProductVersion.ProductVersionID == productVersionID && a.IsDefault == true).FirstOrDefault(); if (productTerms != null) { // Map default terms to the GeniusX policy terms = xiapHeader.AddNewTerms(productTerms.ProductTermsID); } } } // Note that this isn't an 'else if'. We should always have terms at this point, and now we map the external data onto them. if (terms != null) { // Update terms on GeniusX policy with the required data from the External policy. terms.ExternalReference = externalTerms.ExternalReference; TermsVersion termsVersion = (TermsVersion)terms.GetLatestVersion(); if (termsVersion != null) { termsVersion.TermsTitle = externalTerms.TermsTitle; termsVersion.MainOriginalCurrencyCode = externalTerms.MainOriginalCurrencyCode; } } }
/// <summary> /// Validates the external Genius Policy can be used to refresh the GeniusX policy. /// </summary> /// <param name="xiapheader">The xiapheader.</param> /// <param name="externalheader">The externalheader.</param> /// <param name="results">The results.</param> /// <returns>Process Results Collection</returns> private ProcessResultsCollection ValidateExternalHeader(Header xiapheader, IUWHeader externalheader, ProcessResultsCollection results) { // Genius policy not found if (externalheader == null) { UWBusinessLogicHelper.AddError(results, MessageConstants.INVALID_POLICY_REFERENCE, ProcessInvocationPoint.Virtual, xiapheader); } else { // Genius policy product must match XIAP product if (externalheader.ProductCode != xiapheader.GetProduct().Product.Code) { UWBusinessLogicHelper.AddError(results, UwMessageConstants.GENIUS_PRODUCT_DOES_NOT_MATCH, ProcessInvocationPoint.Virtual, xiapheader); } } return results; }
/// <summary> /// Updates the Major Insured and Major Broker name involvements on the GeniusX policy, from the Genius Policy. /// </summary> /// <param name="xiapHeader">The xiap header.</param> /// <param name="externalHeader">The external header.</param> private void UpdateNameInvolvement(Header xiapHeader, IUWHeader externalHeader) { // Update Insured from Genius policy var insured = externalHeader.IUWNameInvolvements.Where(a => a.NameInvolvementType == (short)StaticValues.NameInvolvementType.MajorInsured).FirstOrDefault(); UwNameInvolvement ni = null; if (insured != null) { // we have an insured on the Genius Policy so see if we have one on the GeniusX policy. ni = xiapHeader.UwNameInvolvements.Where(a => a.NameInvolvementType == (short)StaticValues.NameInvolvementType.MajorInsured).FirstOrDefault(); if (ni != null) { // Update the Name id ni.NameID = insured.NameID; } else { // Check if Insured NI is configured on product and can be created // If so, create and update from Genius long productVersionID = xiapHeader.GetProduct().ProductVersionID; var productNI = ProductService.GetProductNameInvolvementQuery().GetProductNameInvolvementByNameInvolvementType(productVersionID, (short)StaticValues.NameInvolvementType.MajorInsured); if (productNI != null) { ni = xiapHeader.AddNewUwNameInvolvement((short)StaticValues.NameInvolvementType.MajorInsured, insured.NameID); ni.NameUsageTypeCode = insured.NameUsageTypeCode; } } } // Update LossBroker from Genius policy var mjrBroker = externalHeader.IUWNameInvolvements.Where(a => a.NameInvolvementType == (short)StaticValues.NameInvolvementType.MajorBroker).FirstOrDefault(); UwNameInvolvement nameInvMajorBroker = null; if (mjrBroker != null) { // If we have a Major Broker on the Genius Policy, find one on the GeniusX policy var nameInvMajorBrokerVersion = xiapHeader.UwNameInvolvements.Where(a => a.NameInvolvementType == (short)StaticValues.NameInvolvementType.MajorBroker).SelectMany(uni => uni.UwNameInvolvementVersion.Where(lv => lv.IsLatestVersion == true)).FirstOrDefault(); if (nameInvMajorBrokerVersion != null) { // Get the name involvement from the lastest version. nameInvMajorBroker = nameInvMajorBrokerVersion.UwNameInvolvement; } if (nameInvMajorBroker != null) { // Update the Name id already existing on the GeniusX policy nameInvMajorBroker.NameID = mjrBroker.NameID; } else { // Check if Major Broker NI is configured on product and can be created // Create it, if so, and apply Genius policy data. long productVersionID = xiapHeader.GetProduct().ProductVersionID; var productNI = ProductService.GetProductNameInvolvementQuery().GetProductNameInvolvementByNameInvolvementType(productVersionID, (short)StaticValues.NameInvolvementType.MajorInsured); if (productNI != null) { nameInvMajorBroker = xiapHeader.AddNewUwNameInvolvement((short)StaticValues.NameInvolvementType.MajorBroker, mjrBroker.NameID); nameInvMajorBroker.NameUsageTypeCode = mjrBroker.NameUsageTypeCode; } } } }
/// <summary> /// Validates GeniusX policy can be updated from Genius. /// </summary> /// <param name="header">The header.</param> /// <param name="results">The results.</param> /// <returns>Process Results Collection</returns> private ProcessResultsCollection ValidateXiapHeader(Header header, ProcessResultsCollection results) { // If status is verified, creation of components from Genius not allowed if (header.HeaderStatusThreshold >= 30) { UWBusinessLogicHelper.AddError(results, UwMessageConstants.HEADERSTATUS_VERIFIED_GENIUSUPDATE_NOTALLOWED, ProcessInvocationPoint.Virtual, header); } // We can't collect from Genius if we haven't defined the product as actually using an external source (which should be Genius). if (header.GetProduct().Product.ExternalDataSource == null) { UWBusinessLogicHelper.AddError(results, UwMessageConstants.EXTERNALDATASOURCE_REQUIRED, ProcessInvocationPoint.Virtual, header); } // Note that core validation already checks duplicate XIAP header references, so shouldn't have to re-check return results; }