public static Task <IHttpResponse> CreateAsync( [Property(Name = Resources.ProcessStageType.IdPropertyName)] Guid processStageTypeId, [Property(Name = Resources.ProcessStageType.OwnerPropertyName)] Guid ownerId, [Property(Name = Resources.ProcessStageType.GroupPropertyName)] Guid processStageGroupId, [Property(Name = Resources.ProcessStageType.TitlePropertyName)] string title, [Property(Name = Resources.ProcessStageType.ResourceTypePropertyName)] Type resourceType, [Property(Name = Resources.ProcessStageType.ResourceKeysPropertyName)] string[] resourceKeys, [Property(Name = Resources.ProcessStageType.ResourceTypesPropertyName)] Type[] resourceTypes, EastFive.Api.Security security, IHttpRequest request, IProvideUrl url, CreatedResponse onCreated, CreatedBodyResponse <ProcessStageType> onCreatedAndModified, AlreadyExistsResponse onAlreadyExists, AlreadyExistsReferencedResponse onRelationshipAlreadyExists, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { var resourceList = resourceKeys.Zip(resourceTypes, (k, v) => k.PairWithValue(v)).ToArray(); return(ProcessStageTypes.CreateAsync(processStageTypeId, ownerId, processStageGroupId, title, resourceType, resourceList, security, () => onCreated(), () => onAlreadyExists(), () => onReferenceNotFound(), (brokenId) => onReferenceNotFound(), (why) => onFailure(why))); }
public async static Task <HttpResponseMessage> QueryByActorId( [QueryParameter(Name = ActorPropertyName)] Guid actorId, Context context, AzureApplication application, EastFive.Api.SessionToken security, UrlHelper urlHelper, ContentResponse onFound, MultipartResponseAsync onFounds, ReferencedDocumentNotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized, ServiceUnavailableResponse onServiceUnavailable) { return(await await context.PasswordCredentials.GetPasswordCredentialByActorAsync( actorId, security, application, (credentials) => { var credentialResources = credentials .Select( passwordCredential => { var resource = Convert(passwordCredential, urlHelper); var response = onFound(resource); return response; }) .ToArray(); return onFounds(credentialResources); }, () => onNotFound().AsTask(), () => onUnauthorized().AsTask(), (why) => onServiceUnavailable().AsTask())); }
public static async Task <HttpResponseMessage> GetAsync( [QueryParameter(Name = StatePropertyName)] string state, [QueryParameter(Name = ClientPropertyName)] IRef <Client> clientRef, [QueryParameter(Name = ValidationPropertyName)] string validation, Api.Azure.AzureApplication application, UrlHelper urlHelper, //ContentTypeResponse<Authentication> onFound, RedirectResponse onFound, ReferencedDocumentNotFoundResponse <Client> onInvalidClient) { return(await await clientRef.StorageGetAsync( (client) => { var authentication = new Authentication { authenticationRef = SecureGuid.Generate().AsRef <Authentication>(), state = state, }; return authentication.StorageCreateAsync( (entity) => { var location = urlHelper.GetLocation <Authentication>( auth => auth.authenticationRef.AssignQueryValue(authentication.authenticationRef), application); return onFound(location); }, () => throw new Exception("Secure guid not unique")); }, () => onInvalidClient().AsTask())); }
public static async Task <HttpResponseMessage> QueryBySessionAsync( [QueryParameter(Name = "session")] IRef <Session> sessionRef, Api.Azure.AzureApplication application, MultipartResponseAsync <Method> onContent, ReferencedDocumentNotFoundResponse <Session> onIntegrationNotFound) { return(await await sessionRef.StorageGetAsync( session => { var integrationProviders = application.LoginProviders .Where(loginProvider => loginProvider.Value.GetType().IsSubClassOfGeneric(typeof(IProvideSession))) .Select( async loginProvider => { var supportsIntegration = await(loginProvider.Value as IProvideSession).SupportsSessionAsync(session); return supportsIntegration.PairWithValue(loginProvider); }) .Await() .Where(kvp => kvp.Key) .SelectValues() .Select( (loginProvider) => { return new Method { authenticationId = new Ref <Method>(loginProvider.Value.Id), name = loginProvider.Value.Method, }; }); return onContent(integrationProviders); }, () => onIntegrationNotFound().AsTask())); }
public async static Task <HttpResponseMessage> GetByAccountAsync( [QueryParameter(Name = AccountPropertyName)] Guid accountId, Api.Azure.AzureApplication application, SessionToken security, MultipartResponseAsync <XIntegration> onContents, ReferencedDocumentNotFoundResponse <object> onAccountNotFound, UnauthorizedResponse onUnauthorized) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onUnauthorized()); } var integrations = GetIntegrationsByAccount(accountId) .Select( kvp => { var integration = kvp.Key; return(Auth.Method.ById(kvp.Value.Method, application, method => { integration.methodName = method.name; return integration; }, () => default(XIntegration?))); }) .Await() .SelectWhereHasValue(); return(await onContents(integrations)); }
public static Task <HttpResponseMessage> CreateConnectorAsync( [Property] Guid id, [Property(Name = EastFive.Api.Resources.Connector.SourcePropertyName)] Guid source, [Property(Name = EastFive.Api.Resources.Connector.DestinationPropertyName)] Guid destination, [Property(Name = EastFive.Api.Resources.Connector.FlowPropertyName)] Connector.SynchronizationMethod Flow, Security security, Context context, HttpRequestMessage request, UrlHelper url, CreatedResponse onCreated, CreatedBodyResponse <Resources.Connection> onCreatedAndModifiedConnection, CreatedBodyResponse <Resources.Connector> onCreatedAndModified, AlreadyExistsResponse onAlreadyExists, AlreadyExistsReferencedResponse onRelationshipAlreadyExists, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(Connectors.CreateConnectorAsync(id, source, destination, Flow, security.performingAsActorId, security.claims, () => onCreated(), (connection) => { return request.Headers.Accept .OrderByDescending(accept => accept.Quality.HasValue ? accept.Quality.Value : 1.0) .First( (accept, next) => { if ( accept.MediaType.ToLower() == "x-ordering/connection" || accept.MediaType.ToLower() == "x-ordering/connection+json") { return onCreatedAndModifiedConnection( ConnectionController.GetResource(connection, url), "x-ordering/connection+json"); } if ( accept.MediaType.ToLower() == "x-ordering/connector" || accept.MediaType.ToLower() == "x-ordering/connector+json" || accept.MediaType.ToLower() == "application/json") { return onCreatedAndModified( GetResource(connection.connector, url), "x-ordering/connector+json"); } return next(); }, () => onCreatedAndModified(GetResource(connection.connector, url))); }, () => onAlreadyExists(), (existingConnectorId) => onRelationshipAlreadyExists(existingConnectorId), (brokenId) => onReferenceNotFound(), (why) => onFailure(why))); }
public static async Task <HttpResponseMessage> FindByResourceAsync( [QueryParameter] Guid resourceId, EastFive.Api.Security security, UrlHelper url, MultipartAcceptArrayResponseAsync onMultipart, ReferencedDocumentNotFoundResponse onResourceNotFound, UnauthorizedResponse onUnauthorized) { return(await await EastFive.Azure.ProcessStages.FindByResourceAsync(resourceId, security, (processStages) => onMultipart(processStages.Select(ps => GetResource(ps, url))), () => onResourceNotFound().ToTask(), () => onUnauthorized().ToTask())); }
public static HttpResponseMessage Options(HttpRequestMessage request, UrlHelper url, ContentResponse onOption, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized) { var adapter1Id = Guid.NewGuid(); var adapter2Id = Guid.NewGuid(); var connectorId = Guid.NewGuid(); var integration1 = Guid.NewGuid(); return(onOption( GetResource( new Connection() { connector = new Connector() { adapterExternalId = adapter1Id, adapterInternalId = adapter2Id, connectorId = connectorId, createdBy = adapter1Id, synchronizationMethod = Connector.SynchronizationMethod.useExternal, }, adapterInternal = new Adapter() { adapterId = adapter1Id, connectorIds = new Guid[] { connectorId }, identifiers = new KeyValuePair <string, string> [] { "name".PairWithValue("Example Name"), }, integrationId = integration1, key = Guid.NewGuid().ToString(), name = "Example", resourceType = "Product", }, adapterExternal = new Adapter() { adapterId = adapter1Id, connectorIds = new Guid[] { connectorId }, identifiers = new KeyValuePair <string, string>[] { "name".PairWithValue("Test Name"), }, integrationId = integration1, key = Guid.NewGuid().ToString("N"), name = "Test", resourceType = "Product", }, }, url))); }
public static async Task <IHttpResponse> GetAsync( //[WorkflowNewId] //[WorkflowVariable( // Workflows.PasswordLoginCreateAccount.Variables.State, // AuthorizationPropertyName)] [OptionalQueryParameter(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefOptional, [WorkflowParameter( Value = "d989b604-1e25-4d77-b79e-fe1c7d36f833", Description = "Unique and static to each client (i.e. iOS or Web)")] [QueryParameter(Name = ClientPropertyName)] IRef <Client> clientRef, [WorkflowNewId(Description = "No idea what this does.")] [OptionalQueryParameter(Name = ValidationPropertyName)] string validation, IAuthApplication application, IProvideUrl urlHelper, //ContentTypeResponse<Authentication> onFound, [WorkflowVariable( Workflows.PasswordLoginCreateAccount.Variables.Authorization, Authentication.AuthenticationPropertyName)] [WorkflowVariableRedirectUrl( VariableName = Workflows.PasswordLoginCreateAccount.Variables.AuthorizationRedirect)] RedirectResponse onFound, ReferencedDocumentNotFoundResponse <Client> onInvalidClient) { return(await await clientRef.StorageGetAsync( (client) => { var authentication = new Authentication { authenticationRef = SecureGuid.Generate().AsRef <Authentication>(), authorizationMaybe = authorizationRefOptional, client = clientRef, }; return authentication.StorageCreateAsync( (entity) => { var location = urlHelper.GetLocation <Authentication>( auth => auth.authenticationRef.AssignQueryValue(authentication.authenticationRef), application); return onFound(location); }); }, () => onInvalidClient().AsTask())); }
public static async Task <HttpResponseMessage> FindByFirstStepByActorAndTypeAsync( [QueryParameter(Name = Resources.ProcessStage.OwnerPropertyName)] Guid ownerId, [QueryParameter(Name = Resources.ProcessStage.TypePropertyName)] Type resourceType, [QueryParameter(Name = "processstage." + Resources.ProcessStage.ConfirmablePropertyName + "." + Resources.ProcessStage.ConfirmableResource.ProcessStageNextPropertyName)] EastFive.Api.Controllers.WebIdNone nextStage, AzureApplication application, EastFive.Api.Security security, UrlHelper url, MultipartAcceptArrayResponseAsync onMultipart, ReferencedDocumentNotFoundResponse onResourceNotFound, UnauthorizedResponse onUnauthorized) { return(await await EastFive.Azure.ProcessStages.FindStartByActorAndResourceTypeAsync(ownerId, resourceType, security, (processStages) => onMultipart(processStages.Select(ps => GetResource(ps, url))), () => onResourceNotFound().ToTask(), () => onUnauthorized().ToTask())); }
[Api.HttpGet] //(MatchAllBodyParameters = false)] public async static Task <HttpResponseMessage> GetByAccountAsync( [QueryParameter(Name = AccountPropertyName)] Guid accountId, Api.Azure.AzureApplication application, SessionToken security, MultipartResponseAsync <Integration> onContents, ReferencedDocumentNotFoundResponse <object> onAccountNotFound, UnauthorizedResponse onUnauthorized) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onUnauthorized()); } return(await await GetIntegrationsByAccountAsync(accountId, (kvps) => onContents(kvps.SelectKeys()), () => onAccountNotFound().AsTask())); }
public static Task <HttpResponseMessage> FindByRelatedAsync([QueryParameter] string key, [QueryParameter] Guid integration, [QueryParameter] string resourceType, Security security, Context context, HttpRequestMessage request, UrlHelper url, ContentResponse onFound, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized) { return(EastFive.Azure.Synchronization.Connections.FindAdapterByKeyAsync(key, integration, resourceType, security.claims, adapter => { var r = onFound(GetResource(adapter, url)); return r; }, () => onReferenceNotFound(), () => onUnauthorized())); }
public static async Task <HttpResponseMessage> FindByAdapterAsync([QueryParameter] Guid adapter, Security security, Context context, HttpRequestMessage request, UrlHelper url, MultipartAcceptArrayResponseAsync onMultipart, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized) { return(await await EastFive.Azure.Synchronization.Connectors.FindConnectionByAdapterAsync(adapter, security.performingAsActorId, security.claims, connectors => { var r = onMultipart(connectors.Select(connector => GetResource(connector, url))); return r; }, () => onReferenceNotFound().ToTask(), () => onUnauthorized().ToTask())); }
public static Task <IHttpResponse> FindByFirstStepByActorAndTypeAsync( [QueryParameter(Name = Resources.ProcessStage.OwnerPropertyName)] Guid ownerId, [QueryParameter(Name = Resources.ProcessStage.TypePropertyName)] Type resourceType, [QueryParameter(Name = "processstage." + Resources.ProcessStage.ConfirmablePropertyName + "." + Resources.ProcessStage.ConfirmableResource.ProcessStageNextPropertyName)] IRefOptional <IReferenceable> nextStage, EastFive.Api.Security security, IProvideUrl url, MultipartAcceptArrayResponse onMultipart, ReferencedDocumentNotFoundResponse onResourceNotFound, UnauthorizedResponse onUnauthorized) { return(EastFive.Azure.ProcessStages.FindStartByActorAndResourceTypeAsync(ownerId, resourceType, security, (processStages) => onMultipart(processStages.Select(ps => GetResource(ps, url))), () => onResourceNotFound(), () => onUnauthorized())); }
public static async Task <HttpResponseMessage> FindByRelatedAsync( [QueryParameter] Guid relatedTo, [QueryParameter] Guid integration, // int top, int skip Security security, Context context, HttpRequestMessage request, UrlHelper url, MultipartAcceptArrayResponseAsync onMultipart, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized) { return(await await EastFive.Azure.Synchronization.Connections.FindAdaptersByRelatedAsync(relatedTo, integration, security.claims, synchronizations => { var r = onMultipart(synchronizations.Select(synchronization => GetResource(synchronization, url))); return r; }, () => onReferenceNotFound().ToTask(), () => onUnauthorized().ToTask())); }
public static Task <IHttpResponse> CreateAsync( [Property(Name = Resources.ProcessStage.IdPropertyName)] Guid processStageId, [Property(Name = Resources.ProcessStage.OwnerPropertyName)] Guid ownerId, [Property(Name = Resources.ProcessStage.TypePropertyName)] Guid processStageTypeId, [PropertyOptional(Name = Resources.ProcessStage.TitlePropertyName)] string title, [PropertyOptional(Name = Resources.ProcessStage.ViewablePropertyName)] Guid [] viewableIds, [PropertyOptional(Name = Resources.ProcessStage.CompletablePropertyName)] Guid [] completableIds, [PropertyOptional(Name = Resources.ProcessStage.EditablePropertyName)] Guid [] editableIds, [PropertyOptional(Name = Resources.ProcessStage.ConfirmablePropertyName)] Resources.ProcessStage.ConfirmableResource [] confirmables, EastFive.Api.Security security, EastFive.Api.Azure.AzureApplication application, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStageType> onTypeDoesNotExist, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStage> onConfirmationStageDoesNotExist, ReferencedDocumentNotFoundResponse onActorDoesNotExists, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(EastFive.Azure.ProcessStages.CreateAsync(processStageId, ownerId, processStageTypeId, title, viewableIds, editableIds, completableIds, confirmables .Select( confirmable => confirmable.ProcessStageNext.ToGuid().Value .PairWithKey( confirmable.Positions .Select(position => position.ToGuid().Value) .ToArray())) .ToArray(), security, () => onCreated(), () => onAlreadyExists(), () => onTypeDoesNotExist(), (missingStageId) => onConfirmationStageDoesNotExist(), () => onActorDoesNotExists(), (why) => onFailure(why))); }
public static Task <IHttpResponse> FindByResourceTypeAsync( [EastFive.Api.QueryParameter(Name = ActorPropertyName)] Guid actorId, [EastFive.Api.QueryParameter(Name = Resources.ProcessStageType.ResourceTypePropertyName)] Type resourceType, EastFive.Api.Security security, AzureApplication application, IProvideUrl url, [Display(Name = "Found")] MultipartAcceptArrayResponse onMultipart, ReferencedDocumentNotFoundResponse onResourceNotFound, UnauthorizedResponse onUnauthorized) { return(EastFive.Azure.ProcessResourceViews.FindByResourceAsync(actorId, resourceType, security, (views) => { var viewResources = views.Select(ps => GetResource(ps, application, url)).ToArray(); return onMultipart(viewResources); }, () => onResourceNotFound(), () => onUnauthorized())); }
public static async Task <HttpResponseMessage> QueryByIntegrationAsync( [QueryParameter(Name = "integration")] IRef <Integration> integrationRef, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, MultipartResponseAsync <Method> onContent, UnauthorizedResponse onUnauthorized, ReferencedDocumentNotFoundResponse <Integration> onIntegrationNotFound) { return(await await integrationRef.StorageGetAsync( async (integration) => { var accountId = integration.accountId; if (!await application.CanAdministerCredentialAsync(accountId, security)) { return onUnauthorized(); } var integrationProviders = application.LoginProviders .Where(loginProvider => loginProvider.Value.GetType().IsSubClassOfGeneric(typeof(IProvideIntegration))) .Select( async loginProvider => { var integrationProvider = loginProvider.Value as IProvideIntegration; var supportsIntegration = await integrationProvider.SupportsIntegrationAsync(accountId); return supportsIntegration.PairWithValue(loginProvider); }) .Await() .Where(kvp => kvp.Key) .SelectValues() .Select( (loginProvider) => { var integrationProvider = loginProvider.Value as IProvideIntegration; return new Method { authenticationId = new Ref <Method>(loginProvider.Value.Id), name = integrationProvider.GetDefaultName(new Dictionary <string, string>()), }; }); return await onContent(integrationProviders); }, () => onIntegrationNotFound().AsTask())); }
public static async Task <HttpResponseMessage> FindByIntegrationAsync( [QueryParameter] Guid integration, [QueryParameter] string resourceType, Security security, Context context, HttpRequestMessage request, UrlHelper url, MultipartAcceptArrayResponseAsync onMultipart, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized) { return(await await EastFive.Azure.Synchronization.Synchronizations.FindAdaptersByIntgrationAndResourceTypeAsync(integration, resourceType, security.performingAsActorId, security.claims, synchronizations => { var r = onMultipart(synchronizations.Select(synchronization => GetResource(synchronization, url))); return r; }, // TODO: Clean these up () => onReferenceNotFound().ToTask(), () => onReferenceNotFound().AddReason($"Resource type [{resourceType}] is not currently supported.").ToTask(), () => onReferenceNotFound().AddReason($"The integration needs to be authenticated before it can be queried (this should be a 409).").ToTask(), () => onUnauthorized().ToTask(), (why) => onReferenceNotFound().AddReason(why + " (this should be a 409)").ToTask())); }
public static HttpResponseMessage Options(HttpRequestMessage request, UrlHelper url, ContentResponse onOption, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized) { var adapter1Id = Guid.NewGuid(); var adapter2Id = Guid.NewGuid(); var connectorId = Guid.NewGuid(); var integration1 = Guid.NewGuid(); return(onOption( GetResource( new Connector() { adapterExternalId = adapter1Id, adapterInternalId = adapter2Id, connectorId = connectorId, createdBy = adapter1Id, synchronizationMethod = Connector.SynchronizationMethod.useExternal, }, url))); }