public ResourceCreateDescription(SegmentFluentMethodGroup fluentMethodGroup)
 {
     this.FluentMethodGroup = fluentMethodGroup;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates NonGroupableTopLevelModelMemberVariablesForCreate holding member variables corrosponding to 'Create' method parameters.
 /// </summary>
 /// <param name="fluentMethodGroup">The method group that the 'Create' method belongs to</param>
 public NonGroupableTopLevelModelMemberVariablesForCreate(SegmentFluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup)
 {
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates GroupableModelMemberVariablesForCreate holding member variables corrosponding to 'Create' method parameters.
 /// </summary>
 /// <param name="fluentMethodGroup">The method group that the 'Create' method belongs to</param>
 public GroupableModelMemberVariablesForCreate(SegmentFluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup, ARMTrackedResourceProperties)
 {
 }
 /// <summary>
 /// Creates ListDescriptionBase.
 /// </summary>
 /// <param name="fluentMethodGroup">The method group containing the standard model whose listing this type describes</param>
 protected ListDescriptionBase(SegmentFluentMethodGroup fluentMethodGroup)
 {
     this.FluentMethodGroup = fluentMethodGroup;
 }
Ejemplo n.º 5
0
 public ListByImmediateParentDescription(SegmentFluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup)
 {
 }
Ejemplo n.º 6
0
 public NonStandardToStandardModelMappingHelper(SegmentFluentMethodGroup fluentMethodGroup)
 {
     this.fluentMethodGroup = fluentMethodGroup;
     this.standardModel     = this.fluentMethodGroup.StandardFluentModel;
     this.Init();
 }
Ejemplo n.º 7
0
 public FluentModelMemberVariablesForCreate(SegmentFluentMethodGroup fluentMethodGroup) :
     this(fluentMethodGroup, new List <string>())
 {
 }
Ejemplo n.º 8
0
 public AncestorsStack(SegmentFluentMethodGroup fluentMethodGroup)
 {
     this.fluentMethodGroup = fluentMethodGroup;
 }
        public static SegmentFluentMethodGroups InnerMethodGroupToSegmentFluentMethodGroups(CodeModelJvaf codeModel)
        {
            IEnumerable <MethodGroupJv> allInnerMethodGroups = codeModel.AllOperations;
            //
            SegmentFluentMethodGroups fluentMethodGroups = new SegmentFluentMethodGroups(codeModel);

            //
            foreach (MethodGroupJvaf currentInnerMethodGroup in allInnerMethodGroups)
            {
                SegmentFluentMethodGroupList fluentMethodGroupsInCurrentInnerMethodGroup = new SegmentFluentMethodGroupList(currentInnerMethodGroup);
                //
                fluentMethodGroups.Add(fluentMethodGroupsInCurrentInnerMethodGroup);
                //
                foreach (MethodJvaf innerMethod in currentInnerMethodGroup.Methods)
                {
                    if (innerMethod.Name.ToLowerInvariant().StartsWith("begin", StringComparison.OrdinalIgnoreCase))
                    {
                        // Skip LRO begin methods
                        continue;
                    }
                    else
                    {
                        ARMUri armUri = new ARMUri(innerMethod);
                        // Skip below two methods
                        //    1. uri can be empty for method such as 'listNext'
                        //    2. uri can be just 'nextLink' for method to retrieve next page
                        if (!armUri.IsNullOrEmpty() && !(armUri.Count == 1 && armUri.First().Name.EqualsIgnoreCase("nextLink")))
                        {
                            IEnumerable <Segment> segments = armUri.SegmentsAfterProvider;
                            segments = segments.Any() ? segments : armUri;
                            //
                            if (segments.Any())
                            {
                                SegmentFluentMethodGroup fluentMethodGroup = null;
                                if (segments.Count() == 1 && (segments.First() is TerminalSegment))
                                {
                                    // e.g. providers/Microsoft.Network/networkInterfaces
                                    // e.g. providers/Microsoft.Network/checkNameAvailability
                                    //
                                    string name = segments.First().Name;
                                    fluentMethodGroup = new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                                                     localName: DeferredFluentMethodGroupNamePrefix.AddPrefix(name));
                                }
                                else
                                {
                                    string methodGroupDefaultName = Utils.TrimInnerSuffix(currentInnerMethodGroup.Name.ToString());
                                    fluentMethodGroup = SegmentFluentMethodGroup.ResolveFluentMethodGroup(fluentMethodGroups, innerMethod, segments, methodGroupDefaultName);
                                    fluentMethodGroup = fluentMethodGroup ?? throw new ArgumentNullException(nameof(fluentMethodGroup));
                                }
                                // Checks whether we already derived a method group with same name in the current "Inner Method Group"
                                //
                                SegmentFluentMethodGroup matchedFluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup.FindFluentMethodGroup(fluentMethodGroup.LocalNameInPascalCase);
                                if (matchedFluentMethodGroup != null)
                                {
                                    matchedFluentMethodGroup.AddInnerMethod(innerMethod);
                                }
                                else
                                {
                                    fluentMethodGroup.AddInnerMethod(innerMethod);
                                    fluentMethodGroupsInCurrentInnerMethodGroup.AddFluentMethodGroup(fluentMethodGroup);
                                }
                            }
                        }
                    }
                }
            }
            //
            fluentMethodGroups.ResolveDeferredSegmentFluentMethodGroups(codeModel);
            fluentMethodGroups.LinkSegmentFluentMethodGroups();
            fluentMethodGroups.InjectPlaceHolderSegmentFluentMethodGroups();
            fluentMethodGroups.DeriveStandardInnerModelForMethodGroups();
            fluentMethodGroups.PruneMethodGroups();
            fluentMethodGroups.Select(m => m.Value).SelectMany(fluentMethodGroupList => fluentMethodGroupList)
            .ForEach(fluentMethodGroup =>
            {
                fluentMethodGroup.JavaInterfaceName = fluentMethodGroup.LocalNameInPascalCase;
            });
            fluentMethodGroups.EnsureUniqueJvaModelInterfaceName();
            fluentMethodGroups.SpecializeFluentModels();
            //
            return(fluentMethodGroups);
        }
        private void EnsureUniqueJvaModelInterfaceName()
        {
            // -- Multiple fluent method group each with different inner method group
            //=======================================================================


            // Each FluentMethodGroup work with only the InnerMethodGroup it was derived from.
            // "FluentMethodGroup : HasInner<InnerMethodGroup>
            // If there two FluentMethodGroup wrapping different InnerMethodGroups
            //
            // 1. FluentMethodGroup1 : HasInner<InnerMethodGroup1>
            // 2. FluentMethodGroup2 : HasInner<InnerMethodGroup2>
            //
            // and if these two FMG has the same StandardFluentModel name then we need abandon
            // that SFM name and derive two different new StandardFluentModel names, one for each FMG.
            //
            // Let's say SFM represents a child resource with different parent then when creating this child resource
            // the def flow need to take different parent & SFM needs to have accessor for the parent which needs
            // to be named explcitly.Hence we need different SFM here.
            //

            var standardModelsToCheckForConflict = this.Select(kv => kv.Value)
                                                   .SelectMany(group => group)
                                                   .Where(group => group.StandardFluentModel != null)
                                                   .Select(group => {
                return(new
                {
                    fluentMethodGroup = group,
                    standardFluentModel = group.StandardFluentModel
                });
            });

            // SFM => [FluentMethodGroup] where FMG just wrapper for innerMG
            //
            Dictionary <string, List <SegmentFluentMethodGroup> > dict = new Dictionary <string, List <SegmentFluentMethodGroup> >();

            this.ResetAncestorsStacks();
            while (true)
            {
                standardModelsToCheckForConflict
                .Select(smtc => smtc.fluentMethodGroup)
                .ForEach(currentFmg => {
                    string modelJvaInterfaceName = currentFmg.StandardFluentModel.JavaInterfaceName;
                    if (!dict.ContainsKey(modelJvaInterfaceName))
                    {
                        dict.Add(modelJvaInterfaceName, new List <SegmentFluentMethodGroup>());
                    }

                    string currentMgInnerName = currentFmg.InnerMethodGroup.Name;
                    bool exists = dict[modelJvaInterfaceName].Any(fmg =>
                    {
                        string mgInnerName = fmg.InnerMethodGroup.Name;
                        return(mgInnerName.EqualsIgnoreCase(currentMgInnerName));
                    });
                    if (!exists)
                    {
                        dict[modelJvaInterfaceName].Add(currentFmg);
                    }
                });

                // Note: a specific StandardFluentModel wraps a single inner model (one to one mapping)

                // If there are multiple different innerMG for specific StandardFluentModel then disambiguate it.
                // By disambiguate it means there will be multiple StandardFluentModel diff names wrapping the
                // same inner model
                //
                var conflicts = dict.Where(kv => kv.Value.Count() > 1);
                if (conflicts.Any())
                {
                    IDictionary <string, List <SegmentFluentMethodGroup> > failedToDeconflict = new Dictionary <string, List <SegmentFluentMethodGroup> >();
                    //

                    conflicts
                    .SelectMany(kv => kv.Value)
                    .ForEach(fluentMethodGroup =>
                    {
                        string modelJvaInterfaceCurrentName = fluentMethodGroup.StandardFluentModel.JavaInterfaceName;
                        string ancestorName             = fluentMethodGroup.AncestorsStack.PopNextAncestorSingularName;
                        string modelJvaInterfaceNewName = $"{ancestorName}{fluentMethodGroup.StandardFluentModel.JavaInterfaceName}";
                        fluentMethodGroup.StandardFluentModel.SetJavaInterfaceName(modelJvaInterfaceNewName);
                        if (ancestorName == null)
                        {
                            // If parentMethodGeoup is null then we need to start using Model suffix to avoid infinite
                            // conflict resolution attempts, hence track FMG with 'failed to de-conflicte std model'.
                            if (!failedToDeconflict.ContainsKey(fluentMethodGroup.StandardFluentModel.JavaInterfaceName))
                            {
                                failedToDeconflict.Add(fluentMethodGroup.StandardFluentModel.JavaInterfaceName, new List <SegmentFluentMethodGroup>());
                            }
                            failedToDeconflict[fluentMethodGroup.StandardFluentModel.JavaInterfaceName].Add(fluentMethodGroup);
                        }
                    });

                    foreach (var kv in failedToDeconflict)
                    {
                        List <SegmentFluentMethodGroup> fluentMethodGroups = kv.Value;
                        if (fluentMethodGroups.Count > 1)
                        {
                            // Skip one "FMG" so that it's std model get good name without "Model". Giving "Model" suffix to next one.
                            SegmentFluentMethodGroup secondFluentMethodGroup = fluentMethodGroups.Skip(1).First();
                            string modelJavaInterfaceName = secondFluentMethodGroup.StandardFluentModel.JavaInterfaceName;
                            secondFluentMethodGroup.StandardFluentModel.SetJavaInterfaceName(modelJavaInterfaceName + "Model");
                            // If there are more than two conflicting FMG then start using suffix "Model{1 <= i <= n}"
                            int i = 1;
                            foreach (SegmentFluentMethodGroup nextFluentMethodGroup in fluentMethodGroups.Skip(2))
                            {
                                modelJavaInterfaceName = nextFluentMethodGroup.StandardFluentModel.JavaInterfaceName;
                                nextFluentMethodGroup.StandardFluentModel.SetJavaInterfaceName(modelJavaInterfaceName + $"Model{i}");
                                i++;
                            }
                        }
                    }
                }
                else
                {
                    break;
                }
                dict.Clear();
            }


            // -- Multiple fluent method group sharing the same inner method group
            //=======================================================================

            // disambiguation is required only if the model is creatable, updatable.
            //

            // SFM.Name_InnerMethodGroup.Name => [FMG]
            //
            dict.Clear();
            this.ResetAncestorsStacks();
            while (true)
            {
                standardModelsToCheckForConflict
                .Select(smtc => smtc.fluentMethodGroup)
                .ForEach(currentFmg =>
                {
                    string key = $"{currentFmg.InnerMethodGroup.Name}:{currentFmg.StandardFluentModel.JavaInterfaceName}";
                    if (!dict.ContainsKey(key))
                    {
                        dict.Add(key, new List <SegmentFluentMethodGroup>());
                    }

                    string currentMgInnerName = currentFmg.InnerMethodGroup.Name;
                    bool exists = dict[key].Any(fmg => fmg.JavaInterfaceName.EqualsIgnoreCase(currentFmg.JavaInterfaceName));
                    if (!exists)
                    {
                        dict[key].Add(currentFmg);
                    }
                });

                var conflicts = dict.Where(kv => kv.Value.Count() > 1)
                                .Where(kv => kv.Value.Any(v => v.ResourceCreateDescription.SupportsCreating || v.ResourceUpdateDescription.SupportsUpdating));

                if (conflicts.Any())
                {
                    IDictionary <string, List <SegmentFluentMethodGroup> > failedToDeconflict = new Dictionary <string, List <SegmentFluentMethodGroup> >();

                    conflicts
                    .SelectMany(kv => kv.Value)
                    .ForEach(fmg =>
                    {
                        string modelJvaInterfaceCurrentName = fmg.StandardFluentModel.JavaInterfaceName;

                        if (!modelJvaInterfaceCurrentName.EndsWith(fmg.LocalNameInPascalCase))
                        {
                            fmg.StandardFluentModel.SetJavaInterfaceName(fmg.LocalNameInPascalCase);
                        }
                        else
                        {
                            string ancestorName             = fmg.AncestorsStack.PopNextAncestorSingularName;
                            string modelJvaInterfaceNewName = $"{ancestorName}{fmg.StandardFluentModel.JavaInterfaceName}";
                            // If parentMethodGeoup is null then we need to start using Model suffix to avoid infinite
                            // conflict resolution attempts, hence track FMG with 'failed to de-conflicte std model'.
                            if (!failedToDeconflict.ContainsKey(fmg.StandardFluentModel.JavaInterfaceName))
                            {
                                failedToDeconflict.Add(fmg.StandardFluentModel.JavaInterfaceName, new List <SegmentFluentMethodGroup>());
                            }
                            failedToDeconflict[fmg.StandardFluentModel.JavaInterfaceName].Add(fmg);
                        }
                    });

                    foreach (var kv in failedToDeconflict)
                    {
                        List <SegmentFluentMethodGroup> fluentMethodGroups = kv.Value;
                        if (fluentMethodGroups.Count > 1)
                        {
                            // Skip one "FMG" so that it's std model get good name without "Model". Giving "Model" suffix to next one.
                            SegmentFluentMethodGroup secondFluentMethodGroup = fluentMethodGroups.Skip(1).First();
                            string modelJavaInterfaceName = secondFluentMethodGroup.StandardFluentModel.JavaInterfaceName;
                            secondFluentMethodGroup.StandardFluentModel.SetJavaInterfaceName(modelJavaInterfaceName + "Model");
                            // If there are more than two conflicting FMG then start using suffix "Model{1 <= i <= n}"
                            int i = 1;
                            foreach (SegmentFluentMethodGroup nextFluentMethodGroup in fluentMethodGroups.Skip(2))
                            {
                                modelJavaInterfaceName = nextFluentMethodGroup.StandardFluentModel.JavaInterfaceName;
                                nextFluentMethodGroup.StandardFluentModel.SetJavaInterfaceName(modelJavaInterfaceName + $"Model{i}");
                                i++;
                            }
                        }
                    }
                }
                else
                {
                    break;
                }
                dict.Clear();
            }
        }
 public ListBySubscriptionDescription(SegmentFluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup)
 {
 }