public NestedFluentModelInterface(FluentModel rawFluentModel, FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup, new NestedFluentModelMemberVariablesForCreate(fluentMethodGroup), new NestedFluentModelMemberVariablesForUpdate(fluentMethodGroup), new NestedFluentModelMemberVariablesForGet(fluentMethodGroup), rawFluentModel.InnerModel.Name) { this.rawFluentModel = rawFluentModel; }
public ReadOnlyFluentModelInterface(FluentModel rawFluentModel, string managerTypeName) { this.rawFluentModel = rawFluentModel; this.ManagerTypeName = managerTypeName; }
public string ListBySubscriptionAsyncMethodImplementation(string innerClientName, string modelInterfaceName) { StringBuilder methodBuilder = new StringBuilder(); if (this.SupportsListBySubscription) { FluentMethod method = this.ListBySubscriptionMethod; // string modelInnerName = method.ReturnModel.InnerModel.ClassName; string innerReturnTypeName = method.InnerReturnType.ClassName; // if (!method.InnerMethod.IsPagingOperation) { FluentModel returnModel = method.ReturnModel; // methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> listAsync() {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async()"); if (method.InnerMethod.SimulateAsPagingOperation) { methodBuilder.AppendLine($" .flatMap(new Func1<Page<{innerReturnTypeName}>, Observable<{innerReturnTypeName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{innerReturnTypeName}> call(Page<{innerReturnTypeName}> innerPage) {{"); methodBuilder.AppendLine($" return Observable.from(innerPage.items());"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }})"); } methodBuilder.AppendLine($" .map(new Func1<{innerReturnTypeName}, {modelInterfaceName}>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public {modelInterfaceName} call({innerReturnTypeName} inner) {{"); methodBuilder.AppendLine($" return wrapModel(inner);"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); } else { string nextPageMethodName = $"listNextInnerPageAsync"; methodBuilder.AppendLine($"private Observable<Page<{innerReturnTypeName}>> {nextPageMethodName}(String nextLink) {{"); methodBuilder.AppendLine($" if (nextLink == null) {{"); methodBuilder.AppendLine($" Observable.empty();"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}NextAsync(nextLink)"); methodBuilder.AppendLine($" .flatMap(new Func1<Page<{innerReturnTypeName}>, Observable<Page<{innerReturnTypeName}>>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<Page<{innerReturnTypeName}>> call(Page<{innerReturnTypeName}> page) {{"); methodBuilder.AppendLine($" return Observable.just(page).concatWith({nextPageMethodName}(page.nextPageLink()));"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> listAsync() {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async()"); methodBuilder.AppendLine($" .flatMap(new Func1<Page<{innerReturnTypeName}>, Observable<Page<{innerReturnTypeName}>>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<Page<{innerReturnTypeName}>> call(Page<{innerReturnTypeName}> page) {{"); methodBuilder.AppendLine($" return {nextPageMethodName}(page.nextPageLink());"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }})"); methodBuilder.AppendLine($" .flatMapIterable(new Func1<Page<{innerReturnTypeName}>, Iterable<{innerReturnTypeName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Iterable<{innerReturnTypeName}> call(Page<{innerReturnTypeName}> page) {{"); methodBuilder.AppendLine($" return page.items();"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }})"); methodBuilder.AppendLine($" .map(new Func1<{innerReturnTypeName}, {modelInterfaceName}>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public {modelInterfaceName} call({innerReturnTypeName} inner) {{"); methodBuilder.AppendLine($" return wrapModel(inner);"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); } } return(methodBuilder.ToString()); }
private void SpecializeFluentModels() { HashSet <string> topLevelAndNestedModelNames = new HashSet <string>(); // Promotes the general fluent models to top-level-groupable vs top-level-non-groupable nested child vs other. // // Specialize the GROUPABLEMODEL // this.GroupableFluentModels = this.Select(kv => kv.Value) .SelectMany(fmg => fmg) .Where(fmg => fmg.StandardFluentModel != null) .Where(fmg => fmg.IsGroupableTopLevel) .Select(fmg => new GroupableFluentModelInterface(fmg.StandardFluentModel, fmg)) .Distinct(GroupableFluentModelInterface.EqualityComparer()); this.GroupableFluentModels.ForEach(m => topLevelAndNestedModelNames.Add(m.JavaInterfaceName)); // Specialize the NESTEDFLUENTMODEL // this.NestedFluentModels = this.Select(kv => kv.Value) .SelectMany(fmg => fmg) .Where(fmg => fmg.StandardFluentModel != null) .Where(fmg => fmg.IsNested) .Select(fmg => new NestedFluentModelInterface(fmg.StandardFluentModel, fmg)) .Distinct(NestedFluentModelInterface.EqualityComparer()); this.NestedFluentModels.ForEach(m => topLevelAndNestedModelNames.Add(m.JavaInterfaceName)); // Specialize the TOP-LEVEL NONGROUPABLEMODEL // this.NonGroupableTopLevelFluentModels = this.Select(kv => kv.Value) .SelectMany(fmg => fmg) .Where(fmg => fmg.StandardFluentModel != null) .Where(fmg => fmg.IsNonGroupableTopLevel) .Select(fmg => new NonGroupableTopLevelFluentModelInterface(fmg.StandardFluentModel, fmg)) .Distinct(NonGroupableTopLevelFluentModelInterface.EqualityComparer()); NonGroupableTopLevelFluentModels.ForEach(m => topLevelAndNestedModelNames.Add(m.JavaInterfaceName)); // Specialize the READONLYMODEL // this.ReadonlyFluentModels = this.Select(kv => kv.Value) .SelectMany(fmg => fmg) .SelectMany(fmg => fmg.OtherMethods.OtherFluentModels) .Where(m => !(m is PrimtiveFluentModel)) .Distinct(FluentModel.EqualityComparer()) .Where(fluentModel => !topLevelAndNestedModelNames.Contains(fluentModel.JavaInterfaceName)) .Select(fluentModel => new ReadOnlyFluentModelInterface(fluentModel, this.ManagerTypeName)); // Not groupable or nested method group // this.ActionOrChildAccessorOnlyMethodGroups = new Dictionary <string, ActionOrChildAccessorOnlyMethodGroupImpl>(); this.Select(kv => kv.Value) .SelectMany(fmg => fmg) .Where(fmg => fmg.StandardFluentModel == null) .ForEach(fmg => { if (!ActionOrChildAccessorOnlyMethodGroups.ContainsKey(fmg.JavaInterfaceName)) { ActionOrChildAccessorOnlyMethodGroups.Add(fmg.JavaInterfaceName, new ActionOrChildAccessorOnlyMethodGroupImpl(fmg)); } }); }
internal void DeriveStandrdFluentModelForMethodGroup() { if (this.derivedFluentModels) { return; } this.derivedFluentModels = true; // Find "ONE" fluent model that can be used across "Standard methods" (GetByResourceGroup | // ListByResourceGroup | ListBySubscription | GetByImmediateParent | ListByImmediateParent | // Create in RG, Update) // // Derive an "inner model then a fluent model" that represents the return type of standard methods // in this fluent model. We want all thoses standard methods to return same fluent type though the // inner methods can return different inner model types. // CompositeTypeJvaf standardModelInner = null; this.innersRequireWrapping = new Dictionary <string, CompositeTypeJvaf>(); if (ResourceGetDescription.SupportsGetByResourceGroup) { standardModelInner = ResourceGetDescription.GetByResourceGroupMethod.InnerReturnType; } else if (ResourceCreateDescription.SupportsCreating) { standardModelInner = ResourceCreateDescription.CreateMethod.InnerReturnType; } else if (ResourceListingDescription.SupportsListByResourceGroup) { standardModelInner = ResourceListingDescription.ListByResourceGroupMethod.InnerReturnType; } else if (ResourceListingDescription.SupportsListBySubscription) { standardModelInner = ResourceListingDescription.ListBySubscriptionMethod.InnerReturnType; } else if (ResourceGetDescription.SupportsGetByImmediateParent) { standardModelInner = ResourceGetDescription.GetByImmediateParentMethod.InnerReturnType; } else if (ResourceListingDescription.SupportsListByImmediateParent) { standardModelInner = ResourceListingDescription.ListByImmediateParentMethod.InnerReturnType; } else if (ResourceUpdateDescription.SupportsUpdating) { standardModelInner = ResourceUpdateDescription.UpdateMethod.InnerReturnType; } // For the "standard model" (FModel) in a FluentMethodGroup we need to gen "FModel wrapModel(ModelInner)" // but if there are different ModelInner types mapping that needs to be mapped to the same FModel // we will be generating one over load per inner -> FModel mapping // if (standardModelInner != null) { this.standardFluentModel = new FluentModel(standardModelInner); if (ResourceGetDescription.SupportsGetByResourceGroup) { var im = ResourceGetDescription.GetByResourceGroupMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } if (ResourceCreateDescription.SupportsCreating) { var im = ResourceCreateDescription.CreateMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } if (ResourceListingDescription.SupportsListByResourceGroup) { var im = ResourceListingDescription.ListByResourceGroupMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } if (ResourceListingDescription.SupportsListBySubscription) { var im = ResourceListingDescription.ListBySubscriptionMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } if (ResourceGetDescription.SupportsGetByImmediateParent) { var im = ResourceGetDescription.GetByImmediateParentMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } if (ResourceListingDescription.SupportsListByImmediateParent) { var im = ResourceListingDescription.ListByImmediateParentMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } if (ResourceUpdateDescription.SupportsUpdating) { var im = ResourceUpdateDescription.UpdateMethod.InnerReturnType; this.innersRequireWrapping.AddIfNotExists(im.ClassName, im); } // Remove wrapping for standard model as each fluent method group takes care of it locally // this.innersRequireWrapping.Remove(this.standardFluentModel.InnerModel.ClassName); } }