public string GetRxAsyncMethodImplementation(bool isGeneralized) { if (this.SupportsGet) { if (isGeneralized) { StandardModel standardModel = this.FluentMethodGroup.StandardFluentModel; string modelInterfaceName = standardModel.JavaInterfaceName; string modelInnerName = standardModel.RawModelName; // var method = this.GetMethod; // StringBuilder methodBuilder = new StringBuilder(); // methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> {method.Name}Async(String resourceGroupName, String name) {{"); methodBuilder.AppendLine($" return this.{this.getInnerAsyncFuncFactory.GetFromResourceGroupAsyncFunc.GeneralizedMethodName}(resourceGroupName, name).flatMap(new Func1<{modelInnerName}, Observable<{modelInterfaceName}>> () {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{modelInterfaceName}> call({modelInnerName} inner) {{"); methodBuilder.AppendLine($" if (inner == null) {{"); methodBuilder.AppendLine($" return Observable.empty();"); methodBuilder.AppendLine($" }} else {{"); methodBuilder.AppendLine($" return Observable.just(({modelInterfaceName}){standardModel.WrapExistingModelFunc.GeneralizedMethodName}(inner));"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); // return(methodBuilder.ToString()); } else { StandardModel standardModel = this.FluentMethodGroup.StandardFluentModel; string modelInterfaceName = standardModel.JavaInterfaceName; string modelInnerName = standardModel.RawModelName; // Obs<T> getByResourceGroupAsync(String resourceGroupName, String name) // StringBuilder methodBuilder = new StringBuilder(); methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> getByResourceGroupAsync(String resourceGroupName, String name) {{"); methodBuilder.AppendLine($" return this.{this.getInnerAsyncFuncFactory.GetFromResourceGroupAsyncFunc.MethodName}(resourceGroupName, name).flatMap(new Func1<{modelInnerName}, Observable<{modelInterfaceName}>> () {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{modelInterfaceName}> call({modelInnerName} innerT) {{"); methodBuilder.AppendLine($" if (inner == null) {{"); methodBuilder.AppendLine($" return Observable.empty();"); methodBuilder.AppendLine($" }} else {{"); methodBuilder.AppendLine($" return Observable.just(({modelInterfaceName}){standardModel.WrapExistingModelFunc.MethodName}(innerT));"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); // return(methodBuilder.ToString()); } } else { return(string.Empty); } }
/// <summary> /// Provide implementation of sync list method. /// </summary> /// <param name="convertToPagedListMethodName">the method to use for converting inner paged list to fluent page list</param> /// <param name="method">the method representing list apiCall (that wraps inner list method)</param> /// <param name="fluentMethodName">the name for the sync list method</param> /// <param name="parameterDecl">the parameter declaration part of the sync list method</param> /// <param name="parameterInvoke">the parameter invocation string for invoking inner list method</param> /// <param name="isGeneralized">true for implementation in generalized form, false for normal form</param> /// <returns>list method implementation</returns> protected string ListSyncMethodImplementation(string convertToPagedListMethodName, StandardFluentMethod method, string fluentMethodName, string parameterDecl, string parameterInvoke, bool isGeneralized) { StringBuilder methodBuilder = new StringBuilder(); // StandardModel standardModel = this.FluentMethodGroup.StandardFluentModel; string standardModelInnerName = standardModel.RawModelName; string standardModelInterfaceName = standardModel.JavaInterfaceName; // string innerReturnTypeName = method.InnerReturnType.ClassName; string innerClientName = this.FluentMethodGroup.InnerMethodGroupTypeName; // TODO: Check return type is "PagedList" then "converter.convert" // If return type is "List" create a Page, then PagedList from it then "converter.convert" // methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public PagedList<{standardModelInterfaceName}> {fluentMethodName}({parameterDecl}) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); if (innerReturnTypeName.EqualsIgnoreCase(standardModelInnerName)) { methodBuilder.AppendLine($" return {convertToPagedListMethodName}(client.{method.Name}({parameterInvoke}));"); } else { string convertor = this.FluentMethodGroup.ModelMapper.GetPagedListConvertor(innerReturnTypeName, $"client.{method.Name}({parameterInvoke})", isGeneralized); methodBuilder.AppendLine(convertor); } methodBuilder.AppendLine($"}}"); // return(methodBuilder.ToString()); }
public GroupableFluentModelInterface(StandardModel standardModel) : base(new GroupableFluentModelMemberVariablesForCreate(standardModel.FluentMethodGroup), new GroupableFluentModelMemberVariablesForUpdate(standardModel.FluentMethodGroup), new GroupableFluentModelMemberVariablesForGet(standardModel.FluentMethodGroup), standardModel) { if (standardModel.Type != StanardModelType.GroupableTopLevel) { throw new ArgumentException($"Expected 'StanardModelType.GroupableTopLevel' received {standardModel.Type}"); } }
protected ClientFluentMethodGroupImpl(IFluentMethodGroup fluentMethodGroup) { if (fluentMethodGroup.Type != MethodGroupType.ActionsOnly) { if (fluentMethodGroup.StandardFluentModel == null) { throw new ArgumentNullException($"Fluent method group type is '{fluentMethodGroup.Type}' but standard model is null."); } this.model = fluentMethodGroup.StandardFluentModel; } else { this.model = null; // i.e. FMG exposes only actions and child accessors & does not wrap a model } this.Interface = fluentMethodGroup; }
public string GetRxAsyncMethodImplementation(bool isGeneralized) { if (this.SupportsGet) { StringBuilder methodBuilder = new StringBuilder(); // StandardModel standardModel = this.FluentMethodGroup.StandardFluentModel; string modelInterfaceName = standardModel.JavaInterfaceName; string modelInnerName = standardModel.RawModelName; string innerClientName = this.FluentMethodGroup.InnerMethodGroupTypeName; // var method = this.GetMethod; string parameterDecl = method.InnerMethod.MethodRequiredParameterDeclaration; string wrapExistingMethodName; if (isGeneralized) { wrapExistingMethodName = standardModel.WrapExistingModelFunc.GeneralizedMethodName; } else { wrapExistingMethodName = standardModel.WrapExistingModelFunc.MethodName; } methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> {method.Name}Async({parameterDecl}) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async({method.InnerMethodInvocationParameters})"); methodBuilder.AppendLine($" .flatMap(new Func1<{modelInnerName}, Observable<{modelInterfaceName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{modelInterfaceName}> call({modelInnerName} inner) {{"); methodBuilder.AppendLine($" if (inner == null) {{"); methodBuilder.AppendLine($" return Observable.empty();"); methodBuilder.AppendLine($" }} else {{"); methodBuilder.AppendLine($" return Observable.just(({modelInterfaceName}){wrapExistingMethodName}(inner));"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); // return(methodBuilder.ToString()); } else { return(string.Empty); } }
protected CreatableUpdatableModel(FluentModelMemberVariablesForCreate cVariables, FluentModelMemberVariablesForUpdate uVariables, FluentModelMemberVariablesForGet gVariable, StandardModel standardModel) { this.StandardModel = standardModel ?? throw new ArgumentException(nameof(standardModel)); // this.cVariables = cVariables; this.uVariables = uVariables; this.gVariable = gVariable; // this.DisambiguatedMemberVariables = new FluentModelDisambiguatedMemberVariables() .WithCreateMemberVariable(this.cVariables) .WithUpdateMemberVariable(this.uVariables) .WithGetMemberVariable(this.gVariable) .Disambiguate(); // this.cVariables.SetDisambiguatedMemberVariables(this.DisambiguatedMemberVariables); this.uVariables.SetDisambiguatedMemberVariables(this.DisambiguatedMemberVariables); }
/// <summary> /// Provide implementation of async list method. /// </summary> /// <param name="method">the method representing list apiCall (that wraps inner list method)</param> /// <param name="fluentMethodName">the name for the async list method</param> /// <param name="parameterDecl">the parameter declaration part of the async list method</param> /// <param name="parameterInvoke">the parameter invocation string for invoking inner list method</param> /// <param name="isGeneralized">true for implementation in generalized form, false for normal form</param> /// <returns>list method implementation</returns> protected string ListRxAsyncMethodImplementation(StandardFluentMethod method, string fluentMethodName, string parameterDecl, string parameterInvoke, bool isGeneralized) { StringBuilder methodBuilder = new StringBuilder(); // StandardModel standardModel = this.FluentMethodGroup.StandardFluentModel; string stdandardModelInnerName = standardModel.RawModelName; string modelInterfaceName = standardModel.JavaInterfaceName; string innerClientName = this.FluentMethodGroup.InnerMethodGroupTypeName; // string methodReturnInnerModelName = method.InnerReturnType.ClassName; // if (!method.InnerMethod.IsPagingOperation) { methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> {fluentMethodName}Async({parameterDecl}) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async({parameterInvoke})"); if (method.InnerMethod.SimulateAsPagingOperation) { methodBuilder.AppendLine($" .flatMap(new Func1<Page<{methodReturnInnerModelName}>, Observable<{methodReturnInnerModelName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{methodReturnInnerModelName}> call(Page<{methodReturnInnerModelName}> innerPage) {{"); methodBuilder.AppendLine($" return Observable.from(innerPage.items());"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }})"); } else if (method.InnerMethod.ReturnTypeResponseName.StartsWith("List<")) { methodBuilder.AppendLine($" .flatMap(new Func1<List<{methodReturnInnerModelName}>, Observable<{methodReturnInnerModelName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{methodReturnInnerModelName}> call(List<{methodReturnInnerModelName}> innerList) {{"); methodBuilder.AppendLine($" return Observable.from(innerList);"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }})"); } string flatMap = this.FluentMethodGroup.ModelMapper.GetFlatMapToStandardModelFor(methodReturnInnerModelName, isGeneralized); if (!string.IsNullOrEmpty(flatMap)) { methodBuilder.AppendLine($"{flatMap}"); } string wrapExistingModelName; if (isGeneralized) { wrapExistingModelName = standardModel.WrapExistingModelFunc.GeneralizedMethodName; } else { wrapExistingModelName = standardModel.WrapExistingModelFunc.MethodName; } methodBuilder.AppendLine($" .map(new Func1<{stdandardModelInnerName}, {modelInterfaceName}>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public {modelInterfaceName} call({stdandardModelInnerName} inner) {{"); methodBuilder.AppendLine($" return {wrapExistingModelName}(inner);"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); } else { methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> {fluentMethodName}Async({parameterDecl}) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async({parameterInvoke})"); methodBuilder.AppendLine($" .flatMapIterable(new Func1<Page<{methodReturnInnerModelName}>, Iterable<{methodReturnInnerModelName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Iterable<{methodReturnInnerModelName}> call(Page<{methodReturnInnerModelName}> page) {{"); methodBuilder.AppendLine($" return page.items();"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }})"); string flatMap = this.FluentMethodGroup.ModelMapper.GetFlatMapToStandardModelFor(methodReturnInnerModelName, isGeneralized); if (flatMap != null) { methodBuilder.AppendLine($"{flatMap}"); } string wrapExistingModelName; if (isGeneralized) { wrapExistingModelName = standardModel.WrapExistingModelFunc.GeneralizedMethodName; } else { wrapExistingModelName = standardModel.WrapExistingModelFunc.MethodName; } methodBuilder.AppendLine($" .map(new Func1<{stdandardModelInnerName}, {modelInterfaceName}>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public {modelInterfaceName} call({stdandardModelInnerName} inner) {{"); methodBuilder.AppendLine($" return {wrapExistingModelName}(inner);"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" }});"); methodBuilder.AppendLine($"}}"); } return(methodBuilder.ToString()); }
public NonStandardToStandardModelMappingHelper(SegmentFluentMethodGroup fluentMethodGroup) { this.fluentMethodGroup = fluentMethodGroup; this.standardModel = this.fluentMethodGroup.StandardFluentModel; this.Init(); }