Skip to content
Open
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
41 changes: 23 additions & 18 deletions src/lib/mappers/asset-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ export class AssetMapper {
}

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

if (targetMapping && sourceMapping && targetMapping !== sourceMapping) {
throw new Error(`Invalid Mappings detected! Source mediaID: ${sourceAsset.mediaID}, Target mediaID: ${targetAsset.mediaID}`);
}

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

const newMapping: AssetMapping = {
Expand All @@ -130,22 +135,22 @@ export class AssetMapper {
this.saveMapping();
}

updateMapping(sourceAsset: mgmtApi.Media, targetAsset: mgmtApi.Media) {
const mapping = this.getAssetMapping(targetAsset, 'target');
if (mapping) {
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceDateModified = sourceAsset.dateModified;
mapping.targetDateModified = targetAsset.dateModified;
mapping.sourceMediaID = sourceAsset.mediaID;
mapping.targetMediaID = targetAsset.mediaID;
mapping.sourceUrl = sourceAsset.edgeUrl;
mapping.targetUrl = targetAsset.edgeUrl;
mapping.sourceContainerEdgeUrl = sourceAsset.containerEdgeUrl;
mapping.targetContainerEdgeUrl = targetAsset.containerEdgeUrl;
mapping.sourceContainerOriginUrl = sourceAsset.containerOriginUrl;
mapping.targetContainerOriginUrl = targetAsset.containerOriginUrl;
updateMapping(sourceAsset: mgmtApi.Media, targetAsset: mgmtApi.Media, mapping: AssetMapping) {
if (targetAsset.mediaID !== mapping.targetMediaID) {
throw new Error(`Invalid items trying to be mapped! Source mediaID: ${sourceAsset.mediaID}, Target mediaID: ${targetAsset.mediaID}`);
}
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceDateModified = sourceAsset.dateModified;
mapping.targetDateModified = targetAsset.dateModified;
mapping.sourceMediaID = sourceAsset.mediaID;
mapping.targetMediaID = targetAsset.mediaID;
mapping.sourceUrl = sourceAsset.edgeUrl;
mapping.targetUrl = targetAsset.edgeUrl;
mapping.sourceContainerEdgeUrl = sourceAsset.containerEdgeUrl;
mapping.targetContainerEdgeUrl = targetAsset.containerEdgeUrl;
mapping.sourceContainerOriginUrl = sourceAsset.containerOriginUrl;
mapping.targetContainerOriginUrl = targetAsset.containerOriginUrl;
this.saveMapping();
}

Expand Down
36 changes: 20 additions & 16 deletions src/lib/mappers/container-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ export class ContainerMapper {
}

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

if (mapping) {
this.updateMapping(sourceContainer, targetContainer);
if (targetMapping && sourceMapping && targetMapping !== sourceMapping) {
throw new Error(`Invalid Mappings detected! Source contentViewID: ${sourceContainer.contentViewID}, Target contentViewID: ${targetContainer.contentViewID}`);
}

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

const newMapping: ContainerMapping = {
Expand All @@ -122,20 +127,19 @@ export class ContainerMapper {
this.saveMapping();
}

updateMapping(sourceContainer: mgmtApi.Container, targetContainer: mgmtApi.Container) {
const mapping = this.getContainerMapping(targetContainer, 'target');
if (mapping) {
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceContentViewID = sourceContainer.contentViewID;
mapping.targetContentViewID = targetContainer.contentViewID;
mapping.sourceLastModifiedDate = sourceContainer.lastModifiedDate;
mapping.targetLastModifiedDate = targetContainer.lastModifiedDate;
mapping.sourceReferenceName = sourceContainer.referenceName;
mapping.targetReferenceName = targetContainer.referenceName;
this.saveMapping();
updateMapping(sourceContainer: mgmtApi.Container, targetContainer: mgmtApi.Container, mapping: ContainerMapping) {
if (targetContainer.contentViewID !== mapping.targetContentViewID) {
throw new Error(`Invalid items trying to be mapped! Source contentViewID: ${sourceContainer.contentViewID}, Target contentViewID: ${targetContainer.contentViewID}`);
}

mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceContentViewID = sourceContainer.contentViewID;
mapping.targetContentViewID = targetContainer.contentViewID;
mapping.sourceLastModifiedDate = sourceContainer.lastModifiedDate;
mapping.targetLastModifiedDate = targetContainer.lastModifiedDate;
mapping.sourceReferenceName = sourceContainer.referenceName;
mapping.targetReferenceName = targetContainer.referenceName;
this.saveMapping();
}

loadMapping() {
Expand Down
60 changes: 43 additions & 17 deletions src/lib/mappers/content-item-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fileOperations } from "../../core";
import * as mgmtApi from "@agility/management-sdk";
import { ContainerMapper } from "./container-mapper";

export interface ContentItemMapping {
sourceGuid: string;
Expand All @@ -17,13 +18,15 @@ export class ContentItemMapper {
private targetGuid: string;
private mappings: ContentItemMapping[];
private directory: string;
private containerMapper: ContainerMapper;
public locale: string;

constructor(sourceGuid: string, targetGuid: string, locale: string) {
this.sourceGuid = sourceGuid;
this.targetGuid = targetGuid;
this.directory = 'item';
this.locale = locale;
this.containerMapper = new ContainerMapper(sourceGuid, targetGuid);
// this will provide access to the /agility-files/{GUID}/{locale} folder
this.fileOps = new fileOperations(targetGuid, locale);
this.mappings = this.loadMapping();
Expand Down Expand Up @@ -80,39 +83,62 @@ export class ContentItemMapper {
}
}

/*
* Function to check if the items are mappable. If the definitions are the same, the contentviews are mapped, then we are safe
*/
checkItemIsMappable(sourceContentItem: mgmtApi.ContentItem, targetContentItem: mgmtApi.ContentItem): void {

// check if the models are the same
if(sourceContentItem.properties.definitionName !== targetContentItem.properties.definitionName){
throw new Error(`Items cannot be mapped. They are not congruent, the content models are different. source contentID: ${sourceContentItem.contentID}, target contentID: ${targetContentItem.contentID}`);
}

// use the reference name to check if the containers are truly mapped together
const sourceContainerMapping = this.containerMapper.getContainerMappingByReferenceName(sourceContentItem.properties.referenceName, "source");
const targetContainerMapping = this.containerMapper.getContainerMappingByReferenceName(targetContentItem.properties.referenceName, "target");

if(sourceContainerMapping !== targetContainerMapping){
throw new Error(`Items cannot be mapped. The containers are not mapped to each other. source contentID: ${sourceContentItem.contentID}, target contentID: ${targetContentItem.contentID}`);
}
}

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

if (mapping) {
this.updateMapping(sourceContentItem, targetContentItem);
} else {
if(targetMapping && sourceMapping && targetMapping !== sourceMapping){
throw new Error(`Invalid Mappings detected! The two items have different mappings, Source contentID: ${sourceContentItem.contentID}, Target contentID: ${targetContentItem.contentID}`);
}

// At this point target and source mappings should be the same
if (targetMapping) {
this.updateMapping(sourceContentItem, targetContentItem, targetMapping);
} 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.saveMapping();
}

updateMapping(sourceContentItem: mgmtApi.ContentItem, targetContentItem: mgmtApi.ContentItem) {
const mapping = this.getContentItemMapping(targetContentItem, 'target');
if (mapping) {
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceContentID = sourceContentItem.contentID;
mapping.targetContentID = targetContentItem.contentID;
mapping.sourceVersionID = sourceContentItem.properties.versionID;
mapping.targetVersionID = targetContentItem.properties.versionID;
updateMapping(sourceContentItem: mgmtApi.ContentItem, targetContentItem: mgmtApi.ContentItem, mapping: ContentItemMapping) {

if(targetContentItem.contentID !== mapping.targetContentID){
throw new Error(`Invalid items trying to be mapped! Source contentID: ${sourceContentItem.contentID}, Target contentID: ${targetContentItem.contentID}`);
}

mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceContentID = sourceContentItem.contentID;
mapping.targetContentID = targetContentItem.contentID;
mapping.sourceVersionID = sourceContentItem.properties.versionID;
mapping.targetVersionID = targetContentItem.properties.versionID;
this.saveMapping();
}

Expand Down Expand Up @@ -167,4 +193,4 @@ export class ContentItemMapper {
};
}

}
}
29 changes: 17 additions & 12 deletions src/lib/mappers/gallery-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ export class GalleryMapper {
}

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

if (targetMapping && sourceMapping && targetMapping !== sourceMapping) {
throw new Error(`Invalid Mappings detected! Source mediaGroupingID: ${sourceGallery.mediaGroupingID}, Target mediaGroupingID: ${targetGallery.mediaGroupingID}`);
}

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

const newMapping: GalleryMapping = {
Expand All @@ -85,16 +90,16 @@ export class GalleryMapper {
this.saveMapping();
}

updateMapping(sourceGallery: mgmtApi.assetMediaGrouping, targetGallery: mgmtApi.assetMediaGrouping) {
const mapping = this.getGalleryMapping(targetGallery, 'target');
if (mapping) {
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceMediaGroupingID = sourceGallery.mediaGroupingID;
mapping.targetMediaGroupingID = targetGallery.mediaGroupingID;
mapping.sourceModifiedOn = sourceGallery.modifiedOn;
mapping.targetModifiedOn = targetGallery.modifiedOn;
updateMapping(sourceGallery: mgmtApi.assetMediaGrouping, targetGallery: mgmtApi.assetMediaGrouping, mapping: GalleryMapping) {
if (targetGallery.mediaGroupingID !== mapping.targetMediaGroupingID) {
throw new Error(`Invalid items trying to be mapped! Source mediaGroupingID: ${sourceGallery.mediaGroupingID}, Target mediaGroupingID: ${targetGallery.mediaGroupingID}`);
}
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceMediaGroupingID = sourceGallery.mediaGroupingID;
mapping.targetMediaGroupingID = targetGallery.mediaGroupingID;
mapping.sourceModifiedOn = sourceGallery.modifiedOn;
mapping.targetModifiedOn = targetGallery.modifiedOn;
this.saveMapping();
}

Expand Down
33 changes: 19 additions & 14 deletions src/lib/mappers/model-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ export class ModelMapper {
}

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

if (targetMapping && sourceMapping && targetMapping !== sourceMapping) {
throw new Error(`Invalid Mappings detected! Source model ID: ${sourceModel.id}, Target model ID: ${targetModel.id}`);
}

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

const newMapping: ModelMapping = {
Expand All @@ -96,18 +101,18 @@ export class ModelMapper {
this.saveMapping();
}

updateMapping(sourceModel: mgmtApi.Model, targetModel: mgmtApi.Model) {
const mapping = this.getModelMapping(targetModel, 'target');
if (mapping) {
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceID = sourceModel.id;
mapping.targetID = targetModel.id;
mapping.sourceReferenceName = sourceModel.referenceName;
mapping.targetReferenceName = targetModel.referenceName;
mapping.sourceLastModifiedDate = sourceModel.lastModifiedDate;
mapping.targetLastModifiedDate = targetModel.lastModifiedDate;
updateMapping(sourceModel: mgmtApi.Model, targetModel: mgmtApi.Model, mapping: ModelMapping) {
if (targetModel.id !== mapping.targetID) {
throw new Error(`Invalid items trying to be mapped! Source model ID: ${sourceModel.id}, Target model ID: ${targetModel.id}`);
}
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourceID = sourceModel.id;
mapping.targetID = targetModel.id;
mapping.sourceReferenceName = sourceModel.referenceName;
mapping.targetReferenceName = targetModel.referenceName;
mapping.sourceLastModifiedDate = sourceModel.lastModifiedDate;
mapping.targetLastModifiedDate = targetModel.lastModifiedDate;
this.saveMapping();
}

Expand Down
33 changes: 19 additions & 14 deletions src/lib/mappers/page-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ export class PageMapper {
}

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

if (mapping) {
this.updateMapping(sourcePage, targetPage);
if (targetMapping && sourceMapping && targetMapping !== sourceMapping) {
throw new Error(`Invalid Mappings detected! Source pageID: ${sourcePage.pageID}, Target pageID: ${targetPage.pageID}`);
}

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

const newMapping: PageMapping = {
Expand All @@ -90,18 +95,18 @@ export class PageMapper {
this.saveMapping();
}

updateMapping(sourcePage: mgmtApi.PageItem, targetPage: mgmtApi.PageItem) {
const mapping = this.getPageMapping(targetPage, 'target');
if (mapping) {
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourcePageID = sourcePage.pageID;
mapping.targetPageID = targetPage.pageID;
mapping.sourceVersionID = sourcePage.properties.versionID;
mapping.targetVersionID = targetPage.properties.versionID;
mapping.sourcePageTemplateName = sourcePage.templateName;
mapping.targetPageTemplateName = targetPage.templateName;
updateMapping(sourcePage: mgmtApi.PageItem, targetPage: mgmtApi.PageItem, mapping: PageMapping) {
if (targetPage.pageID !== mapping.targetPageID) {
throw new Error(`Invalid items trying to be mapped! Source pageID: ${sourcePage.pageID}, Target pageID: ${targetPage.pageID}`);
}
mapping.sourceGuid = this.sourceGuid;
mapping.targetGuid = this.targetGuid;
mapping.sourcePageID = sourcePage.pageID;
mapping.targetPageID = targetPage.pageID;
mapping.sourceVersionID = sourcePage.properties.versionID;
mapping.targetVersionID = targetPage.properties.versionID;
mapping.sourcePageTemplateName = sourcePage.templateName;
mapping.targetPageTemplateName = targetPage.templateName;
this.saveMapping();
}

Expand Down
Loading
Loading