public async Task <string> Execute(AddResouceSetParameter addResourceSetParameter)
        {
            var json = addResourceSetParameter == null ? string.Empty : JsonConvert.SerializeObject(addResourceSetParameter);

            _umaServerEventSource.StartToAddResourceSet(json);
            if (addResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(addResourceSetParameter));
            }

            var resourceSet = new ResourceSet
            {
                Id      = Guid.NewGuid().ToString(),
                Name    = addResourceSetParameter.Name,
                Uri     = addResourceSetParameter.Uri,
                Type    = addResourceSetParameter.Type,
                Scopes  = addResourceSetParameter.Scopes,
                IconUri = addResourceSetParameter.IconUri
            };

            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (!await _resourceSetRepository.Insert(resourceSet))
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheResourceSetCannotBeInserted);
            }

            _umaServerEventSource.FinishToAddResourceSet(JsonConvert.SerializeObject(resourceSet));
            return(resourceSet.Id);
        }
        public async Task <bool> Execute(UpdateResourceSetParameter udpateResourceSetParameter)
        {
            if (udpateResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(udpateResourceSetParameter));
            }

            if (await _resourceSetRepository.Get(udpateResourceSetParameter.Id) == null)
            {
                return(false);
            }

            var resourceSet = new ResourceSet
            {
                Id      = udpateResourceSetParameter.Id,
                Name    = udpateResourceSetParameter.Name,
                Uri     = udpateResourceSetParameter.Uri,
                Type    = udpateResourceSetParameter.Type,
                Scopes  = udpateResourceSetParameter.Scopes,
                IconUri = udpateResourceSetParameter.IconUri
            };

            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (!await _resourceSetRepository.Update(resourceSet))
            {
                throw new BaseUmaException(
                          ErrorCodes.InternalError,
                          string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, resourceSet.Id));
            }

            return(true);
        }
Exemplo n.º 3
0
        public async Task <bool> Execute(UpdateResourceSetParameter udpateResourceSetParameter)
        {
            if (udpateResourceSetParameter == null)
            {
                throw new ArgumentNullException(nameof(udpateResourceSetParameter));
            }

            var json = JsonConvert.SerializeObject(udpateResourceSetParameter);

            _umaServerEventSource.StartToUpdateResourceSet(json);
            var resourceSet = new ResourceSet
            {
                Id      = udpateResourceSetParameter.Id,
                Name    = udpateResourceSetParameter.Name,
                Uri     = udpateResourceSetParameter.Uri,
                Type    = udpateResourceSetParameter.Type,
                Scopes  = udpateResourceSetParameter.Scopes,
                IconUri = udpateResourceSetParameter.IconUri,
                Owner   = udpateResourceSetParameter.Owner,
                AcceptPendingRequest = udpateResourceSetParameter.AcceptPendingRequest
            };

            if (string.IsNullOrWhiteSpace(udpateResourceSetParameter.Id))
            {
                throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, "id"));
            }
            _resourceSetParameterValidator.CheckResourceSetParameter(resourceSet);
            if (await _resourceSetRepository.Get(udpateResourceSetParameter.Id) == null)
            {
                return(false);
            }

            if (!await _resourceSetRepository.Update(resourceSet))
            {
                throw new BaseUmaException(ErrorCodes.InternalError, string.Format(ErrorDescriptions.TheResourceSetCannotBeUpdated, resourceSet.Id));
            }

            _umaServerEventSource.FinishToUpdateResourceSet(json);
            return(true);
        }