Ejemplo n.º 1
0
        private async Task <IActionResult> InternalPatch(string id, PatchRepresentationParameter patchRepresentation)
        {
            _logger.LogInformation(string.Format(Global.PatchResource, id));
            try
            {
                var newRepresentation = await _patchRepresentationCommandHandler.Handle(new PatchRepresentationCommand(id, patchRepresentation));

                return(BuildHTTPResult(newRepresentation, HttpStatusCode.OK, false));
            }
            catch (SCIMFilterException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidFilter));
            }
            catch (SCIMBadSyntaxException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }
            catch (SCIMNotFoundException ex)
            {
                return(this.BuildError(HttpStatusCode.NotFound, ex.Message, SCIMConstants.ErrorSCIMTypes.Unknown));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError));
            }
        }
Ejemplo n.º 2
0
        protected async Task <IActionResult> InternalPatch(string id, PatchRepresentationParameter patchRepresentation)
        {
            _logger.LogInformation(string.Format(Global.PatchResource, id, patchRepresentation == null ? string.Empty : JsonConvert.SerializeObject(patchRepresentation)));
            try
            {
                var newRepresentation = await _patchRepresentationCommandHandler.Handle(new PatchRepresentationCommand(id, ResourceType, patchRepresentation, Request.GetAbsoluteUriWithVirtualPath()));

                var location = GetLocation(newRepresentation);
                var content  = newRepresentation.ToResponse(location, false);
                if (SCIMConstants.MappingScimResourceTypeToCommonType.ContainsKey(_resourceType))
                {
                    await _busControl.Publish(new RepresentationUpdatedEvent(newRepresentation.Id, newRepresentation.Version, SCIMConstants.MappingScimResourceTypeToCommonType[_resourceType], content, _options.IncludeToken ? Request.GetToken() : string.Empty));
                }

                return(BuildHTTPResult(HttpStatusCode.OK, location, newRepresentation.Version, content));
            }
            catch (SCIMDuplicateAttributeException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.NoContent, ex.Message, SCIMConstants.ErrorSCIMTypes.Uniqueness));
            }
            catch (SCIMUniquenessAttributeException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.Conflict, ex.Message, SCIMConstants.ErrorSCIMTypes.Uniqueness));
            }
            catch (SCIMFilterException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidFilter));
            }
            catch (SCIMBadSyntaxException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }
            catch (SCIMNoTargetException ex)
            {
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.NoTarget));
            }
            catch (SCIMNotFoundException ex)
            {
                return(this.BuildError(HttpStatusCode.NotFound, ex.Message, SCIMConstants.ErrorSCIMTypes.Unknown));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError));
            }
        }
Ejemplo n.º 3
0
        private async Task <IActionResult> InternalPatch(string id, JObject jObj)
        {
            try
            {
                var newRepresentation = await _patchRepresentationCommandHandler.Handle(new PatchRepresentationCommand(id, jObj));

                return(BuildHTTPResult(newRepresentation, HttpStatusCode.OK, false));
            }
            catch (SCIMBadRequestException)
            {
                return(this.BuildError(HttpStatusCode.BadRequest, "Request is unparsable, syntactically incorrect, or violates schema.", "invalidSyntax"));
            }
            catch (SCIMNotFoundException)
            {
                return(this.BuildError(HttpStatusCode.NotFound, "Resource does not exist", "notFound"));
            }
        }
Ejemplo n.º 4
0
        protected async Task <IActionResult> InternalPatch(string id, PatchRepresentationParameter patchRepresentation)
        {
            _logger.LogInformation(string.Format(Global.PatchResource, id));
            try
            {
                var newRepresentation = await _patchRepresentationCommandHandler.Handle(new PatchRepresentationCommand(id, patchRepresentation));

                var location = GetLocation(newRepresentation);
                var content  = newRepresentation.ToResponse(location, false);
                await _busControl.Publish(new RepresentationUpdatedEvent(newRepresentation.Id, newRepresentation.VersionNumber, _resourceType, content));

                return(BuildHTTPResult(HttpStatusCode.OK, location, newRepresentation.Version, content));
            }
            catch (SCIMFilterException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidFilter));
            }
            catch (SCIMBadSyntaxException ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.InvalidSyntax));
            }
            catch (SCIMNoTargetException ex)
            {
                return(this.BuildError(HttpStatusCode.BadRequest, ex.Message, SCIMConstants.ErrorSCIMTypes.NoTarget));
            }
            catch (SCIMNotFoundException ex)
            {
                return(this.BuildError(HttpStatusCode.NotFound, ex.Message, SCIMConstants.ErrorSCIMTypes.Unknown));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(this.BuildError(HttpStatusCode.InternalServerError, ex.ToString(), SCIMConstants.ErrorSCIMTypes.InternalServerError));
            }
        }