Skip to content

Commit 5711f59

Browse files
Merge pull request #818 from contentstack/fix/CMG-750
refactor: add reserved field mappings and improve UID handling in aem…
2 parents 99fbe8f + 795bc67 commit 5711f59

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

api/src/constants/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,8 @@ export const GET_AUDIT_DATA = {
293293
AUDIT_REPORT: "audit-report",
294294
FILTERALL: "all",
295295
}
296+
297+
export const RESERVED_FIELD_MAPPINGS: Record<string, string> = {
298+
'locale': 'cm_locale'
299+
// Add other reserved fields if needed
300+
};

api/src/services/aem.service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid';
66
import { JSDOM } from "jsdom";
77
import { htmlToJson } from '@contentstack/json-rte-serializer';
88
import { buildSchemaTree } from '../utils/content-type-creator.utils.js';
9-
import { MIGRATION_DATA_CONFIG, LOCALE_MAPPER } from '../constants/index.js';
9+
import { MIGRATION_DATA_CONFIG, LOCALE_MAPPER, RESERVED_FIELD_MAPPINGS } from '../constants/index.js';
1010
import { getLogMessage } from '../utils/index.js';
1111
import customLogger from '../utils/custom-logger.utils.js';
1212
import { orgService } from './org.service.js';
@@ -144,6 +144,17 @@ function getFieldValue(items: any, fieldName: string): any {
144144
return undefined;
145145
}
146146

147+
148+
function getActualFieldUid(uid: string, fieldUid: string): string {
149+
if (RESERVED_FIELD_MAPPINGS[uid]) {
150+
return RESERVED_FIELD_MAPPINGS[uid];
151+
}
152+
if (RESERVED_FIELD_MAPPINGS[fieldUid]) {
153+
return RESERVED_FIELD_MAPPINGS[fieldUid];
154+
}
155+
return uid;
156+
}
157+
147158
/**
148159
* Finds and returns the asset object from assetJsonData where assetPath matches the given string.
149160
* @param assetJsonData - The asset JSON data object.
@@ -613,15 +624,16 @@ function processFieldsRecursive(
613624
}
614625

615626
case 'single_line_text': {
616-
const aemFieldName = field?.otherCmsField ? getLastKey(field.otherCmsField, ' > ') : getLastKey(field?.uid);
627+
const aemFieldName = field?.otherCmsField ? getLastKey(field?.otherCmsField, ' > ') : getLastKey(field?.uid);
617628
let value = getFieldValue(items, aemFieldName);
618629
const uid = getLastKey(field?.contentstackFieldUid);
619630

631+
const actualUid = getActualFieldUid(uid, field?.uid);
620632
if (value && typeof value === 'string' && /<[^>]+>/.test(value)) {
621633
value = stripHtmlTags(value);
622634
}
623635

624-
obj[uid] = value !== null && value !== undefined ? String(value) : "";
636+
obj[actualUid] = value !== null && value !== undefined ? String(value) : "";
625637
break;
626638
}
627639

upload-api/migration-aem/libs/contentType/components/SearchComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class SearchComponent extends ContentstackComponent {
4545
uid: key,
4646
displayName: key,
4747
description: "",
48-
defaultValue: null
48+
defaultValue: ""
4949
}).toContentstack(),
5050
object: () => null,
5151
array: () => null

upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class TeaserComponent extends ContentstackComponent {
6565
uid: key,
6666
displayName: key,
6767
description: "",
68-
defaultValue: null
68+
defaultValue: ""
6969
}).toContentstack(),
7070
object: (key, schemaProp) => {
7171
const data = { convertedSchema: schemaProp }

0 commit comments

Comments
 (0)