Skip to content

Commit

Permalink
Remove dependencies of Migration.Tool.Core.K11 on Migration.Tool.KXP
Browse files Browse the repository at this point in the history
Refactor: Remove dependencies of Migration.Tool.Core.K11 on Migration.Tool.KXP
  • Loading branch information
akfakmot committed Nov 13, 2024
1 parent c7adf66 commit 26c142d
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 334 deletions.
8 changes: 4 additions & 4 deletions Migration.Tool.Core.K11/Contexts/KeyMappingContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Linq.Expressions;

using CMS.DataEngine;
using Migration.Tool.Core.K11.Services;

namespace Migration.Tool.Core.K11.Contexts;
Expand All @@ -11,15 +11,15 @@ public class KeyMappingContext(PrimaryKeyMappingContext primaryKeyMappingContext
public MapSourceKeyResult<TTargetKey> MapSourceKey<TSource, TTarget, TTargetKey>(Expression<Func<TSource, object>> sourceKeySelector,
Expression<Func<TSource, Guid>> sourceGuidSelector,
object? sourceKey,
Expression<Func<TTarget, TTargetKey>> targetKeySelector,
Expression<Func<TTarget, Guid>> targetGuidSelector) where TSource : class where TTarget : class
Func<TTarget, TTargetKey> targetKeySelector,
Func<Guid, TTarget?> targetByGuidProvider) where TSource : class where TTarget : AbstractInfoBase<TTarget>, new()
{
if (sourceKey is int id && primaryKeyMappingContext.MapSourceId(sourceKeySelector, id) is { Success: true, MappedId: TTargetKey targetKey })
{
return new MapSourceKeyResult<TTargetKey>(true, targetKey);
}

if (keyLocatorService.TryLocate(sourceKeySelector, targetKeySelector, sourceGuidSelector, targetGuidSelector, sourceKey, out var located))
if (keyLocatorService.TryLocate(sourceKeySelector, targetKeySelector, sourceGuidSelector, targetByGuidProvider, sourceKey, out var located))
{
return new MapSourceKeyResult<TTargetKey>(true, located);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private ValueInterceptorResult ContactValueInterceptor(int ordinal, string colum
s => s.UserGuid,
sourceUserId,
t => t.MemberID,
t => t.MemberGuid
guid => MemberInfo.Provider.Get(guid)
) is { Success: true, Mapped: { } memberId })
{
return ValueInterceptorResult.ReplaceValue(memberId);
Expand Down Expand Up @@ -309,7 +309,7 @@ private ValueInterceptorResult ActivityValueInterceptor(int columnOrdinal, strin
s => s.SiteGuid,
sourceActivitySiteId.NullIfZero(),
t => t.ChannelID,
t => t.ChannelGUID
guid => ChannelInfo.Provider.Get().WhereEquals(nameof(ChannelInfo.ChannelGUID), guid).SingleOrDefault()
);
switch (result)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using CMS.ContactManagement;
using CMS.DataEngine;
using CMS.DataProtection;

using MediatR;

using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

Expand All @@ -14,7 +12,6 @@
using Migration.Tool.Core.K11.Contexts;
using Migration.Tool.K11;
using Migration.Tool.K11.Models;
using Migration.Tool.KXP.Context;

namespace Migration.Tool.Core.K11.Handlers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private async Task MigrateUserRole(int k11RoleId)
if (!primaryKeyMappingContext.TryRequireMapFromSource<CmsRole>(u => u.RoleId, k11RoleId, out int xbkRoleId))
{
var handbookRef = HandbookReferences
.MissingRequiredDependency<KXP.Models.CmsRole>(nameof(UserRoleInfo.RoleID), k11UserRole.RoleId)
.MissingRequiredDependency<RoleInfo>(nameof(UserRoleInfo.RoleID), k11UserRole.RoleId)
.NeedsManualAction();

protocol.Append(handbookRef);
Expand Down
33 changes: 17 additions & 16 deletions Migration.Tool.Core.K11/Helpers/Printer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using CMS.ContactManagement;
using CMS.DataEngine;
using CMS.DataProtection;
using CMS.FormEngine;
using CMS.Globalization;
using CMS.MediaLibrary;
using CMS.Membership;
using CMS.Modules;

using CMS.OnlineForms;
using Migration.Tool.Common.Helpers;
using Migration.Tool.Common.Services;
using Migration.Tool.K11.Models;
Expand All @@ -19,15 +21,15 @@ public static string PrintKxpModelInfo<T>(T model)

return model switch
{
KXP.Models.MediaLibrary mediaLibrary => $"{currentTypeName}: {nameof(mediaLibrary.LibraryGuid)}={mediaLibrary.LibraryGuid}",
KXP.Models.MediaFile mediaFile => $"{currentTypeName}: {nameof(mediaFile.FileGuid)}={mediaFile.FileGuid}",
KXP.Models.CmsRole role => $"{currentTypeName}: {nameof(role.RoleGuid)}={role.RoleGuid}, {nameof(role.RoleName)}={role.RoleName}",
KXP.Models.CmsUser user => $"{currentTypeName}: {nameof(user.UserGuid)}={user.UserGuid}, {nameof(user.UserName)}={user.UserName}",
KXP.Models.CmsResource resource => $"{currentTypeName}: {nameof(resource.ResourceGuid)}={resource.ResourceGuid}, {nameof(resource.ResourceName)}={resource.ResourceName}",
KXP.Models.CmsSettingsCategory settingsCategory => $"{currentTypeName}: {nameof(settingsCategory.CategoryName)}={settingsCategory.CategoryName}",
KXP.Models.CmsSettingsKey settingsKey => $"{currentTypeName}: {nameof(settingsKey.KeyGuid)}={settingsKey.KeyGuid}, {nameof(settingsKey.KeyName)}={settingsKey.KeyName}",
KXP.Models.CmsForm form => $"{currentTypeName}: {nameof(form.FormGuid)}={form.FormGuid}, {nameof(form.FormName)}={form.FormName}",
KXP.Models.OmContactGroup omContactGroup => $"{currentTypeName}: {nameof(omContactGroup.ContactGroupGuid)}={omContactGroup.ContactGroupGuid}, {nameof(omContactGroup.ContactGroupName)}={omContactGroup.ContactGroupName}",
MediaLibraryInfo mediaLibrary => $"{currentTypeName}: {nameof(mediaLibrary.LibraryGUID)}={mediaLibrary.LibraryGUID}",
MediaFileInfo mediaFile => $"{currentTypeName}: {nameof(mediaFile.FileGUID)}={mediaFile.FileGUID}",
RoleInfo role => $"{currentTypeName}: {nameof(role.RoleGUID)}={role.RoleGUID}, {nameof(role.RoleName)}={role.RoleName}",
UserInfo user => $"{currentTypeName}: {nameof(user.UserGUID)}={user.UserGUID}, {nameof(user.UserName)}={user.UserName}",
ResourceInfo resource => $"{currentTypeName}: {nameof(resource.ResourceGUID)}={resource.ResourceGUID}, {nameof(resource.ResourceName)}={resource.ResourceName}",
SettingsCategoryInfo settingsCategory => $"{currentTypeName}: {nameof(settingsCategory.CategoryName)}={settingsCategory.CategoryName}",
SettingsKeyInfo settingsKey => $"{currentTypeName}: {nameof(settingsKey.KeyGUID)}={settingsKey.KeyGUID}, {nameof(settingsKey.KeyName)}={settingsKey.KeyName}",
BizFormInfo form => $"{currentTypeName}: {nameof(form.FormGUID)}={form.FormGUID}, {nameof(form.FormName)}={form.FormName}",
ContactGroupInfo omContactGroup => $"{currentTypeName}: {nameof(omContactGroup.ContactGroupGUID)}={omContactGroup.ContactGroupGUID}, {nameof(omContactGroup.ContactGroupName)}={omContactGroup.ContactGroupName}",

null => $"{currentTypeName}: <null>",
_ => $"TODO: {typeof(T).FullName}"
Expand Down Expand Up @@ -61,12 +63,11 @@ string FormatModel(string inner) => printType
RoleInfo item => FormatModel($"ID={item.RoleID}, Guid={item.RoleGUID} Name={item.RoleName}"),
MemberInfo item => FormatModel($"ID={item.MemberID}, Guid={item.MemberGuid} Name={item.MemberName}"),

KXP.Models.CmsForm item => FormatModel($"ID={item.FormId}, GUID={item.FormGuid}, Name={item.FormName}"),
KXP.Models.CmsUser item => FormatModel($"ID={item.UserId}, GUID={item.UserGuid}, Name={item.UserName}"),
KXP.Models.CmsConsent item => FormatModel($"ID={item.ConsentId}, GUID={item.ConsentGuid}, Name={item.ConsentName}"),
KXP.Models.CmsConsentArchive item => FormatModel($"ID={item.ConsentArchiveId}, GUID={item.ConsentArchiveGuid}"),
KXP.Models.CmsConsentAgreement item => FormatModel($"ID={item.ConsentAgreementId}, GUID={item.ConsentAgreementGuid}"),
KXP.Models.CmsSettingsKey item => FormatModel($"ID={item.KeyId}, GUID={item.KeyGuid}, Name={item.KeyName}"),
BizFormInfo item => FormatModel($"ID={item.FormID}, GUID={item.FormGUID}, Name={item.FormName}"),
ConsentInfo item => FormatModel($"ID={item.ConsentID}, GUID={item.ConsentGuid}, Name={item.ConsentName}"),
ConsentArchiveInfo item => FormatModel($"ID={item.ConsentArchiveID}, GUID={item.ConsentArchiveGuid}"),
ConsentAgreementInfo item => FormatModel($"ID={item.ConsentAgreementID}, GUID={item.ConsentAgreementGuid}"),
SettingsKeyInfo item => FormatModel($"ID={item.KeyID}, GUID={item.KeyGUID}, Name={item.KeyName}"),

CmsRole item => FormatModel($"ID={item.RoleId}, GUID={item.RoleGuid}, Name={item.RoleName}, SiteId={item.SiteId}"),
CmsAttachment item => FormatModel($"ID={item.AttachmentId}, GUID={item.AttachmentGuid}, Name={item.AttachmentName}"),
Expand Down
6 changes: 3 additions & 3 deletions Migration.Tool.Core.K11/K11CoreDiExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CMS.ContactManagement;
using CMS.DataEngine;
using CMS.DataProtection;
using CMS.FormEngine;
Expand Down Expand Up @@ -53,13 +54,12 @@ public static IServiceCollection UseK11ToolCore(this IServiceCollection services
services.AddTransient<IEntityMapper<CmsConsentArchive, ConsentArchiveInfo>, CmsConsentArchiveMapper>();
services.AddTransient<IEntityMapper<AlternativeFormMapperSource, AlternativeFormInfo>, AlternativeFormMapper>();
services.AddTransient<IEntityMapper<CmsRole, RoleInfo>, RoleInfoMapper>();
services.AddTransient<IEntityMapper<CmsSettingsCategory, KXP.Models.CmsSettingsCategory>, CmsSettingsCategoryMapper>();
services.AddTransient<IEntityMapper<CmsSettingsKey, SettingsKeyInfo>, CmsSettingsKeyMapper>();
services.AddTransient<IEntityMapper<CmsUser, UserInfo>, UserInfoMapper>();
services.AddTransient<IEntityMapper<MemberInfoMapperSource, MemberInfo>, MemberInfoMapper>();
services.AddTransient<IEntityMapper<CmsUserRole, UserRoleInfo>, UserRoleInfoMapper>();
services.AddTransient<IEntityMapper<OmContactGroup, KXP.Models.OmContactGroup>, OmContactGroupMapper>();
services.AddTransient<IEntityMapper<OmContactStatus, KXP.Models.OmContactStatus>, OmContactStatusMapper>();
services.AddTransient<IEntityMapper<OmContactGroup, ContactGroupInfo>, OmContactGroupMapper>();
services.AddTransient<IEntityMapper<OmContactStatus, ContactStatusInfo>, OmContactStatusMapper>();
services.AddTransient<IEntityMapper<CmsCountry, CountryInfo>, CountryInfoMapper>();
services.AddTransient<IEntityMapper<CmsState, StateInfo>, StateInfoMapper>();

Expand Down
83 changes: 0 additions & 83 deletions Migration.Tool.Core.K11/Mappers/CmsFormMapper.cs

This file was deleted.

97 changes: 0 additions & 97 deletions Migration.Tool.Core.K11/Mappers/CmsSettingsCategoryMapper.cs

This file was deleted.

Loading

0 comments on commit 26c142d

Please sign in to comment.