protected override Task Context() { _parameterMapper = A.Fake <ParameterMapper>(); _schemaItemMapper = A.Fake <SchemaItemMapper>(); _schemaFactory = A.Fake <ISchemaFactory>(); sut = new SchemaMapper(_parameterMapper, _schemaItemMapper, _schemaFactory); _schemaItem = new SchemaItem().WithName("Item1"); _schema = new Schema { Description = "Hello", Name = "Tralala" }; _schema.AddSchemaItem(_schemaItem); _parameter = DomainHelperForSpecs.ConstantParameterWithValue(3).WithName("Param1"); //Schema item parameters that have a value IsDefault true should still be saved to snapshot _parameter1 = DomainHelperForSpecs.ConstantParameterWithValue(1, isDefault: true).WithName(Constants.Parameters.START_TIME); _parameter2 = DomainHelperForSpecs.ConstantParameterWithValue(2, isDefault: true).WithName(CoreConstants.Parameters.NUMBER_OF_REPETITIONS); _parameter3 = DomainHelperForSpecs.ConstantParameterWithValue(3, isDefault: true).WithName(CoreConstants.Parameters.TIME_BETWEEN_REPETITIONS); _schema.Add(_parameter); _schema.Add(_parameter1); _schema.Add(_parameter2); _schema.Add(_parameter3); A.CallTo(() => _parameterMapper.MapToSnapshot(_parameter)).Returns(new Snapshots.Parameter().WithName(_parameter.Name)); A.CallTo(() => _parameterMapper.MapToSnapshot(_parameter1)).Returns(new Snapshots.Parameter().WithName(_parameter1.Name)); A.CallTo(() => _parameterMapper.MapToSnapshot(_parameter2)).Returns(new Snapshots.Parameter().WithName(_parameter2.Name)); A.CallTo(() => _parameterMapper.MapToSnapshot(_parameter3)).Returns(new Snapshots.Parameter().WithName(_parameter3.Name)); A.CallTo(() => _schemaItemMapper.MapToSnapshot(_schemaItem)).Returns(new Snapshots.SchemaItem().WithName(_schemaItem.Name)); return(Task.FromResult(true)); }
public BookingService( IDistributedCacheWrapper distributedCache, IPageHelper pageHelper, IEnumerable <IBookingProvider> bookingProviders, IPageFactory pageFactory, IMappingService mappingService, IWebHostEnvironment environment, ISchemaFactory schemaFactory, ISessionHelper sessionHelper, IHashUtil hashUtil, IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration, IHttpContextAccessor httpContextAccessor) { _distributedCache = distributedCache; _pageHelper = pageHelper; _bookingProviders = bookingProviders; _pageFactory = pageFactory; _mappingService = mappingService; _environment = environment; _schemaFactory = schemaFactory; _sessionHelper = sessionHelper; _hashUtil = hashUtil; _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value; _httpContextAccessor = httpContextAccessor; }
public BookingController(IBookingService bookingService, ISchemaFactory schemaFactory, IPageHelper pageHelper, ISessionHelper sessionHelper) { _bookingService = bookingService; _schemaFactory = schemaFactory; _pageHelper = pageHelper; _sessionHelper = sessionHelper; }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { var schema = new OpenApiSchema { Type = "array", Title = para.Comment, }; var props = schemaFactory.GetProperties(para.Properties); var dicSchema = new OpenApiSchema(); if (props["value"].Properties != null && props["value"].Properties.Any()) { dicSchema.Properties.Add(props["key"].Type, new OpenApiSchema { Properties = props["value"].Properties }); } else { dicSchema.Properties.Add(props["key"].Type, props["value"]); } schema.Items = dicSchema; return(new SchemaModel(para.Name, schema)); }
public SimpleProtocolToSchemaMapper(ISchemaFactory schemaFactory, ISchemaItemFactory schemaItemFactory, ISchemaItemParameterRetriever schemaItemParameterRetriever) { _schemaFactory = schemaFactory; _schemaItemFactory = schemaItemFactory; _schemaItemParameterRetriever = schemaItemParameterRetriever; }
protected override Task Context() { _parameterMapper = A.Fake <ParameterMapper>(); _schemaItemMapper = A.Fake <SchemaItemMapper>(); _schemaFactory = A.Fake <ISchemaFactory>(); sut = new SchemaMapper(_parameterMapper, _schemaItemMapper, _schemaFactory); _schemaItem = new SchemaItem().WithName("Item1"); _schema = new Schema { Description = "Hello", Name = "Tralala" }; _schema.AddSchemaItem(_schemaItem); _parameter = DomainHelperForSpecs.ConstantParameterWithValue(3).WithName("Param1"); _schema.Add(_parameter); A.CallTo(() => _parameterMapper.MapToSnapshot(_parameter)).Returns(new Snapshots.Parameter().WithName(_parameter.Name)); A.CallTo(() => _schemaItemMapper.MapToSnapshot(_schemaItem)).Returns(new Snapshots.SchemaItem().WithName(_schemaItem.Name)); return(Task.FromResult(true)); }
protected override void Context() { _executionContext = A.Fake <IExecutionContext>(); _schemaItemFactory = A.Fake <ISchemaItemFactory>(); _schemaFactory = A.Fake <ISchemaFactory>(); sut = new SchemaTask(_executionContext, _schemaFactory, _schemaItemFactory); }
public BookingController(IBookingService bookingService, ISchemaFactory schemaFactory, IPageService pageService) { _bookingService = bookingService; _schemaFactory = schemaFactory; _pageService = pageService; }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { return(new SchemaModel(para.Name, new OpenApiSchema { Type = "string", Format = "date-time", Title = para.Comment })); }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { return(new SchemaModel(para.Name, new OpenApiSchema { Type = "object", Title = para.Comment, Properties = schemaFactory.GetProperties(para.Properties) })); }
protected override void Context() { _schemaFactory = new SchemaFactoryForTest(); _schemaItemFactory = new SchemaItemFactoryForTest(); _schemaItemRepo = A.Fake <ISchemaItemRepository>(); _cloner = A.Fake <ICloner>(); _schemaItemParameterRetriever = new SchemaItemParameterRetriever(_schemaItemRepo, _cloner); sut = new SimpleProtocolToSchemaMapper(_schemaFactory, _schemaItemFactory, _schemaItemParameterRetriever); }
public IEnumerable <RuleViolation> AddSchema( string schemaContents, ConfigurationSet config, ISchemaFactory <TSchemaContents> schemaFactory) { if (config == null) { throw new ArgumentNullException($"{nameof(config)} cannot be null"); } if (schemaFactory == null) { throw new ArgumentNullException($"{nameof(schemaFactory)} cannot be null"); } if (config.SchemaGroupId != this.Id) { throw new ArgumentException($"Config with schema group id {config.SchemaGroupId} cannot be used for schema group with id {this.Id}"); } Schema <TSchemaContents> lastSchema = this.schemas.LastOrDefault(); Version newVersion = lastSchema?.Version.Next() ?? Version.Initial; Schema <TSchemaContents> newSchema = schemaFactory.CreateNew(newVersion, schemaContents); var ruleViolations = new List <RuleViolation>(); IReadOnlyDictionary <RuleCode, RuleConfig> rulesConfig = config.GetRulesConfiguration(); if (lastSchema != null) { var schemaEnumerator = this.schemas.Reverse().GetEnumerator(); schemaEnumerator.MoveNext(); do { Schema <TSchemaContents> oldSchema = schemaEnumerator.Current; if (config.BackwardCompatible) { ruleViolations.AddRange(this.ValidateSchemas(newSchema, oldSchema, rulesConfig, true)); } if (config.ForwardCompatible) { ruleViolations.AddRange(this.ValidateSchemas(newSchema, oldSchema, rulesConfig, false)); } }while (schemaEnumerator.MoveNext() && config.Transitive); } IEnumerable <RuleViolation> fatalViolations = ruleViolations.Where(ruleViolation => ruleViolation.Severity.IsFatal); if (!fatalViolations.Any()) { this.schemas.Add(newSchema); } return(ruleViolations); }
public GraphQLController( ILogger <GraphQLController> logger, ShopContext dbContext, ISchemaFactory schemaFactory) { _logger = logger; _dbContext = dbContext; _schemaFactory = schemaFactory; }
public GraphSchemaProvider(ISchemaFactory schemaFactory, IGraphServiceDiscoverer serviceDiscoverer) { Guard.ArgumentNotNull(schemaFactory, nameof(schemaFactory)); Guard.ArgumentNotNull(serviceDiscoverer, nameof(serviceDiscoverer)); _schemaAccessor = new Lazy <IGraphSchema>(() => { return(schemaFactory.Create(serviceDiscoverer.Services)); }); }
public ActionsWorkflow(IRetrieveExternalDataService retrieveExternalDataService, IEmailService emailService, ISchemaFactory schemaFactory, IValidateService validateService) { _retrieveExternalDataService = retrieveExternalDataService; _emailService = emailService; _schemaFactory = schemaFactory; _validateService = validateService; }
public ProtocolFactory(IObjectBaseFactory objectBaseFactory, ISchemaFactory schemaFactory, IParameterFactory parameterFactory, IDimensionRepository dimensionRepository, ISchemaItemParameterRetriever schemaItemParameterRetriever, IDisplayUnitRetriever displayUnitRetriever) { _objectBaseFactory = objectBaseFactory; _schemaFactory = schemaFactory; _parameterFactory = parameterFactory; _dimensionRepository = dimensionRepository; _schemaItemParameterRetriever = schemaItemParameterRetriever; _displayUnitRetriever = displayUnitRetriever; }
public MappingService(IDistributedCacheWrapper distributedCache, IElementMapper elementMapper, ISchemaFactory schemaFactory, IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration, ILogger <MappingService> logger) { _distributedCache = distributedCache; _elementMapper = elementMapper; _schemaFactory = schemaFactory; _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value; _logger = logger; }
public MappingService(IDistributedCacheWrapper distributedCache, IElementMapper elementMapper, ISchemaFactory schemaFactory, IWebHostEnvironment environment, IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration, IDetectionService detectionService, ILogger <MappingService> logger) { _distributedCache = distributedCache; _elementMapper = elementMapper; _schemaFactory = schemaFactory; _environment = environment; _detectionService = detectionService; _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value; _logger = logger; }
protected override void Context() { _schemaFactory = A.Fake <ISchemaFactory>(); _objectBaseFactory = A.Fake <IObjectBaseFactory>(); _parameterFactory = A.Fake <IParameterFactory>(); _dimensionRepository = A.Fake <IDimensionRepository>(); _schemaItemParameterRetriever = A.Fake <ISchemaItemParameterRetriever>(); _displayUnitRetriever = A.Fake <IDisplayUnitRetriever>(); sut = new ProtocolFactory(_objectBaseFactory, _schemaFactory, _parameterFactory, _dimensionRepository, _schemaItemParameterRetriever, _displayUnitRetriever); _timeDimension = A.Fake <IDimension>(); _doseDimension = A.Fake <IDimension>(); _defaultTimeUnit = A.Fake <Unit>(); A.CallTo(() => _dimensionRepository.Mass).Returns(_doseDimension); A.CallTo(() => _dimensionRepository.Time).Returns(_timeDimension); A.CallTo(() => _displayUnitRetriever.PreferredUnitFor(_timeDimension)).Returns(_defaultTimeUnit); }
public PageService( IEnumerable <IElementValidator> validators, IPageHelper pageHelper, ISessionHelper sessionHelper, IAddressService addressService, IFileUploadService fileUploadService, IStreetService streetService, IOrganisationService organisationService, IDistributedCacheWrapper distributedCache, IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration, IWebHostEnvironment environment, ISuccessPageFactory successPageFactory, IPageFactory pageFactory, IBookingService bookingService, ISchemaFactory schemaFactory, IIncomingDataHelper incomingDataHelper, IActionsWorkflow actionsWorkflow, IAddAnotherService addAnotherService, IFormAvailabilityService formAvailabilityService, ILogger <IPageService> logger, IEnumerable <IFileStorageProvider> fileStorageProviders, IConfiguration configuration) { _validators = validators; _pageHelper = pageHelper; _sessionHelper = sessionHelper; _streetService = streetService; _addressService = addressService; _bookingService = bookingService; _organisationService = organisationService; _fileUploadService = fileUploadService; _distributedCache = distributedCache; _schemaFactory = schemaFactory; _successPageContentFactory = successPageFactory; _pageContentFactory = pageFactory; _environment = environment; _formAvailabilityService = formAvailabilityService; _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value; _incomingDataHelper = incomingDataHelper; _actionsWorkflow = actionsWorkflow; _logger = logger; _addAnotherService = addAnotherService; _fileStorageProviders = fileStorageProviders; _configuration = configuration; }
public async Task Invoke(HttpContext context, ISchemaFactory schemaService) { if (!IsGraphQLRequest(context)) { await _next(context); } else { if (CurrentUser.IsAuthenticated) { await ExecuteAsync(context, schemaService); } else { await context.ChallengeAsync("Api"); } } }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { var model = new SchemaModel(para.Name, new OpenApiSchema { Type = para.Type, Title = para.Comment, }); if (!string.IsNullOrEmpty(para.Default)) { try { switch (model.Value.Type) { case "string": model.Value.Example = new OpenApiString(para.Default); break; case "integer": model.Value.Example = new OpenApiInteger(Convert.ToInt32(para.Default)); break; case "number": model.Value.Example = new OpenApiDouble(Convert.ToDouble(para.Default)); break; case "datetime": model.Value.Example = new OpenApiDateTime(Convert.ToDateTime(para.Default)); break; case "boolean": model.Value.Example = new OpenApiBoolean(Convert.ToBoolean(para.Default)); break; default: break; } } catch { } } return(model); }
public GraphQLQueryService( ILiquidTemplateManager liquidTemplateManager, IOptions <TemplateOptions> templateOptions, IOptions <GraphQLSettings> settingsAccessor, IDocumentExecuter executer, IDocumentExecutionListener dataLoaderDocumentListener, IEnumerable <IValidationRule> validationRules, ISchemaFactory schemaService, IHttpContextAccessor httpContextAccessor) { _liquidTemplateManager = liquidTemplateManager; _settingsAccessor = settingsAccessor; _executer = executer; _dataLoaderDocumentListener = dataLoaderDocumentListener; _validationRules = validationRules; _schemaService = schemaService; _templateOptions = templateOptions.Value; _httpContextAccessor = httpContextAccessor; }
public SubmitService( IGateway gateway, IPageHelper pageHelper, IWebHostEnvironment environment, IOptions <SubmissionServiceConfiguration> submissionServiceConfiguration, IDistributedCacheWrapper distributedCache, ISchemaFactory schemaFactory, IReferenceNumberProvider referenceNumberProvider, IEnumerable <ISubmitProvider> submitProviders, ILogger <SubmitService> logger) { _gateway = gateway; _pageHelper = pageHelper; _environment = environment; _submissionServiceConfiguration = submissionServiceConfiguration.Value; _distributedCache = distributedCache; _schemaFactory = schemaFactory; _referenceNumberProvider = referenceNumberProvider; _submitProviders = submitProviders; _logger = logger; }
public PageService( IEnumerable <IElementValidator> validators, IPageHelper pageHelper, ISessionHelper sessionHelper, IAddressService addressService, IFileUploadService fileUploadService, IStreetService streetService, IOrganisationService organisationService, IDistributedCacheWrapper distributedCache, IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration, IWebHostEnvironment environment, ISuccessPageFactory successPageFactory, IPageFactory pageFactory, IBookingService bookingService, ISchemaFactory schemaFactory, IMappingService mappingService, IPayService payService, IIncomingDataHelper incomingDataHelper, IActionsWorkflow actionsWorkflow) { _validators = validators; _pageHelper = pageHelper; _sessionHelper = sessionHelper; _streetService = streetService; _addressService = addressService; _bookingService = bookingService; _organisationService = organisationService; _fileUploadService = fileUploadService; _distributedCache = distributedCache; _schemaFactory = schemaFactory; _successPageContentFactory = successPageFactory; _pageContentFactory = pageFactory; _environment = environment; _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value; _payService = payService; _mappingService = mappingService; _incomingDataHelper = incomingDataHelper; _actionsWorkflow = actionsWorkflow; }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { var schema = new OpenApiSchema { Type = "array", Title = para.Comment }; if (para.Properties != null && para.Properties.Count == 1 && (para.Properties.First().Properties == null || !para.Properties.First().Properties.Any())) { schema.Items = new OpenApiSchema { Type = para.Properties.First().Type }; } else { schema.Items = new OpenApiSchema { Properties = schemaFactory.GetProperties(para.Properties) }; } return(new SchemaModel(para.Name, schema)); }
public SchemaTask(IExecutionContext executionContext, ISchemaFactory schemaFactory, ISchemaItemFactory schemaItemFactory) { _executionContext = executionContext; _schemaFactory = schemaFactory; _schemaItemFactory = schemaItemFactory; }
private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaService) { var schema = await schemaService.GetSchemaAsync(); GraphQLRequest request = null; // c.f. https://graphql.org/learn/serving-over-http/#post-request if (HttpMethods.IsPost(context.Request.Method)) { var mediaType = new MediaType(context.Request.ContentType); try { if (mediaType.IsSubsetOf(_jsonMediaType)) { using (var sr = new StreamReader(context.Request.Body)) { // Asynchronous read is mandatory. var json = await sr.ReadToEndAsync(); request = JObject.Parse(json).ToObject <GraphQLRequest>(); } } else if (mediaType.IsSubsetOf(_graphQlMediaType)) { request = new GraphQLRequest(); using (var sr = new StreamReader(context.Request.Body)) { request.Query = await sr.ReadToEndAsync(); } } else if (context.Request.Query.ContainsKey("query")) { request = new GraphQLRequest { Query = context.Request.Query["query"] }; if (context.Request.Query.ContainsKey("variables")) { request.Variables = JObject.Parse(context.Request.Query["variables"]); } if (context.Request.Query.ContainsKey("operationName")) { request.OperationName = context.Request.Query["operationName"]; } } } catch (Exception e) { await WriteErrorAsync(context, "An error occurred while processing the GraphQL query", e); return; } } else if (HttpMethods.IsGet(context.Request.Method)) { if (!context.Request.Query.ContainsKey("query")) { await WriteErrorAsync(context, "The 'query' query string parameter is missing"); return; } request = new GraphQLRequest { Query = context.Request.Query["query"] }; } var queryToExecute = request.Query; if (!String.IsNullOrEmpty(request.NamedQuery)) { var namedQueries = context.RequestServices.GetServices <INamedQueryProvider>(); var queries = namedQueries .SelectMany(dict => dict.Resolve()) .ToDictionary(pair => pair.Key, pair => pair.Value); queryToExecute = queries[request.NamedQuery]; } var dataLoaderDocumentListener = context.RequestServices.GetRequiredService <IDocumentExecutionListener>(); var result = await _executer.ExecuteAsync(_ => { _.Schema = schema; _.Query = queryToExecute; _.OperationName = request.OperationName; _.Inputs = request.Variables.ToInputs(); _.UserContext = _settings.BuildUserContext?.Invoke(context); _.ExposeExceptions = _settings.ExposeExceptions; _.ValidationRules = DocumentValidator.CoreRules() .Concat(context.RequestServices.GetServices <IValidationRule>()); _.ComplexityConfiguration = new ComplexityConfiguration { MaxDepth = _settings.MaxDepth, MaxComplexity = _settings.MaxComplexity, FieldImpact = _settings.FieldImpact }; _.Listeners.Add(dataLoaderDocumentListener); }); context.Response.StatusCode = (int)(result.Errors == null || result.Errors.Count == 0 ? HttpStatusCode.OK : result.Errors.Any(x => x.Code == RequiresPermissionValidationRule.ErrorCode) ? HttpStatusCode.Unauthorized : HttpStatusCode.BadRequest); context.Response.ContentType = "application/json"; // Asynchronous write to the response body is mandatory. var encodedBytes = _utf8Encoding.GetBytes(JObject.FromObject(result).ToString()); await context.Response.Body.WriteAsync(encodedBytes, 0, encodedBytes.Length); }
public GraphQLController(IDocumentExecuter documentExecuter, ISchemaFactory schemaFactory) { this._documentExecuter = documentExecuter; this._schemaFactory = schemaFactory; }
public GraphService(ISchemaFactory SchemaGenerator) { schemaGenerator = SchemaGenerator; }
private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaService) { var schema = await schemaService.GetSchema(); AbpGraphQLRequest request = null; if (HttpMethods.IsPost(context.Request.Method)) { var mediaType = new MediaType(context.Request.ContentType); try { if (mediaType.IsSubsetOf(JsonMediaType)) { using (var sr = new StreamReader(context.Request.Body)) { using (var jsonTextReader = new JsonTextReader(sr)) { request = Serializer.Deserialize <AbpGraphQLRequest>(jsonTextReader); } } } else if (mediaType.IsSubsetOf(GraphQLMediaType)) { request = new AbpGraphQLRequest(); using (var sr = new StreamReader(context.Request.Body)) { request.Query = await sr.ReadToEndAsync(); } } else if (context.Request.Query.ContainsKey("query")) { request = new AbpGraphQLRequest { Query = context.Request.Query["query"] }; if (context.Request.Query.ContainsKey("variables")) { request.Variables = JObject.Parse(context.Request.Query["variables"]); } if (context.Request.Query.ContainsKey("operationName")) { request.OperationName = context.Request.Query["operationName"]; } } } catch (Exception e) { await WriteErrorAsync(context, "An error occured while processing the GraphQL query", e); return; } } else if (HttpMethods.IsGet(context.Request.Method)) { if (!context.Request.Query.ContainsKey("query")) { await WriteErrorAsync(context, "The 'query' query string parameter is missing"); return; } request = new AbpGraphQLRequest { Query = context.Request.Query["query"] }; } var queryToExecute = request.Query; if (!string.IsNullOrEmpty(request.NamedQuery)) { var namedQueries = context.RequestServices.GetServices <INamedQueryProvider>(); var queries = namedQueries .SelectMany(dict => dict.Resolve()) .ToDictionary(pair => pair.Key, pair => pair.Value); queryToExecute = queries[request.NamedQuery]; } var result = await _executor.ExecuteAsync(_ => { _.Schema = schema; _.Query = queryToExecute; _.OperationName = request.OperationName; _.Inputs = request.Variables.ToInputs(); _.UserContext = _options.BuildUserContext?.Invoke(context); #if DEBUG _.ExposeExceptions = true; #endif }); var httpResult = result.Errors?.Count > 0 ? HttpStatusCode.BadRequest : HttpStatusCode.OK; context.Response.StatusCode = (int)httpResult; context.Response.ContentType = "application/json"; await _writer.WriteAsync(context.Response.Body, result); }