public ResourceBase CreateResource(string resourceType, ResourceBase target) { this.ThrowIfNotReady(); try { // Setup outgoing content // Create or update? var handler = FhirResourceHandlerUtil.GetResourceHandler(resourceType); if (handler == null) { throw new FileNotFoundException(); // endpoint not found! } var result = handler.Create(target, TransactionMode.Commit); RestOperationContext.Current.OutgoingResponse.StatusCode = (int)HttpStatusCode.Created; AuditUtil.AuditDataAction <ResourceBase>(EventTypeCodes.Import, ActionType.Create, AuditableObjectLifecycle.Creation, EventIdentifierType.Import, OutcomeIndicator.Success, null, result); String baseUri = MessageUtil.GetBaseUri(); RestOperationContext.Current.OutgoingResponse.Headers.Add("Content-Location", String.Format("{0}/{1}/{2}/_history/{3}", baseUri, resourceType, result.Id, result.VersionId)); RestOperationContext.Current.OutgoingResponse.SetLastModified(result.Timestamp); RestOperationContext.Current.OutgoingResponse.SetETag($"W/\"{result.VersionId}\""); return(result); } catch (Exception e) { this.m_tracer.TraceError("Error creating FHIR resource {0}: {1}", resourceType, e); AuditUtil.AuditDataAction <ResourceBase>(EventTypeCodes.Import, ActionType.Create, AuditableObjectLifecycle.Creation, EventIdentifierType.Import, OutcomeIndicator.EpicFail, null); throw; } }
public ResourceBase DeleteResource(string resourceType, string id) { this.ThrowIfNotReady(); try { // Setup outgoing content/ RestOperationContext.Current.OutgoingResponse.StatusCode = (int)HttpStatusCode.NoContent; // Create or update? var handler = FhirResourceHandlerUtil.GetResourceHandler(resourceType); if (handler == null) { throw new FileNotFoundException(); // endpoint not found! } var result = handler.Delete(id, TransactionMode.Commit); AuditUtil.AuditDataAction <ResourceBase>(EventTypeCodes.Import, ActionType.Delete, AuditableObjectLifecycle.LogicalDeletion, EventIdentifierType.Import, OutcomeIndicator.Success, id, result); return(null); } catch (Exception e) { this.m_tracer.TraceError("Error deleting FHIR resource {0}({1}): {2}", resourceType, id, e); AuditUtil.AuditDataAction <ResourceBase>(EventTypeCodes.Import, ActionType.Delete, AuditableObjectLifecycle.LogicalDeletion, EventIdentifierType.Import, OutcomeIndicator.EpicFail, id); throw; } }
public virtual object Obsolete(object key) { try { var retVal = Activator.CreateInstance(this.Type, this.GetRepository().Obsolete((Guid)key)); AuditUtil.AuditDataAction(EventTypeCodes.SecurityObjectChanged, Core.Auditing.ActionType.Delete, Core.Auditing.AuditableObjectLifecycle.LogicalDeletion, Core.Auditing.EventIdentifierType.SecurityAlert, Core.Auditing.OutcomeIndicator.Success, key.ToString(), retVal); // Special case for security entity wrappers, we want to load them from DB from fresh ApplicationServiceContext.Current.GetService <IDataCachingService>()?.Remove((Guid)key); return(retVal); } catch { AuditUtil.AuditDataAction <TSecurityEntity>(EventTypeCodes.SecurityObjectChanged, Core.Auditing.ActionType.Delete, Core.Auditing.AuditableObjectLifecycle.LogicalDeletion, Core.Auditing.EventIdentifierType.SecurityAlert, Core.Auditing.OutcomeIndicator.MinorFail, key.ToString()); throw; } }
public virtual object Create(object data, bool updateIfExists) { // First, we want to copy over the roles var td = data as ISecurityEntityInfo <TSecurityEntity>; if (td is null) { this.m_tracer.TraceError($"Invalid type {nameof(data)}"); throw new ArgumentException(this.m_localizationService.FormatString("error.type.ArgumentException", new { param = nameof(data) })); } try { // Now for the fun part we want to map any policies over to the wrapped type if (td.Entity.Policies != null && td.Policies != null) { td.Entity.Policies = td.Policies.Select(p => new SecurityPolicyInstance(p.Policy, p.Grant)).ToList(); } if (updateIfExists) { td.Entity = this.GetRepository().Save(td.Entity); AuditUtil.AuditDataAction(EventTypeCodes.SecurityObjectChanged, Core.Auditing.ActionType.Update, Core.Auditing.AuditableObjectLifecycle.Amendment, Core.Auditing.EventIdentifierType.SecurityAlert, Core.Auditing.OutcomeIndicator.Success, null, td.Entity); } else { td.Entity = this.GetRepository().Insert(td.Entity); AuditUtil.AuditDataAction(EventTypeCodes.SecurityObjectChanged, Core.Auditing.ActionType.Create, Core.Auditing.AuditableObjectLifecycle.Creation, Core.Auditing.EventIdentifierType.SecurityAlert, Core.Auditing.OutcomeIndicator.Success, null, td.Entity); } // Special case for security entity wrappers, we want to load them from DB from fresh ApplicationServiceContext.Current.GetService <IDataCachingService>()?.Remove(td.Entity.Key.Value); return(td); } catch { AuditUtil.AuditDataAction <TSecurityEntity>(EventTypeCodes.SecurityObjectChanged, Core.Auditing.ActionType.Create, Core.Auditing.AuditableObjectLifecycle.Creation, Core.Auditing.EventIdentifierType.SecurityAlert, Core.Auditing.OutcomeIndicator.MinorFail, null, td.Entity); throw; } }