public string CreateResourceAsyncMethodImplementation(StandardFluentMethod createMethod,
                                                              string createMethodParameters,
                                                              string createdResourceInterfaceName,
                                                              string innerMethodGroupTypeName,
                                                              string preCreateStatements = "")
        {
            StringBuilder methodBuilder = new StringBuilder();

            methodBuilder.AppendLine("@Override");
            methodBuilder.AppendLine($"public Observable<{createdResourceInterfaceName}> createResourceAsync() {{");
            methodBuilder.AppendLine($"    {innerMethodGroupTypeName} client = this.manager().inner().{this.FluentMethodGroup.InnerMethodGroup.Name}();");
            if (!this.SupportsCreating)
            {
                methodBuilder.AppendLine("    return null; // NOP createResourceAsync implementation as create is not supported");
            }
            else
            {
                if (!string.IsNullOrEmpty(preCreateStatements))
                {
                    methodBuilder.AppendLine(preCreateStatements);
                }
                //
                if (this.RequireCreateResultToInnerModelMapping)
                {
                    string createReturnTypeName = createMethod.ReturnModel.RawModel.Name;

                    methodBuilder.AppendLine($"return client.{createMethod.InnerMethod.Name}Async({createMethodParameters})");
                    methodBuilder.AppendLine($"        .flatMap(new Func1<{createReturnTypeName}, Observable<{InnerModelName}>>() {{");
                    methodBuilder.AppendLine($"           @Override");
                    methodBuilder.AppendLine($"           public Observable<{InnerModelName}> call({createReturnTypeName} resource) {{");
                    if (this.RequirePayloadReset)
                    {
                        methodBuilder.AppendLine($"               {CreatableUpdatableModel.ResetCreateUpdateParametersMethodName}(); ");
                    }
                    methodBuilder.AppendLine($"               return getInnerAsync(); ");
                    methodBuilder.AppendLine($"           }} ");
                    methodBuilder.AppendLine($"        }})");
                    methodBuilder.AppendLine($"        .map(innerToFluentMap(this));");
                }
                else
                {
                    string createReturnTypeName = createMethod.ReturnModel.RawModel.Name;

                    methodBuilder.AppendLine($"    return client.{createMethod.InnerMethod.Name}Async({createMethodParameters})");
                    if (this.RequirePayloadReset)
                    {
                        methodBuilder.AppendLine($"        .map(new Func1<{InnerModelName}, {InnerModelName}>() {{");
                        methodBuilder.AppendLine($"           @Override");
                        methodBuilder.AppendLine($"           public {createReturnTypeName} call({createReturnTypeName} resource) {{");
                        methodBuilder.AppendLine($"               {CreatableUpdatableModel.ResetCreateUpdateParametersMethodName}(); ");
                        methodBuilder.AppendLine($"               return resource; ");
                        methodBuilder.AppendLine($"           }} ");
                        methodBuilder.AppendLine($"        }})");
                    }
                    methodBuilder.AppendLine($"        .map(innerToFluentMap(this));");
                }
            }
            methodBuilder.AppendLine("}");
            return(methodBuilder.ToString());
        }
Пример #2
0
 private void CheckDeleteBySubscriptionSupport()
 {
     if (this.fluentMethodGroup.Level == 0)
     {
         foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Delete))
         {
             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() == 1)
                 {
                     var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                     if (subscriptionSegment != null)
                     {
                         bool hasResourceParm = requiredParameters.Any(p => p.SerializedName.EqualsIgnoreCase(resourceSegment.Parameter.SerializedName));
                         if (hasResourceParm)
                         {
                             this.supportsDeleteBySubscription = true;
                             this.deleteBySubscriptionMethod   = new StandardFluentMethod(innerMethod, this.fluentMethodGroup);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsDeleteBySubscription = false;
         this.deleteBySubscriptionMethod   = null;
     }
 }
Пример #3
0
 /// <summary>
 /// Creates FluentModelMemberVariables.
 /// </summary>
 /// <param name="fluentMethod">The method for which memeber variables will be used as parameters</param>
 public FluentModelMemberVariables(StandardFluentMethod fluentMethod)
 {
     if (fluentMethod != null)
     {
         this.FluentMethod = fluentMethod;
         this.Init();
     }
 }
 private StandardFluentMethod TryGetCreateInSubscriptionMethod()
 {
     foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods)
     {
         string innerMethodName = innerMethod.Name.ToLowerInvariant();
         if (innerMethodName.Contains("update") && !innerMethodName.Contains("create"))
         {
             // There are resources that does not support create, but support update through PUT
             // here using method name pattern as heuristics to skip such methods to be considered
             // as create method.
             //
             continue;
         }
         if (innerMethod.HttpMethod == HttpMethod.Put)
         {
             bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
             if (!isResponseCompositeType)
             {
                 // In order to be able to implement SupportsCreating<T> where T is class/interface type, we should be
                 // able to map response resource of create to T. if the return type is primitive type (e.g. void),
                 // sequence type, dict type then mapping cannot be done. Skip create methods returning such types
                 // they will be appear as other methods
                 continue;
             }
             else if (!Utils.HasProperty(innerMethod.ReturnTypeJva.BodyClientType, "name"))
             {
                 // A model that is creatable has to be derive from CreatableUpdatableImpl which requires name
                 // property to present.
                 continue;
             }
             else
             {
                 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))
                     {
                         if (this.FluentMethodGroup.Level == 0)
                         {
                             var subscriptionSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("subscriptions"));
                             if (subscriptionSegment != null)
                             {
                                 var resourceGroupSegment = armUri.OfType <ParentSegment>().FirstOrDefault(segment => segment.Name.EqualsIgnoreCase("resourceGroups"));
                                 if (resourceGroupSegment == null && StandardFluentMethod.CanWrap(innerMethod))
                                 {
                                     return(new StandardFluentMethod(innerMethod, this.FluentMethodGroup));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
Пример #5
0
        private StandardFluentMethod TryGetUpdateAsNestedChildMethod(bool findPatchUpdate)
        {
            bool findPutUpdate = !findPatchUpdate;

            //
            foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods)
            {
                if ((findPatchUpdate && innerMethod.HttpMethod == HttpMethod.Patch) || (findPutUpdate && innerMethod.HttpMethod == HttpMethod.Put))
                {
                    bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                    if (!isResponseCompositeType)
                    {
                        // In order to be able to implement SupportUpdating<T>, we should be able to map resource of update to T
                        // if the return type is primitive type (e.g. void) then mapping cannot be done. Skip update methods
                        // returning such primitve they will be appear as other methods
                        continue;
                    }
                    else if (!Utils.HasProperty(innerMethod.ReturnTypeJva.BodyClientType, "name"))
                    {
                        // A model that is updatable has to be derive from CreatableUpdatableImpl which requires name
                        // property to present.
                        continue;
                    }
                    else
                    {
                        if (findPutUpdate)
                        {
                            string innerMethodName = innerMethod.Name.ToLowerInvariant();
                            if (innerMethodName.Contains("create") && !innerMethodName.Contains("update"))
                            {
                                // There are resources that does not support update, but support create through PUT
                                // here using method name pattern as heuristics to skip such methods to be considered
                                // as update method.
                                //
                                continue;
                            }
                        }
                        //
                        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))
                            {
                                if (this.fluentMethodGroup.Level > 0 && StandardFluentMethod.CanWrap(innerMethod))
                                {
                                    return(new StandardFluentMethod(innerMethod, this.fluentMethodGroup));
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Пример #6
0
 private void CheckGetByImmediateParentSupport()
 {
     if (this.FluentMethodGroup.Level > 0)
     {
         foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             IFluentMethodGroup parentMethodGroup = this.FluentMethodGroup.ParentFluentMethodGroup;
             if (parentMethodGroup != null)
             {
                 bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                 if (!isResponseCompositeType)
                 {
                     // In order to be able to map response to standard model T where T is class/interface type
                     // it need to be composite type. If the return type is primitive type (e.g. void), sequence type
                     // dict type then mapping cannot be done. Skip get methods returning such types they will be appear
                     // as other methods
                     continue;
                 }
                 else
                 {
                     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))
                                 {
                                     if (StandardFluentMethod.CanWrap(innerMethod))
                                     {
                                         this.supportsGet = true;
                                         this.getMethod   = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsGet = false;
         this.getMethod   = null;
     }
 }
Пример #7
0
 private bool SupportsOnlyTagsUpdate(StandardFluentMethod fluentMethod)
 {
     if (fluentMethod.InnerMethod.Body is ParameterJv p && p.ClientType is CompositeTypeJvaf payloadType)
     {
         var properties = payloadType.Properties;
         if (properties.Count == 1 && properties.First().SerializedName.EqualsIgnoreCase("tags"))
         {
             return(true);
         }
     }
     return(false);
 }
 private void CheckGetByResourceGroupSupport()
 {
     if (this.FluentMethodGroup.Level == 0)
     {
         foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
         {
             bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
             if (!isResponseCompositeType)
             {
                 // In order to be able to implement SupportsGetByResourceGroup<T> where T is class/interface type,
                 // we should be able to map respone resource of get to T. If the return type is primitive type
                 // (e.g. void), sequence type, dict type then mapping cannot be done. Skip get methods returning
                 // such types they will be appear as "OtherMethod"s.
                 continue;
             }
             else
             {
                 var     armUri      = new ARMUri(innerMethod);
                 Segment lastSegment = armUri.LastOrDefault();
                 if (lastSegment != null && lastSegment is ParentSegment)
                 {
                     ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                     var           requiredParameters = Utils.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)
                             {
                                 if (StandardFluentMethod.CanWrap(innerMethod))
                                 {
                                     this.supportsGet = true;
                                     this.getMethod   = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsGet = false;
         this.getMethod   = null;
     }
 }
 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;
         StandardFluentMethod createInRgMethod = this.TryGetCreateInResourceGroupMethod();
         if (createInRgMethod != null)
         {
             this.createMethod = createInRgMethod;
             this.createType   = CreateType.WithResourceGroupAsParent;
         }
         else
         {
             StandardFluentMethod createInSubMethod = this.TryGetCreateInSubscriptionMethod();
             if (createInSubMethod != null)
             {
                 this.createMethod = createInSubMethod;
                 this.createType   = CreateType.WithSubscriptionAsParent;
             }
             else
             {
                 StandardFluentMethod createInParamParentMethod = this.TryGetCreateInParameterizedParentMethod();
                 if (createInParamParentMethod != null)
                 {
                     this.createMethod = createInParamParentMethod;
                     this.createType   = CreateType.WithParameterizedParent;
                 }
                 else
                 {
                     StandardFluentMethod createAsNestedMethod = this.TryGetCreateAsNestedChildMethod();
                     if (createAsNestedMethod != null)
                     {
                         this.createMethod = createAsNestedMethod;
                         this.createType   = CreateType.AsNestedChild;
                     }
                 }
             }
         }
     }
 }
Пример #10
0
        private void CheckGetByParameterizedParentSupport()
        {
            if (this.FluentMethodGroup.Level == 0)
            {
                foreach (MethodJvaf innerMethod in FluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Get))
                {
                    bool isResponseCompositeType = innerMethod.ReturnTypeJva.BodyClientType is CompositeTypeJv;
                    if (!isResponseCompositeType)
                    {
                        // In order to be able to map response to standard model T where T is class/interface type
                        // it need to be composite type. If the return type is primitive type (e.g. void), sequence type
                        // dict type then mapping cannot be done. Skip get methods returning such types they will be appear
                        // as "OtherMethod"s
                        continue;
                    }
                    else
                    {
                        var     armUri      = new ARMUri(innerMethod);
                        Segment lastSegment = armUri.LastOrDefault();
                        if (lastSegment != null && lastSegment is ParentSegment)
                        {
                            ParentSegment resourceSegment    = (ParentSegment)lastSegment;
                            var           requiredParameters = Utils.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)
                                {
                                    if (StandardFluentMethod.CanWrap(innerMethod))
                                    {
                                        this.supportsGet = true;
                                        this.getMethod   = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                this.supportsGet = false;
                this.getMethod   = null;
            }
        }
 /// <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))
         {
             IFluentMethodGroup 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<"))
                                 {
                                     if (StandardFluentMethod.CanWrap(innerMethod))
                                     {
                                         this.supportsListing = true;
                                         this.listMethod      = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsListing = false;
         this.listMethod      = null;
     }
 }
 /// <summary>
 /// Checks can support "SupportsListByResourceGroup" interface
 /// </summary>
 private void CheckListByResourceGroupSupport()
 {
     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 = Utils.RequiredParametersOfMethod(innerMethod);
                 if (terminalSegment.Name.EqualsIgnoreCase(FluentMethodGroup.LocalNameInPascalCase) && requiredParameters.Count() == 1)
                 {
                     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)
                     {
                         var singleParameter = requiredParameters.First();
                         if (resourceGroupSegment.Parameter.SerializedName.EqualsIgnoreCase(singleParameter.SerializedName))
                         {
                             if (innerMethod.ReturnTypeResponseName.StartsWith("PagedList<") ||
                                 innerMethod.ReturnTypeResponseName.StartsWith("List<"))
                             {
                                 if (StandardFluentMethod.CanWrap(innerMethod))
                                 {
                                     this.supportsListing = true;
                                     this.listMethod      = new StandardFluentMethod(innerMethod, this.FluentMethodGroup);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsListing = false;
         this.listMethod      = null;
     }
 }
        public string GetInnerAsyncMethodImplementation(StandardFluentMethod getMethod,
                                                        string getMethodParameters,
                                                        string innerMethodGroupTypeName)
        {
            StringBuilder methodBuilder = new StringBuilder();

            methodBuilder.AppendLine("@Override");
            methodBuilder.AppendLine($"protected Observable<{InnerModelName}> 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());
        }
Пример #14
0
 private void CheckDeleteByImmediateParentSupport()
 {
     if (this.fluentMethodGroup.Level > 0)
     {
         foreach (MethodJvaf innerMethod in fluentMethodGroup.InnerMethods.Where(method => method.HttpMethod == HttpMethod.Delete))
         {
             ISegmentFluentMethodGroup 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.supportsDeleteByImmediateParent = true;
                                 this.deleteByImmediateParentMethod   = new StandardFluentMethod(innerMethod, this.fluentMethodGroup);
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         this.supportsDeleteByImmediateParent = false;
         this.deleteByImmediateParentMethod   = null;
     }
 }
Пример #15
0
        public static StandardMethodsInfo StandardMethodsInfo(this ISegmentFluentMethodGroup fluentMethodGroup)
        {
            StandardMethodsInfo standardMethods = new StandardMethodsInfo();
            //
            HashSet <string> knownMethodNames = new HashSet <string>();

            if (fluentMethodGroup.ResourceCreateDescription.SupportsCreating)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceCreateDescription.CreateMethod.Name.ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceUpdateDescription.SupportsUpdating)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceUpdateDescription.UpdateMethod.Name.ToLowerInvariant());
                //
                StandardFluentMethod updateMethod = fluentMethodGroup.ResourceUpdateDescription.UpdateMethod;
                if (updateMethod.InnerMethod.HttpMethod == HttpMethod.Put)
                {
                    // If PUT based update is supported then skip any PATCH based update method
                    // being treated as "Other methods".
                    //
                    var patchUpdateMethod = fluentMethodGroup.InnerMethods
                                            .Where(m => m.HttpMethod == HttpMethod.Patch)
                                            .Where(m => m.Url.EqualsIgnoreCase(updateMethod.InnerMethod.Url))
                                            .FirstOrDefault();
                    if (patchUpdateMethod != null)
                    {
                        standardMethods.InnerMethodNames.Add(patchUpdateMethod.Name.ToLowerInvariant());
                    }
                }
            }

            if (fluentMethodGroup.ResourceListingDescription.SupportsListByImmediateParent)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceListingDescription.ListByImmediateParentMethod.Name.ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceListingDescription.SupportsListByResourceGroup)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceListingDescription.ListByResourceGroupMethod.Name.ToLowerInvariant());
                standardMethods.FluentMethodNames.Add("listByResourceGroup".ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceListingDescription.SupportsListBySubscription)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceListingDescription.ListBySubscriptionMethod.Name.ToLowerInvariant());
                standardMethods.FluentMethodNames.Add("list".ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceGetDescription.SupportsGetByImmediateParent)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceGetDescription.GetByImmediateParentMethod.Name.ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceGetDescription.SupportsGetByResourceGroup)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceGetDescription.GetByResourceGroupMethod.Name.ToLowerInvariant());
                standardMethods.FluentMethodNames.Add("getByResourceGroup".ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceDeleteDescription.SupportsDeleteByImmediateParent)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceDeleteDescription.DeleteByImmediateParentMethod.Name.ToLowerInvariant());
            }

            if (fluentMethodGroup.ResourceDeleteDescription.SupportsDeleteByResourceGroup)
            {
                standardMethods.InnerMethodNames.Add(fluentMethodGroup.ResourceDeleteDescription.DeleteByResourceGroupMethod.Name.ToLowerInvariant());
                standardMethods.FluentMethodNames.Add("deleteByResourceGroup".ToLowerInvariant());
                standardMethods.FluentMethodNames.Add("deleteByIds".ToLowerInvariant());
            }
            //
            return(standardMethods);
        }
Пример #16
0
        private void Process()
        {
            if (this.isProcessed)
            {
                return;
            }
            //
            this.isProcessed = true;
            //
            // ALGO:
            // 1. Look for an update operation using PATCH
            // 2. If only tags can be updated through PATCH then look for an update operation using PUT with method name heuristics
            // 3. If no such update then use create description for update
            //
            // Why: ARM is mandating atlease to have an update for tags, we don't want to pick such update or resource update
            //
            StandardFluentMethod patchUpdateInRgMethod = this.TryGetUpdateInResourceGroupMethod(findPatchUpdate: true);

            if (patchUpdateInRgMethod != null)
            {
                bool canUpdateOnlyTags = SupportsOnlyTagsUpdate(patchUpdateInRgMethod);
                if (canUpdateOnlyTags == false)
                {
                    this.updateMethod = patchUpdateInRgMethod;
                    this.updateType   = UpdateType.WithResourceGroupAsParent;
                }
                else
                {
                    // Only tags can be updated through PATCH
                    //
                    StandardFluentMethod putUpdateInRgMethod = this.TryGetUpdateInResourceGroupMethod(findPatchUpdate: false);
                    if (putUpdateInRgMethod != null)
                    {
                        this.updateMethod = putUpdateInRgMethod;
                        this.updateType   = UpdateType.WithResourceGroupAsParent;
                    }
                    else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithResourceGroupAsParent)
                    {
                        this.updateMethod = this.createDescription.CreateMethod;
                        this.updateType   = UpdateType.WithResourceGroupAsParent;
                    }
                    else
                    {
                        this.updateMethod = patchUpdateInRgMethod;
                        this.updateType   = UpdateType.WithResourceGroupAsParent;
                    }
                }
            }
            else
            {
                StandardFluentMethod putUpdateInRgMethod = this.TryGetUpdateInResourceGroupMethod(findPatchUpdate: false);
                if (putUpdateInRgMethod != null)
                {
                    this.updateMethod = putUpdateInRgMethod;
                    this.updateType   = UpdateType.WithResourceGroupAsParent;
                }
                else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithResourceGroupAsParent)
                {
                    this.updateMethod = this.createDescription.CreateMethod;
                    this.updateType   = UpdateType.WithResourceGroupAsParent;
                }
            }
            //
            if (this.updateType != UpdateType.None)
            {
                return;
            }
            //
            StandardFluentMethod patchUpdateInSubMethod = this.TryGetUpdateInSubscriptionMethod(findPatchUpdate: true);

            if (patchUpdateInSubMethod != null)
            {
                bool canUpdateOnlyTags = SupportsOnlyTagsUpdate(patchUpdateInSubMethod);
                if (canUpdateOnlyTags == false)
                {
                    this.updateMethod = patchUpdateInSubMethod;
                    this.updateType   = UpdateType.WithSubscriptionAsParent;
                }
                else
                {
                    StandardFluentMethod putUpdateInSubMethod = this.TryGetUpdateInSubscriptionMethod(findPatchUpdate: false);
                    if (putUpdateInSubMethod != null)
                    {
                        this.updateMethod = putUpdateInSubMethod;
                        this.updateType   = UpdateType.WithSubscriptionAsParent;
                    }
                    else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithSubscriptionAsParent)
                    {
                        this.updateMethod = this.createDescription.CreateMethod;
                        this.updateType   = UpdateType.WithSubscriptionAsParent;
                    }
                    else
                    {
                        this.updateMethod = patchUpdateInSubMethod;
                        this.updateType   = UpdateType.WithSubscriptionAsParent;
                    }
                }
            }
            else
            {
                StandardFluentMethod putUpdateInSubMethod = this.TryGetUpdateInSubscriptionMethod(findPatchUpdate: false);
                if (putUpdateInSubMethod != null)
                {
                    this.updateMethod = putUpdateInSubMethod;
                    this.updateType   = UpdateType.WithSubscriptionAsParent;
                }
                else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithSubscriptionAsParent)
                {
                    this.updateMethod = this.createDescription.CreateMethod;
                    this.updateType   = UpdateType.WithSubscriptionAsParent;
                }
            }
            //
            if (this.updateType != UpdateType.None)
            {
                return;
            }
            //
            StandardFluentMethod patchUpdateInParameterizedParentMethod = this.TryGetUpdateInParameterizedParentMethod(findPatchUpdate: true);

            if (patchUpdateInParameterizedParentMethod != null)
            {
                bool canUpdateOnlyTags = SupportsOnlyTagsUpdate(patchUpdateInParameterizedParentMethod);
                if (canUpdateOnlyTags == false)
                {
                    this.updateMethod = patchUpdateInParameterizedParentMethod;
                    this.updateType   = UpdateType.WithParameterizedParent;
                }
                else
                {
                    StandardFluentMethod putUpdateInParameterizedParentMethod = this.TryGetUpdateInParameterizedParentMethod(findPatchUpdate: false);
                    if (putUpdateInParameterizedParentMethod != null)
                    {
                        this.updateMethod = putUpdateInParameterizedParentMethod;
                        this.updateType   = UpdateType.WithParameterizedParent;
                    }
                    else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithParameterizedParent)
                    {
                        this.updateMethod = this.createDescription.CreateMethod;
                        this.updateType   = UpdateType.WithParameterizedParent;
                    }
                    else
                    {
                        this.updateMethod = patchUpdateInParameterizedParentMethod;
                        this.updateType   = UpdateType.WithParameterizedParent;
                    }
                }
            }
            else
            {
                StandardFluentMethod putUpdateInParameterizedParentMethod = this.TryGetUpdateInParameterizedParentMethod(findPatchUpdate: false);
                if (putUpdateInParameterizedParentMethod != null)
                {
                    this.updateMethod = putUpdateInParameterizedParentMethod;
                    this.updateType   = UpdateType.WithParameterizedParent;
                }
                else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.WithParameterizedParent)
                {
                    this.updateMethod = this.createDescription.CreateMethod;
                    this.updateType   = UpdateType.WithParameterizedParent;
                }
            }
            //
            if (this.updateType != UpdateType.None)
            {
                return;
            }
            //
            StandardFluentMethod patchUpdateAsNestedMethod = this.TryGetUpdateAsNestedChildMethod(findPatchUpdate: true);

            if (patchUpdateAsNestedMethod != null)
            {
                bool canUpdateOnlyTags = SupportsOnlyTagsUpdate(patchUpdateAsNestedMethod);
                if (canUpdateOnlyTags == false)
                {
                    this.updateMethod = patchUpdateAsNestedMethod;
                    this.updateType   = UpdateType.AsNestedChild;
                }
                else
                {
                    StandardFluentMethod putUpdateAsNestedMethod = this.TryGetUpdateAsNestedChildMethod(findPatchUpdate: false);
                    if (putUpdateAsNestedMethod != null)
                    {
                        this.updateMethod = putUpdateAsNestedMethod;
                        this.updateType   = UpdateType.AsNestedChild;
                    }
                    else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.AsNestedChild)
                    {
                        this.updateMethod = this.createDescription.CreateMethod;
                        this.updateType   = UpdateType.AsNestedChild;
                    }
                    else
                    {
                        this.updateMethod = patchUpdateAsNestedMethod;
                        this.updateType   = UpdateType.AsNestedChild;
                    }
                }
            }
            else
            {
                StandardFluentMethod putUpdateAsNestedMethod = this.TryGetUpdateAsNestedChildMethod(findPatchUpdate: false);
                if (putUpdateAsNestedMethod != null)
                {
                    this.updateMethod = putUpdateAsNestedMethod;
                    this.updateType   = UpdateType.AsNestedChild;
                }
                else if (this.createDescription.SupportsCreating && this.createDescription.CreateType == CreateType.AsNestedChild)
                {
                    this.updateMethod = this.createDescription.CreateMethod;
                    this.updateType   = UpdateType.AsNestedChild;
                }
            }
        }
        /// <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());
        }
Пример #18
0
        public IEnumerable <string> BatchDeleteAyncAndSyncMethodImplementations()
        {
            if (this.SupportsDeleteByResourceGroup)
            {
                // It is understood that if delete by resource group is supported in service then batch delete is also supported in SDK
                //
                StandardFluentMethod 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 = ResourceUtilsCore.groupFromResourceId(id);");
                methodBuilder.AppendLine($"        final String name = ResourceUtilsCore.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;
            }
        }
        /// <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());
        }