public HttpResponseMessage CreateMetadataDefinitionGroup(MetadataDefinitionGroupResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentEmptyException("resource");
            }

            _logWriter.Info("Cleaning Record");
            resource.Clean();

            _logWriter.Info(String.Format("Beginning of processing creation of Definition Group: {0}", resource.Name));
            _logWriter.Debug(resource.ToString());

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

            if (_metadataDefinitonGroupReadService.FindByName(resource.Name).Exists)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exist. Names must be unique"));
            }

            var command = resource.ToCreateMetadataDefinitionGroupCommand();

            _dispatcher.Dispatch(command);

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

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

            dispatcher.Dispatch(new ReLabelMetadataDefinitionGroupCommand(updated.Identity, new MetadataDefinitionGroupName(updated.Name), new MetadataDefinitionGroupDescription(updated.Description), updated.Tracking));
        }
        public bool DiscriptionMatches(MetadataDefinitionGroupResource other)
        {
            if(other == null)
                throw new InvariantGuardFailureException();

            return other.PublicInstancePropertiesEqual(this);
        }
        public HttpResponseMessage CreateNewSchema(MetadataDefinitionGroupResource resource)
        {
            var command = resource.ToCreateMetadataDefinitionGroupCommand();
            _dispatcher.Dispatch(command);

            return Request.CreateResponse(HttpStatusCode.Created);
        }
        private static void GenerateAssociationCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated)
        {
            if (original.DefinitionIdsMatch(updated))
                return;

            dispatcher.Dispatch(new AssociateDefinitionsToMetadataDefinitionGroupCommand(original.Identity, updated.Definitions.Select(x=> x.Id).ToArray()));
        }
Beispiel #6
0
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated)
        {
            if (original.DiscriptionMatches(updated))
            {
                return;
            }

            dispatcher.Dispatch(new ReLabelMetadataDefinitionGroupCommand(updated.Identity, new MetadataDefinitionGroupName(updated.Name), new MetadataDefinitionGroupDescription(updated.Description), updated.Tracking));
        }
        public bool DiscriptionMatches(MetadataDefinitionGroupResource other)
        {
            if (other == null)
            {
                throw new InvariantGuardFailureException();
            }

            return(other.PublicInstancePropertiesEqual(this));
        }
        public static void GenerateCommands(this ICommandDispatcher dispatcher, IMetadataDefinitonGroupReadService readService, MetadataDefinitionGroupResource resource)
        {
            var current = readService.FindByIdentity(resource.Identity);

            current.Foreach(original =>
            {
                GenerateReLabelCommand(dispatcher, original, resource);
                GenerateAssociationCommand(dispatcher, original, resource);
            });
        }
        public bool DefinitionIdsMatch(MetadataDefinitionGroupResource other)
        {
            if (other == null)
                throw new InvariantGuardFailureException();

            if (Definitions.Count() != other.Definitions.Count())
                return false;

            var result = Definitions.Intersect(other.Definitions).Count() == Definitions.Count();
            return result;
        }
        public bool DefinitionIdsMatch(MetadataDefinitionGroupResource other)
        {
            if (other == null)
            {
                throw new InvariantGuardFailureException();
            }

            if (Definitions.Count() != other.Definitions.Count())
            {
                return(false);
            }

            var result = Definitions.Intersect(other.Definitions).Count() == Definitions.Count();

            return(result);
        }
        public HttpResponseMessage CreateMetadataDefinitionGroup(MetadataDefinitionGroupResource resource)
        {
            if (resource == null)
                throw new ArgumentEmptyException("resource");

            _logWriter.Info("Cleaning Record");
            resource.Clean();

            _logWriter.Info(String.Format("Beginning of processing creation of Definition Group: {0}", resource.Name));
            _logWriter.Debug(resource.ToString());

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

            if (_metadataDefinitonGroupReadService.FindByName(resource.Name).Exists)
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest,resource.Name + " already exist. Names must be unique");

            var command = resource.ToCreateMetadataDefinitionGroupCommand();
            _dispatcher.Dispatch(command);

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

            return Request.CreateResponse(HttpStatusCode.Created);
        }
        public HttpResponseMessage UpdateMetadataDefinitionGroup([FromUri] Guid identity, [FromBody] MetadataDefinitionGroupResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentEmptyException("resource");
            }

            _logWriter.Info("Cleaning Record");
            resource.Clean();

            _logWriter.Info(String.Format("Update request for Metadata Definition Group: {0}", identity));
            resource.Identity = identity;

            var current      = _metadataDefinitonGroupReadService.FindByIdentity(resource.Identity);
            var matchingName = _metadataDefinitonGroupReadService.FindByName(resource.Name);

            if (matchingName.Exists && matchingName.Value.Identity != resource.Identity)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"));
            }

            if (current == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group not found"));
            }

            if (current.Value.Identity != resource.Identity)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group not found"));
            }

            _dispatcher.GenerateCommands(_metadataDefinitonGroupReadService, resource);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #13
0
        public static void GenerateCommands(this ICommandDispatcher dispatcher, IMetadataDefinitonGroupReadService readService, MetadataDefinitionGroupResource resource)
        {
            var current = readService.FindByIdentity(resource.Identity);

            current.Foreach(original =>
            {
                GenerateReLabelCommand(dispatcher, original, resource);
                GenerateAssociationCommand(dispatcher, original, resource);
            });
        }
Beispiel #14
0
        private static void GenerateAssociationCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated)
        {
            if (original.DefinitionIdsMatch(updated))
            {
                return;
            }

            dispatcher.Dispatch(new AssociateDefinitionsToMetadataDefinitionGroupCommand(original.Identity, updated.Definitions.Select(x => x.Id).ToArray()));
        }
 public static CreateMetadataDefinitionGroupCommand ToCreateMetadataDefinitionGroupCommand(this MetadataDefinitionGroupResource resource)
 {
     return(new CreateMetadataDefinitionGroupCommand(resource.Identity, resource.Name, resource.Description, new MetadataBag(resource.Definitions.Select(x => x.Id).ToArray()), resource.Tracking));
 }