예제 #1
0
        public object InheritedCollections(
            ResourceProfileData profileData,
            ResourceClassBase resource,
            TemplateContext templateContext)
        {
            if (resource.IsDescriptorEntity())
            {
                return(ResourceRenderer.DoRenderProperty);
            }

            string ns = profileData.GetProfileNamespace(resource);

            var activeResource = profileData.GetProfileActiveResource(resource);

            return(activeResource.IsDerived && activeResource.Collections.Any()
                ? new
            {
                Inherited =
                    activeResource.Collections
                    .Where(x => x.IsInherited)
                    .OrderBy(x => x.PropertyName)
                    .Select(
                        x => new
                {
                    BaseEntity =
                        $"{resource.Entity.BaseEntity.Name}.{resource.Entity.BaseEntity.SchemaProperCaseName()}",
                    BaseEntityInterfaceName = $"I{resource.Entity.BaseEntity.Name}",
                    ItemTypeNamespacePrefix = GetContextualNamespacePrefix(x.ItemType),
                    ItemType = x.ItemType.Name,
                    Collection = x.ItemType.PluralName,
                    PropertyName = x.PropertyName,
                    JsonPropertyName =
                        x.IsDerivedEntityATypeEntity()
                                            ? x.Association.OtherEntity.PluralName.ToCamelCase()
                                            : x.JsonPropertyName,
                    PropertyFieldName = x.ItemType.PluralName.ToCamelCase(),
                    ParentName = x.ParentFullName.Name,
                    PropertyNamespace = ns,
                    ResourceName = resource.Name,
                    Standard =
                        profileData.IsIncluded(resource, x) &&
                        !profileData.IsFilteredCollection(resource, x),
                    Null = !profileData.IsIncluded(resource, x),
                    Filtered = profileData.IsIncluded(resource, x) &&
                               profileData.IsFilteredCollection(
                        resource,
                        x)
                })
                    .ToList()
            }
                : ResourceRenderer.DoNotRenderProperty);
        }
예제 #2
0
        private object AssembleConstructor(ResourceProfileData profileData, ResourceClassBase resource)
        {
            string ns = profileData.GetProfileNamespace(resource);

            var activeResource = profileData.GetProfileActiveResource(resource);

            return(activeResource.Collections.Any()
                ? new
            {
                Inherited = resource.IsDerived && activeResource.Collections.Any(x => x.IsInherited)
                        ? ResourceRenderer.DoRenderProperty
                        : ResourceRenderer.DoNotRenderProperty,
                InheritedCollections = resource.Collections
                                       .Where(x => x.IsInherited)
                                       .Select(
                    x =>
                    new
                {
                    BaseEntity =
                        $"{resource.Entity.BaseEntity.Name}.{resource.Entity.BaseEntity.SchemaProperCaseName()}",
                    PropertyName = x.ItemType.PluralName,
                    PropertyNamespace = ns,
                    CollectionName = x.ItemType.Name
                })
                                       .ToList(),
                Standard = resource.Collections.Any(x => !x.IsInherited)
                        ? ResourceRenderer.DoRenderProperty
                        : ResourceRenderer.DoNotRenderProperty,
                Collections = resource.Collections
                              .Where(
                    x =>
                    !x.IsInherited &&
                    profileData.IsIncluded(resource, x) &&
                    TemplateContext.ShouldRenderResourceClass(
                        x.ItemType))
                              .Select(
                    x => new
                {
                    PropertyName = x.ItemType.PluralName,
                    PropertyNamespace = ns,
                    CollectionName = x.ItemType.Name
                })
                              .ToList()
            }
                : ResourceRenderer.DoNotRenderProperty);
        }
        public object References(ResourceProfileData profileData, ResourceClassBase resource, TemplateContext TemplateContext)
        {
            var activeResource = profileData.GetProfileActiveResource(resource);

            var references = activeResource.References
                             .ToList();

            if (!references.Any(x => profileData.IsIncluded(resource, x)))
            {
                return(ResourceRenderer.DoNotRenderProperty);
            }

            if (activeResource.IsAggregateRoot() || !activeResource.HasBackReferences())
            {
                return(new
                {
                    Collections = references
                                  .Where(x => profileData.IsIncluded(resource, x))
                                  .OrderBy(x => x.PropertyName)
                                  .Select(
                        x =>
                    {
                        bool renderNamespace =
                            !(x.Association.IsSelfReferencing ||
                              x.Association.IsSelfReferencingManyToMany) ||
                            x.Association.OtherEntity.IsAbstract ||
                            !x.Association.OtherEntity.IsSameAggregate(
                                resource.Entity);

                        string referenceName = !renderNamespace
                                    ? x.ReferenceTypeName
                                    : $"{x.ReferencedResourceName}.{x.ReferencedResource.Entity.SchemaProperCaseName()}.{x.ReferenceTypeName}";

                        return new
                        {
                            Reference = new
                            {
                                ReferencedResourceName = x.ReferencedResourceName,
                                ReferenceTypeName =
                                    !x.ReferencedResource.Entity
                                    .IsExtensionEntity &&
                                    !x.ReferenceTypeName.Replace("Reference", string.Empty)
                                    .Equals(resource.Name) &&
                                    !x.ReferenceTypeName.Replace("Reference", string.Empty)
                                    .Equals((resource as ResourceChildItem)?.Parent.Name)
                                                ? $"{x.ReferencedResourceName}.{EdFiConventions.ProperCaseName}.{x.ReferenceTypeName}"
                                                : referenceName,
                                Name = x.ParentFullName.Name,

                                // using the property name so we do not break the data member contract
                                // from the original template.
                                JsonPropertyName = x.PropertyName.ToCamelCase(),
                                PropertyName = x.PropertyName,
                                PropertyFieldName = x.PropertyName.ToCamelCase(),
                                IsRequired = x.IsRequired,
                                IsIdentifying = x.Association.IsIdentifying
                            },
                            Standard = ResourceRenderer.DoRenderProperty
                        };
                    }
                        )
                                  .ToList()
                });
            }

            return(new
            {
                Collections = activeResource.References
                              .OrderBy(x => x.PropertyName)
                              .Select(
                    x => new
                {
                    Reference = new
                    {
                        ReferencedResourceName = x.ReferencedResourceName,
                        ReferenceTypeName = x.ReferenceTypeName,
                        Name = x.ParentFullName.Name,
                        JsonPropertyName = x.JsonPropertyName,
                        PropertyName = x.PropertyName,
                        PropertyFieldName = x.PropertyName.ToCamelCase(),
                        IsRequired = x.IsRequired,
                        IsIdentifying = x.Association.IsIdentifying,
                        BackReferenceType =
                            string.Format(
                                "{0}To{1}Reference",
                                x.Association.ThisEntity.Name,
                                x.Association.OtherEntity.Name)
                    },
                    Backref = ResourceRenderer.DoRenderProperty
                }
                    )
                              .ToList()
            });
        }
예제 #4
0
        public object AssemblePrimaryKeys(
            ResourceProfileData profileData,
            ResourceClassBase resourceClass,
            TemplateContext templateContext)
        {
            if (profileData == null)
            {
                throw new ArgumentNullException(nameof(profileData));
            }

            if (resourceClass == null)
            {
                throw new ArgumentNullException(nameof(resourceClass));
            }

            if (templateContext == null)
            {
                throw new ArgumentNullException(nameof(templateContext));
            }

            var pks = new List <object>();

            var activeResource = profileData.GetProfileActiveResource(resourceClass);

            var filteredResource = profileData.GetContainedResource(resourceClass) ?? resourceClass;

            if (resourceClass is ResourceChildItem)
            {
                pks.Add(
                    new
                {
                    HasParent = ResourceRenderer.DoRenderProperty,
                    Property  = new
                    {
                        PropertyName =
                            resourceClass.GetResourceInterfaceName(
                                templateContext.GetSchemaProperCaseNameForResource(resourceClass),
                                templateContext.IsProfiles,
                                templateContext.IsExtension),
                        ReferencesWithUnifiedKey =
                            resourceClass.References
                            .Where(@ref => @ref.Properties.Any(rp => rp.IsUnified()))
                            .Select(@ref => new
                        {
                            ReferencePropertyName = @ref.PropertyName,
                            ReferenceFieldName    = @ref.PropertyName.ToCamelCase(),
                            UnifiedKeyProperties  = @ref.Properties
                                                    .Where(rp => rp.IsUnified())
                                                    .Select(rp => new
                            {
                                UnifiedKeyPropertyName = rp.PropertyName
                            })
                        })
                    }
                });
            }

            var props = new List <PropertyData>();

            foreach (var property in activeResource.AllProperties
                     .Where(x => x.IsIdentifying)
                     .OrderBy(x => x.PropertyName))
            {
                if (activeResource.IsDescriptorEntity())
                {
                    props.Add(PropertyData.CreateDerivedProperty(property));
                    continue;
                }

                if (activeResource.IsAggregateRoot())
                {
                    if (resourceClass.IsDerived)
                    {
                        props.Add(AssembleDerivedProperty(property));
                    }
                    else
                    {
                        props.Add(
                            property.IsPersonOrUsi() && !templateContext.IsExtension
                                ? PropertyData.CreateUsiPrimaryKey(property)
                                : property.HasAssociations() && !property.IsDirectLookup
                                    ? PropertyData.CreateReferencedProperty(property, resource: filteredResource)
                                    : PropertyData.CreateStandardProperty(property));
                    }
                }
                else
                {
                    // non aggregate root
                    if (activeResource.References.Any())
                    {
                        if (property.IsPersonOrUsi())
                        {
                            props.Add(PropertyData.CreateUsiPrimaryKey(property));
                            continue;
                        }

                        if (resourceClass.HasBackReferences() &&
                            resourceClass.BackReferencedProperties()
                            .Contains(property, ModelComparers.ResourcePropertyNameOnly))
                        {
                            continue;
                        }

                        props.Add(
                            property.HasAssociations() && !property.IsDirectLookup
                                ? PropertyData.CreateReferencedProperty(property)
                                : PropertyData.CreateStandardProperty(property));
                    }
                    else
                    {
                        props.Add(PropertyData.CreateStandardProperty(property));
                    }
                }
            }

            pks.AddRange(CreatePropertyDtos(props));

            return(pks.Any()
                ? new { Properties = pks }
                : ResourceRenderer.DoNotRenderProperty);
        }
예제 #5
0
        public object AssembleIdentifiers(
            ResourceProfileData profileData,
            ResourceClassBase resource,
            AssociationView association = null)
        {
            if (profileData == null)
            {
                throw new ArgumentNullException(nameof(profileData));
            }

            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            if (!resource.IdentifyingProperties.Any() && association == null)
            {
                return(ResourceRenderer.DoNotRenderProperty);
            }

            IList <ResourceProperty> properties;

            var activeResource = profileData.GetProfileActiveResource(resource);

            if (resource.IsAggregateRoot())
            {
                properties = activeResource.IdentifyingProperties
                             .OrderBy(x => x.PropertyName)
                             .ToList();
            }
            else
            {
                if (association != null)
                {
                    properties = association.ThisProperties
                                 .Where(x => !(x.IsUnified && x.IsIdentifying))
                                 .Select(
                        x =>
                        association.PropertyMappingByThisName[x.PropertyName]
                        .OtherProperty
                        .ToResourceProperty(resource))
                                 .OrderBy(x => x.PropertyName)
                                 .ToList();
                }
                else
                {
                    properties = resource.IdentifyingProperties
                                 .Where(x => !x.EntityProperty.IsLocallyDefined)
                                 .OrderBy(x => x.PropertyName)
                                 .ToList();
                }
            }

            ResourceProperty first = properties.FirstOrDefault();
            ResourceProperty last  = properties.LastOrDefault();

            return(properties.Any()
                ? properties.Select(
                       y => new PropertyData(y)
            {
                IsFirstProperty = y == first,
                IsLastProperty = y == last
            }.Render())
                   .ToList()
                : ResourceRenderer.DoNotRenderProperty);
        }