Exemplo n.º 1
0
        /*
         * public TagList TagsFromServer()
         * {
         *  IEnumerable<Tag> tags = tagstore.Tags();
         *  return new TagList(tags);
         * }
         *
         * public TagList TagsFromResource(string resourcetype)
         * {
         *  RequestValidator.ValidateCollectionName(resourcetype);
         *  IEnumerable<Tag> tags = tagstore.Tags(resourcetype);
         *  return new TagList(tags);
         * }
         *
         *
         * public TagList TagsFromInstance(string collection, string id)
         * {
         *  Uri key = BuildKey(collection, id);
         *  BundleEntry entry = store.Get(key);
         *
         *  if (entry == null)
         *      throwNotFound("Cannot retrieve tags because entry {0}/{1} does not exist", collection, id);
         *
         *  return new TagList(entry.Tags);
         * }
         *
         *
         * public TagList TagsFromHistory(string collection, string id, string vid)
         * {
         *  Uri key = BuildKey(collection, id, vid);
         *  BundleEntry entry = store.Get(key);
         *
         *  if (entry == null)
         *      throwNotFound("Cannot retrieve tags because entry {0}/{1} does not exist", collection, id, vid);
         *
         *  else if (entry is DeletedEntry)
         *  {
         *      throw new SparkException(HttpStatusCode.Gone,
         *          "A {0} resource with version {1} and id {2} exists, but it is a deletion (deleted on {3}).",
         *          collection, vid, id, (entry as DeletedEntry).When);
         *  }
         *
         *  return new TagList(entry.Tags);
         * }
         *
         * public void AffixTags(string collection, string id, IEnumerable<Tag> tags)
         * {
         *  if (tags == null) throw new SparkException("No tags specified on the request");
         *  Uri key = BuildKey(collection, id);
         *  BundleEntry entry = store.Get(key);
         *
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *  entry.AffixTags(tags);
         *  store.Add(entry);
         * }
         *
         * public void AffixTags(string collection, string id, string vid, IEnumerable<Tag> tags)
         * {
         *  Uri key = BuildKey(collection, id, vid);
         *  if (tags == null) throw new SparkException("No tags specified on the request");
         *
         *  BundleEntry entry = store.Get(key);
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *  entry.AffixTags(tags);
         *  store.Replace(entry);
         * }
         *
         * public void RemoveTags(string collection, string id, IEnumerable<Tag> tags)
         * {
         *  if (tags == null) throw new SparkException("No tags specified on the request");
         *
         *  Uri key = BuildKey(collection, id);
         *  BundleEntry entry = store.Get(key);
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *  if (entry.Tags != null)
         *  {
         *      entry.Tags = entry.Tags.Exclude(tags).ToList();
         *  }
         *
         *  store.Replace(entry);
         * }
         *
         * public void RemoveTags(string collection, string id, string vid, IEnumerable<Tag> tags)
         * {
         *  if (tags == null) throw new SparkException("Can not delete tags if no tags specified were specified");
         *
         *  Uri key = BuildKey(collection, id, vid);
         *
         *  ResourceEntry entry = (ResourceEntry)store.Get(key);
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *
         *  if (entry.Tags != null)
         *      entry.Tags = entry.Tags.Exclude(tags).ToList();
         *
         *  store.Replace(entry);
         * }
         */

        public FhirResponse ValidateOperation(Key key, Resource resource)
        {
            if (resource == null)
            {
                throw Error.BadRequest("Validate needs a Resource in the body payload");
            }
            //if (entry.Resource == null) throw new SparkException("Validate needs a Resource in the body payload");

            //  DSTU2: validation
            // entry.Resource.Title = "Validation test entity";
            // entry.LastUpdated = DateTime.Now;
            // entry.Id = id != null ? ResourceIdentity.Build(Endpoint, collection, id) : null;

            Validate.ResourceType(key, resource);

            // DSTU2: validation
            var outcome = Validate.AgainstSchema(resource);

            if (outcome == null)
            {
                return(Respond.WithCode(HttpStatusCode.OK));
            }
            else
            {
                return(Respond.WithResource(422, outcome));
            }
        }
Exemplo n.º 2
0
        public FhirResponse GetFhirResponse(Entry entry, object input)
        {
            var parameters = ConvertInput(input);

            if (parameters == null)
            {
                return(null);
            }

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

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

            return((matchTags ?? true) && (matchModifiedDate ?? true)
                ? Respond.WithCode(HttpStatusCode.NotModified)
                : null);
        }
Exemplo n.º 3
0
        public FhirResponse HandleInteraction(Entry interaction)
        {
            switch (interaction.Method)
            {
            case Bundle.HTTPVerb.PUT:
                return(this.Put(interaction));

            case Bundle.HTTPVerb.POST:
                return(this.Create(interaction));

            case Bundle.HTTPVerb.DELETE:
                var resourceStorage = GetFeature <IResourceStorageService>();
                var current         = resourceStorage.Get(interaction.Key.WithoutVersion());
                if (current != null && current.IsPresent)
                {
                    return(this.Delete(interaction));
                }
                // FIXME: there's no way to distinguish between "successfully deleted"
                // and "resource not deleted because it doesn't exist" responses, all return NoContent.
                // Same with Delete method above.
                return(Respond.WithCode(HttpStatusCode.NoContent));

            case Bundle.HTTPVerb.GET:
                return(this.VersionRead((Key)interaction.Key));

            default:
                return(Respond.Success);
            }
        }
        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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Delete a resource.
        /// </summary>
        /// <param name="collection">The resource type, in lowercase</param>
        /// <param name="id">The id part of a Resource id</param>
        /// <remarks>
        /// Upon successful deletion the server should return
        ///   * 204 (No Content).
        ///   * If the resource does not exist on the server, the server must return 404 (Not found).
        ///   * Performing this operation on a resource that is already deleted has no effect, and should return 204 (No Content).
        /// </remarks>
        public FhirResponse Delete(IKey key)
        {
            Validate.Key(key);
            Validate.HasNoVersion(key);

            Interaction current = store.Get(key);

            if (current == null)
            {
                return(Respond.NotFound(key));
            }

            if (current.IsPresent)
            {
                // Add a new deleted-entry to mark this entry as deleted
                //Entry deleted = importer.ImportDeleted(location);
                key = generator.NextHistoryKey(key);
                Interaction deleted = Interaction.DELETE(key, DateTimeOffset.UtcNow);

                Store(deleted);
                return(Respond.WithCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(Respond.Gone(current));
            }
        }
Exemplo n.º 6
0
        public async Task <FhirResponse> ConditionalDelete(IKey key, IEnumerable <Tuple <string, string> > parameters)
        {
            var deleteOperation = await key.CreateDelete(_searchService, SearchParams.FromUriParamList(parameters))
                                  .ConfigureAwait(false);

            return(await _transactionService.HandleTransaction(deleteOperation, this)
                   .ConfigureAwait(false)
                   ?? Respond.WithCode(HttpStatusCode.NotFound));
        }
Exemplo n.º 7
0
        public FhirResponse ConditionalDelete(IKey key, SearchParams _params)
        {
            ISearchService      searchStore        = this.FindExtension <ISearchService>();
            ITransactionService transactionService = this.FindExtension <ITransactionService>();

            if (searchStore == null || transactionService == null)
            {
                throw new NotSupportedException("Operation not supported");
            }

            return(transactionService.HandleTransaction(ResourceManipulationOperationFactory.CreateDelete(key, searchStore, _params),
                                                        this) ?? Respond.WithCode(HttpStatusCode.NotFound));
        }
Exemplo n.º 8
0
        public FhirResponse Delete(IKey key)
        {
            Validate.Key(key);
            Validate.HasNoVersion(key);

            var resourceStorage = GetFeature <IResourceStorageService>();

            Entry current = resourceStorage.Get(key);

            if (current != null && current.IsPresent)
            {
                return(Delete(Entry.DELETE(key, DateTimeOffset.UtcNow)));
            }
            return(Respond.WithCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Delete a resource.
        /// </summary>
        /// <param name="collection">The resource type, in lowercase</param>
        /// <param name="id">The id part of a Resource id</param>
        /// <remarks>
        /// Upon successful deletion the server should return
        ///   * 204 (No Content).
        ///   * If the resource does not exist on the server, the server must return 404 (Not found).
        ///   * Performing this operation on a resource that is already deleted has no effect, and should return 204 (No Content).
        /// </remarks>
        public FhirResponse Delete(IKey key)
        {
            Validate.Key(key);
            Validate.HasNoVersion(key);

            Entry current = fhirStore.Get(key);

            if (current != null && current.IsPresent)
            {
                // Add a new deleted-entry to mark this entry as deleted
                //Entry deleted = importer.ImportDeleted(location);
                key = keyGenerator.NextHistoryKey(key);
                Entry deleted = Entry.DELETE(key, DateTimeOffset.UtcNow);

                Store(deleted);
            }
            return(Respond.WithCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 10
0
        public FhirResponse ValidateOperation(IKey key, Resource resource)
        {
            if (resource == null)
            {
                throw Error.BadRequest("Validate needs a Resource in the body payload");
            }
            Validate.ResourceType(key, resource);

            // DSTU2: validation
            var outcome = Validate.AgainstSchema(resource);

            if (outcome == null)
            {
                return(Respond.WithCode(HttpStatusCode.OK));
            }
            else
            {
                return(Respond.WithResource(422, outcome));
            }
        }
Exemplo n.º 11
0
 public FhirResponse Delete(Entry entry)
 {
     Validate.Key(entry.Key);
     Store(entry);
     return(Respond.WithCode(HttpStatusCode.NoContent));
 }