SchedulerResourceUtil { public static HashMap<String, Serializable> handlePDIScheduling( RepositoryFile file, HashMap<String, Serializable> parameterMap, Map<String, String> pdiParameters ) { HashMap<String, Serializable> convertedParameterMap = new HashMap<>(); boolean paramsAdded = false; if ( pdiParameters != null ) { convertedParameterMap.put( ScheduleExportUtil.RUN_PARAMETERS_KEY, (Serializable) pdiParameters ); paramsAdded = true; } else { pdiParameters = new HashMap<String, String>(); } if ( file != null && isPdiFile( file ) ) { Iterator<String> it = parameterMap.keySet().iterator(); while ( it.hasNext() ) { String param = (String) it.next(); if ( !StringUtils.isEmpty( param ) && parameterMap.containsKey( param ) ) { convertedParameterMap.put( param, parameterMap.get( param ).toString() ); if ( !paramsAdded ) { pdiParameters.put( param, parameterMap.get( param ).toString() ); } } } convertedParameterMap.put( "directory", FilenameUtils.getPathNoEndSeparator( file.getPath() ) ); String type = isTransformation( file ) ? "transformation" : "job"; convertedParameterMap.put( type, FilenameUtils.getBaseName( file.getPath() ) ); } else { convertedParameterMap.putAll( parameterMap ); } convertedParameterMap.putIfAbsent( ScheduleExportUtil.RUN_PARAMETERS_KEY, (Serializable) pdiParameters ); return convertedParameterMap; }  static IJobTrigger convertScheduleRequestToJobTrigger( JobScheduleRequest scheduleRequest,
                                                                IScheduler scheduler ); static void updateStartDateForTimeZone( JobScheduleRequest request ); static Date convertDateToServerTimeZone( Date dateTime, String timeZone ); static HashMap<String, Serializable> handlePDIScheduling( RepositoryFile file,
                                                                   HashMap<String, Serializable> parameterMap, Map<String, String> pdiParameters ); static boolean isPdiFile( RepositoryFile file ); static boolean isTransformation( RepositoryFile file ); static boolean isJob( RepositoryFile file ); static String resolveActionId( final String inputFile ); static String getExtension( final String filename ); static final String RESERVEDMAPKEY_LINEAGE_ID; static final String RESERVED_BACKGROUND_EXECUTION_ACTION_ID; }
@Test public void testHandlePdiScheduling_ktr() throws Exception { HashMap<String, Serializable> params = new HashMap<>(); params.put( "test", "value" ); when( repo.getName() ).thenReturn( "transform.ktr" ); when( repo.getPath() ).thenReturn( "/home/me/transform.ktr" ); HashMap<String, String> pdiParams = new HashMap<>(); pdiParams.put( "pdiParam", "pdiParamValue" ); HashMap<String, Serializable> result = SchedulerResourceUtil.handlePDIScheduling( repo, params, pdiParams ); assertEquals( params.size() + 3, result.size() ); assertEquals( "transform", result.get( "transformation" ) ); assertEquals( "home/me", result.get( "directory" ) ); assertEquals( "pdiParamValue", ( (HashMap) result.get( ScheduleExportUtil.RUN_PARAMETERS_KEY ) ).get( "pdiParam" ) ); }
@Test public void testHandlePdiScheduling_requestParamsAreTransferred() throws Exception { HashMap<String, Serializable> params = new HashMap<>(); params.put( "test1", "value1" ); params.put( "test2", "value2" ); params.put( "test3", "value3" ); when( repo.getName() ).thenReturn( "job.kjb" ); when( repo.getPath() ).thenReturn( "/home/me/job.kjb" ); HashMap<String, Serializable> result = SchedulerResourceUtil.handlePDIScheduling( repo, params, null ); assertEquals( params.size() + 3, result.size() ); Map<String, String> resultPdiMap = (HashMap<String, String>) result.get( ScheduleExportUtil.RUN_PARAMETERS_KEY ); assertEquals( "value1", resultPdiMap.get( "test1" ) ); assertEquals( "value2", resultPdiMap.get( "test2" ) ); assertEquals( "value3", resultPdiMap.get( "test3" ) ); }
@Test public void testHandlePdiScheduling_job() throws Exception { HashMap<String, Serializable> params = new HashMap<>(); params.put( "test", "value" ); when( repo.getName() ).thenReturn( "job.kjb" ); when( repo.getPath() ).thenReturn( "/home/me/job.kjb" ); HashMap<String, String> pdiParams = new HashMap<>(); pdiParams.put( "pdiParam", "pdiParamValue" ); HashMap<String, Serializable> result = SchedulerResourceUtil.handlePDIScheduling( repo, params, pdiParams ); assertEquals( params.size() + 3, result.size() ); assertEquals( "job", result.get( "job" ) ); assertEquals( "home/me", result.get( "directory" ) ); assertEquals( "pdiParamValue", ( (HashMap) result.get( ScheduleExportUtil.RUN_PARAMETERS_KEY ) ).get( "pdiParam" ) ); }
@Test public void testHandlePdiScheduling_notPdiFile() throws Exception { HashMap<String, Serializable> params = new HashMap<>(); params.put( "test", "value" ); when( repo.getName() ).thenReturn( "readme.txt" ); HashMap<String, String> pdiParams = new HashMap<>(); pdiParams.put( "pdiParam", "pdiParamValue" ); HashMap<String, Serializable> result = SchedulerResourceUtil.handlePDIScheduling( repo, params, pdiParams ); assertEquals( params.size() + pdiParams.size(), result.size() ); }