示例#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
                });
            });
        }
        public override LazyDictionary <string, ItemField> GetValue(TypedEntity source)
        {
            var d = new LazyDictionary <string, ItemField>();

            foreach (var a in source.Attributes)
            {
                if (a.Values.Count == 1)
                {
                    StoreFieldValue(a.AttributeDefinition.AttributeType.SerializationType,
                                    FixedAttributeIndexFields.AttributePrefix + a.AttributeDefinition.Alias,
                                    a.DynamicValue,
                                    d);
                }
                else if (a.Values.Count > 1)
                {
                    //we need to put multiple values in the index with dot notation
                    foreach (var val in a.Values)
                    {
                        var key = FixedAttributeIndexFields.AttributePrefix + a.AttributeDefinition.Alias + "." + val.Key;
                        StoreFieldValue(a.AttributeDefinition.AttributeType.SerializationType,
                                        key,
                                        val.Value,
                                        d);
                    }
                }

                //put attribute alias/name/id in there
                FixedAttributeIndexFields.AddAttributeAlias(d, a);
                //FixedAttributeIndexFields.AddAttributeName(d, a);
                FixedAttributeIndexFields.AddAttributeId(d, a);
            }

            //Get the parent Id.
            //TODO: We should support all relation types in some magical way
            foreach (var r in source.RelationProxies.GetParentRelations(FixedRelationTypes.DefaultRelationType))
            {
                d.AddOrUpdate(FixedIndexedFields.ParentId, new ItemField(r.Item.SourceId.Value.ToString()));
            }

            d.AddOrUpdate(FixedIndexedFields.SchemaId,
                          new Lazy <ItemField>(() => new ItemField(source.EntitySchema.Id.Value.ToString())),
                          (k, i) => new Lazy <ItemField>(() => new ItemField(source.EntitySchema.Id.Value.ToString())));
            d.Add(FixedIndexedFields.SchemaAlias, new ItemField(source.EntitySchema.Alias));
            d.AddOrUpdate(FixedIndexedFields.SchemaName, new ItemField(source.EntitySchema.Name));
            d.AddOrUpdate(FixedIndexedFields.SchemaType, new ItemField(source.EntitySchema.SchemaType));

            ExamineHelper.SetTimestampsOnEntityAndIndexFields(d, source);
            return(d);
        }
示例#3
0
        public override LazyDictionary <string, ItemField> GetValue(AttributeType source)
        {
            ////TODO: This is purely a hack in order to get the installer working with Examine, its also a required hack until the underlying
            //// issue is fixed: Currently we need to make sure that the properties of an Attribute type remain constant in the repository unless
            //// that property is explicitly changed. This is mostly to do with the RenderTypeProvider property as we don't want it to be overwritten
            //// with a empty value when a system attribute type is committed.
            //if (!source.Id.IsNullValueOrEmpty())
            //{
            //    var existing = _helper.PerformGet<AttributeType>(true, LuceneIndexer.IndexNodeIdFieldName, source.Id);
            //    var destination = existing.LastOrDefault();
            //    if (destination != null)
            //    {
            //        //This copies across all changed (Dirty) properties from the source to the destination except for a few of the properties
            //        destination.SetAllChangedProperties<AttributeType, object>(source,
            //                                            x => x.Id,
            //                                            x => x.ConcurrencyToken,
            //                                            x => x.PersistenceMetadata,
            //                                            x => x.UtcCreated,
            //                                            x => x.UtcModified,
            //                                            x => x.UtcStatusChanged);
            //        //now that all properties are updated that have changed, overwrite the 'source' object with the destination so it can be mapped
            //        //to the index fields properly to be stored.
            //        source = destination;
            //    }
            //}

            //convert the source to a dictionary object ignoring some of its properties
            var d = source.ToDictionary <AttributeType, object, object>(
                x => x.Id,
                x => x.SerializationType,
                x => x.ConcurrencyToken);

            //add the serialization FQN so we can re-create it later
            d.Add(FixedIndexedFields.SerializationType, source.SerializationType.GetType().FullName);

            var output = new LazyDictionary <string, ItemField>();

            foreach (var i in d)
            {
                output.Add(i.Key, new ItemField(i.Value));
            }

            ExamineHelper.SetTimestampsOnEntityAndIndexFields(output, source);

            return(output);
        }
        public override LazyDictionary <string, ItemField> GetValue(AttributeGroup source)
        {
            //convert the source to a dictionary object ignoring some of its properties
            var d = source.ToDictionary <AttributeGroup, object, object>(
                x => x.Id,
                x => x.ConcurrencyToken);

            var output = new LazyDictionary <string, ItemField>();

            foreach (var i in d)
            {
                output.Add(i.Key, new ItemField(i.Value));
            }

            ExamineHelper.SetTimestampsOnEntityAndIndexFields(output, source);

            return(output);
        }
示例#5
0
        public override LazyDictionary <string, ItemField> GetValue(AttributeDefinition source)
        {
            //convert the source to a dictionary object ignoring some of its properties
            var d = source.ToDictionary <AttributeDefinition, object, object>(
                x => x.Id,
                x => x.AttributeGroup,
                x => x.AttributeType,
                x => x.ConcurrencyToken);

            var output = new LazyDictionary <string, ItemField>();

            foreach (var i in d)
            {
                output.Add(i.Key, new ItemField(i.Value));
            }

            ExamineHelper.SetTimestampsOnEntityAndIndexFields(output, source);

            //add some lazy delegates for the ids of the group/attribute type
            output.Add(FixedIndexedFields.GroupId, new Lazy <ItemField>(() => new ItemField(source.AttributeGroup.Id.Value)));
            output.Add(FixedIndexedFields.AttributeTypeId, new Lazy <ItemField>(() => new ItemField(source.AttributeType.Id.Value)));

            return(output);
        }