private void CheckGetByResourceGroupSupport() { if (this.fluentMethodGroup.Level == 0) { foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get)) { var armUri = new ARMUri(innerMethod); Segment lastSegment = armUri.LastOrDefault(); if (lastSegment != null && lastSegment is ParentSegment) { ParentSegment resourceSegment = (ParentSegment)lastSegment; var requiredParameters = RequiredParametersOfMethod(innerMethod); if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 2) { var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups")); if (resourceGroupSegment != null) { bool hasResourceGroupParam = requiredParameters.Any(p => p.SerializedName.EqualsIgnoreCase(resourceGroupSegment.Parameter.SerializedName)); bool hasResourceParm = requiredParameters.Any(p => p.SerializedName.EqualsIgnoreCase(resourceSegment.Parameter.SerializedName)); if (hasResourceGroupParam && hasResourceParm) { this.supportsGetByResourceGroup = true; this.getByResourceGroupMethod = new FluentMethod(true, innerMethod, this.fluentMethodGroup); } } } } } } else { this.supportsGetByResourceGroup = false; this.getByResourceGroupMethod = null; } }
private void CheckGetByParameterizedParentSupport() { if (this.fluentMethodGroup.Level == 0) { foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get)) { var armUri = new ARMUri(innerMethod); Segment lastSegment = armUri.LastOrDefault(); if (lastSegment != null && lastSegment is ParentSegment) { ParentSegment resourceSegment = (ParentSegment)lastSegment; var requiredParameters = RequiredParametersOfMethod(innerMethod); if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase)) { var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions")); var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups")); if (subscriptionSegment == null && resourceGroupSegment == null) { this.supportsGetByParameterizedParent = true; this.getByParameterizedParentMethod = new FluentMethod(true, innerMethod, this.fluentMethodGroup); break; } } } } } else { this.supportsGetByParameterizedParent = false; this.getByParameterizedParentMethod = null; } }
/// <summary> /// Checks can support "SupportsListBySubscription" interface /// </summary> private void CheckListBySubscriptionSupport() { if (this.fluentMethodGroup.Level == 0) { foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get)) { var armUri = new ARMUri(innerMethod); Segment lastSegment = armUri.LastOrDefault(); if (lastSegment != null && lastSegment is TerminalSegment) { TerminalSegment terminalSegment = (TerminalSegment)lastSegment; var requiredParameters = RequiredParametersOfMethod(innerMethod); if (terminalSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 0) { var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions")); if (subscriptionSegment != null) { if (innerMethod.ReturnTypeResponseName.StartsWith("PagedList") || innerMethod.ReturnTypeResponseName.StartsWith("List")) { this.supportsListBySubscription = true; this.listBySubscriptionMethod = new FluentMethod(true, innerMethod, this.fluentMethodGroup); break; } } } } } } else { this.supportsListBySubscription = false; this.listBySubscriptionMethod = null; } }
/// <summary> /// Creates FluentModelMemberVariables. /// </summary> /// <param name="fluentMethod">The method for which declared memeber variables will be used</param> public FluentModelMemberVariables(FluentMethod fluentMethod) { if (fluentMethod != null) { this.FluentMethod = fluentMethod; this.Pluralizer = new Pluralizer(); this.Init(); } }
public string UpdateResourceAsyncMethodImplementation(FluentMethod updateMethod, string updateMethodParameters, string updatedResourceInterfaceName, string innerMethodGroupTypeName) { StringBuilder methodBuilder = new StringBuilder(); methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public Observable<{updatedResourceInterfaceName}> updateResourceAsync() {{"); methodBuilder.AppendLine($" {innerMethodGroupTypeName} client = this.manager().inner().{this.FluentMethodGroup.InnerMethodGroup.Name}();"); if (!this.SupportsUpdating) { methodBuilder.AppendLine(" return null; // NOP updateResourceAsync implementation as update is not supported"); } else { if (this.RequireUpdateResultToInnerModelMapping) { string updateReturnTypeName = updateMethod.ReturnModel.InnerModel.Name; methodBuilder.AppendLine($"return client.{updateMethod.InnerMethod.Name}Async({updateMethodParameters})"); methodBuilder.AppendLine($" .flatMap(new Func1<{updateReturnTypeName}, Observable<{innerModelTypeName}>>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public Observable<{innerModelTypeName}> call({updateReturnTypeName} r) {{"); if (this.RequirePayloadReset) { methodBuilder.AppendLine($" {CreatableUpdatableModel.ResetCreateUpdateParametersMethodName}(); "); } methodBuilder.AppendLine($" return getInnerAsync(); "); methodBuilder.AppendLine($" }} "); methodBuilder.AppendLine($" }})"); methodBuilder.AppendLine($" .map(innerToFluentMap(this));"); } else { string updateReturnTypeName = updateMethod.ReturnModel.InnerModel.Name; methodBuilder.AppendLine($" return client.{updateMethod.InnerMethod.Name}Async({updateMethodParameters})"); if (this.RequirePayloadReset) { methodBuilder.AppendLine($" .map(new Func1<{innerModelTypeName}, {innerModelTypeName}>() {{"); methodBuilder.AppendLine($" @Override"); methodBuilder.AppendLine($" public {updateReturnTypeName} call({updateReturnTypeName} resource) {{"); methodBuilder.AppendLine($" {CreatableUpdatableModel.ResetCreateUpdateParametersMethodName}(); "); methodBuilder.AppendLine($" return resource; "); methodBuilder.AppendLine($" }} "); methodBuilder.AppendLine($" }})"); } methodBuilder.AppendLine($" .map(innerToFluentMap(this));"); } } methodBuilder.AppendLine("}"); return(methodBuilder.ToString()); }
private void Process() { if (this.isProcessed) { return; } else { // A "fluent method group" can expose only one "define(name)" method. Though some resource can be // created in different scope (immediately under a resource group, in subscription etc..), // we need to decide which one to expose via "define". Below we choose one from multiple create // methods, if there are. The unchoosen create methods will be exposed as it is in "fluent method group", // just lik any "other methods". // this.isProcessed = true; FluentMethod createInRgMethod = this.TryGetCreateInResourceGroupMethod(); if (createInRgMethod != null) { this.createMethod = createInRgMethod; this.createType = CreateType.WithResourceGroupAsParent; } else { FluentMethod createInSubMethod = this.TryGetCreateInSubscriptionMethod(); if (createInSubMethod != null) { this.createMethod = createInSubMethod; this.createType = CreateType.WithSubscriptionAsParent; } else { FluentMethod createInParamParentMethod = this.TryGetCreateInParameterizedParentMethod(); if (createInParamParentMethod != null) { this.createMethod = createInParamParentMethod; this.createType = CreateType.WithParameterizedParent; } else { FluentMethod createAsNestedMethod = this.TryGetCreateAsNestedChildMethod(); if (createAsNestedMethod != null) { this.createMethod = createAsNestedMethod; this.createType = CreateType.AsNestedChild; } } } } } }
public string ListByResourceGroupSyncMethodImplementation(string covertToPagedListMethodName, string innerClientName, string modelInterfaceName) { StringBuilder methodBuilder = new StringBuilder(); if (this.SupportsListByResourceGroup) { FluentMethod method = this.ListByResourceGroupMethod; // methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public PagedList<{modelInterfaceName}> listByResourceGroup(String resourceGroupName) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return {covertToPagedListMethodName}(client.{method.Name}(resourceGroupName));"); methodBuilder.AppendLine($"}}"); } return(methodBuilder.ToString()); }
public string ListBySubscriptionSyncMethodImplementation(string convertToPagedListMethodName, string innerClientName, string modelInterfaceName) { StringBuilder methodBuilder = new StringBuilder(); if (this.SupportsListBySubscription) { FluentMethod method = this.ListBySubscriptionMethod; // 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<{modelInterfaceName}> list() {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return {convertToPagedListMethodName}(client.{method.Name}());"); methodBuilder.AppendLine($"}}"); } return(methodBuilder.ToString()); }
/// <summary> /// Check can support list by immediate parent. /// </summary> private void CheckListByImmediateParentSupport() { if (this.fluentMethodGroup.Level > 0) { foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get)) { FluentMethodGroup parentMethodGroup = this.fluentMethodGroup.ParentFluentMethodGroup; if (parentMethodGroup != null) { var armUri = new ARMUri(innerMethod); Segment lastSegment = armUri.LastOrDefault(); if (lastSegment != null && lastSegment is TerminalSegment) { TerminalSegment terminalSegment = (TerminalSegment)lastSegment; if (terminalSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase)) { Segment secondLastSegment = armUri.SkipLast(1).LastOrDefault(); if (secondLastSegment != null && secondLastSegment is ParentSegment) { ParentSegment parentSegment = (ParentSegment)secondLastSegment; if (parentSegment.Name.EqualsIgnoreCase(parentMethodGroup.LocalNameInPascalCase)) { if (innerMethod.ReturnTypeResponseName.StartsWith("PagedList") || innerMethod.ReturnTypeResponseName.StartsWith("List")) { this.supportsListByImmediateParent = true; this.listByImmediateParentMethod = new FluentMethod(true, innerMethod, this.fluentMethodGroup); break; } } } } } } } } else { this.supportsListByImmediateParent = false; this.listByImmediateParentMethod = null; } }
public string GetInnerAsyncMethodImplementation(FluentMethod getMethod, string getMethodParameters, string innerMethodGroupTypeName) { StringBuilder methodBuilder = new StringBuilder(); methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"protected Observable<{innerModelTypeName}> getInnerAsync() {{"); methodBuilder.AppendLine($" {innerMethodGroupTypeName} client = this.manager().inner().{this.FluentMethodGroup.InnerMethodGroup.Name}();"); if (!this.SupportsGetting) { methodBuilder.AppendLine(" return null; // NOP getInnerAsync implementation as get is not supported"); } else { methodBuilder.AppendLine($" return client.{getMethod.InnerMethod.Name}Async({getMethodParameters});"); } methodBuilder.AppendLine("}"); return(methodBuilder.ToString()); }
private void CheckGetByImmediateParentSupport() { if (this.fluentMethodGroup.Level > 0) { foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get)) { FluentMethodGroup parentMethodGroup = this.fluentMethodGroup.ParentFluentMethodGroup; if (parentMethodGroup != null) { var armUri = new ARMUri(innerMethod); Segment lastSegment = armUri.LastOrDefault(); if (lastSegment != null && lastSegment is ParentSegment) { ParentSegment resourceSegment = (ParentSegment)lastSegment; if (resourceSegment.Name.EqualsIgnoreCase(fluentMethodGroup.LocalNameInPascalCase)) { Segment secondLastSegment = armUri.SkipLast(1).LastOrDefault(); if (secondLastSegment != null && secondLastSegment is ParentSegment) { ParentSegment parentSegment = (ParentSegment)secondLastSegment; if (parentSegment.Name.EqualsIgnoreCase(parentMethodGroup.LocalNameInPascalCase)) { this.supportsGetByImmediateParent = true; this.getByImmediateParentMethod = new FluentMethod(true, innerMethod, this.fluentMethodGroup); break; } } } } } } } else { this.supportsGetByImmediateParent = false; this.getByImmediateParentMethod = null; } }
public string InnerGetMethodImplementation(bool applyOverride, string innerClientName, string modelInnerName) { StringBuilder methodBuilder = new StringBuilder(); // if (applyOverride) { methodBuilder.AppendLine("@Override"); } methodBuilder.AppendLine($"protected Observable<{modelInnerName}> getInnerAsync(String resourceGroupName, String name) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); if (this.SupportsGetByResourceGroup) { FluentMethod method = this.GetByResourceGroupMethod; methodBuilder.AppendLine($" return client.{method.Name}Async(resourceGroupName, name);"); } else { methodBuilder.AppendLine($" return null; // NOP Retrive by RG not supported"); } methodBuilder.AppendLine($"}}"); // return(methodBuilder.ToString()); }
public IEnumerable <string> BatchDeleteAyncAndSyncMethodImplementations(string innerClientName) { if (this.SupportsDeleteByResourceGroup) { // It is understood that if delete by resource group is supported in service then batch delete is also supported in SDK // FluentMethod method = this.DeleteByResourceGroupMethod; // StringBuilder methodBuilder = new StringBuilder(); // // BatchDeleteByIdCol async methodBuilder.Clear(); methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public Observable<String> deleteByIdsAsync(Collection<String> ids) {{"); methodBuilder.AppendLine($" if (ids == null || ids.isEmpty()) {{"); methodBuilder.AppendLine($" return Observable.empty();"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" Collection<Observable<String>> observables = new ArrayList<>();"); methodBuilder.AppendLine($" for (String id : ids) {{"); methodBuilder.AppendLine($" final String resourceGroupName = ResourceUtils.groupFromResourceId(id);"); methodBuilder.AppendLine($" final String name = ResourceUtils.nameFromResourceId(id);"); methodBuilder.AppendLine($" Observable<String> o = RXMapper.map(this.inner().{method.Name}Async(resourceGroupName, name), id);"); methodBuilder.AppendLine($" observables.add(o);"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($" return Observable.mergeDelayError(observables);"); methodBuilder.AppendLine($"}}"); yield return(methodBuilder.ToString()); // // BatchDeleteByIdVarArgs async methodBuilder.Clear(); methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public Observable<String> deleteByIdsAsync(String...ids) {{"); methodBuilder.AppendLine($" return this.deleteByIdsAsync(new ArrayList<String>(Arrays.asList(ids)));"); methodBuilder.AppendLine($"}}"); yield return(methodBuilder.ToString()); // // BatchDeleteByIdCol sync methodBuilder.Clear(); methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public void deleteByIds(Collection<String> ids) {{"); methodBuilder.AppendLine($" if (ids != null && !ids.isEmpty()) {{"); methodBuilder.AppendLine($" this.deleteByIdsAsync(ids).toBlocking().last();"); methodBuilder.AppendLine($" }}"); methodBuilder.AppendLine($"}}"); yield return(methodBuilder.ToString()); // // BatchDeleteByIdVarArgs sync // methodBuilder.Clear(); methodBuilder.AppendLine("@Override"); methodBuilder.AppendLine($"public void deleteByIds(String...ids) {{"); methodBuilder.AppendLine($" this.deleteByIds(new ArrayList<String>(Arrays.asList(ids)));"); methodBuilder.AppendLine($"}}"); yield return(methodBuilder.ToString()); } else { yield break; } }
private void Process() { if (this.isProcessed) { return; } // this.isProcessed = true; FluentMethod updateInRgMethod = this.TryGetUpdateInResourceGroupMethod(); if (updateInRgMethod != null) { this.updateMethod = updateInRgMethod; this.updateType = UpdateType.WithResourceGroupAsParent; } else { if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithResourceGroupAsParent) { this.updateMethod = this.createDescription.CreateMethod; this.updateType = UpdateType.WithResourceGroupAsParent; } else { FluentMethod updateInSubMethod = this.TryGetUpdateInSubscriptionMethod(); if (updateInSubMethod != null) { this.updateMethod = updateInSubMethod; this.updateType = UpdateType.WithSubscriptionAsParent; } else { if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithSubscriptionAsParent) { this.updateMethod = this.createDescription.CreateMethod; this.updateType = UpdateType.WithSubscriptionAsParent; } else { FluentMethod updateInParameterizedParentMethod = this.TryGetUpdateInParameterizedParentMethod(); if (updateInParameterizedParentMethod != null) { this.updateMethod = updateInParameterizedParentMethod; this.updateType = UpdateType.WithParameterizedParent; } else { if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithParameterizedParent) { this.updateMethod = this.createDescription.CreateMethod; this.updateType = UpdateType.WithParameterizedParent; } else { FluentMethod updateAsNestedMethod = this.TryGetUpdateAsNestedChildMethod(); if (updateAsNestedMethod != null) { this.updateMethod = updateAsNestedMethod; this.updateType = UpdateType.AsNestedChild; } else { if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.AsNestedChild) { this.updateMethod = this.createDescription.CreateMethod; this.updateType = UpdateType.AsNestedChild; } } } } } } } } }
public string ListByResourceGroupAsyncMethodImplementation(string innerClientName, string modelInterfaceName) { StringBuilder methodBuilder = new StringBuilder(); if (this.SupportsListByResourceGroup) { FluentMethod method = this.ListByResourceGroupMethod; // string modelInnerName = method.ReturnModel.InnerModel.ClassName; string innerReturnTypeName = method.InnerReturnType.ClassName; // if (!method.InnerMethod.IsPagingOperation) { // methodBuilder.AppendLine($"@Override"); methodBuilder.AppendLine($"public Observable<{modelInterfaceName}> listByResourceGroupAsync(String resourceGroupName) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async(resourceGroupName)"); 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 = $"listByResourceGroupNextInnerPageAsync"; 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}> listByResourceGroupAsync(String resourceGroupName) {{"); methodBuilder.AppendLine($" {innerClientName} client = this.inner();"); methodBuilder.AppendLine($" return client.{method.Name}Async(resourceGroupName)"); 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()); }