Skip to content

Commit

Permalink
Remove dependencies of Migration.Tool.Core.KX13 on Migration.Tool.KXP
Browse files Browse the repository at this point in the history
Refactor: Remove dependencies of Migration.Tool.Core.KX13 on Migration.Tool.KXP
  • Loading branch information
akfakmot committed Nov 15, 2024
1 parent 352589a commit dc3b367
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 458 deletions.
6 changes: 3 additions & 3 deletions Migration.Tool.Core.KX13/Contexts/KeyMappingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 : class
{
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
14 changes: 7 additions & 7 deletions Migration.Tool.Core.KX13/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using CMS.ContactManagement;
using CMS.DataEngine;
using CMS.DataProtection;
using CMS.FormEngine;
using CMS.Globalization;
using CMS.MediaLibrary;
Expand All @@ -18,7 +20,6 @@
using Migration.Tool.Core.KX13.Helpers;
using Migration.Tool.Core.KX13.Mappers;
using Migration.Tool.Core.KX13.Services;
using Migration.Tool.KXP.Models;

namespace Migration.Tool.Core.KX13;

Expand Down Expand Up @@ -47,18 +48,17 @@ public static IServiceCollection UseKx13ToolCore(this IServiceCollection service

// mappers
services.AddTransient<IEntityMapper<CmsAttachmentMapperSource, MediaFileInfo>, CmsAttachmentMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsConsent, CmsConsent>, CmsConsentMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsConsentAgreement, CmsConsentAgreement>, CmsConsentAgreementMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsConsentArchive, CmsConsentArchive>, CmsConsentArchiveMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsConsent, ConsentInfo>, CmsConsentMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsConsentAgreement, ConsentAgreementInfo>, CmsConsentAgreementMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsConsentArchive, ConsentArchiveInfo>, CmsConsentArchiveMapper>();
services.AddTransient<IEntityMapper<AlternativeFormMapperSource, AlternativeFormInfo>, AlternativeFormMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsRole, RoleInfo>, RoleInfoMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsSettingsCategory, CmsSettingsCategory>, CmsSettingsCategoryMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsSettingsKey, SettingsKeyInfo>, CmsSettingsKeyMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsUser, UserInfo>, UserInfoMapper>();
services.AddTransient<IEntityMapper<MemberInfoMapperSource, MemberInfo>, MemberInfoMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsUserRole, UserRoleInfo>, UserRoleInfoMapper>();
services.AddTransient<IEntityMapper<KX13M.OmContactGroup, OmContactGroup>, OmContactGroupMapper>();
services.AddTransient<IEntityMapper<KX13M.OmContactStatus, OmContactStatus>, OmContactStatusMapper>();
services.AddTransient<IEntityMapper<KX13M.OmContactGroup, ContactGroupInfo>, OmContactGroupMapper>();
services.AddTransient<IEntityMapper<KX13M.OmContactStatus, ContactStatusInfo>, OmContactStatusMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsCountry, CountryInfo>, CountryInfoMapper>();
services.AddTransient<IEntityMapper<KX13M.CmsState, StateInfo>, StateInfoMapper>();

Expand Down

Large diffs are not rendered by default.

175 changes: 47 additions & 128 deletions Migration.Tool.Core.KX13/Handlers/MigrateDataProtectionCommandHandler.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Migration.Tool.Core.KX13.Contexts;
using Migration.Tool.KX13.Context;
using Migration.Tool.KXP.Api.Enums;
using Migration.Tool.KXP.Models;

namespace Migration.Tool.Core.KX13.Handlers;

Expand Down Expand Up @@ -195,7 +194,7 @@ private async Task MigrateUserRole(int kx13RoleId)
if (!primaryKeyMappingContext.TryRequireMapFromSource<KX13M.CmsRole>(u => u.RoleId, kx13RoleId, out int xbkRoleId))
{
var handbookRef = HandbookReferences
.MissingRequiredDependency<CmsRole>(nameof(UserRoleInfo.RoleID), kx13UserRole.RoleId)
.MissingRequiredDependency<RoleInfo>(nameof(UserRoleInfo.RoleID), kx13UserRole.RoleId)
.NeedsManualAction();

protocol.Append(handbookRef);
Expand Down
34 changes: 17 additions & 17 deletions Migration.Tool.Core.KX13/Helpers/Printer.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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.KXP.Models;

namespace Migration.Tool.Core.KX13.Helpers;

Expand All @@ -19,15 +20,15 @@ public static string PrintKxpModelInfo<T>(T model)

return model switch
{
MediaLibrary mediaLibrary => $"{currentTypeName}: {nameof(mediaLibrary.LibraryGuid)}={mediaLibrary.LibraryGuid}",
MediaFile mediaFile => $"{currentTypeName}: {nameof(mediaFile.FileGuid)}={mediaFile.FileGuid}",
CmsRole role => $"{currentTypeName}: {nameof(role.RoleGuid)}={role.RoleGuid}, {nameof(role.RoleName)}={role.RoleName}",
CmsUser user => $"{currentTypeName}: {nameof(user.UserGuid)}={user.UserGuid}, {nameof(user.UserName)}={user.UserName}",
CmsResource resource => $"{currentTypeName}: {nameof(resource.ResourceGuid)}={resource.ResourceGuid}, {nameof(resource.ResourceName)}={resource.ResourceName}",
CmsSettingsCategory settingsCategory => $"{currentTypeName}: {nameof(settingsCategory.CategoryName)}={settingsCategory.CategoryName}",
CmsSettingsKey settingsKey => $"{currentTypeName}: {nameof(settingsKey.KeyGuid)}={settingsKey.KeyGuid}, {nameof(settingsKey.KeyName)}={settingsKey.KeyName}",
CmsForm form => $"{currentTypeName}: {nameof(form.FormGuid)}={form.FormGuid}, {nameof(form.FormName)}={form.FormName}",
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 +62,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}"),

CmsForm item => FormatModel($"ID={item.FormId}, GUID={item.FormGuid}, Name={item.FormName}"),
CmsUser item => FormatModel($"ID={item.UserId}, GUID={item.UserGuid}, Name={item.UserName}"),
CmsConsent item => FormatModel($"ID={item.ConsentId}, GUID={item.ConsentGuid}, Name={item.ConsentName}"),
CmsConsentArchive item => FormatModel($"ID={item.ConsentArchiveId}, GUID={item.ConsentArchiveGuid}"),
CmsConsentAgreement item => FormatModel($"ID={item.ConsentAgreementId}, GUID={item.ConsentAgreementGuid}"),
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}"),

KX13M.CmsPageTemplateConfiguration item => FormatModel($"ID={item.PageTemplateConfigurationId}, GUID={item.PageTemplateConfigurationGuid}, Name={item.PageTemplateConfigurationName}, SiteId={item.PageTemplateConfigurationSiteId}"),
KX13M.CmsRole item => FormatModel($"ID={item.RoleId}, GUID={item.RoleGuid}, Name={item.RoleName}, SiteId={item.SiteId}"),
Expand Down
12 changes: 6 additions & 6 deletions Migration.Tool.Core.KX13/Mappers/CmsConsentAgreementMapper.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using CMS.DataProtection;
using Microsoft.Extensions.Logging;

using Migration.Tool.Common.Abstractions;
using Migration.Tool.Common.MigrationProtocol;
using Migration.Tool.Core.KX13.Contexts;
using Migration.Tool.KXP.Models;

namespace Migration.Tool.Core.KX13.Mappers;

public class CmsConsentAgreementMapper : EntityMapperBase<KX13M.CmsConsentAgreement, CmsConsentAgreement>
public class CmsConsentAgreementMapper : EntityMapperBase<KX13M.CmsConsentAgreement, ConsentAgreementInfo>
{
public CmsConsentAgreementMapper(ILogger<CmsConsentAgreementMapper> logger, PrimaryKeyMappingContext primaryKeyMappingContext, IProtocol protocol) : base(logger, primaryKeyMappingContext, protocol)
{
}

protected override CmsConsentAgreement? CreateNewInstance(KX13M.CmsConsentAgreement source, MappingHelper mappingHelper, AddFailure addFailure) => new();
protected override ConsentAgreementInfo? CreateNewInstance(KX13M.CmsConsentAgreement source, MappingHelper mappingHelper, AddFailure addFailure) => new();

protected override CmsConsentAgreement MapInternal(KX13M.CmsConsentAgreement source, CmsConsentAgreement target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure)
protected override ConsentAgreementInfo MapInternal(KX13M.CmsConsentAgreement source, ConsentAgreementInfo target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure)
{
target.ConsentAgreementGuid = source.ConsentAgreementGuid;
target.ConsentAgreementRevoked = source.ConsentAgreementRevoked;
Expand All @@ -24,12 +24,12 @@ protected override CmsConsentAgreement MapInternal(KX13M.CmsConsentAgreement sou

if (mappingHelper.TranslateRequiredId<KX13M.OmContact>(c => c.ContactId, source.ConsentAgreementContactId, out int contactId))
{
target.ConsentAgreementContactId = contactId;
target.ConsentAgreementContactID = contactId;
}

if (mappingHelper.TranslateRequiredId<KX13M.CmsConsent>(r => r.ConsentId, source.ConsentAgreementConsentId, out int consentId))
{
target.ConsentAgreementConsentId = consentId;
target.ConsentAgreementConsentID = consentId;
}

return target;
Expand Down
10 changes: 5 additions & 5 deletions Migration.Tool.Core.KX13/Mappers/CmsConsentArchiveMapper.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using CMS.DataProtection;
using Microsoft.Extensions.Logging;

using Migration.Tool.Common.Abstractions;
using Migration.Tool.Common.MigrationProtocol;
using Migration.Tool.Core.KX13.Contexts;
using Migration.Tool.KXP.Models;

namespace Migration.Tool.Core.KX13.Mappers;

public class CmsConsentArchiveMapper : EntityMapperBase<KX13M.CmsConsentArchive, CmsConsentArchive>
public class CmsConsentArchiveMapper : EntityMapperBase<KX13M.CmsConsentArchive, ConsentArchiveInfo>
{
public CmsConsentArchiveMapper(ILogger<CmsConsentArchiveMapper> logger, PrimaryKeyMappingContext primaryKeyMappingContext,
IProtocol protocol) : base(logger, primaryKeyMappingContext, protocol)
{
}

protected override CmsConsentArchive? CreateNewInstance(KX13M.CmsConsentArchive source, MappingHelper mappingHelper, AddFailure addFailure) => new();
protected override ConsentArchiveInfo? CreateNewInstance(KX13M.CmsConsentArchive source, MappingHelper mappingHelper, AddFailure addFailure) => new();

protected override CmsConsentArchive MapInternal(KX13M.CmsConsentArchive source, CmsConsentArchive target, bool newInstance,
protected override ConsentArchiveInfo MapInternal(KX13M.CmsConsentArchive source, ConsentArchiveInfo target, bool newInstance,
MappingHelper mappingHelper, AddFailure addFailure)
{
target.ConsentArchiveContent = source.ConsentArchiveContent;
Expand All @@ -26,7 +26,7 @@ protected override CmsConsentArchive MapInternal(KX13M.CmsConsentArchive source,

if (mappingHelper.TranslateRequiredId<KX13M.CmsConsent>(r => r.ConsentId, source.ConsentArchiveConsentId, out int consentId))
{
target.ConsentArchiveConsentId = consentId;
target.ConsentArchiveConsentID = consentId;
}

return target;
Expand Down
11 changes: 5 additions & 6 deletions Migration.Tool.Core.KX13/Mappers/CmsConsentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
using System.Xml.XPath;

using CMS.ContentEngine;

using CMS.DataProtection;
using Microsoft.Extensions.Logging;

using Migration.Tool.Common.Abstractions;
using Migration.Tool.Common.MigrationProtocol;
using Migration.Tool.Core.KX13.Contexts;
using Migration.Tool.KXP.Models;

namespace Migration.Tool.Core.KX13.Mappers;

public class CmsConsentMapper : EntityMapperBase<KX13M.CmsConsent, CmsConsent>
public class CmsConsentMapper : EntityMapperBase<KX13M.CmsConsent, ConsentInfo>
{
public CmsConsentMapper(ILogger<CmsConsentMapper> logger, PrimaryKeyMappingContext pkContext, IProtocol protocol) : base(logger, pkContext, protocol)
{
}

protected override CmsConsent? CreateNewInstance(KX13M.CmsConsent source, MappingHelper mappingHelper, AddFailure addFailure) => new();
protected override ConsentInfo? CreateNewInstance(KX13M.CmsConsent source, MappingHelper mappingHelper, AddFailure addFailure) => new();

protected override CmsConsent MapInternal(KX13M.CmsConsent source, CmsConsent target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure)
protected override ConsentInfo MapInternal(KX13M.CmsConsent source, ConsentInfo target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure)
{
target.ConsentDisplayName = source.ConsentDisplayName;
var defaultContentLanguageInfo = ContentLanguageInfo.Provider.Get().WhereEquals(nameof(ContentLanguageInfo.ContentLanguageIsDefault), true).FirstOrDefault() ?? throw new InvalidCastException("Missing default content language");
target.ConsentName = source.ConsentName;
target.ConsentContent = ConsentContentPatcher.PatchConsentContent(source.ConsentContent, defaultContentLanguageInfo);
target.ConsentGuid = source.ConsentGuid;
target.ConsentLastModified = source.ConsentLastModified;
target.ConsentHash = source.ConsentHash;
target.SetValue(nameof(target.ConsentHash), source.ConsentHash);

return target;
}
Expand Down
Loading

0 comments on commit dc3b367

Please sign in to comment.