Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions src/lib/mappers/asset-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,41 @@ export class AssetMapper {
}

addMapping(sourceAsset: mgmtApi.Media, targetAsset: mgmtApi.Media) {
const mapping = this.getAssetMapping(targetAsset, 'target');
const mappingByTarget = this.getAssetMapping(targetAsset, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourceAsset, targetAsset);
} else {

const newMapping: AssetMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceDateModified: sourceAsset.dateModified,
targetDateModified: targetAsset.dateModified,
sourceMediaID: sourceAsset.mediaID,
targetMediaID: targetAsset.mediaID,
sourceUrl: sourceAsset.edgeUrl,
targetUrl: targetAsset.edgeUrl,
sourceContainerEdgeUrl: sourceAsset.containerEdgeUrl,
targetContainerEdgeUrl: targetAsset.containerEdgeUrl,
sourceContainerOriginUrl: sourceAsset.containerOriginUrl,
targetContainerOriginUrl: targetAsset.containerOriginUrl,
// Guard against duplicates when the same source asset re-maps to a new target ID
const mappingBySource = this.getAssetMapping(sourceAsset, 'source');

if (mappingBySource) {
mappingBySource.targetMediaID = targetAsset.mediaID;
mappingBySource.sourceDateModified = sourceAsset.dateModified;
mappingBySource.targetDateModified = targetAsset.dateModified;
mappingBySource.sourceUrl = sourceAsset.edgeUrl;
mappingBySource.targetUrl = targetAsset.edgeUrl;
mappingBySource.sourceContainerEdgeUrl = sourceAsset.containerEdgeUrl;
mappingBySource.targetContainerEdgeUrl = targetAsset.containerEdgeUrl;
mappingBySource.sourceContainerOriginUrl = sourceAsset.containerOriginUrl;
mappingBySource.targetContainerOriginUrl = targetAsset.containerOriginUrl;
} else {
const newMapping: AssetMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceDateModified: sourceAsset.dateModified,
targetDateModified: targetAsset.dateModified,
sourceMediaID: sourceAsset.mediaID,
targetMediaID: targetAsset.mediaID,
sourceUrl: sourceAsset.edgeUrl,
targetUrl: targetAsset.edgeUrl,
sourceContainerEdgeUrl: sourceAsset.containerEdgeUrl,
targetContainerEdgeUrl: targetAsset.containerEdgeUrl,
sourceContainerOriginUrl: sourceAsset.containerOriginUrl,
targetContainerOriginUrl: targetAsset.containerOriginUrl,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down
38 changes: 23 additions & 15 deletions src/lib/mappers/container-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,33 @@ export class ContainerMapper {
}

addMapping(sourceContainer: mgmtApi.Container, targetContainer: mgmtApi.Container) {
const mapping = this.getContainerMapping(targetContainer, 'target');
const mappingByTarget = this.getContainerMapping(targetContainer, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourceContainer, targetContainer);
} else {

const newMapping: ContainerMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceContentViewID: sourceContainer.contentViewID,
targetContentViewID: targetContainer.contentViewID,
sourceLastModifiedDate: sourceContainer.lastModifiedDate,
targetLastModifiedDate: targetContainer.lastModifiedDate,
sourceReferenceName: sourceContainer.referenceName,
targetReferenceName: targetContainer.referenceName

// Guard against duplicates when the same source container re-maps to a new target ID
const mappingBySource = this.getContainerMapping(sourceContainer, 'source');

if (mappingBySource) {
mappingBySource.targetContentViewID = targetContainer.contentViewID;
mappingBySource.sourceLastModifiedDate = sourceContainer.lastModifiedDate;
mappingBySource.targetLastModifiedDate = targetContainer.lastModifiedDate;
mappingBySource.sourceReferenceName = sourceContainer.referenceName;
mappingBySource.targetReferenceName = targetContainer.referenceName;
} else {
const newMapping: ContainerMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceContentViewID: sourceContainer.contentViewID,
targetContentViewID: targetContainer.contentViewID,
sourceLastModifiedDate: sourceContainer.lastModifiedDate,
targetLastModifiedDate: targetContainer.lastModifiedDate,
sourceReferenceName: sourceContainer.referenceName,
targetReferenceName: targetContainer.referenceName,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down
33 changes: 20 additions & 13 deletions src/lib/mappers/content-item-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,30 @@ export class ContentItemMapper {
}

addMapping(sourceContentItem: mgmtApi.ContentItem, targetContentItem: mgmtApi.ContentItem) {
const mapping = this.getContentItemMapping(targetContentItem, 'target');
const mappingByTarget = this.getContentItemMapping(targetContentItem, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourceContentItem, targetContentItem);
} else {

const newMapping: ContentItemMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceContentID: sourceContentItem.contentID,
targetContentID: targetContentItem.contentID,
sourceVersionID: sourceContentItem.properties.versionID,
targetVersionID: targetContentItem.properties.versionID,

// Guard against duplicates when the same source item re-maps to a new target ID
// (e.g. target file was deleted and the item was re-created with a fresh ID)
const mappingBySource = this.getContentItemMapping(sourceContentItem, 'source');

if (mappingBySource) {
mappingBySource.targetContentID = targetContentItem.contentID;
mappingBySource.sourceVersionID = sourceContentItem.properties.versionID;
mappingBySource.targetVersionID = targetContentItem.properties.versionID;
} else {
const newMapping: ContentItemMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceContentID: sourceContentItem.contentID,
targetContentID: targetContentItem.contentID,
sourceVersionID: sourceContentItem.properties.versionID,
targetVersionID: targetContentItem.properties.versionID,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down
32 changes: 19 additions & 13 deletions src/lib/mappers/gallery-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,29 @@ export class GalleryMapper {
}

addMapping(sourceGallery: mgmtApi.assetMediaGrouping, targetGallery: mgmtApi.assetMediaGrouping) {
const mapping = this.getGalleryMapping(targetGallery, 'target');
const mappingByTarget = this.getGalleryMapping(targetGallery, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourceGallery, targetGallery);
} else {

const newMapping: GalleryMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceMediaGroupingID: sourceGallery.mediaGroupingID,
targetMediaGroupingID: targetGallery.mediaGroupingID,
sourceModifiedOn: sourceGallery.modifiedOn,
targetModifiedOn: targetGallery.modifiedOn,

// Guard against duplicates when the same source gallery re-maps to a new target ID
const mappingBySource = this.getGalleryMapping(sourceGallery, 'source');

if (mappingBySource) {
mappingBySource.targetMediaGroupingID = targetGallery.mediaGroupingID;
mappingBySource.sourceModifiedOn = sourceGallery.modifiedOn;
mappingBySource.targetModifiedOn = targetGallery.modifiedOn;
} else {
const newMapping: GalleryMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceMediaGroupingID: sourceGallery.mediaGroupingID,
targetMediaGroupingID: targetGallery.mediaGroupingID,
sourceModifiedOn: sourceGallery.modifiedOn,
targetModifiedOn: targetGallery.modifiedOn,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down
38 changes: 23 additions & 15 deletions src/lib/mappers/model-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,33 @@ export class ModelMapper {
}

addMapping(sourceModel: mgmtApi.Model, targetModel: mgmtApi.Model) {
const mapping = this.getModelMapping(targetModel, 'target');
const mappingByTarget = this.getModelMapping(targetModel, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourceModel, targetModel);
} else {

const newMapping: ModelMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceID: sourceModel.id,
targetID: targetModel.id,
sourceReferenceName: sourceModel.referenceName,
targetReferenceName: targetModel.referenceName,
sourceLastModifiedDate: sourceModel.lastModifiedDate,
targetLastModifiedDate: targetModel.lastModifiedDate,

// Guard against duplicates when the same source model re-maps to a new target ID
const mappingBySource = this.getModelMapping(sourceModel, 'source');

if (mappingBySource) {
mappingBySource.targetID = targetModel.id;
mappingBySource.sourceReferenceName = sourceModel.referenceName;
mappingBySource.targetReferenceName = targetModel.referenceName;
mappingBySource.sourceLastModifiedDate = sourceModel.lastModifiedDate;
mappingBySource.targetLastModifiedDate = targetModel.lastModifiedDate;
} else {
const newMapping: ModelMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourceID: sourceModel.id,
targetID: targetModel.id,
sourceReferenceName: sourceModel.referenceName,
targetReferenceName: targetModel.referenceName,
sourceLastModifiedDate: sourceModel.lastModifiedDate,
targetLastModifiedDate: targetModel.lastModifiedDate,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down
37 changes: 23 additions & 14 deletions src/lib/mappers/page-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,33 @@ export class PageMapper {
}

addMapping(sourcePage: mgmtApi.PageItem, targetPage: mgmtApi.PageItem) {
const mapping = this.getPageMapping(targetPage, 'target');
const mappingByTarget = this.getPageMapping(targetPage, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourcePage, targetPage);
} else {

const newMapping: PageMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourcePageID: sourcePage.pageID,
targetPageID: targetPage.pageID,
sourceVersionID: sourcePage.properties.versionID,
targetVersionID: targetPage.properties.versionID,
sourcePageTemplateName: sourcePage.templateName,
targetPageTemplateName: targetPage.templateName,
// Guard against duplicates when the same source page re-maps to a new target ID
const mappingBySource = this.getPageMapping(sourcePage, 'source');

if (mappingBySource) {
mappingBySource.targetPageID = targetPage.pageID;
mappingBySource.sourceVersionID = sourcePage.properties.versionID;
mappingBySource.targetVersionID = targetPage.properties.versionID;
mappingBySource.sourcePageTemplateName = sourcePage.templateName;
mappingBySource.targetPageTemplateName = targetPage.templateName;
} else {
const newMapping: PageMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourcePageID: sourcePage.pageID,
targetPageID: targetPage.pageID,
sourceVersionID: sourcePage.properties.versionID,
targetVersionID: targetPage.properties.versionID,
sourcePageTemplateName: sourcePage.templateName,
targetPageTemplateName: targetPage.templateName,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down
31 changes: 19 additions & 12 deletions src/lib/mappers/template-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,29 @@ export class TemplateMapper {
}

addMapping(sourceTemplate: mgmtApi.PageModel, targetTemplate: mgmtApi.PageModel) {
const mapping = this.getTemplateMapping(targetTemplate, 'target');
const mappingByTarget = this.getTemplateMapping(targetTemplate, 'target');

if (mapping) {
if (mappingByTarget) {
this.updateMapping(sourceTemplate, targetTemplate);
} else {

const newMapping: TemplateMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourcePageTemplateID: sourceTemplate.pageTemplateID,
targetPageTemplateID: targetTemplate.pageTemplateID,
sourcePageTemplateName: sourceTemplate.pageTemplateName,
targetPageTemplateName: targetTemplate.pageTemplateName,
// Guard against duplicates when the same source template re-maps to a new target ID
const mappingBySource = this.getTemplateMapping(sourceTemplate, 'source');

if (mappingBySource) {
mappingBySource.targetPageTemplateID = targetTemplate.pageTemplateID;
mappingBySource.sourcePageTemplateName = sourceTemplate.pageTemplateName;
mappingBySource.targetPageTemplateName = targetTemplate.pageTemplateName;
} else {
const newMapping: TemplateMapping = {
sourceGuid: this.sourceGuid,
targetGuid: this.targetGuid,
sourcePageTemplateID: sourceTemplate.pageTemplateID,
targetPageTemplateID: targetTemplate.pageTemplateID,
sourcePageTemplateName: sourceTemplate.pageTemplateName,
targetPageTemplateName: targetTemplate.pageTemplateName,
}
this.mappings.push(newMapping);
}

this.mappings.push(newMapping);
}

this.saveMapping();
Expand Down