@@ -42,20 +42,88 @@ export class Step {
4242 step . options . outputFormat = 'json' ;
4343 return step ;
4444 }
45+
4546 static createMappingStep ( ) : Step {
4647 const step = new Step ( ) ;
4748 step . options = new MappingOptions ( ) ;
4849 return step ;
4950 }
51+
5052 static createMasteringStep ( ) : Step {
5153 const step = new Step ( ) ;
5254 step . options = new MasteringOptions ( ) ;
5355 return step ;
5456 }
57+
5558 static createCustomStep ( ) : Step {
5659 const step = new Step ( ) ;
5760 step . modulePath = '' ;
5861 step . options = new CustomOptions ( ) ;
5962 return step ;
6063 }
64+
65+ static fromJSON ( json , projectDirectory , databases ) {
66+ const newStep = new Step ( ) ;
67+ if ( json . id ) {
68+ newStep . id = json . id ;
69+ }
70+ if ( json . name ) {
71+ newStep . name = json . name ;
72+ }
73+ if ( json . selectedSource ) {
74+ newStep . selectedSource = json . selectedSource ;
75+ }
76+ if ( json . stepDefinitionName ) {
77+ newStep . stepDefinitionName = json . stepDefinitionName ;
78+ }
79+ if ( json . stepDefinitionType ) {
80+ newStep . stepDefinitionType = json . stepDefinitionType ;
81+ }
82+ if ( json . fileLocations ) {
83+ newStep . fileLocations = json . fileLocations ;
84+ }
85+ if ( json . isValid ) {
86+ newStep . isValid = json . isValid ;
87+ }
88+ if ( json . modulePath ) {
89+ newStep . modulePath = json . modulePath ;
90+ }
91+ // Check options
92+ if ( json . options ) {
93+ // set defaults for each step type
94+ if ( json . stepDefinitionType === StepType . INGESTION ) {
95+ // Hard check to see if it's default gradle step
96+ if ( json . fileLocations . inputFilePath === 'path/to/folder' ) {
97+ const fileLocations = {
98+ inputFilePath : projectDirectory ,
99+ inputFileType : 'json' ,
100+ outputURIReplacement : ''
101+ } ;
102+ newStep . fileLocations = fileLocations ;
103+ }
104+ newStep . options = new IngestionOptions ( ) ;
105+ newStep . options . permissions = 'rest-reader,read,rest-writer,update' ;
106+ newStep . options . outputFormat = 'json' ;
107+ newStep . options . targetDatabase = databases . staging ;
108+ }
109+ if ( json . stepDefinitionType === StepType . MAPPING ) {
110+ newStep . options = new MappingOptions ( ) ;
111+ newStep . options . sourceDatabase = databases . staging ;
112+ newStep . options . targetDatabase = databases . final ;
113+ }
114+ if ( json . stepDefinitionType === StepType . MASTERING ) {
115+ newStep . options = new MasteringOptions ( ) ;
116+ newStep . options . sourceDatabase = databases . final ;
117+ newStep . options . targetDatabase = databases . final ;
118+ }
119+ if ( json . stepDefinitionType === StepType . CUSTOM ) {
120+ newStep . options = new CustomOptions ( ) ;
121+ newStep . options . sourceDatabase = databases . staging ;
122+ newStep . options . targetDatabase = databases . final ;
123+ }
124+ const newOptions = Object . assign ( newStep . options , json . options ) ;
125+ newStep . options = newOptions ;
126+ }
127+ return newStep ;
128+ }
61129}
0 commit comments