private void InjectPlaceHolderFluentMethodGroups() { IEnumerable <FluentMethodGroup> orphanFluentMethodGroups = this.Select(kv => kv.Value) .SelectMany(fluentMethodGroupList => fluentMethodGroupList.OrphanFluentMethodGroups) .OrderByDescending(group => group.Level); if (!orphanFluentMethodGroups.Any()) { return; } else { foreach (FluentMethodGroup orphanFluentMethodGroup in orphanFluentMethodGroups) { string ancestorName = orphanFluentMethodGroup.ParentMethodGroupNames.LastOrDefault(); if (ancestorName != null) { FluentMethodGroupList fluentMethodGroupList = this[orphanFluentMethodGroup.InnerMethodGroup.Name]; FluentMethodGroup fosterParentFluentMethodGroup = fluentMethodGroupList.FindFluentMethodGroup(ancestorName, orphanFluentMethodGroup.Level - 1); if (fosterParentFluentMethodGroup == null) { fosterParentFluentMethodGroup = new FluentMethodGroup(fluentMethodGroups: this, localName: ancestorName, parentMethodGroupNames: orphanFluentMethodGroup.ParentMethodGroupNames.SkipLast(1).ToList()); // fluentMethodGroupList.AddFluentMethodGroup(fosterParentFluentMethodGroup); } orphanFluentMethodGroup.SetParentFluentMethodGroup(fosterParentFluentMethodGroup); fosterParentFluentMethodGroup.AddToChildFluentMethodGroup(orphanFluentMethodGroup); } } this.InjectPlaceHolderFluentMethodGroups(); } }
private void ResolveDeferredFluentMethodGroups(CodeModelJvaf codeModel) { // For each "Inner Method Group", process list of "Fluent Method Groups" belongs to it. // foreach (FluentMethodGroupList fluentMethodGroupList in this.Values) { List <FluentMethodGroup> deferredFluentMethodGroups = fluentMethodGroupList.DeferredFluentMethodGroups; // foreach (FluentMethodGroup deferredFluentMethodGroup in deferredFluentMethodGroups) { string possibleFluentMethodGroupName = DeferredFluentMethodGroupNamePrefix.RemovePrefix(deferredFluentMethodGroup.LocalNameInPascalCase); // // Find a "Fluent Method Group" that can own the methods in the "Deferred Fluent Method Group". // FluentMethodGroup newOwnerFluentMethodGroup = fluentMethodGroupList.FindFluentMethodGroup(possibleFluentMethodGroupName); if (newOwnerFluentMethodGroup == null) { newOwnerFluentMethodGroup = fluentMethodGroupList.FindBestMatchingLevel0FluentMethodGroupOrCreateOne(this); } // Migrate methods in "Defered Fluent Method Group" to new owner // newOwnerFluentMethodGroup.AddInnerMethods(deferredFluentMethodGroup.InnerMethods); // Remove "Defered Fluent Method Group", given it's methods has new owner // fluentMethodGroupList.RemoveFluentMethodGroup(deferredFluentMethodGroup.LocalNameInPascalCase); } } }
public OtherMethods(FluentMethodGroup fluentMethodGroup, HashSet <string> standardMethods) { this.fluentMethodGroup = fluentMethodGroup; this.AddRange(this.fluentMethodGroup.InnerMethods .Where(im => !standardMethods.Contains(im.Name.ToLowerInvariant())) .Select(im => new FluentMethod(false, im, this.fluentMethodGroup)) .ToList()); }
public FluentModelMemberVariablesForUpdate(FluentMethodGroup fluentMethodGroup, List <string> propertiesOfPayloadToSkip) : base(fluentMethodGroup.ResourceUpdateDescription.SupportsUpdating ? fluentMethodGroup.ResourceUpdateDescription.UpdateMethod : null) { this.FluentMethodGroup = fluentMethodGroup; this.updateStages = null; this.propertiesOfPayloadToSkip = propertiesOfPayloadToSkip; this.resourceName = fluentMethodGroup.StandardFluentModel.JavaInterfaceName.ToLower(); }
public NestedFluentModelInterface(FluentModel rawFluentModel, FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup, new NestedFluentModelMemberVariablesForCreate(fluentMethodGroup), new NestedFluentModelMemberVariablesForUpdate(fluentMethodGroup), new NestedFluentModelMemberVariablesForGet(fluentMethodGroup), rawFluentModel.InnerModel.Name) { this.rawFluentModel = rawFluentModel; }
public OtherMethods(FluentMethodGroup fluentMethodGroup) { StandardMethodsInfo standardMethods = fluentMethodGroup.StandardMethodsInfo(); // this.fluentMethodGroup = fluentMethodGroup; this.AddRange(this.fluentMethodGroup.InnerMethods .Where(innerMethod => !standardMethods.IsStandardInnerMethod(innerMethod) && !standardMethods.IsConfictWithStandardFluentMethod(innerMethod)) .Select(innerMethod => new OtherMethod(innerMethod, this.fluentMethodGroup)) .ToList()); }
/// <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 StandardModel(FluentMethodGroup group, CompositeTypeJvaf standardInnerModel) : base(standardInnerModel) { switch (group.Type) { case MethodGroupType.GroupableTopLevel: this.Type = StanardModelType.GroupableTopLevel; break; case MethodGroupType.NonGroupableTopLevel: this.Type = StanardModelType.NonGroupableTopLevel; break; case MethodGroupType.Nested: this.Type = StanardModelType.Nested; break; default: throw new ArgumentException($"group with type '{group.Type}' is not eligible to have a standard model."); } this.FluentMethodGroup = group; }
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; } }
protected CreatableUpdatableModel(FluentMethodGroup fluentMethodGroup, FluentModelMemberVariablesForCreate cVariables, FluentModelMemberVariablesForUpdate uVariables, FluentModelMemberVariablesForGet gVariable, string innerModelTypeName) { this.FluentMethodGroup = fluentMethodGroup; // this.cVariables = cVariables; this.uVariables = uVariables; this.gVariable = gVariable; // this.innerModelTypeName = innerModelTypeName; // this.DisambiguatedMemberVariables = new FluentModelDisambiguatedMemberVariables() .WithCreateMemberVariable(this.cVariables) .WithUpdateMemberVariable(this.uVariables) .WithGetMemberVariable(this.gVariable) .Disambiguate(); // this.cVariables.SetDisambiguatedMemberVariables(this.DisambiguatedMemberVariables); this.uVariables.SetDisambiguatedMemberVariables(this.DisambiguatedMemberVariables); }
public NonGroupableTopLevelMethodGroupImpl(NonGroupableTopLevelFluentModelImpl fluentModelImpl) { this.fluentModelImpl = fluentModelImpl; this.Interface = fluentModelImpl.Interface.FluentMethodGroup; }
public NonGroupableTopLevelFluentModelMemberVariablesForUpdate(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }
public ResourceCreateDescription(FluentMethodGroup fluentMethodGroup) { this.FluentMethodGroup = fluentMethodGroup; }
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 <FluentMethodGroup> > dict = new Dictionary <string, List <FluentMethodGroup> >(); 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 <FluentMethodGroup>()); } 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 <FluentMethodGroup> > failedToDeconflict = new Dictionary <string, List <FluentMethodGroup> >(); // 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 <FluentMethodGroup>()); } failedToDeconflict[fluentMethodGroup.StandardFluentModel.JavaInterfaceName].Add(fluentMethodGroup); } }); foreach (var kv in failedToDeconflict) { List <FluentMethodGroup> 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. FluentMethodGroup 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 (FluentMethodGroup 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 <FluentMethodGroup>()); } 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 <FluentMethodGroup> > failedToDeconflict = new Dictionary <string, List <FluentMethodGroup> >(); 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 <FluentMethodGroup>()); } failedToDeconflict[fmg.StandardFluentModel.JavaInterfaceName].Add(fmg); } }); foreach (var kv in failedToDeconflict) { List <FluentMethodGroup> 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. FluentMethodGroup 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 (FluentMethodGroup nextFluentMethodGroup in fluentMethodGroups.Skip(2)) { modelJavaInterfaceName = nextFluentMethodGroup.StandardFluentModel.JavaInterfaceName; nextFluentMethodGroup.StandardFluentModel.SetJavaInterfaceName(modelJavaInterfaceName + $"Model{i}"); i++; } } } } else { break; } dict.Clear(); } }
public static FluentMethodGroups InnerMethodGroupToFluentMethodGroups(CodeModelJvaf codeModel) { IEnumerable <MethodGroupJv> allInnerMethodGroups = codeModel.AllOperations; // FluentMethodGroups fluentMethodGroups = new FluentMethodGroups(codeModel); // foreach (MethodGroupJvaf currentInnerMethodGroup in allInnerMethodGroups) { FluentMethodGroupList fluentMethodGroupsInCurrentInnerMethodGroup = new FluentMethodGroupList(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()) { FluentMethodGroup 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 FluentMethodGroup(fluentMethodGroups: fluentMethodGroups, localName: DeferredFluentMethodGroupNamePrefix.AddPrefix(name)); } else { string methodGroupDefaultName = Utils.TrimInnerSuffix(currentInnerMethodGroup.Name.ToString()); fluentMethodGroup = FluentMethodGroup.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" // FluentMethodGroup matchedFluentMethodGroup = fluentMethodGroupsInCurrentInnerMethodGroup.FindFluentMethodGroup(fluentMethodGroup.LocalNameInPascalCase); if (matchedFluentMethodGroup != null) { matchedFluentMethodGroup.AddInnerMethod(innerMethod); } else { fluentMethodGroup.AddInnerMethod(innerMethod); fluentMethodGroupsInCurrentInnerMethodGroup.AddFluentMethodGroup(fluentMethodGroup); } } } } } } // fluentMethodGroups.ResolveDeferredFluentMethodGroups(codeModel); fluentMethodGroups.LinkFluentMethodGroups(); fluentMethodGroups.InjectPlaceHolderFluentMethodGroups(); fluentMethodGroups.DeriveStandardInnerModelForMethodGroups(); fluentMethodGroups.PruneMethodGroups(); fluentMethodGroups.Select(m => m.Value).SelectMany(fluentMethodGroupList => fluentMethodGroupList) .ForEach(fluentMethodGroup => { fluentMethodGroup.JavaInterfaceName = fluentMethodGroup.LocalNameInPascalCase; }); fluentMethodGroups.EnsureUniqueJvaModelInterfaceName(); fluentMethodGroups.SpecializeFluentModels(); // return(fluentMethodGroups); }
public NestedFluentModelMemberVariablesForCreate(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }
/// <summary> /// Creates ListDescriptionBase. /// </summary> /// <param name="fluentMethodGroup">The method group containing the standard model whose listing this type describes</param> protected ListDescriptionBase(FluentMethodGroup fluentMethodGroup) { this.FluentMethodGroup = fluentMethodGroup; }
public ActionOrChildAccessorOnlyMethodGroupImpl(FluentMethodGroup fluentMethodGroup) { this.Interface = fluentMethodGroup; }
public ResourceListingDescription(FluentMethodGroup fluentMethodGroup) { this.listByResourceGroup = new ListByResourceGroupDescription(fluentMethodGroup); this.listBySubscription = new ListBySubscriptionDescription(fluentMethodGroup); this.listByImmediateParent = new ListByImmediateParentDescription(fluentMethodGroup); }
public NonStandardToStandardModelMappingHelper(FluentMethodGroup fluentMethodGroup) { this.fluentMethodGroup = fluentMethodGroup; this.standardModel = this.fluentMethodGroup.StandardFluentModel; this.Init(); }
public ResourceGetDescription(FluentMethodGroup fluentMethodGroup) { this.fluentMethodGroup = fluentMethodGroup; }
public ResourceUpdateDescription(IResourceCreateDescription createDescription, FluentMethodGroup fluentMethodGroup) { this.createDescription = createDescription; this.fluentMethodGroup = fluentMethodGroup; }
public FluentModelMemberVariablesForCreate(FluentMethodGroup fluentMethodGroup) : this(fluentMethodGroup, new List <string>()) { }
public GroupableFluentModelMemberVariablesForCreate(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup, ARMTrackedResourceProperties) { }
public ListBySubscriptionDescription(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }
public ListByImmediateParentDescription(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }
public GroupableFluentMethodGroupImpl(GroupableFluentModelImpl fluentModelImpl) { this.fluentModelImpl = fluentModelImpl; this.Interface = fluentModelImpl.Interface.FluentMethodGroup; }
public GroupableFluentModelMemberVariablesForGet(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup, fluentMethodGroup.ResourceGetDescription.SupportsGetByResourceGroup ? fluentMethodGroup.ResourceGetDescription.GetByResourceGroupMethod : null) { }
public FluentMethod(bool isStandard, MethodJvaf innerMethod, FluentMethodGroup methodGroup) { this.isStandard = isStandard; this.InnerMethod = innerMethod; this.MethodGroup = methodGroup; }
public ListByResourceGroupDescription(FluentMethodGroup fluentMethodGroup) : base(fluentMethodGroup) { }