Beispiel #1
0
        public TypedEntityToIndexOperation(AbstractFluentMappingEngine engine)
            : base(engine)
        {
            MappingContext
            .CreateUsing(x => new NestedHiveIndexOperation())
            .ForMember(x => x.Entity, opt => opt.MapFrom(y => y))
            .ForMember(x => x.OperationType, opt => opt.MapFrom(y => IndexOperationType.Add))
            .ForMember(x => x.Id, opt => opt.MapFrom(y => new Lazy <string>(() => y.Id.Value.ToString())))
            .ForMember(x => x.ItemCategory, opt => opt.MapFrom(y => typeof(TypedEntity).Name))
            .ForMember(x => x.Fields, opt => opt.MapUsing <TypedEntityToIndexFields>())
            .AfterMap((s, t) =>
            {
                //create sub operations for each of the children
                //NOTE: we don't store TypedAttribute seperately in the index, they get stored with the TypedEntity!

                //NOTE: we need to store the entity id in a seperate field to the normal id when using revisions
                t.AddOrUpdateField(FixedIndexedFields.EntityId, new Lazy <string>(() => s.Id.Value.ToString()));

                s.MapRelations(t, MappingContext.Engine);

                t.SubIndexOperations.Add(MappingContext.Engine.Map <EntitySchema, NestedHiveIndexOperation>(s.EntitySchema));

                ExamineHelper.SetTimestampsOnEntityAndIndexFields(t.Fields, s);

                //ensure the IsLatest flag is set, this is only used if we're supporting Revisions. If we change
                //to a NullRevisionFactory then only one TypedEntity will ever exist.
                t.Fields.Add(FixedRevisionIndexFields.IsLatest, new ItemField(1)
                {
                    DataType = FieldDataType.Int
                });
            });
        }
Beispiel #2
0
 public EntitySnapshotToContentEditorModel(AbstractFluentMappingEngine engine)
     : base(engine)
 {
     MappingContext
     .CreateUsing(x => MappingContext.Engine.Map <Revision <TypedEntity>, TContentModel>(x.Revision))
     .AfterMap(
         (source, dest) =>
     {
         dest.UtcPublishedDate = source.PublishedDate();
     });
 }
Beispiel #3
0
 public RevisionToContentEditorModel(AbstractFluentMappingEngine engine)
     : base(engine)
 {
     MappingContext
     .CreateUsing(x =>
     {
         var output        = MappingContext.Engine.Map <TypedEntity, TContentModel>(x.Item);
         output.RevisionId = x.MetaData.Id;
         return(output);
     });
 }
Beispiel #4
0
 public ContentEditorModelToRevision(AbstractFluentMappingEngine engine)
     : base(engine)
 {
     MappingContext
     .CreateUsing(x => new Revision <TypedEntity>()
     {
         Item = MappingContext.Engine.Map <TContentModel, TypedEntity>(x),
         //TODO: Is this correctly mapped ??
         MetaData = new RevisionData(x.RevisionId, FixedStatusTypes.Draft)
     });
 }
        public DocumentTypePropertyToAttributeDefinition(
            AbstractFluentMappingEngine engine,
            MapResolverContext resolverContext,
            bool mapAttributeGroup = true)
            : base(engine)
        {
            _resolverContext = resolverContext;

            MappingContext
            .CreateUsing(x => new AttributeDefinition(x.Alias, x.Name))
            .MapMemberFrom(x => x.Ordinal, x => x.SortOrder)
            .MapMemberUsing(x => x.AttributeType, new DocumentTypePropertyToAttributeType(engine, _resolverContext))
            .MapMemberUsing(x => x.AttributeGroup, new DocumentTypePropertyToAttributeGroup(engine, _resolverContext, !mapAttributeGroup))
            .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>())
            .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>())
            .AfterMap((source, dest) =>
            {
                if (dest.AttributeType == null)
                {
                    throw new InvalidOperationException("The DataType property of the DocumentTypeProperty object cannot be null when mapping from DocumentTypeProperty -> AttributeDefinition");
                }

                //This will check if the pre-value editor has overriding field capabilities.
                //If it does, it will persist these values to the RenderTypeProviderConfigOverride instead of the underlying
                //data type.
                if (source.PreValueEditor != null)
                {
                    var preValueMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => source.PreValueEditor, source.GetType());
                    //checks if the model contains overrides
                    var hasOverrides = preValueMetadata
                                       .Properties
                                       .Any(metaProp =>
                                            metaProp.AdditionalValues.ContainsKey(RebelMetadataAdditionalInfo.AllowDocumentTypePropertyOverride.ToString()));

                    //if this pre-value model has overrides, then persist them
                    if (hasOverrides)
                    {
                        dest.RenderTypeProviderConfigOverride = source.PreValueEditor.GetSerializedValue();
                    }
                }
            });
        }
        public DataTypeToAttributeType(AbstractFluentMappingEngine engine, Action <TInput, AttributeType> additionalAfterMap = null)
            : base(engine)
        {
            MappingContext
            .CreateUsing(x =>
            {
                var typeRegistry = AttributeTypeRegistry.Current;
                if (typeRegistry != null)
                {
                    var existing = typeRegistry.TryGetAttributeType(x.Name).Result;
                    if (existing != null)
                    {
                        return(existing);
                    }
                }
                return(new AttributeType()
                {
                    Id = x.Id
                });
            })
            // Ignore the Id. In the CreateUsing, we either return the AttributeType from the registry with its inferred Id,
            // or we set the Id there from the source.
            .ForMember(x => x.Id, opt => opt.Ignore())
            .ForMember(x => x.UtcCreated, opt => opt.MapUsing <UtcCreatedMapper>())
            .ForMember(x => x.UtcModified, opt => opt.MapUsing <UtcModifiedMapper>())
            .AfterMap((source, dest) =>
            {
                if (string.IsNullOrEmpty(dest.Alias))
                {
                    dest.Alias = source.Name.ToRebelAlias();
                }

                //TODO: Detect serialization type from DataType
                dest.SerializationType = new LongStringSerializationType();

                if (additionalAfterMap != null)
                {
                    additionalAfterMap(source, dest);
                }
            });
        }
        public EntitySchemaToSchemaEditorModel(
            AbstractFluentMappingEngine engine,
            Func <EntitySchema, TEditorModel> createWith,
            Action <EntitySchema, TEditorModel> additionalAfterMap = null)
            : base(engine)
        {
            MappingContext
            .CreateUsing(createWith)
            .MapMemberFrom(x => x.Thumbnail, x => x.GetXmlConfigProperty("thumb"))
            .MapMemberFrom(x => x.AllowedChildIds, x => x.GetXmlPropertyAsList <HiveId>("allowed-children"))
            .MapMemberFrom(x => x.Icon, x => x.GetXmlConfigProperty("icon"))
            .MapMemberFrom(x => x.Thumbnail, x => x.GetXmlConfigProperty("thumb"))
            .MapMemberFrom(x => x.DefinedTabs, x => MappingContext.Engine.Map <IEnumerable <AttributeGroup>, HashSet <Tab> >(x.AttributeGroups.ToArray()))
            .MapMemberFrom(x => x.Description, x => x.GetXmlConfigProperty("description"))
            .MapMemberFrom(x => x.IsAbstract, x => x.GetXmlConfigProperty("is-abstract") != null && bool.Parse(x.GetXmlConfigProperty("is-abstract")))
            .AfterMap((from, to) =>
            {
                // Commented out the below as working on multi-inheritance and the blow assumes one parent only (MB - 2011-11-15)

                //var firstParentFound =
                //from.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType).
                //    FirstOrDefault();

                //if (firstParentFound != null && !firstParentFound.Item.SourceId.IsNullValueOrEmpty())
                //    to.ParentId = firstParentFound.Item.SourceId;

                //first, map the properties from the attribute definition (but not the special fields)
                to.Properties.Clear();
                from.AttributeDefinitions
                //.Where(x => !FixedAttributeDefinitionAliases.AllAliases.Contains(x.Alias))
                .ForEach(y =>
                         to.Properties.Add(
                             MappingContext.Engine.Map <AttributeDefinition, DocumentTypeProperty>(y)));

                //set the available tabs select list
                to.AvailableTabs = new List <SelectListItem>(
                    to.DefinedTabs.Where(x => !x.Id.IsNullValueOrEmpty()).OrderBy(x => x.SortOrder)
                    .Select(x => new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                }))
                                   .ToArray();

                //set the inherit from list
                to.InheritFromIds =
                    from.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType).Select(
                        x => x.Item.SourceId);

                var merged = from as CompositeEntitySchema;
                if (merged != null)
                {
                    to.InheritedProperties.Clear();
                    merged.InheritedAttributeDefinitions
                    .ForEach(y => to.InheritedProperties.Add(MappingContext.Engine.Map <AttributeDefinition, DocumentTypeProperty>(y)));

                    to.InheritedTabs =
                        MappingContext.Engine.Map <IEnumerable <AttributeGroup>, HashSet <Tab> >(
                            merged.InheritedAttributeGroups.ToArray());
                }

                if (additionalAfterMap != null)
                {
                    additionalAfterMap(from, to);
                }
            });
        }