private static void GenerateChangeGroupCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DefinitionGroup != null && Equals(original.DefinitionGroup.Id, updated.DefinitionGroup.Id))
                return;

            dispatcher.Dispatch(new EntityChangedGroupCommand(updated.Identity, updated.DefinitionGroup.Id));
        }
Example #2
0
        public bool DiscriptionMatches(EntityResource other)
        {
            if (other == null)
                return false;

            return Equals(Name, other.Name);
        }
Example #3
0
        public HttpResponseMessage Create(EntityResource resource)
        {
            _logWriter.Info(String.Format("Beginning of processing creation of Entity : {0}", resource.Name));

            if (resource == null)
            {
                throw new ArgumentEmptyException("resource");
            }

            _logWriter.Debug(resource.ToString());

            if (_readService.FindByIdentity(resource.Identity).Exists)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Identity already exists. Identities must be unique"));
            }

            return(_readService.FindByName(resource.Name).Fold(x =>
                                                               Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"),
                                                               () =>
            {
                var command = resource.ToCreateCommand();
                _dispatcher.Dispatch(command);

                _logWriter.Info(String.Format("Completion of processing creation of Entity : {0}", resource.Name));

                return Request.CreateResponse(HttpStatusCode.Created);
            }));
        }
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DiscriptionMatches(updated))
                return;

            dispatcher.Dispatch(new ReLabelEntityCommand(updated.Identity, new EntityName(updated.Name.Trim())));
        }
Example #5
0
        public bool DiscriptionMatches(EntityResource other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Equals(Name, other.Name));
        }
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DiscriptionMatches(updated))
            {
                return;
            }

            dispatcher.Dispatch(new ReLabelEntityCommand(updated.Identity, new EntityName(updated.Name.Trim())));
        }
        public static void GenerateCommands(this ICommandDispatcher dispatcher, IEntityReadService readService, EntityResource resource)
        {
            var current = readService.FindByIdentity(resource.Identity);

            current.Foreach(original =>
            {
                GenerateReLabelCommand(dispatcher, original, resource);
                GenerateChangeGroupCommand(dispatcher, original, resource);
                GenerateValues(dispatcher, original, resource);
            });
        }
Example #8
0
        public bool ValuesMatch(EntityResource other)
        {
            if (other == null)
                return false;

            if (DefinitionValues == null)
                return other.DefinitionValues == null || !other.DefinitionValues.Any();

            if (other.DefinitionValues == null)
                return DefinitionValues == null || !DefinitionValues.Any();

            return DefinitionValues.Count == other.DefinitionValues.Count && DefinitionValues.Intersect(other.DefinitionValues).Count() == DefinitionValues.Count;
        }
        private static void GenerateValues(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.ValuesMatch(updated))
                return;

            if (updated.DefinitionValues == null || !updated.DefinitionValues.Any())
            {
                dispatcher.Dispatch(new RemoveAllEntityValuesCommand(updated.Identity));
                return;
            }

            dispatcher.Dispatch(new UpdateEntityValuesCommand(updated.Identity, BuildEntityValues(updated.Identity, updated.DefinitionValues)));
        }
        private static IEnumerable<ValueSet> GetValues(EntityResource resource)
        {
            if (resource.DefinitionValues == null || !resource.DefinitionValues.Any())
                return Enumerable.Empty<ValueSet>();

            return resource.DefinitionValues.Select(x => new ValueSet
            {
                MetadataDefinitionIdentity = x.MetadataDefinitionIdentity,
                Name = x.Name,
                DataType = x.DataType,
                Regex = x.Regex,
                Values = new List<string>(x.Values)
            });
        }
        private static void GenerateValues(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.ValuesMatch(updated))
            {
                return;
            }

            if (updated.DefinitionValues == null || !updated.DefinitionValues.Any())
            {
                dispatcher.Dispatch(new RemoveAllEntityValuesCommand(updated.Identity));
                return;
            }

            dispatcher.Dispatch(new UpdateEntityValuesCommand(updated.Identity, BuildEntityValues(updated.Identity, updated.DefinitionValues)));
        }
Example #12
0
        private static IEnumerable <ValueSet> GetValues(EntityResource resource)
        {
            if (resource.DefinitionValues == null || !resource.DefinitionValues.Any())
            {
                return(Enumerable.Empty <ValueSet>());
            }

            return(resource.DefinitionValues.Select(x => new ValueSet
            {
                MetadataDefinitionIdentity = x.MetadataDefinitionIdentity,
                Name = x.Name,
                DataType = x.DataType,
                Regex = x.Regex,
                Values = new List <string>(x.Values)
            }));
        }
Example #13
0
        public HttpResponseMessage UpdateEntity([FromUri] Guid identity, [FromBody] EntityResource resource)
        {
            _logWriter.Info(String.Format("Update request for Entity: {0}", identity));
            resource.Identity = identity;

            var current        = _readService.FindByIdentity(resource.Identity);
            var matchingByName = _readService.FindByName(resource.Name);

            return(matchingByName.Filter(x => x.Identity != resource.Identity)
                   .Fold(x => Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"),
                         () => current.Fold(z =>
            {
                _dispatcher.GenerateCommands(_readService, resource);
                return Request.CreateResponse(HttpStatusCode.OK);
            },
                                            () => Request.CreateErrorResponse(HttpStatusCode.NotFound, "Entity Resource Not Found"))
                         ));
        }
Example #14
0
        public bool ValuesMatch(EntityResource other)
        {
            if (other == null)
            {
                return(false);
            }

            if (DefinitionValues == null)
            {
                return(other.DefinitionValues == null || !other.DefinitionValues.Any());
            }

            if (other.DefinitionValues == null)
            {
                return(DefinitionValues == null || !DefinitionValues.Any());
            }

            return(DefinitionValues.Count == other.DefinitionValues.Count && DefinitionValues.Intersect(other.DefinitionValues).Count() == DefinitionValues.Count);
        }
Example #15
0
        public HttpResponseMessage Create(EntityResource resource)
        {
            _logWriter.Info(String.Format("Beginning of processing creation of Entity : {0}", resource.Name));

            if (resource == null)
                throw new ArgumentEmptyException("resource");

            _logWriter.Debug(resource.ToString());

            if (_readService.FindByIdentity(resource.Identity).Exists)
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Identity already exists. Identities must be unique");

            return _readService.FindByName(resource.Name).Fold(x =>
                                                                    Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"),
                                                                    () =>
                                                                    {
                                                                        var command = resource.ToCreateCommand();
                                                                        _dispatcher.Dispatch(command);

                                                                        _logWriter.Info(String.Format("Completion of processing creation of Entity : {0}", resource.Name));

                                                                        return Request.CreateResponse(HttpStatusCode.Created);
                                                                    });
        }
        public static void GenerateCommands(this ICommandDispatcher dispatcher, IEntityReadService readService, EntityResource resource)
        {
            var current = readService.FindByIdentity(resource.Identity);

            current.Foreach(original =>
            {
                GenerateReLabelCommand(dispatcher, original, resource);
                GenerateChangeGroupCommand(dispatcher, original, resource);
                GenerateValues(dispatcher, original, resource);
            });
        }
        private static void GenerateChangeGroupCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DefinitionGroup != null && Equals(original.DefinitionGroup.Id, updated.DefinitionGroup.Id))
            {
                return;
            }

            dispatcher.Dispatch(new EntityChangedGroupCommand(updated.Identity, updated.DefinitionGroup.Id));
        }
Example #18
0
 public static CreateEntityCommand ToCreateCommand(this EntityResource resource)
 {
     return(new CreateEntityCommand(resource.Identity, resource.DefinitionGroup.Id, resource.Name, GetValues(resource)));
 }