private DateTime?GetScheduledDate(IContent source, ContentScheduleAction action, MapperContext context) { var culture = context.GetCulture() ?? string.Empty; var schedule = source.ContentSchedule.GetSchedule(culture, action); return(schedule.FirstOrDefault()?.Date); // take the first, it's ordered by date }
/// <summary> /// Assigns the PropertyEditor, Id, Alias and Value to the property /// </summary> /// <returns></returns> public virtual void Map(IProperty property, TDestination dest, MapperContext context) { IDataEditor?editor = property.PropertyType is not null ? _propertyEditors[property.PropertyType.PropertyEditorAlias] : null; if (editor == null) { _logger.LogError( new NullReferenceException("The property editor with alias " + property.PropertyType?.PropertyEditorAlias + " does not exist"), "No property editor '{PropertyEditorAlias}' found, converting to a Label", property.PropertyType?.PropertyEditorAlias); editor = _propertyEditors[Constants.PropertyEditors.Aliases.Label]; if (editor == null) { throw new InvalidOperationException( $"Could not resolve the property editor {Constants.PropertyEditors.Aliases.Label}"); } } dest.Id = property.Id; dest.Alias = property.Alias; dest.PropertyEditor = editor; dest.Editor = editor.Alias; dest.DataTypeKey = property.PropertyType !.DataTypeKey; // if there's a set of property aliases specified, we will check if the current property's value should be mapped. // if it isn't one of the ones specified in 'includeProperties', we will just return the result without mapping the Value. var includedProperties = context.GetIncludedProperties(); if (includedProperties != null && !includedProperties.Contains(property.Alias)) { return; } // Get the culture from the context which will be set during the mapping operation for each property var culture = context.GetCulture(); // a culture needs to be in the context for a property type that can vary if (culture == null && property.PropertyType.VariesByCulture()) { throw new InvalidOperationException( $"No culture found in mapping operation when one is required for the culture variant property type {property.PropertyType.Alias}"); } // set the culture to null if it's an invariant property type culture = !property.PropertyType.VariesByCulture() ? null : culture; dest.Culture = culture; // Get the segment, which is always allowed to be null even if the propertyType *can* be varied by segment. // There is therefore no need to perform the null check like with culture above. var segment = !property.PropertyType.VariesBySegment() ? null : context.GetSegment(); dest.Segment = segment; // if no 'IncludeProperties' were specified or this property is set to be included - we will map the value and return. dest.Value = editor.GetValueEditor().ToEditor(property, culture, segment); }
private static string MapName(IEntitySlim source, MapperContext context) { if (!(source is DocumentEntitySlim doc)) { return(source.Name); } // invariant = only 1 name if (!doc.Variations.VariesByCulture()) { return(source.Name); } // variant = depends on culture var culture = context.GetCulture(); // if there's no culture here, the issue is somewhere else (UI, whatever) - throw! if (culture == null) { //throw new InvalidOperationException("Missing culture in mapping options."); // TODO: we should throw, but this is used in various places that won't set a culture yet return(source.Name); } // if we don't have a name for a culture, it means the culture is not available, and // hey we should probably not be mapping it, but it's too late, return a fallback name return(doc.CultureNames.TryGetValue(culture, out var name) && !name.IsNullOrWhiteSpace() ? name : $"({source.Name})"); }
public ContentSavedState Map(IContent source, MapperContext context) { PublishedState publishedState; bool isEdited; bool isCreated; if (source.ContentType.VariesByCulture()) { // Get the culture from the context which will be set during the mapping operation for each variant var culture = context.GetCulture(); // a culture needs to be in the context for a variant content item if (culture == null) { throw new InvalidOperationException( "No culture found in mapping operation when one is required for a culture variant"); } publishedState = source.PublishedState == PublishedState .Unpublished // if the entire document is unpublished, then flag every variant as unpublished ? PublishedState.Unpublished : source.IsCulturePublished(culture) ? PublishedState.Published : PublishedState.Unpublished; isEdited = source.IsCultureEdited(culture); isCreated = source.Id > 0 && source.IsCultureAvailable(culture); } else { publishedState = source.PublishedState == PublishedState.Unpublished ? PublishedState.Unpublished : PublishedState.Published; isEdited = source.Edited; isCreated = source.Id > 0; } if (!isCreated) { return(ContentSavedState.NotCreated); } if (publishedState == PublishedState.Unpublished) { return(ContentSavedState.Draft); } if (publishedState == PublishedState.Published) { return(isEdited ? ContentSavedState.PublishedPendingChanges : ContentSavedState.Published); } throw new NotSupportedException($"PublishedState {publishedState} is not supported."); }
private DateTime?GetScheduledDate(IContent source, ContentScheduleAction action, MapperContext context) { _ = context.Items.TryGetValue("Schedule", out var untypedSchedule); if (untypedSchedule is not ContentScheduleCollection scheduleCollection) { throw new ApplicationException("GetScheduledDate requires a ContentScheduleCollection in the MapperContext for Key: Schedule"); } var culture = context.GetCulture() ?? string.Empty; IEnumerable <ContentSchedule> schedule = scheduleCollection.GetSchedule(culture, action); return(schedule.FirstOrDefault()?.Date); // take the first, it's ordered by date }
/// <summary> /// Assigns the PropertyEditor, Id, Alias and Value to the property /// </summary> /// <returns></returns> public virtual void Map(Property property, TDestination dest, MapperContext context) { var editor = _propertyEditors[property.PropertyType.PropertyEditorAlias]; if (editor == null) { _logger.Error <ContentPropertyBasicMapper <TDestination> >( new NullReferenceException("The property editor with alias " + property.PropertyType.PropertyEditorAlias + " does not exist"), "No property editor '{PropertyEditorAlias}' found, converting to a Label", property.PropertyType.PropertyEditorAlias); editor = _propertyEditors[Constants.PropertyEditors.Aliases.Label]; } dest.Id = property.Id; dest.Alias = property.Alias; dest.PropertyEditor = editor; dest.Editor = editor.Alias; dest.DataTypeKey = property.PropertyType.DataTypeKey; // if there's a set of property aliases specified, we will check if the current property's value should be mapped. // if it isn't one of the ones specified in 'includeProperties', we will just return the result without mapping the Value. var includedProperties = context.GetIncludedProperties(); if (includedProperties != null && !includedProperties.Contains(property.Alias)) { return; } //Get the culture from the context which will be set during the mapping operation for each property var culture = context.GetCulture(); //a culture needs to be in the context for a property type that can vary if (culture == null && property.PropertyType.VariesByCulture()) { throw new InvalidOperationException($"No culture found in mapping operation when one is required for the culture variant property type {property.PropertyType.Alias}"); } //set the culture to null if it's an invariant property type culture = !property.PropertyType.VariesByCulture() ? null : culture; dest.Culture = culture; // if no 'IncludeProperties' were specified or this property is set to be included - we will map the value and return. dest.Value = editor.GetValueEditor().ToEditor(property, DataTypeService, culture); }
private string GetName(IContent source, MapperContext context) { // invariant = only 1 name if (!source.ContentType.VariesByCulture()) { return(source.Name); } // variant = depends on culture var culture = context.GetCulture(); // if there's no culture here, the issue is somewhere else (UI, whatever) - throw! if (culture == null) { throw new InvalidOperationException("Missing culture in mapping options."); } // if we don't have a name for a culture, it means the culture is not available, and // hey we should probably not be mapping it, but it's too late, return a fallback name return(source.CultureInfos.TryGetValue(culture, out var name) && !name.Name.IsNullOrWhiteSpace() ? name.Name : $"({source.Name})"); }
private DateTime GetUpdateDate(IContent source, MapperContext context) { // invariant = global date if (!source.ContentType.VariesByCulture()) { return(source.UpdateDate); } // variant = depends on culture var culture = context.GetCulture(); // if there's no culture here, the issue is somewhere else (UI, whatever) - throw! if (culture == null) { throw new InvalidOperationException("Missing culture in mapping options."); } // if we don't have a date for a culture, it means the culture is not available, and // hey we should probably not be mapping it, but it's too late, return a fallback date var date = source.GetUpdateDate(culture); return(date ?? source.UpdateDate); }
// Umbraco.Code.MapAll -Alias -Trashed private static void Map(ISearchResult source, SearchResultEntity target, MapperContext context) { target.Id = source.Id; target.Score = source.Score; // TODO: Properly map this (not aftermap) //get the icon if there is one target.Icon = source.Values.ContainsKey(UmbracoExamineIndex.IconFieldName) ? source.Values[UmbracoExamineIndex.IconFieldName] : Constants.Icons.DefaultIcon; target.Name = source.Values.ContainsKey("nodeName") ? source.Values["nodeName"] : "[no name]"; var culture = context.GetCulture(); if (culture.IsNullOrWhiteSpace() == false) { target.Name = source.Values.ContainsKey($"nodeName_{culture}") ? source.Values[$"nodeName_{culture}"] : target.Name; } if (source.Values.TryGetValue(UmbracoExamineIndex.UmbracoFileFieldName, out var umbracoFile)) { if (umbracoFile != null) { target.Name = $"{target.Name} ({umbracoFile})"; } } if (source.Values.ContainsKey(UmbracoExamineIndex.NodeKeyFieldName)) { if (Guid.TryParse(source.Values[UmbracoExamineIndex.NodeKeyFieldName], out var key)) { target.Key = key; //need to set the UDI if (source.Values.ContainsKey(LuceneIndex.CategoryFieldName)) { switch (source.Values[LuceneIndex.CategoryFieldName]) { case IndexTypes.Member: target.Udi = new GuidUdi(Constants.UdiEntityType.Member, target.Key); break; case IndexTypes.Content: target.Udi = new GuidUdi(Constants.UdiEntityType.Document, target.Key); break; case IndexTypes.Media: target.Udi = new GuidUdi(Constants.UdiEntityType.Media, target.Key); break; } } } } if (source.Values.ContainsKey("parentID")) { if (int.TryParse(source.Values["parentID"], out var parentId)) { target.ParentId = parentId; } else { target.ParentId = -1; } } target.Path = source.Values.ContainsKey(UmbracoExamineIndex.IndexPathFieldName) ? source.Values[UmbracoExamineIndex.IndexPathFieldName] : ""; if (source.Values.ContainsKey(LuceneIndex.ItemTypeFieldName)) { target.AdditionalData.Add("contentType", source.Values[LuceneIndex.ItemTypeFieldName]); } }