/// <summary> /// Resolve an item /// </summary> /// <param name="sourceId"></param> public void Resolve(decimal sourceId) { // Get all Services IAuditorService auditSvc = ApplicationContext.CurrentContext.GetService(typeof(IAuditorService)) as IAuditorService; IClientRegistryMergeService mergeSvc = ApplicationContext.CurrentContext.GetService(typeof(IClientRegistryMergeService)) as IClientRegistryMergeService; // Audit message AuditData auditMessage = this.ConstructAuditData(ActionType.Update, EventIdentifierType.ApplicationActivity); auditMessage.EventTypeCode = new CodeValue("ADM_Resolve"); try { // Prepare merge VersionedDomainIdentifier resolveId = new VersionedDomainIdentifier() { Domain = ApplicationContext.ConfigurationService.OidRegistrar.GetOid("REG_EVT").Oid, Identifier = sourceId.ToString() }; // Merge mergeSvc.MarkResolved(resolveId); auditMessage.AuditableObjects.Add(new AuditableObject() { IDTypeCode = AuditableObjectIdType.ReportNumber, LifecycleType = AuditableObjectLifecycle.Verification, ObjectId = string.Format("{0}^^^&{1}&ISO", resolveId.Identifier, resolveId.Domain), Role = AuditableObjectRole.Job, Type = AuditableObjectType.SystemObject }); } catch (Exception e) { auditMessage.Outcome = OutcomeIndicator.EpicFail; Trace.TraceError("Could not execute Merge : {0}", e.ToString()); #if DEBUG throw new FaultException(new FaultReason(e.ToString()), new FaultCode(e.GetType().Name)); #else throw new FaultException(new FaultReason(e.Message), new FaultCode(e.GetType().Name)); #endif } finally { if (auditSvc != null) { auditSvc.SendAudit(auditMessage); } } }
/// <summary> /// Perform a merge /// </summary> public Core.ComponentModel.RegistrationEvent Merge(decimal[] sourceIds, decimal targetId) { // Get all Services IAuditorService auditSvc = ApplicationContext.CurrentContext.GetService(typeof(IAuditorService)) as IAuditorService; IDataPersistenceService repSvc = ApplicationContext.CurrentContext.GetService(typeof(IDataPersistenceService)) as IDataPersistenceService; IClientRegistryMergeService mergeSvc = ApplicationContext.CurrentContext.GetService(typeof(IClientRegistryMergeService)) as IClientRegistryMergeService; // Audit message List <AuditData> auditMessages = new List <AuditData>(); try { // Prepare merge List <VersionedDomainIdentifier> domainId = new List <VersionedDomainIdentifier>(sourceIds.Length); foreach (var srcId in sourceIds) { domainId.Add(new VersionedDomainIdentifier() { Domain = ApplicationContext.ConfigurationService.OidRegistrar.GetOid("REG_EVT").Oid, Identifier = srcId.ToString() }); var am = ConstructAuditData(ActionType.Delete, EventIdentifierType.Import); am.EventTypeCode = new CodeValue("ADM_Merge"); am.AuditableObjects.Add(new AuditableObject() { IDTypeCode = AuditableObjectIdType.ReportNumber, LifecycleType = AuditableObjectLifecycle.LogicalDeletion, ObjectId = String.Format("{0}^^^&{1}&ISO", srcId, ApplicationContext.ConfigurationService.OidRegistrar.GetOid("REG_EVT").Oid), Role = AuditableObjectRole.MasterFile, Type = AuditableObjectType.SystemObject }); auditMessages.Add(am); } VersionedDomainIdentifier survivorId = new VersionedDomainIdentifier() { Domain = ApplicationContext.ConfigurationService.OidRegistrar.GetOid("REG_EVT").Oid, Identifier = targetId.ToString() }; var updateAudit = ConstructAuditData(ActionType.Update, EventIdentifierType.Import); updateAudit.EventTypeCode = new CodeValue("ADM_Merge"); updateAudit.AuditableObjects.Add(new AuditableObject() { IDTypeCode = AuditableObjectIdType.ReportNumber, LifecycleType = AuditableObjectLifecycle.Amendment, ObjectId = String.Format("{0}^^^&{1}&ISO", survivorId.Identifier, survivorId.Domain), Role = AuditableObjectRole.MasterFile, Type = AuditableObjectType.SystemObject }); auditMessages.Add(updateAudit); // Merge mergeSvc.Resolve(domainId, survivorId, DataPersistenceMode.Production); // Now load return(repSvc.GetContainer(survivorId, true) as RegistrationEvent); } catch (Exception e) { foreach (var am in auditMessages) { am.Outcome = OutcomeIndicator.EpicFail; } Trace.TraceError("Could not execute Merge : {0}", e.ToString()); #if DEBUG throw new FaultException(new FaultReason(e.ToString()), new FaultCode(e.GetType().Name)); #else throw new FaultException(new FaultReason(e.Message), new FaultCode(e.GetType().Name)); #endif } finally { if (auditSvc != null) { foreach (var am in auditMessages) { auditSvc.SendAudit(am); } } } }
/// <summary> /// Get all merge candidates /// </summary> public ConflictCollection GetConflicts(int offset, int count, bool identifierOnly) { // Get all Services IAuditorService auditSvc = ApplicationContext.CurrentContext.GetService(typeof(IAuditorService)) as IAuditorService; IDataPersistenceService repSvc = ApplicationContext.CurrentContext.GetService(typeof(IDataPersistenceService)) as IDataPersistenceService; IClientRegistryMergeService mergeSvc = ApplicationContext.CurrentContext.GetService(typeof(IClientRegistryMergeService)) as IClientRegistryMergeService; // Audit message AuditData audit = this.ConstructAuditData(ActionType.Read, EventIdentifierType.Export); audit.EventTypeCode = new CodeValue("ADM_GetConflicts"); try { // Get all with a merge var mergeResults = mergeSvc.GetOutstandingConflicts(); var retVal = new ConflictCollection(); retVal.Count = mergeResults.Count(); // Loop and load foreach (var merge in mergeResults.Skip(offset).Take(count)) { // Construct the return, and load match Conflict conf = new Conflict(); if (!identifierOnly) { conf.Source = repSvc.GetContainer(merge, true) as RegistrationEvent; // Add audit data audit.AuditableObjects.Add(new AuditableObject() { IDTypeCode = AuditableObjectIdType.ReportNumber, LifecycleType = AuditableObjectLifecycle.Export, ObjectId = String.Format("{0}^^^&{1}&ISO", conf.Source.AlternateIdentifier.Identifier, conf.Source.AlternateIdentifier.Domain), Role = AuditableObjectRole.MasterFile, Type = AuditableObjectType.SystemObject, QueryData = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("loadFast=false")) }); } // Load the matches foreach (var match in mergeSvc.GetConflicts(merge)) { if (!identifierOnly) { var matchRecord = repSvc.GetContainer(match, true) as RegistrationEvent; conf.Match.Add(matchRecord); // Add audit data audit.AuditableObjects.Add(new AuditableObject() { IDTypeCode = AuditableObjectIdType.ReportNumber, LifecycleType = AuditableObjectLifecycle.Export, ObjectId = String.Format("{0}^^^&{1}&ISO", matchRecord.AlternateIdentifier.Identifier, matchRecord.AlternateIdentifier.Domain), Role = AuditableObjectRole.MasterFile, Type = AuditableObjectType.SystemObject, QueryData = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("loadFast=false")) }); } else { conf.Match.Add(new RegistrationEvent() { AlternateIdentifier = match }); } } retVal.Conflict.Add(conf); } return(retVal); } catch (Exception e) { Trace.TraceError("Could not execute GetConflicts : {0}", e.ToString()); audit.Outcome = OutcomeIndicator.EpicFail; #if DEBUG throw new FaultException(new FaultReason(e.ToString()), new FaultCode(e.GetType().Name)); #else throw new FaultException(new FaultReason(e.Message), new FaultCode(e.GetType().Name)); #endif } finally { if (auditSvc != null) { auditSvc.SendAudit(audit); } } }