public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrWhiteSpace(Component) || !ID.IsID(Component)) { var path = importRow is Item ? ((Item)importRow).Paths.FullPath : "N/A"; Logger.Log($"The Component value is empty or is not an id", path, LogType.FieldToComponent, "Component", Component); return; } var deviceItem = PresentationService.FindDeviceDefinition(newItem, Device); var dsName = DatasourcePath.Contains("/") ? DatasourcePath.Substring(DatasourcePath.LastIndexOf("/") + 1) : DatasourcePath; if (!OverwriteExisting) { var datasource = PresentationService.CreateDatasource(map, newItem, deviceItem, dsName, DatasourceFolder, DatasourcePath, Component, OverwriteExisting); if (datasource == null) { return; } var isSet = SetField(map, datasource, importRow, importValue); if (!isSet) { datasource.Delete(); } else { PresentationService.AddComponent(newItem, datasource, Placeholder, Component, Device, Parameters, IsSXA); } } else { var rendering = PresentationService.FindRendering(deviceItem, Placeholder, Component); if (rendering == null) { Logger.Log($"There was no rendering matching device:{Device} - placeholder:{Placeholder} - component:{Component}", newItem.Paths.FullPath, LogType.MultilistToComponent, "device xml", deviceItem.ToXml()); return; } var datasource = PresentationService.FindDatasourceByName(map, newItem, rendering, dsName); if (datasource == null) { Logger.Log($"There was no datasource found matching name:{dsName}", newItem.Paths.FullPath, LogType.MultilistToComponent, "rendering xml", rendering.ToXml()); return; } var isSet = SetField(map, datasource, importRow, importValue); if (!isSet) { datasource.Delete(); PresentationService.RemoveComponent(newItem, rendering, Device); } } }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrEmpty(importValue)) { var path = importRow is Item ? ((Item)importRow).Paths.FullPath : "N/A"; Logger.Log($"There was no import value", path, LogType.MultilistToComponent); return; } var layoutField = newItem.Fields[FieldIDs.FinalLayoutField]; if (layoutField == null) { return; } var layout = LayoutDefinition.Parse(layoutField.Value); var deviceItem = layout.GetDevice(Device); var entries = importValue.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); var sitecoreMap = (SitecoreDataMap)map; var itemList = entries.Select(a => sitecoreMap.FromDB.GetItem(new ID(a))).Where(b => b != null).ToList(); foreach (var i in itemList) { var itemTemplate = i.TemplateID.ToString(); if (!ComponentMaps.ContainsKey(itemTemplate)) { Logger.Log($"There was no component mapping found", i.Paths.FullPath, LogType.MultilistToComponent, i.TemplateName, itemTemplate); continue; } var cm = ComponentMaps[itemTemplate]; var dsName = cm.DatasourcePath.Contains("/") ? cm.DatasourcePath.Substring(cm.DatasourcePath.LastIndexOf("/") + 1) : cm.DatasourcePath; if (!cm.OverwriteExisting) { var datasource = PresentationService.CreateDatasource(map, newItem, deviceItem, dsName, DatasourceFolder, cm.DatasourcePath, cm.Component, cm.OverwriteExisting); if (datasource == null) { Logger.Log($"There was no datasource created for matching device:{Device} - placeholder:{cm.Placeholder} - component:{cm.Component}", i.Paths.FullPath, LogType.MultilistToComponent, "device xml", deviceItem.ToXml()); continue; } SetFields(i, datasource, cm, sitecoreMap); PresentationService.AddComponent(newItem, datasource, cm.Placeholder, cm.Component, Device, cm.Parameters, IsSXA); } else { var rendering = PresentationService.FindRendering(deviceItem, cm.Placeholder, cm.Component); if (rendering == null) { Logger.Log($"There was no rendering matching device:{Device} - placeholder:{cm.Placeholder} - component:{cm.Component}", i.Paths.FullPath, LogType.MultilistToComponent, "device xml", deviceItem.ToXml()); continue; } var datasource = PresentationService.FindDatasourceByName(map, newItem, rendering, dsName); if (datasource == null) { Logger.Log($"There was no datasource found matching name:{dsName}", i.Paths.FullPath, LogType.MultilistToComponent, "rendering xml", rendering.ToXml()); continue; } SetFields(i, datasource, cm, sitecoreMap); } } }