List of usage examples for org.springframework.batch.core StepExecution getJobParameters
public JobParameters getJobParameters()
From source file:biz.c24.io.spring.batch.reader.C24BatchItemReaderTests.java
private StepExecution getStepExecution() throws IOException { JobParameters jobParams = mock(JobParameters.class); StepExecution stepExecution = mock(StepExecution.class); when(stepExecution.getJobParameters()).thenReturn(jobParams); return stepExecution; }
From source file:biz.c24.batchdemo.writers.SplittingFileWriterSource.java
@Override public void initialise(StepExecution stepExecution) { // Extract the name of the file we're supposed to be writing to String fileName = stepExecution.getJobParameters().getString("output.file"); // Remove any leading file:// if it exists if (fileName.startsWith("file://")) { fileName = fileName.substring("file://".length()); }// w w w.jav a2 s . c o m try { outputFile = new FileWriter(fileName); } catch (IOException ioEx) { throw new RuntimeException(ioEx); } }
From source file:biz.c24.io.spring.batch.writer.source.FileWriterSource.java
@Override public void initialise(StepExecution stepExecution) { // Extract the name of the file we're supposed to be writing to String fileName = resource != null ? resource.getPath() : stepExecution.getJobParameters().getString("output.file"); // Remove any leading file:// if it exists if (fileName.startsWith("file://")) { fileName = fileName.substring("file://".length()); }//from ww w . j av a 2 s . c o m try { outputFile = new OutputStreamWriter(new FileOutputStream(fileName), getEncoding()); } catch (IOException ioEx) { throw new RuntimeException(ioEx); } }
From source file:biz.c24.io.spring.batch.writer.C24ItemWriterTests.java
/** * Mock up the necessary job parameters/*from w w w . j a v a2 s. c o m*/ * * @param outputFileName The filename we want the ItemWriter to write to */ private StepExecution getStepExecution(String outputFileName) throws IOException { JobParameters jobParams = mock(JobParameters.class); when(jobParams.getString("output.file")).thenReturn(outputFileName); StepExecution stepExecution = mock(StepExecution.class); when(stepExecution.getJobParameters()).thenReturn(jobParams); return stepExecution; }
From source file:biz.c24.io.spring.batch.writer.source.ZipFileWriterSource.java
@Override public void initialise(StepExecution stepExecution) { // Extract the name of the file we're supposed to be writing to String fileName = resource != null ? resource.getPath() : stepExecution.getJobParameters().getString("output.file"); // Remove any leading file:// if it exists if (fileName.startsWith("file://")) { fileName = fileName.substring("file://".length()); }/* w w w .jav a2s . c o m*/ // Now create the name of our zipEntry // Strip off the leading path and the suffix (ie the zip extension) int tailStarts = fileName.lastIndexOf(pathSepString) + 1; int tailEnds = fileName.lastIndexOf('.'); if (tailStarts < 0) { tailStarts = 0; } if (tailEnds < 0) { tailEnds = fileName.length(); } String tailName = fileName.substring(tailStarts, tailEnds); try { FileOutputStream fileStream = new FileOutputStream(fileName); zipStream = new ZipOutputStream(fileStream); zipStream.putNextEntry(new ZipEntry(tailName)); outputWriter = new OutputStreamWriter(zipStream, getEncoding()); } catch (IOException ioEx) { throw new RuntimeException(ioEx); } }
From source file:uk.ac.ebi.intact.editor.batch.admin.MailNotifierStepExecutionListener.java
public void beforeStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[Editor_import] Started step: " + stepExecution.getStepName() + ""); message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(stepExecution.getJobParameters().getString("email.recipient")); try {// w w w . java 2 s . c o m mailSender.send(message); } catch (MailException e) { log.error("Impossible to send e-mail", e); } }
From source file:org.obiba.onyx.core.etl.participant.impl.AppointmentListUpdateListener.java
/** * Called after the step of the AppointmentUpdateList job. Persists the job resuming data. * @param stepExecution// www . j ava 2s . c o m * @return */ @AfterStep public ExitStatus afterUpdateCompleted(StepExecution stepExecution) { ExitStatus status = stepExecution.getExitStatus(); if (status.getExitCode().equals("COMPLETED")) { AppointmentUpdateStats appointmentUpdateStats = new AppointmentUpdateStats( stepExecution.getJobParameters().getDate("date"), getAddedParticipants(), getUpdatedParticipants(), getIgnoredParticipants(), getUnreadableParticipants()); appointmentUpdateStats.setFileName(stepExecution.getExecutionContext().get("fileName").toString()); appointmentManagementService.saveAppointmentUpdateStats(appointmentUpdateStats); } AppointmentUpdateLog.addErrorLog(stepExecution.getExecutionContext(), new AppointmentUpdateLog(new Date(), AppointmentUpdateLog.Level.INFO, "End updating appointments")); return status; }
From source file:uk.ac.ebi.intact.editor.batch.admin.MailNotifierStepExecutionListener.java
public ExitStatus afterStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[Editor_import] Finished step: " + stepExecution.getStepName() + " Exit status: " + stepExecution.getExitStatus().getExitCode()); message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext()); message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(stepExecution.getJobParameters().getString("email.recipient")); try {/* www . j av a 2 s .c om*/ mailSender.send(message); } catch (MailException e) { log.error("Impossible to send e-mail", e); } return stepExecution.getExitStatus(); }
From source file:biz.c24.io.spring.batch.reader.source.FileSource.java
public void initialise(StepExecution stepExecution) { try {/*from w ww . j a v a 2s.co m*/ // Get an InputStream and a name for where we're reading from // Use the Resource if supplied InputStream source = null; if (resource != null) { name = resource.getFilename(); source = resource.getInputStream(); } else { // If no resource supplied, fallback to a Job parameter called input.file name = stepExecution.getJobParameters().getString("input.file"); // Remove any leading file:// if it exists if (name.startsWith("file://")) { name = name.substring("file://".length()); } source = new FileInputStream(name); } // Prime the reader LOG.debug("Opening {} with encoding {}", name, getEncoding()); reader = new SplittingReader(new InputStreamReader(source, getEncoding()), consistentLineTerminators); if (skipLines > 0) { for (int i = 0; i < skipLines && reader.ready(); i++) { // Skip the line reader.readLine(); } } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:biz.c24.io.spring.batch.reader.source.ZipFileSource.java
public void initialise(StepExecution stepExecution) { try {//from www. ja va 2 s.c o m // Get an File and a name for where we're reading from // Use the Resource if supplied File source = null; if (resource != null) { name = resource.getDescription(); source = resource.getFile(); } else { // If no resource supplied, fallback to a Job parameter called input.file name = stepExecution.getJobParameters().getString("input.file"); // Remove any leading file:// if it exists if (name.startsWith("file://")) { name = name.substring("file://".length()); } source = new File(name); } zipFile = new ZipFile(source); zipEntries = zipFile.entries(); ZipEntry entry = getNextZipEntry(); if (entry != null) { // Prime the reader reader = getReader(entry); } // If we have a large number of ZipEntries and the first one looks relatively small, advise // callers to use a thread per reader if (entry != null && zipFile.size() > 20 && (entry.getSize() == -1 || entry.getSize() < 100000)) { useMultipleThreadsPerReader = false; } } catch (IOException e) { throw new RuntimeException(e); } }