<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Examine;
using Examine.LuceneEngine.Providers;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Examine;

namespace Umbraco.Web.Models.Mapping
{
    internal class EntityMapDefinition : IMapDefinition
    {
        public void DefineMaps(UmbracoMapper mapper)
        {
            mapper.Define<IEntitySlim, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<PropertyType, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<PropertyGroup, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<IUser, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<ITemplate, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<EntityBasic, ContentTypeSort>((source, context) => new ContentTypeSort(), Map);
            mapper.Define<IContentTypeComposition, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<IEntitySlim, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
            mapper.Define<ISearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
            mapper.Define<ISearchResults, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
            mapper.Define<IEnumerable<ISearchResult>, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
        }

        // Umbraco.Code.MapAll -Alias
        private static void Map(IEntitySlim source, EntityBasic target, MapperContext context)
        {
            target.Icon = MapContentTypeIcon(source);
            target.Id = source.Id;
            target.Key = source.Key;
            target.Name = MapName(source, context);
            target.ParentId = source.ParentId;
            target.Path = source.Path;
            target.Trashed = source.Trashed;
            target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);

            if (source.NodeObjectType == Constants.ObjectTypes.Member && target.Icon.IsNullOrWhiteSpace())
                target.Icon = Constants.Icons.Member;

            if (source is IContentEntitySlim contentSlim)
                source.AdditionalData["ContentTypeAlias"] = contentSlim.ContentTypeAlias;

            if (source is IMediaEntitySlim mediaSlim)
                source.AdditionalData["MediaPath"] = mediaSlim.MediaPath;

            // NOTE: we're mapping the objects in AdditionalData by object reference here.<commit_msg>Added metadata indicating if document published for content picker display<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Examine;
using Examine.LuceneEngine.Providers;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Examine;

namespace Umbraco.Web.Models.Mapping
{
    internal class EntityMapDefinition : IMapDefinition
    {
        public void DefineMaps(UmbracoMapper mapper)
        {
            mapper.Define<IEntitySlim, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<PropertyType, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<PropertyGroup, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<IUser, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<ITemplate, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<EntityBasic, ContentTypeSort>((source, context) => new ContentTypeSort(), Map);
            mapper.Define<IContentTypeComposition, EntityBasic>((source, context) => new EntityBasic(), Map);
            mapper.Define<IEntitySlim, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
            mapper.Define<ISearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
            mapper.Define<ISearchResults, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
            mapper.Define<IEnumerable<ISearchResult>, IEnumerable<SearchResultEntity>>((source, context) => context.MapEnumerable<ISearchResult, SearchResultEntity>(source));
        }

        // Umbraco.Code.MapAll -Alias
        private static void Map(IEntitySlim source, EntityBasic target, MapperContext context)
        {
            target.Icon = MapContentTypeIcon(source);
            target.Id = source.Id;
            target.Key = source.Key;
            target.Name = MapName(source, context);
            target.ParentId = source.ParentId;
            target.Path = source.Path;
            target.Trashed = source.Trashed;
            target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key);

            if (source.NodeObjectType == Constants.ObjectTypes.Member && target.Icon.IsNullOrWhiteSpace())
                target.Icon = Constants.Icons.Member;

            if (source is IContentEntitySlim contentSlim)
            {
                source.AdditionalData["ContentTypeAlias"] = contentSlim.ContentTypeAlias;
            }

            if (source is IDocumentEntitySlim documentSlim)
            {
                source.AdditionalData["IsPublished"] = documentSlim.Published;
            }

            if (source is IMediaEntitySlim mediaSlim)
            {
                source.AdditionalData["MediaPath"] = mediaSlim.MediaPath;
            }

            // NOTE: we're mapping the objects in AdditionalData by object reference here.
{'fraction_non_alphanumeric': 0.10815280304283116, 'fraction_numerical': 0.0, 'mean_word_length': 3.2501756851721715, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6738989', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1593, 'n_words': 331}