Skip to content

Commit e1626c3

Browse files
committed
Merge branch 'dev' of https://github.com/contentstack/migration-v2-node-server into feature/test-migration
2 parents 4f58154 + dd32815 commit e1626c3

File tree

11 files changed

+178
-68
lines changed

11 files changed

+178
-68
lines changed

api/src/constants/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export const HTTP_TEXTS = {
9393
PROJECT_REVERT:
9494
"Project Reverted Successfully",
9595
LOGS_NOT_FOUND:
96-
"Sorry, no logs found for requested stack migration."
96+
"Sorry, no logs found for requested stack migration.",
97+
MIGRATION_EXECUTION_KEY_UPDATED:
98+
"Project's migration execution key updated successfully"
9799
};
98100

99101
export const HTTP_RESPONSE_HEADERS = {
@@ -207,7 +209,7 @@ export const MIGRATION_DATA_CONFIG = {
207209
ASSETS_DIR_NAME : "assets",
208210
ASSETS_FILE_NAME : "assets.json",
209211
// ASSETS_SCHEMA_FILE : "index.json",
210-
ASSETS_SCHEMA_FILE : "assetsSchema.json",
212+
ASSETS_SCHEMA_FILE : "index.json",
211213
ASSETS_FAILED_FILE : "cs_failed.json",
212214
ASSETS_METADATA_FILE :"metadata.json",
213215

api/src/controllers/projects.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ const updateStackDetails = async (req: Request, res: Response): Promise<void> =>
166166
res.status(project.status).json(project);
167167
}
168168

169+
const updateMigrationExecution = async (req: Request, res: Response): Promise<void> => {
170+
const project = await projectService.updateMigrationExecution(req);
171+
res.status(project.status).json(project);
172+
}
173+
169174
export const projectController = {
170175
getAllProjects,
171176
getProject,
@@ -180,5 +185,6 @@ export const projectController = {
180185
updateCurrentStep,
181186
deleteProject,
182187
revertProject,
183-
updateStackDetails
188+
updateStackDetails,
189+
updateMigrationExecution,
184190
};

api/src/models/project-lowdb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ interface Project {
7474
mapperKeys: {};
7575
extract_path: string;
7676
isMigrationStarted: boolean;
77+
migration_execution: boolean;
7778
}
7879

7980
interface ProjectDocument {

api/src/routes/projects.routes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ router.patch("/:projectId", asyncRouter(projectController.revertProject));
7777
//update stack details Project Route
7878
router.patch("/:projectId/stack-details", asyncRouter(projectController.updateStackDetails));
7979

80+
//update migration execution key
81+
router.put("/:projectId/migration-excution",asyncRouter(projectController.updateMigrationExecution));
82+
8083
export default router;

api/src/services/projects.service.ts

Lines changed: 115 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ const createProject = async (req: Request) => {
126126
isNewStack: false
127127
},
128128
mapperKeys: {},
129-
isMigrationStarted: false
129+
isMigrationStarted: false,
130+
migration_execution:false,
130131
};
131132

132133
try {
@@ -690,6 +691,8 @@ const updateCurrentStep = async (req: Request) => {
690691
const token_payload = req.body.token_payload;
691692
const srcFunc = "updateCurrentStep";
692693

694+
695+
693696
try {
694697
await ProjectModelLowdb.read();
695698
const projectIndex = (await getProjectUtil(
@@ -709,6 +712,12 @@ const updateCurrentStep = async (req: Request) => {
709712
const isStepCompleted =
710713
project?.legacy_cms?.cms && project?.legacy_cms?.file_format;
711714

715+
console.info((project.status === NEW_PROJECT_STATUS[0] ||
716+
!isStepCompleted ||
717+
!project?.destination_stack_id ||
718+
project?.content_mapper?.length === 0 ||
719+
!project?.current_test_stack_id) || !project?.migration_execution);
720+
712721
switch (project.current_step) {
713722
case STEPPER_STEPS.LEGACY_CMS: {
714723
if (project.status !== NEW_PROJECT_STATUS[0] || !isStepCompleted) {
@@ -789,12 +798,13 @@ const updateCurrentStep = async (req: Request) => {
789798
}
790799
case STEPPER_STEPS.TESTING: {
791800
if (
792-
project.status === NEW_PROJECT_STATUS[0] ||
801+
(project.status === NEW_PROJECT_STATUS[0] ||
793802
!isStepCompleted ||
794803
!project?.destination_stack_id ||
795804
project?.content_mapper?.length === 0 ||
796-
!project?.current_test_stack_id
805+
!project?.current_test_stack_id) || !project?.migration_execution
797806
) {
807+
798808
logger.error(
799809
getLogMessage(
800810
srcFunc,
@@ -806,44 +816,44 @@ const updateCurrentStep = async (req: Request) => {
806816
HTTP_TEXTS.CANNOT_PROCEED_TEST_MIGRATION
807817
);
808818
}
809-
810-
ProjectModelLowdb.update((data: any) => {
811-
data.projects[projectIndex].current_step =
812-
STEPPER_STEPS.MIGRATION;
813-
data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
814-
data.projects[projectIndex].updated_at = new Date().toISOString();
815-
});
816-
break;
817-
}
818-
case STEPPER_STEPS.MIGRATION: {
819-
if (
820-
project.status === NEW_PROJECT_STATUS[0] ||
821-
!isStepCompleted ||
822-
!project?.destination_stack_id ||
823-
project?.content_mapper?.length === 0 ||
824-
!project?.current_test_stack_id ||
825-
!project?.isMigrationStarted
826-
) {
827-
logger.error(
828-
getLogMessage(
829-
srcFunc,
830-
HTTP_TEXTS.CANNOT_PROCEED_MIGRATION,
831-
token_payload
832-
)
833-
);
834-
throw new BadRequestError(
835-
HTTP_TEXTS.CANNOT_PROCEED_MIGRATION
836-
);
837-
}
838-
819+
839820
ProjectModelLowdb.update((data: any) => {
840821
data.projects[projectIndex].current_step =
841822
STEPPER_STEPS.MIGRATION;
842-
data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
823+
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
843824
data.projects[projectIndex].updated_at = new Date().toISOString();
844825
});
845826
break;
846827
}
828+
// case STEPPER_STEPS.MIGRATION: {
829+
// if (
830+
// project.status === NEW_PROJECT_STATUS[0] ||
831+
// !isStepCompleted ||
832+
// !project?.destination_stack_id ||
833+
// project?.content_mapper?.length === 0 ||
834+
// !project?.current_test_stack_id ||
835+
// !project?.isMigrationStarted
836+
// ) {
837+
// logger.error(
838+
// getLogMessage(
839+
// srcFunc,
840+
// HTTP_TEXTS.CANNOT_PROCEED_MIGRATION,
841+
// token_payload
842+
// )
843+
// );
844+
// throw new BadRequestError(
845+
// HTTP_TEXTS.CANNOT_PROCEED_MIGRATION
846+
// );
847+
// }
848+
849+
// ProjectModelLowdb.update((data: any) => {
850+
// data.projects[projectIndex].current_step =
851+
// STEPPER_STEPS.MIGRATION;
852+
// data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
853+
// data.projects[projectIndex].updated_at = new Date().toISOString();
854+
// });
855+
// break;
856+
// }
847857
}
848858
logger.info(
849859
getLogMessage(
@@ -1132,6 +1142,75 @@ const updateContentMapper = async (req: Request) => {
11321142
}
11331143
};
11341144

1145+
/**
1146+
* Updates the `migration_execution` key for a project in the `ProjectModelLowdb`.
1147+
* @param req - The request object containing parameters and body.
1148+
*/
1149+
const updateMigrationExecution = async (req: Request) => {
1150+
const { orgId, projectId } = req.params; // Extract organization and project IDs from the route parameters
1151+
const { token_payload, stack_details } = req.body; // Extract token payload and stack details from the request body
1152+
const srcFunc = "updateMigrationExecutionKey";
1153+
1154+
// Ensure the `ProjectModelLowdb` database is ready to be read
1155+
await ProjectModelLowdb.read();
1156+
1157+
// Retrieve the project index using the `getProjectUtil` helper
1158+
const projectIndex = (await getProjectUtil(
1159+
projectId,
1160+
{
1161+
id: projectId,
1162+
org_id: orgId,
1163+
region: token_payload?.region,
1164+
owner: token_payload?.user_id,
1165+
},
1166+
srcFunc,
1167+
true
1168+
)) as number;
1169+
try {
1170+
1171+
// Update the project in the `ProjectModelLowdb` database
1172+
ProjectModelLowdb.update((data: any) => {
1173+
data.projects[projectIndex].migration_execution = true; // Set migration execution to true
1174+
data.projects[projectIndex].updated_at = new Date().toISOString(); // Update the `updated_at` timestamp
1175+
});
1176+
1177+
// Log success message
1178+
logger.info(
1179+
getLogMessage(
1180+
srcFunc,
1181+
`migration execution key for project [Id : ${projectId}] has been successfully updated.`,
1182+
token_payload
1183+
)
1184+
);
1185+
1186+
// Return success response
1187+
return {
1188+
status: HTTP_CODES.OK,
1189+
data: {
1190+
message: HTTP_TEXTS.MIGRATION_EXECUTION_KEY_UPDATED,
1191+
},
1192+
};
1193+
1194+
} catch (error: any) {
1195+
// Log error message
1196+
logger.error(
1197+
getLogMessage(
1198+
srcFunc,
1199+
`Error occurred while updating content mapping for project [Id : ${projectId}].`,
1200+
token_payload,
1201+
error
1202+
)
1203+
);
1204+
1205+
// Throw a custom exception with the error details
1206+
throw new ExceptionFunction(
1207+
error?.message || HTTP_TEXTS.INTERNAL_ERROR,
1208+
error?.statusCode || error?.status || HTTP_CODES.SERVER_ERROR
1209+
);
1210+
}
1211+
};
1212+
1213+
11351214

11361215
export const projectService = {
11371216
getAllProjects,
@@ -1148,5 +1227,6 @@ export const projectService = {
11481227
deleteProject,
11491228
revertProject,
11501229
updateStackDetails,
1151-
updateContentMapper
1230+
updateContentMapper,
1231+
updateMigrationExecution
11521232
};

ui/src/components/ContentMapper/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
298298
},[tableData]);
299299

300300
useEffect(() => {
301-
const mappedContentType = contentModels && contentModels?.find((item)=> item?.title === newMigrationData?.content_mapping?.content_type_mapping?.[otherCmsTitle]);
302-
301+
const mappedContentType = contentModels && contentModels?.find((item)=> item?.uid === newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || '']);
303302
// if (contentTypeMapped && otherCmsTitle ) {
304303

305304
if (mappedContentType?.uid) {
@@ -334,7 +333,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
334333

335334
// useEffect for rendering mapped fields with existing stack
336335
useEffect(() => {
337-
if (newMigrationData?.content_mapping?.content_type_mapping?.[otherCmsTitle] === otherContentType?.label) {
336+
console.log(otherContentType);
337+
338+
if (newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || ''] === otherContentType?.id) {
338339
tableData?.forEach((row) => {
339340
contentTypeSchema?.forEach((schema) => {
340341

@@ -1415,7 +1416,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
14151416
isDisabled={OptionValue?.isDisabled || newMigrationData?.project_current_step > 4}
14161417
/>
14171418
</div>
1418-
{!OptionValue?.isDisabled && (
1419+
{!OptionValue?.isDisabled || OptionValue?.label === 'Dropdown' && (
14191420
<div className='advanced-setting-button'>
14201421
<Tooltip
14211422
content="Advanced properties"
@@ -1466,7 +1467,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
14661467
content_type_mapping: {
14671468

14681469
...newMigrationData?.content_mapping?.content_type_mapping ?? {},
1469-
[otherCmsTitle]: otherContentType?.label
1470+
[selectedContentType?.contentstackUid]: otherContentType?.id || ''
14701471
}
14711472
}
14721473
};

ui/src/components/LogScreen/index.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,6 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs
134134

135135
if (message === "Test Migration Process Completed") {
136136

137-
138-
// push test migration completion in redux
139-
const newMigrationDataObj : INewMigration = {
140-
...newMigrationData,
141-
test_migration:{
142-
...newMigrationData?.test_migration,
143-
isMigrationComplete:true,
144-
isMigrationStarted: false,
145-
}
146-
}
147-
dispatch(updateNewMigrationData(newMigrationDataObj));
148-
149137
// Save test migration state to local storage
150138
saveStateToLocalStorage({
151139
isTestMigrationCompleted : true,
@@ -165,7 +153,12 @@ const TestMigrationLogViewer = ({ serverPath, sendDataToParent,projectId }: Logs
165153
// Update testStacks data in Redux
166154
const newMigrationObj: INewMigration = {
167155
...newMigrationData,
168-
testStacks: [...newMigrationData?.testStacks ?? [], {stackUid: newMigrationData?.test_migration?.stack_api_key, stackName: newMigrationData?.test_migration?.stack_name, isMigrated: true}]
156+
testStacks: [...newMigrationData?.testStacks ?? [], {stackUid: newMigrationData?.test_migration?.stack_api_key, stackName: newMigrationData?.test_migration?.stack_name, isMigrated: true}],
157+
test_migration:{
158+
...newMigrationData?.test_migration,
159+
isMigrationComplete:true,
160+
isMigrationStarted: false,
161+
}
169162
};
170163

171164
dispatch(updateNewMigrationData((newMigrationObj)));

ui/src/components/MigrationFlowHeader/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,22 @@ const MigrationFlowHeader = ({projectData, handleOnClick, isLoading, finalExecut
6464
} else {
6565
stepValue = 'Save and Continue';
6666
}
67-
67+
68+
const isStep4AndNotMigrated =
69+
params?.stepId === '4' &&
70+
!newMigrationData?.testStacks?.some(
71+
(stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key && stack?.isMigrated
72+
);
73+
74+
const isStepInvalid =
75+
params?.stepId &&
76+
params?.stepId <= '2' &&
77+
newMigrationData?.project_current_step?.toString() !== params?.stepId;
78+
79+
const isExecutionStarted =
80+
finalExecutionStarted ||
81+
newMigrationData?.migration_execution?.migrationStarted;
82+
6883
return (
6984
<div className='d-flex align-items-center justify-content-between migration-flow-header'>
7085
<div className='d-flex align-items-center'>
@@ -81,9 +96,7 @@ const MigrationFlowHeader = ({projectData, handleOnClick, isLoading, finalExecut
8196
version="v2"
8297
aria-label='Save and Continue'
8398
isLoading={isLoading || newMigrationData?.isprojectMapped}
84-
disabled={(params?.stepId === '4' && !(newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated)) ||
85-
(params?.stepId && params?.stepId <= '2' && newMigrationData?.project_current_step?.toString() !== params?.stepId) || (finalExecutionStarted || newMigrationData?.migration_execution?.migrationStarted)
86-
}
99+
disabled={isStep4AndNotMigrated || isStepInvalid || isExecutionStarted}
87100
>
88101
{stepValue}
89102
</Button>

ui/src/components/TestMigration/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const TestMigration = () => {
5050
const [isStackLoading, setIsStackLoading] = useState<boolean>(false);
5151
const [disableTestMigration, setdisableTestMigration] = useState<boolean>(newMigrationData?.test_migration?.isMigrationStarted);
5252

53-
const [disableCreateStack, setDisableCreateStack] = useState<boolean>(newMigrationData?.test_migration?.isMigrationStarted);
53+
const [disableCreateStack, setDisableCreateStack] = useState<boolean>( ! newMigrationData?.testStacks?.find((stack)=>stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated || newMigrationData?.test_migration?.isMigrationStarted );
5454
const [stackLimitReached, setStackLimitReached] = useState<boolean>(false);
5555

5656
// Extract project ID from URL parameters
@@ -78,9 +78,8 @@ const TestMigration = () => {
7878
* to disable Create Test Stack and Start Test Migration buttons as per isMigrated state
7979
*/
8080
useEffect(() => {
81-
if (!newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated && !disableTestMigration) {
82-
83-
setDisableCreateStack(false);
81+
if (!newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated && !disableTestMigration) {
82+
//setDisableCreateStack(false);
8483
}
8584

8685
if (newMigrationData?.testStacks?.find((stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key)?.isMigrated === true) {
@@ -194,6 +193,7 @@ const TestMigration = () => {
194193
test_migration:{
195194
...newMigrationData?.test_migration,
196195
isMigrationStarted:true,
196+
isMigrationComplete: false,
197197
}
198198
}
199199
dispatch(updateNewMigrationData(newMigrationDataObj));

0 commit comments

Comments
 (0)