public async Task <List <ValidationIssue> > ValidateDataElement(Instance instance, DataType dataType, DataElement dataElement) { _logger.LogInformation($"Validation of data element {dataElement.Id} of instance {instance.Id}"); // Todo. Figure out where to get this from Dictionary <string, Dictionary <string, string> > serviceText = new Dictionary <string, Dictionary <string, string> >(); List <ValidationIssue> messages = new List <ValidationIssue>(); if (dataElement.ContentType == null) { ValidationIssue message = new ValidationIssue { InstanceId = instance.Id, Code = ValidationIssueCodes.DataElementCodes.MissingContentType, DataElementId = dataElement.Id, Severity = ValidationIssueSeverity.Error, Description = AppTextHelper.GetAppText( ValidationIssueCodes.DataElementCodes.MissingContentType, serviceText, null, "nb") }; messages.Add(message); } else { string contentTypeWithoutEncoding = dataElement.ContentType.Split(";")[0]; if (dataType.AllowedContentTypes != null && dataType.AllowedContentTypes.Count > 0 && dataType.AllowedContentTypes.All(ct => !ct.Equals(contentTypeWithoutEncoding, StringComparison.OrdinalIgnoreCase))) { ValidationIssue message = new ValidationIssue { InstanceId = instance.Id, DataElementId = dataElement.Id, Code = ValidationIssueCodes.DataElementCodes.ContentTypeNotAllowed, Severity = ValidationIssueSeverity.Error, Description = AppTextHelper.GetAppText( ValidationIssueCodes.DataElementCodes.ContentTypeNotAllowed, serviceText, null, "nb"), Field = dataType.Id }; messages.Add(message); } } if (dataType.MaxSize.HasValue && dataType.MaxSize > 0 && (long)dataType.MaxSize * 1024 * 1024 < dataElement.Size) { ValidationIssue message = new ValidationIssue { InstanceId = instance.Id, DataElementId = dataElement.Id, Code = ValidationIssueCodes.DataElementCodes.DataElementTooLarge, Severity = ValidationIssueSeverity.Error, Description = AppTextHelper.GetAppText( ValidationIssueCodes.DataElementCodes.DataElementTooLarge, serviceText, null, "nb"), Field = dataType.Id }; messages.Add(message); } if (dataType.AppLogic != null) { Type modelType = _altinnApp.GetAppModelType(dataType.AppLogic.ClassRef); Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]); string app = instance.AppId.Split("/")[1]; int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId); dynamic data = await _dataService.GetFormData(instanceGuid, modelType, instance.Org, app, instanceOwnerPartyId, Guid.Parse(dataElement.Id)); ModelStateDictionary validationResults = new ModelStateDictionary(); var actionContext = new ActionContext( _httpContextAccessor.HttpContext, new Microsoft.AspNetCore.Routing.RouteData(), new ActionDescriptor(), validationResults); ValidationStateDictionary validationState = new ValidationStateDictionary(); _objectModelValidator.Validate(actionContext, validationState, null, data); await _altinnApp.RunDataValidation(data, validationResults); if (!validationResults.IsValid) { messages.AddRange(MapModelStateToIssueList(actionContext.ModelState, instance, dataElement.Id, serviceText)); } } return(messages); }