/// <summary> /// Validates general description model. /// </summary> public override void Validate(ModelStateDictionary modelState) { names.Validate(modelState); if (Model.Descriptions?.Where(d => d.Type == DescriptionTypeEnum.Description.ToString()).FirstOrDefault() == null && Model.Descriptions?.Where(d => d.Type == DescriptionTypeEnum.BackgroundDescription.ToString()).FirstOrDefault() == null && newLanguages?.Count > 0) { modelState.AddModelError("Descriptions", string.Format(CoreMessages.OpenApi.RequiredValueWithLanguageAndTypeNotFound, $"{ DescriptionTypeEnum.Description.ToString()} or { DescriptionTypeEnum.BackgroundDescription.ToString()}", newLanguages.First())); descriptions = new LocalizedListValidator(Model.Descriptions, "Descriptions", newLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString() }); } else { var descriptionType = Model.Descriptions?.Where(d => d.Type != DescriptionTypeEnum.ShortDescription.ToString()).Select(d => d.Type).FirstOrDefault(); descriptions = new LocalizedListValidator(Model.Descriptions, "Descriptions", newLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString(), descriptionType }); } descriptions.Validate(modelState); languages.Validate(modelState); serviceClasses.Validate(modelState); ontologyTerms.Validate(modelState); targetGroups.Validate(modelState); lifeEvents.Validate(modelState); industrialClasses.Validate(modelState); status.Validate(modelState); }
/// <summary> /// Ctor - organization validator /// </summary> /// <param name="model">Organization model</param> /// <param name="codeService">Code service</param> /// <param name="organizationService">Organization service</param> /// <param name="commonService">Common service</param> /// <param name="newLanguages">Languages that should be validated within lists</param> /// <param name="availableLanguages">The languages that are available in main model and therefore need to be validated.</param> /// <param name="isCreateOperation">Indicates if organization is beeing inserted or updated.</param> /// <param name="versionNumber">Version number.</param> public OrganizationValidator(IVmOpenApiOrganizationInVersionBase model, ICodeService codeService, IOrganizationService organizationService, IList <string> newLanguages, IList <string> availableLanguages, ICommonService commonService, int versionNumber, bool isCreateOperation = false) : base(model, "Organization") { this.codeService = codeService; if (model == null) { throw new ArgumentNullException(PropertyName, $"{PropertyName} must be defined."); } name = new LocalizedListValidator(model.OrganizationNames, "OrganizationNames", newLanguages, new List <string>() { NameTypeEnum.Name.ToString() }); municipality = new MunicipalityCodeValidator(model.Municipality, codeService); addresses = new AddressListValidator <V7VmOpenApiAddressWithForeignIn>(model.Addresses, codeService); organizationId = new OrganizationIdValidator(model.ParentOrganizationId, commonService, "ParentOrganizationId"); oid = new OidValidator(model.Oid, organizationService, isCreateOperation: isCreateOperation, organizationId: model.Id, sourceId: model.SourceId); phones = new PhoneNumberListValidator <V4VmOpenApiPhone>(model.PhoneNumbers, codeService); status = new PublishingStatusValidator(model.PublishingStatus, model.CurrentPublishingStatus); description = new LocalizedListValidator(model.OrganizationDescriptions, "OrganizationDescriptions", newLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString() }, availableLanguages); this.versionNumber = versionNumber; }
/// <summary> /// Checks if electronic channel model is valid or not. /// </summary> /// <param name="modelState"></param> public override void Validate(ModelStateDictionary modelState) { // Validate names against newly added languages (required languages) var names = new LanguageItemListValidator(Model.ServiceChannelNames, "ServiceChannelNames", requiredLanguages); names.Validate(modelState); // Validate descriptions against newly added languages (required languages), all the available languages does not need to be validated. var descriptions = new LocalizedListValidator(Model.ServiceChannelDescriptions, "ServiceChannelDescriptions", requiredLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString(), DescriptionTypeEnum.Description.ToString() }); descriptions.Validate(modelState); hours.Validate(modelState); organizationId.Validate(modelState); languages.Validate(modelState); phones.Validate(modelState); // Validate publishing status var status = new PublishingStatusValidator(Model.PublishingStatus, currentPublishingStatus); status.Validate(modelState); areas.Validate(modelState); services.Validate(modelState); }
/// <summary> /// Validates printable form channel model. /// </summary> /// <param name="modelState"></param> public override void Validate(ModelStateDictionary modelState) { base.Validate(modelState); address.Validate(modelState); // Validate required channelUrls property var urls = new LocalizedListValidator(Model.ChannelUrls, "ChannelUrls", requiredLanguages: RequiredLanguages, availableLanguages: AvailableLanguages); urls.Validate(modelState); }
/// <summary> /// Ctor - service validator /// </summary> /// <param name="model">Service model</param> /// <param name="generalDescriptionService">General description service</param> /// <param name="codeService">Code service</param> /// <param name="fintoService">Finto item service</param> /// <param name="commonService">Common service</param> /// <param name="channelService">Channel service</param> /// <param name="newLanguages">Languages that should be validated within lists</param> /// <param name="userRole">User role</param> public ServiceValidator( IVmOpenApiServiceInVersionBase model, IGeneralDescriptionService generalDescriptionService, ICodeService codeService, IFintoService fintoService, ICommonService commonService, IChannelService channelService, IList <string> newLanguages, UserRoleEnum userRole ) : base(model, "Service") { this.generalDescriptionService = generalDescriptionService; if (model == null) { throw new ArgumentNullException(PropertyName, $"{PropertyName} must be defined."); } names = new LocalizedListValidator(model.ServiceNames, "ServiceNames", newLanguages, new List <string>() { NameTypeEnum.Name.ToString() }); languages = new LanguageListValidator(model.Languages, codeService); serviceClasses = new ServiceClassListValidator(model.ServiceClasses, fintoService); ontologyTerms = new OntologyTermListValidator(model.OntologyTerms, fintoService); targetGroups = new TargetGroupListValidator(model.TargetGroups, fintoService); lifeEvents = new LifeEventListValidator(model.LifeEvents, fintoService); industrialClasses = new IndustrialClassListValidator(model.IndustrialClasses, fintoService); organizations = new OrganizationIdListValidator(model.OtherResponsibleOrganizations?.Select(o => o.ToString()).ToList(), commonService, "OtherResponsibleOrganizations"); status = new PublishingStatusValidator(model.PublishingStatus, model.CurrentPublishingStatus); areas = new AreaAndTypeValidator(model.Areas, model.AreaType, codeService); var channelList = model.ServiceServiceChannels?.Count > 0 ? model.ServiceServiceChannels.Select(i => i.ChannelGuid).ToList() : new List <Guid>(); channels = new ServiceChannelIdListValidator(channelList, channelService, userRole, "ServiceChannels"); var availableOrganizations = new List <Guid>(); if (!model.MainResponsibleOrganization.IsNullOrEmpty()) { availableOrganizations.Add(model.MainResponsibleOrganization.ParseToGuidWithExeption()); } if (model.OtherResponsibleOrganizations?.Count > 0) { availableOrganizations.AddRange(model.OtherResponsibleOrganizations); } serviceProducers = new ServiceProducerListValidator(model.ServiceProducers, availableOrganizations, commonService); mainOrganization = new OrganizationIdValidator(model.MainResponsibleOrganization, commonService, "MainResponsibleOrganization"); generalDescriptionAttached = !string.IsNullOrEmpty(model.StatutoryServiceGeneralDescriptionId); this.newLanguages = newLanguages; }
/// <summary> /// Ctor - general description validator /// </summary> /// <param name="model">General description model</param> /// <param name="codeService">Code service</param> /// <param name="fintoService">Finto item service</param> /// <param name="newLanguages">Languages that should be validated within lists</param> /// <param name="createOperation">Indicates if general description is beeing created or updated.</param> public GeneralDescriptionValidator(IVmOpenApiGeneralDescriptionInVersionBase model, ICodeService codeService, IFintoService fintoService, IList <string> newLanguages, bool createOperation) : base(model, "GeneralDescription") { if (model == null) { throw new ArgumentNullException(PropertyName, $"{PropertyName} must be defined."); } names = new LocalizedListValidator(model.Names, "Names", newLanguages, new List <string>() { NameTypeEnum.Name.ToString() }); languages = new LanguageListValidator(model.Languages, codeService); serviceClasses = new ServiceClassListValidator(model.ServiceClasses, fintoService); ontologyTerms = new OntologyTermListValidator(model.OntologyTerms, fintoService); targetGroups = new TargetGroupListValidator(model.TargetGroups, fintoService); lifeEvents = new LifeEventListValidator(model.LifeEvents, fintoService); industrialClasses = new IndustrialClassListValidator(model.IndustrialClasses, fintoService); status = new PublishingStatusValidator(model.PublishingStatus, model.CurrentPublishingStatus); this.createOperation = createOperation; this.newLanguages = newLanguages; }
/// <summary> /// Checks if service model is valid or not. /// </summary> public override void Validate(ModelStateDictionary modelState) { if (!generalDescriptionAttached) { // validate names if general description is not set (name is taken from general description if not set). names.Validate(modelState); // Validate all required descriptions descriptions = new LocalizedListValidator(Model.ServiceDescriptions, "ServiceDescriptions", newLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString(), DescriptionTypeEnum.Description.ToString() }); } else { // General description was defined. var gdId = Model.StatutoryServiceGeneralDescriptionId.ParseToGuid(); if (gdId.HasValue) { var gd = generalDescriptionService.GetGeneralDescriptionVersionBase(gdId.Value, 0); if (gd == null || !gd.Id.HasValue) { modelState.AddModelError("StatutoryServiceGeneralDescriptionId", CoreMessages.OpenApi.RecordNotFound); } else { if (gd.Descriptions == null || gd.Descriptions.Where(d => d.Type == DescriptionTypeEnum.Description.ToString() && d.Value != null && d.Value.Length > 0).FirstOrDefault() == null) { // Description was not defined within GD - service model need to include all required description, so let's validate both ShortDescription and Description descriptions = new LocalizedListValidator(Model.ServiceDescriptions, "ServiceDescriptions", newLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString(), DescriptionTypeEnum.Description.ToString() }); } else { // Validate only ShortDescription for Descriptions. Description is not required if it is defined within GD. descriptions = new LocalizedListValidator(Model.ServiceDescriptions, "ServiceDescriptions", newLanguages, new List <string>() { DescriptionTypeEnum.ShortDescription.ToString() }); } } } else { modelState.AddModelError("StatutoryServiceGeneralDescriptionId", CoreMessages.OpenApi.RecordNotFound); } } if (descriptions != null) { descriptions.Validate(modelState); } //municipalities.Validate(modelState); // We do not need to validate municipalities anymore - they are mapped into Model.Areas in VmOpenApiServiceInVersionBase languages.Validate(modelState); serviceClasses.Validate(modelState); ontologyTerms.Validate(modelState); targetGroups.Validate(modelState); lifeEvents.Validate(modelState); industrialClasses.Validate(modelState); organizations.Validate(modelState); status.Validate(modelState); // Validate area type, service areas and municipalities areas.Validate(modelState); channels.Validate(modelState); serviceProducers.Validate(modelState); mainOrganization.Validate(modelState); }