/// <inheritdoc /> public async Task <MetadataDefinitionDto> HandleResult(UpdateValidatorConfigurationCommand command, CancellationToken token) { var definition = _dynamicMetadataDefinitionService.GetById(command.DefinitionId); if (definition == null) { throw new NotFoundException(); } var validator = definition.Validators.FirstOrDefault(x => x.ValidatorId == command.ValidatorId); if (validator == null) { throw new NotFoundException(); } validator.Parameters = command.ValidatorConfiguration.Parameters; bool result = _validationFactory.CreateValidatorFor(validator, definition); if (!result) { throw new BadRequestException("Validator has invalid configuration"); } _dynamicMetadataDefinitionWriteService.UpdateItem(definition, token); await _eventDispatcher.DispatchEvent(new RefreshValidationEvent { DefinitionId = definition.Id }); return(_mapper.Map <MetadataDefinitionDto>(definition)); }
/// <inheritdoc /> public async Task <MetadataDefinitionDto> HandleResult(RemoveValidatorCommand command, CancellationToken token) { var definition = _dynamicMetadataDefinitionService.GetById(command.DefinitionId); if (definition == null) { throw new NotFoundException(); } var validator = definition.Validators.FirstOrDefault(x => x.ValidatorId == command.ValidatorId); if (validator == null) { throw new NotFoundException(); } definition.Validators.Remove(validator); _dynamicMetadataDefinitionWriteService.UpdateItem(definition, token); await _eventDispatcher.DispatchEvent(new RefreshValidationEvent { DefinitionId = definition.Id }); return(_mapper.Map <MetadataDefinitionDto>(definition)); }
/// <inheritdoc /> public async Task <MetadataDefinitionDto> HandleResult(AddValidatorCommand command, CancellationToken token) { var definition = _dynamicMetadataDefinitionService.GetById(command.DefinitionId); if (definition == null) { throw new NotFoundException(); } var validatorConfiguration = _mapper.Map <ValidatorConfiguration>(command.ValidatorData); validatorConfiguration.ValidatorId = Guid.NewGuid().ToString(); bool result = _validationFactory.CreateValidatorFor(validatorConfiguration, definition); if (!result) { throw new BadRequestException("Validator has invalid configuration"); } definition.Validators.Add(validatorConfiguration); _dynamicMetadataDefinitionWriteService.UpdateItem(definition, token); await _eventDispatcher.DispatchEvent(new RefreshValidationEvent { DefinitionId = definition.Id }); return(_mapper.Map <MetadataDefinitionDto>(definition)); }
/// <inheritdoc /> public async Task <List <DynamicMetadataDto> > Execute(GetMovieMetadataQuery query) { var movie = _movieReadService.GetById(query.MovieId); if (movie == null) { return(new List <DynamicMetadataDto>()); } return(_mapper.Map <List <DynamicMetadataDto> >(movie.Metadata)); }
/// <inheritdoc /> public async Task HandleEvent(PropertyDefinitionUpdatedEvent eventData, CancellationToken ct) { var definition = _dynamicMetadataDefinition.GetById(eventData.DefinitionId); var allMovies = _movieReadService.GetAll(); var validator = _validationFactory.GetValidator(definition); var propertyInDefinition = definition.Properties.Single(x => x.Id == eventData.UpdatedPropertyKey); foreach (var movie in allMovies) { var matchedMetadatas = movie.Metadata.Where(x => x.DefinitionId == eventData.DefinitionId).ToList(); if (matchedMetadatas.Any()) { foreach (var matchedMetadata in matchedMetadatas) { var property = matchedMetadata.Properties.Single(x => x.Id == eventData.UpdatedPropertyKey); bool alreadySetStatus = false; if (property.HasDefaultValue) { var copy = _mapper.Map <DynamicMetadataProperty>(propertyInDefinition); copy.HasDefaultValue = true; matchedMetadata.Properties.Remove(property); matchedMetadata.Properties.Add(copy); } else if (property.Type != propertyInDefinition.Type) { property.State = PropertyState.UsesOldType; alreadySetStatus = true; } var validationErrors = validator.Validate(matchedMetadata, movie); if (validationErrors.Any() && !alreadySetStatus) { property.State = PropertyState.Invalidated; } } _movieWriteService.UpdateItem(movie, ct); } } }
/// <inheritdoc /> public async Task <MetadataDefinitionDto> HandleResult(ChangePropertyTypeAndDefaultValueCommand command, CancellationToken token) { var definition = _dynamicMetadataDefinitonService.GetById(command.DefinitionId); if (definition == null) { throw new NotFoundException(); } var existingProperty = definition.Properties.SingleOrDefault(x => x.Id == command.PropertyKey); if (existingProperty == null) { throw new BadRequestException("Property doesn't already exist"); } DynamicMetadataProperty property; try { property = _inputDataParser.DeserializeItem(command.PropertyKey, command.UpdatedObject.Type, command.UpdatedObject.DefaultValue); } catch (JsonException exception) { throw new AggregatedValidationException("Invalid type mismatch") { ErrorCode = 11231, ValidationErrors = new List <Error>() }; } // parsing property definition.Properties.Remove(existingProperty); definition.Properties.Add(property); _dynamicMetadataDefinitionWriteService.UpdateItem(definition, token); await _eventDispatcher.DispatchEvent(new PropertyDefinitionUpdatedEvent { UpdatedPropertyKey = property.Id, DefinitionId = command.DefinitionId }); return(_mapper.Map <MetadataDefinitionDto>(definition)); }
/// <inheritdoc /> public List <Error> Validate(DynamicMetadata dynamicMetadata, Movie context) { var property = dynamicMetadata.Properties.First(x => x.Id == Property); if (property.Value != null) { Model.Person value = (Model.Person)property.Value; var dbItem = _personReadService.GetById(value.Id); if (dbItem == null) { return(new List <Error> { new Error(23123123, "Person doesnt exist") }); } } return(new List <Error>()); }
/// <inheritdoc /> public async Task <bool> HandleResult(DeleteMovieMetadataCommand command, CancellationToken token) { var movie = _movieReadService.GetById(command.MovieId); if (movie == null) { throw new NotFoundException(); } var metadata = movie.Metadata.Single(x => x.Id == command.MetdataId); if (metadata == null) { throw new NotFoundException(); } movie.Metadata.Remove(metadata); _movieWriteService.UpdateItem(movie, token); return(true); }
/// <inheritdoc /> public async Task HandleEvent(PropertyAddedToMetadataDefinitionEvent eventData, CancellationToken ct) { var allMovies = _movieReadService.GetAll(); var updatedDefinition = _dynamicMetadataDefinition.GetById(eventData.DefinitionId); var addedProperty = updatedDefinition.Properties.SingleOrDefault(x => x.Id == eventData.AddedPropertyId); foreach (var movie in allMovies) { var matchedMetadatas = movie.Metadata.Where(x => x.DefinitionId == eventData.DefinitionId).ToList(); if (matchedMetadatas.Any()) { foreach (var matchedMetadata in matchedMetadatas) { var copy = _mapper.Map <DynamicMetadataProperty>(addedProperty); copy.HasDefaultValue = true; matchedMetadata.Properties.Add(copy); } _movieWriteService.UpdateItem(movie, ct); } } }
public async Task HandleEvent(RefreshValidationEvent eventData, CancellationToken ct) { var allMovies = _movieReadService.GetAll(); var metadataDefinition = _metadataReadService.GetById(eventData.DefinitionId); var validators = _validationFactory.GetValidator(metadataDefinition); foreach (var movie in allMovies) { var updatedDefinitions = movie.Metadata.Where(x => x.DefinitionId == metadataDefinition.Id).ToList(); if (!updatedDefinitions.Any()) { continue; } bool isValidMovie = true; foreach (var definition in updatedDefinitions) { var propertyValidationErrors = validators.Validate(definition, movie); if (propertyValidationErrors.Any()) { definition.IsValid = false; isValidMovie = false; } if (!propertyValidationErrors.Any()) { definition.IsValid = true; } } movie.IsValid = isValidMovie; _movieWriteService.UpdateItem(movie, ct); } }
/// <inheritdoc /> public async Task <MetadataDefinitionDto> HandleResult(RemoveMovieMetadataCommand command, CancellationToken token) { var definition = _dynamicMetadataDefinitonService.GetById(command.MetadataDefinitionId); if (definition == null) { throw new NotFoundException(); } var existingProperty = definition.Properties.SingleOrDefault(x => x.Id == command.MetadataKey); if (existingProperty == null) { throw new NotFoundException(); } var validator = _validationFactory.GetValidator(definition); if (validator.WillUseProperty(existingProperty.Id)) { throw new BadRequestException("Property is used by validator") { ErrorCode = 11, }; } definition.Properties.Remove(existingProperty); _dynamicMetadataDefinitionWriteService.UpdateItem(definition, token); await _eventDispatcher.DispatchEvent(new PropertyRemovedFromMetadataDefinitionEvent { RemovedPropertyKey = command.MetadataKey, DefinitionId = command.MetadataDefinitionId }); return(_mapper.Map <MetadataDefinitionDto>(definition)); }
public async Task <Racun> GetById(long id) { return(await _readService.GetById(id)); }
public virtual T GetById(int id) { return(_service.GetById(id)); }
public async Task <Stanje> GetById(long id) { return(await _accountBalanceReadService.GetById(id)); }
public MovieDto GetAll(string movieId, CancellationToken ct) { return(_movieReadService.GetById <MovieDto>(movieId)); }
public virtual Task <T> GetById([FromRoute] int id) { return(_service.GetById(id)); }
public async Task <Klijent> GetById(long id) { return(await _clientRead.GetById(id)); }
/// <inheritdoc /> public async Task <DynamicMetadataDto> HandleResult(UpdateMovieMetadataCommand command, CancellationToken token) { var movie = _movieReadService.GetById(command.MovieId); var metadata = movie.Metadata.FirstOrDefault(x => x.Id == command.MetdataId); var definition = _dynamicMetadataDefinitionReadService.GetById(metadata.DefinitionId); var validator = _validationFactory.GetValidator(definition); foreach (var metadataEntry in command.Metadata.DynamicProperties) { var propertyDefinition = definition.Properties.SingleOrDefault(x => x.Id == metadataEntry.Id); if (propertyDefinition != null) { if (propertyDefinition.Type != metadataEntry.Type) { throw new AggregatedValidationException("Type mismatch") { ErrorCode = 11231, ValidationErrors = new List <Error>() }; } var existingMetadata = metadata.Properties.SingleOrDefault(x => x.Id == metadataEntry.Id); if (existingMetadata != null) { try { var parsedValue = _inputDataParser.DeserializeItem(metadataEntry.Id, metadataEntry.Type, metadataEntry.Value); parsedValue.HasDefaultValue = false; metadata.Properties.Remove(existingMetadata); metadata.Properties.Add(parsedValue); } catch (JsonException exception) { throw new AggregatedValidationException("Invalid type mismatch") { ErrorCode = 11231, ValidationErrors = new List <Error>() }; } } } } var validationResult = validator.Validate(metadata, movie); if (validationResult.Any()) { throw new AggregatedValidationException("Validation exception") { ErrorCode = 1, ValidationErrors = validationResult }; } movie.Metadata.Add(metadata); _movieWriteService.UpdateItem(movie, token); var resultValue = _mapper.Map <DynamicMetadataDto>(metadata); return(resultValue); }
public Read GetReadById(Guid readId) { return(_readService.GetById(readId)); }