示例#1
0
文件: Export.cs 项目: Condeti/spark
 public void Add(Interaction interaction)
 {
     if (interaction.State == InteractionState.Undefined)
     {
         interactions.Add(interaction);
     }
 }
示例#2
0
 public void Delete(Interaction entry)
 {
     string location = entry.Key.ToRelativeUri().ToString();
     string id = entry.Key.ToOperationPath();
     IMongoQuery query = MongoDB.Driver.Builders.Query.EQ(InternalField.ID, id);
     Collection.Remove(query);
 }
示例#3
0
 public void Inform(Uri location, Interaction interaction)
 {
     foreach(IServiceListener listener in listeners)
     {
         Inform(listener, location, interaction);
     }
 }
示例#4
0
        public static FhirResponse Gone(Interaction entry)
        {
            var message = String.Format(
                  "A {0} resource with id {1} existed, but was deleted on {2} (version {3}).",
                  entry.Key.TypeName,
                  entry.Key.ResourceId,
                  entry.When,
                  entry.Key.ToRelativeUri());

            return Respond.WithError(HttpStatusCode.Gone, message);
        }
示例#5
0
文件: Respond.cs 项目: Condeti/spark
 public static FhirResponse WithMeta(Interaction interaction)
 {
     if (interaction.Resource != null && interaction.Resource.Meta != null)
     {
         return Respond.WithMeta(interaction.Resource.Meta);
     }
     else
     {
         return Respond.WithError(HttpStatusCode.InternalServerError, "Could not retrieve meta. Meta was not present on the resource");
     }
 }
示例#6
0
 public void Add(Interaction interaction)
 {
     if (interaction.State == InteractionState.Undefined)
     {
         interactions.Add(interaction);
     }
     else
     {
         // no need to import again.
         // interaction.State.Assert(InteractionState.Undefined);
     }
 }
示例#7
0
 public void Process(Interaction interaction)
 {
     if (interaction.HasResource())
     {
         IndexResource(interaction.Resource, interaction.Key);
     }
     else
     {
         if (interaction.IsDeleted())
         {
             _indexStore.Delete(interaction);
         }
         else throw new Exception("Entry is neither resource nor deleted");
     }
 }
示例#8
0
 public void Process(Interaction interaction)
 {
     if (interaction.HasResource())
     {
         put(interaction);
     }
     else
     {
         if (interaction.IsDeleted())
         {
             store.Delete(interaction);
         }
         else throw new Exception("Entry is neither resource nor deleted");
     }
 }
示例#9
0
        public FhirResponse GetFhirResponse(Interaction interaction, IEnumerable<object> parameters = null)
        {
            if (interaction.IsDeleted())
            {
                return Respond.Gone(interaction);
            }

            FhirResponse response = null;

            if (parameters != null)
            {
                response = interceptorRunner.RunInterceptors(interaction, parameters);
            }

            return response ?? Respond.WithResource(interaction);
        }
        public static Bundle Append(this Bundle bundle, Interaction interaction)
        {
            // API: The api should have a function for this. AddResourceEntry doesn't cut it.
            // Might TransactionBuilder be better suitable?

            Bundle.BundleEntryComponent entry;
            switch (bundle.Type)
            {
                case Bundle.BundleType.History: entry = interaction.ToTransactionEntry(); break;
                case Bundle.BundleType.Searchset: entry = interaction.TranslateToSparseEntry(); break;
                default: entry = interaction.TranslateToSparseEntry(); break;
            }
            bundle.Entry.Add(entry);

            return bundle;
        }
        public FhirResponse GetFhirResponse(Interaction interaction, object input)
        {
            ConditionalHeaderParameters parameters = ConvertInput(input);
            if (parameters == null) return null;

            bool? matchTags = parameters.IfNoneMatchTags.Any() ? parameters.IfNoneMatchTags.Any(t => t == ETag.Create(interaction.Key.VersionId).Tag) : (bool?)null;
            bool? matchModifiedDate = parameters.IfModifiedSince.HasValue
                ? parameters.IfModifiedSince.Value < interaction.Resource.Meta.LastUpdated
                : (bool?) null;

            if (!matchTags.HasValue  && !matchModifiedDate.HasValue)
            {
                return null;
            }

            if ((matchTags ?? true) && (matchModifiedDate ?? true))
            {
                return Respond.WithCode(HttpStatusCode.NotModified);
            }

            return null;
        }
示例#12
0
 public void Externalize(Interaction interaction)
 {
     Export export = new Export(this.localhost);
     export.Add(interaction);
     export.Externalize();
 }
示例#13
0
 public static FhirResponse WithEntry(HttpStatusCode code, Interaction entry)
 {
     return new FhirResponse(code, entry.Key, entry.Resource);
 }
示例#14
0
 public static void AddMetaData(BsonDocument document, Interaction interaction)
 {
     document[Field.METHOD] = interaction.Method;
     document[Field.PRIMARYKEY] = interaction.Key.ToOperationPath();
     document[Field.REFERENCE] = interaction.Key.ToBsonReferenceKey();
     AddMetaData(document, interaction.Key);
 }
示例#15
0
 public static FhirResponse WithResource(Interaction entry)
 {
     return new FhirResponse(HttpStatusCode.OK, entry.Key, entry.Resource);
 }
示例#16
0
 public static FhirResponse WithEntry(HttpStatusCode code, Interaction entry)
 {
     return(new FhirResponse(code, entry.Key, entry.Resource));
 }
示例#17
0
 private void put(Interaction interaction)
 {
     put(interaction.Key, 0, interaction.Resource);
 }
示例#18
0
        private void Store(Interaction interaction)
        {
            fhirStore.Add(interaction);

            //CK: try the new indexing service.
            if (_indexService != null)
            {
                _indexService.Process(interaction);
            }

            else if (fhirIndex != null)
            {
                //TODO: If IndexService is working correctly, remove the reference to fhirIndex.
                fhirIndex.Process(interaction);
            }


            if (serviceListener != null)
            {
                Uri location = localhost.GetAbsoluteUri(interaction.Key);
                // todo: what we want is not to send localhost to the listener, but to add the Resource.Base. But that is not an option in the current infrastructure.
                // It would modify interaction.Resource, while 
                serviceListener.Inform(location, interaction);
            }
        }
示例#19
0
 public static void AddVersionDate(Interaction entry, DateTime when)
 {
     entry.When = when;
     if (entry.Resource != null)
     {
         ensureMeta(entry.Resource);
         entry.Resource.Meta.LastUpdated = when;
     }
 }
示例#20
0
 public FhirResponse GetFhirResponse(Interaction interaction, params object[] parameters)
 {
     return GetFhirResponse(interaction, parameters.ToList());
 }
示例#21
0
 public void Internalize(Interaction interaction)
 {
     var import = new Import(this.localhost, this.generator);
     import.Add(interaction);
     import.Internalize();
 }
示例#22
0
 private void Inform(IServiceListener listener, Uri location, Interaction interaction)
 {
     listener.Inform(location, interaction);
 }
示例#23
0
        private void Store(Interaction interaction)
        {
            store.Add(interaction);

            if (index != null)
            {
                index.Process(interaction);
            }

            if (listener != null)
            {
                Uri location = localhost.GetAbsoluteUri(interaction.Key);
                // todo: what we want is not to send localhost to the listener, but to add the Resource.Base. But that is not an option in the current infrastructure.
                // It would modify interaction.Resource, while
                listener.Inform(location, interaction);
            }
        }
示例#24
0
        void InternalizeKey(Interaction interaction)
        {
            if (interaction.IsDeleted) return;

            Key key = interaction.Key.Clone();

            switch (localhost.GetKeyKind(key))
            {
                case KeyKind.Foreign:
                {
                    interaction.Key = Remap(key);
                    return;
                }
                case KeyKind.Temporary:
                {
                    interaction.Key = Remap(key);
                    return;
                }
                case KeyKind.Local:
                case KeyKind.Internal:
                {
                    if (interaction.Method == Bundle.HTTPVerb.PUT)
                    {
                        interaction.Key = RemapHistoryOnly(key);
                    }
                    else
                    {
                        interaction.Key = Remap(key);
                    }
                    return;

                }
                default:
                {
                    // switch can never get here.
                    throw Error.Internal("Unexpected key for resource: " + interaction.Key.ToString());
                }
            }
        }
示例#25
0
        // Deprecated: only used for Mailbox
        //public static void SaveBody(this HttpRequestMessage request, string contentType, byte[] data)
        //{
        //    Binary b = new Binary { Content = data, ContentType = contentType };

        //    request.Properties.Add(Const.UNPARSED_BODY, b);
        //}

        // Deprecated: only used for Mailbox
        //public static Binary GetBody(this HttpRequestMessage request)
        //{
        //    if (request.Properties.ContainsKey(Const.UNPARSED_BODY))
        //        return request.Properties[Const.UNPARSED_BODY] as Binary;
        //    else
        //        return null;
        //}

        /// <summary>
        /// Temporary hack!
        /// Adds a resourceEntry to the request property bag. To be picked up by the MediaTypeFormatters for adding http headers.
        /// </summary>
        /// <param name="entry">The resource entry with information to generate headers</param>
        /// <remarks> 
        /// The SendAsync is called after the headers are set. The SetDefaultHeaders have no access to the content object.
        /// The only solution is to give the information through the Request Property Bag.
        /// </remarks>
        public static void SaveEntry(this HttpRequestMessage request, Interaction entry)
        {
            request.Properties.Add(Const.RESOURCE_ENTRY, entry);
        }
示例#26
0
 public void Delete(Interaction entry)
 {
     string id = entry.Key.WithoutVersion().ToOperationPath();
     IMongoQuery query = MongoDB.Driver.Builders.Query.EQ(InternalField.ID, id);
     Collection.Remove(query);
 }
示例#27
0
 public FhirResponse HandleInteraction(Interaction interaction)
 {
     switch (interaction.Method)
     {
         case Bundle.HTTPVerb.PUT: return this.Update(interaction.Key, interaction.Resource);
         case Bundle.HTTPVerb.POST: return this.Create(interaction.Key, interaction.Resource);
         case Bundle.HTTPVerb.DELETE: return this.Delete(interaction.Key);
         default: return Respond.Success;
     }
 }
 public FhirResponse RunInterceptors(Interaction interaction, IEnumerable<object> parameters)
 {
     FhirResponse response = null;
     parameters.FirstOrDefault(p => (response = RunInterceptors(interaction, (object) p)) != null);
     return response;
 }
示例#29
0
 public void Process(Interaction interaction)
 {
     _indexer.Process(interaction);
 }
 private FhirResponse RunInterceptors(Interaction interaction, object input)
 {
     FhirResponse response = null;
     GetResponseInterceptors(input).FirstOrDefault(f => (response = f.GetFhirResponse(interaction, input)) != null);
     return response;
 }
示例#31
0
文件: Export.cs 项目: Condeti/spark
 void ExternalizeKey(Interaction interaction)
 {
     interaction.SupplementBase(localhost.DefaultBase);
 }
示例#32
0
 public static FhirResponse WithResource(Interaction entry)
 {
     return(new FhirResponse(HttpStatusCode.OK, entry.Key, entry.Resource));
 }