SolutionImportHandler implements IPlatformImportHandler { protected void importSchedules( List<JobScheduleRequest> scheduleList ) throws PlatformImportException { if ( CollectionUtils.isNotEmpty( scheduleList ) ) { SchedulerResource schedulerResource = new SchedulerResource(); schedulerResource.pause(); for ( JobScheduleRequest jobScheduleRequest : scheduleList ) { boolean jobExists = false; List<Job> jobs = getAllJobs( schedulerResource ); if ( jobs != null ) { Map<String, Serializable> mapParamsRequest = new HashMap<>(); for ( JobScheduleParam paramRequest : jobScheduleRequest.getJobParameters() ) { mapParamsRequest.put( paramRequest.getName(), paramRequest.getValue() ); } for ( Job job : jobs ) { if ( ( mapParamsRequest.get( RESERVEDMAPKEY_LINEAGE_ID ) != null ) && ( mapParamsRequest.get( RESERVEDMAPKEY_LINEAGE_ID ) .equals( job.getJobParams().get( RESERVEDMAPKEY_LINEAGE_ID ) ) ) ) { jobExists = true; } if ( overwriteFile && jobExists ) { JobRequest jobRequest = new JobRequest(); jobRequest.setJobId( job.getJobId() ); schedulerResource.removeJob( jobRequest ); jobExists = false; break; } } } if ( !jobExists ) { try { Response response = createSchedulerJob( schedulerResource, jobScheduleRequest ); if ( response.getStatus() == Response.Status.OK.getStatusCode() ) { if ( response.getEntity() != null ) { ImportSession.getSession().addImportedScheduleJobId( response.getEntity().toString() ); } } } catch ( Exception e ) { if ( jobScheduleRequest.getInputFile().contains( " " ) || jobScheduleRequest.getOutputFile() .contains( " " ) ) { getLogger().info( Messages.getInstance() .getString( "SolutionImportHandler.SchedulesWithSpaces", jobScheduleRequest.getInputFile() ) ); File inFile = new File( jobScheduleRequest.getInputFile() ); File outFile = new File( jobScheduleRequest.getOutputFile() ); String inputFileName = inFile.getParent() + RepositoryFile.SEPARATOR + inFile.getName().replace( " ", "_" ); String outputFileName = outFile.getParent() + RepositoryFile.SEPARATOR + outFile.getName().replace( " ", "_" ); jobScheduleRequest.setInputFile( inputFileName ); jobScheduleRequest.setOutputFile( outputFileName ); try { if ( !File.separator.equals( RepositoryFile.SEPARATOR ) ) { jobScheduleRequest.setInputFile( inputFileName.replace( File.separator, RepositoryFile.SEPARATOR ) ); jobScheduleRequest .setOutputFile( outputFileName.replace( File.separator, RepositoryFile.SEPARATOR ) ); } Response response = createSchedulerJob( schedulerResource, jobScheduleRequest ); if ( response.getStatus() == Response.Status.OK.getStatusCode() ) { if ( response.getEntity() != null ) { ImportSession.getSession().addImportedScheduleJobId( response.getEntity().toString() ); } } } catch ( Exception ex ) { getLogger().error( Messages.getInstance() .getString( "SolutionImportHandler.ERROR_0001_ERROR_CREATING_SCHEDULE", e.getMessage() ), ex ); } } else { getLogger().error( Messages.getInstance() .getString( "SolutionImportHandler.ERROR_0001_ERROR_CREATING_SCHEDULE", e.getMessage() ) ); } } } else { getLogger().info( Messages.getInstance() .getString( "DefaultImportHandler.ERROR_0009_OVERWRITE_CONTENT", jobScheduleRequest.toString() ) ); } } schedulerResource.start(); } } SolutionImportHandler( List<IMimeType> mimeTypes ); ImportSession getImportSession(); Log getLogger(); @Override void importFile( IPlatformImportBundle bundle ); @Override List<IMimeType> getMimeTypes(); IPlatformImportBundle build( RepositoryFileImportBundle.Builder builder ); Response createSchedulerJob( SchedulerResource scheduler, JobScheduleRequest jobScheduleRequest ); boolean isOverwriteFile(); void setOverwriteFile( boolean overwriteFile );  }
@Test public void testImportSchedules() throws Exception { List<JobScheduleRequest> schedules = new ArrayList<>(); JobScheduleRequest scheduleRequest = Mockito.spy( new JobScheduleRequest() ); schedules.add( scheduleRequest ); Response response = Mockito.mock( Response.class ); Mockito.when( response.getStatus() ).thenReturn( Response.Status.OK.getStatusCode() ); Mockito.when( response.getEntity() ).thenReturn( "job id" ); Mockito.doReturn( response ).when( importHandler ) .createSchedulerJob( Mockito.any( SchedulerResource.class ), Mockito.eq( scheduleRequest ) ); mockSchedulerPause(); importHandler.importSchedules( schedules ); Mockito.verify( importHandler ) .createSchedulerJob( Mockito.any( SchedulerResource.class ), Mockito.eq( scheduleRequest ) ); Assert.assertEquals( 1, ImportSession.getSession().getImportedScheduleJobIds().size() ); }