List of usage examples for org.springframework.batch.core StepContribution incrementWriteCount
public void incrementWriteCount(int count)
From source file:es.fcs.batch.integration.chunk.MyRemoteChunkHandlerFactoryBean.java
/** * Update a StepContribution with all the data from a StepContributionSource. The filter and write conuts plus the * exit status will be updated to reflect the data in the source. * /* w w w. java 2 s .c om*/ * @param contribution the current contribution * @param stepContributionSource a source of StepContributions */ protected void updateStepContribution(StepContribution contribution, StepContributionSource stepContributionSource) { for (StepContribution result : stepContributionSource.getStepContributions()) { contribution.incrementFilterCount(result.getFilterCount()); contribution.incrementWriteCount(result.getWriteCount()); for (int i = 0; i < result.getProcessSkipCount(); i++) { contribution.incrementProcessSkipCount(); } for (int i = 0; i < result.getWriteSkipCount(); i++) { contribution.incrementWriteSkipCount(); } contribution.setExitStatus(contribution.getExitStatus().and(result.getExitStatus())); } }
From source file:org.cloudfoundry.identity.uaa.scim.job.AdminUsersTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { String authorities = StringUtils.collectionToCommaDelimitedString( AuthorityUtils.authorityListToSet(authority == UaaAuthority.UAA_USER ? UaaAuthority.USER_AUTHORITIES : UaaAuthority.ADMIN_AUTHORITIES)); for (String user : admins) { int updated = jdbcTemplate.update("update users set authorities=? where userName=?", authorities, user); contribution.incrementWriteCount(updated); }//from w w w. j av a 2 s . c o m return RepeatStatus.FINISHED; }
From source file:org.cloudfoundry.identity.uaa.scim.job.GenericSqlTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { if (sql == null) { return RepeatStatus.FINISHED; }//ww w .ja v a 2s. co m if (sql.toLowerCase().startsWith("select")) { List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); String result = list.toString(); chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("result", result.substring(0, Math.min(result.length(), 4096))); } else { int updated = jdbcTemplate.update(sql); contribution.incrementWriteCount(updated); } return RepeatStatus.FINISHED; }
From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTasklet.java
@Override public RepeatStatus execute(StepContribution sContribution, ChunkContext sChunkContext) throws Exception { Map<String, Object> aSourceParams = new HashMap<String, Object>(); aSourceParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, ((sChunkContext != null) && (sChunkContext.getStepContext() != null)) ? sChunkContext.getStepContext().getStepExecution() : null);//from w w w . ja va2 s . c o m Resource[] aSourceResources = sourceFactory.getResources(aSourceParams); if (LOGGER.isInfoEnabled()) { LOGGER.info("{} file(s) to split", aSourceResources.length); } for (Resource aSourceResource : aSourceResources) { if (sContribution != null) { sContribution.incrementReadCount(); } File aOriginFile = aSourceResource.getFile(); if (aOriginFile.exists()) { int aOutputCount = splitFile(aSourceResource, sChunkContext); if (sContribution != null) { sContribution.incrementWriteCount(aOutputCount); } } else { throw new SplitPDFException("File not found: " + aOriginFile); } } return RepeatStatus.FINISHED; }
From source file:fr.acxio.tools.agia.ftp.FTPUploadTasklet.java
@Override public RepeatStatus execute(StepContribution sContribution, ChunkContext sChunkContext) throws Exception { FTPClient aClient = ftpClientFactory.getFtpClient(); RegexFilenameFilter aFilter = new RegexFilenameFilter(); aFilter.setRegex(regexFilename);//w w w . j ava 2s . c o m try { File aLocalDir = new File(localBaseDir); if (LOGGER.isInfoEnabled()) { LOGGER.info("Listing : {} ({}) for upload to [{}]", localBaseDir, regexFilename, aClient.getRemoteAddress().toString()); } File[] aLocalFiles = aLocalDir.listFiles(aFilter); if (LOGGER.isInfoEnabled()) { LOGGER.info(" {} file(s) found", aLocalFiles.length); } for (File aLocalFile : aLocalFiles) { if (sContribution != null) { sContribution.incrementReadCount(); } URI aRemoteFile = new URI(remoteBaseDir).resolve(aLocalFile.getName()); InputStream aInputStream; aInputStream = new FileInputStream(aLocalFile); try { if (LOGGER.isInfoEnabled()) { LOGGER.info(" Uploading : {} => {}", aLocalFile.getAbsolutePath(), aRemoteFile.toASCIIString()); } aClient.storeFile(aRemoteFile.toASCIIString(), aInputStream); if (sContribution != null) { sContribution.incrementWriteCount(1); } } finally { aInputStream.close(); } } } finally { aClient.logout(); aClient.disconnect(); } return RepeatStatus.FINISHED; }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTasklet.java
protected void zipResource(Resource sSourceResource, ZipArchiveOutputStream sZipArchiveOutputStream, StepContribution sContribution, ChunkContext sChunkContext) throws IOException, ZipFilesException { // TODO : use a queue to reduce the callstack overhead if (sSourceResource.exists()) { File aSourceFile = sSourceResource.getFile(); String aSourcePath = aSourceFile.getCanonicalPath(); if (!aSourcePath.startsWith(sourceBaseDirectoryPath)) { throw new ZipFilesException( "Source file " + aSourcePath + " does not match base directory " + sourceBaseDirectoryPath); }/* ww w . jav a 2s . c o m*/ if (sContribution != null) { sContribution.incrementReadCount(); } String aZipEntryName = aSourcePath.substring(sourceBaseDirectoryPath.length() + 1); sZipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(aZipEntryName)); if (LOGGER.isInfoEnabled()) { LOGGER.info("Zipping {} to {}", sSourceResource.getFile().getCanonicalPath(), aZipEntryName); } if (aSourceFile.isFile()) { InputStream aInputStream = sSourceResource.getInputStream(); IOUtils.copy(aInputStream, sZipArchiveOutputStream); aInputStream.close(); sZipArchiveOutputStream.closeArchiveEntry(); } else { sZipArchiveOutputStream.closeArchiveEntry(); for (File aFile : aSourceFile .listFiles((FileFilter) (recursive ? TrueFileFilter.TRUE : FileFileFilter.FILE))) { zipResource(new FileSystemResource(aFile), sZipArchiveOutputStream, sContribution, sChunkContext); } } if (sContribution != null) { sContribution.incrementWriteCount(1); } } else if (LOGGER.isInfoEnabled()) { LOGGER.info("{} does not exist", sSourceResource.getFilename()); } }
From source file:fr.acxio.tools.agia.ftp.FTPDownloadTasklet.java
@Override public RepeatStatus execute(StepContribution sContribution, ChunkContext sChunkContext) throws Exception { FTPClient aClient = ftpClientFactory.getFtpClient(); RegexFilenameFilter aFilter = new RegexFilenameFilter(); aFilter.setRegex(regexFilename);// w ww.j av a 2s .c o m try { URI aRemoteBaseURI = new URI(remoteBaseDir); URI aRemoteBasePath = new URI(aRemoteBaseURI.toASCIIString() + SEPARATOR); if (LOGGER.isInfoEnabled()) { LOGGER.info("Listing : [{}] {} ({})", aClient.getRemoteAddress().toString(), aRemoteBaseURI.toASCIIString(), regexFilename); } FTPFile[] aRemoteFiles = aClient.listFiles(aRemoteBaseURI.toASCIIString(), aFilter); if (LOGGER.isInfoEnabled()) { LOGGER.info(" {} file(s) found", aRemoteFiles.length); } for (FTPFile aRemoteFile : aRemoteFiles) { if (sContribution != null) { sContribution.incrementReadCount(); } File aLocalFile = new File(localBaseDir, aRemoteFile.getName()); URI aRemoteTFile = aRemoteBasePath.resolve(aRemoteFile.getName()); FileOutputStream aOutputStream = new FileOutputStream(aLocalFile); try { if (LOGGER.isInfoEnabled()) { LOGGER.info(" Downloading : {} => {}", aRemoteTFile.toASCIIString(), aLocalFile.getAbsolutePath()); } aClient.retrieveFile(aRemoteTFile.toASCIIString(), aOutputStream); if (removeRemote) { if (LOGGER.isInfoEnabled()) { LOGGER.info(" Deleting : {}", aRemoteTFile.toASCIIString()); } aClient.deleteFile(aRemoteTFile.toASCIIString()); } if (sContribution != null) { sContribution.incrementWriteCount(1); } } finally { aOutputStream.close(); } } } finally { aClient.logout(); aClient.disconnect(); } return RepeatStatus.FINISHED; }
From source file:fr.acxio.tools.agia.tasks.FileCopyTasklet.java
public RepeatStatus execute(StepContribution sContribution, ChunkContext sChunkContext) throws ResourceCreationException, IOException, FileCopyException { File aOriginFile = origin.getFile(); if (aOriginFile.exists() && aOriginFile.isFile()) { if (!ignoreEmptyFile || (aOriginFile.length() > 0)) { if (sContribution != null) { sContribution.incrementReadCount(); }//from ww w . j a v a2 s . co m if (destinationFactory != null) { Map<String, Object> aDestinationParams = new HashMap<String, Object>(); aDestinationParams.put(ResourceFactoryConstants.PARAM_SOURCE, origin); aDestinationParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, ((sChunkContext != null) && (sChunkContext.getStepContext() != null)) ? sChunkContext.getStepContext().getStepExecution() : null); destination = destinationFactory.getResource(aDestinationParams); } File aDestinationFile = destination.getFile(); if (aDestinationFile.exists()) { if (forceReplace && aDestinationFile.isFile()) { if (!aDestinationFile.delete()) { throw new FileCopyException("Cannot remove: " + destination); } } else { throw new FileCopyException("Cannot replace: " + destination); } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Copying : {} => {}", aOriginFile.getAbsolutePath(), aDestinationFile.getAbsolutePath()); } FileUtils.copyFile(aOriginFile, aDestinationFile); if ((emptyOrigin || deleteOrigin) && !aOriginFile.delete()) { throw new FileCopyException("Cannot delete: " + origin); } if (emptyOrigin && !aOriginFile.createNewFile()) { throw new FileCopyException("Cannot create: " + origin); } if (sContribution != null) { sContribution.incrementWriteCount(1); } } else if (LOGGER.isInfoEnabled()) { LOGGER.info("Ignoring empty file : {}", aOriginFile.getAbsolutePath()); } } else { throw new FileCopyException("File not found: " + origin); } return RepeatStatus.FINISHED; }
From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java
protected List<String> doOperation(Resource aSourceResource, Map<String, Object> aDestinationParams, StepContribution sContribution, StepExecution sStepExecution) throws IOException, ResourceCreationException, FileOperationException { List<String> aDestinationFilesList = new ArrayList<String>(); File aOriginFile = aSourceResource.getFile(); if (aOriginFile.exists()) { if (sContribution != null) { sContribution.incrementReadCount(); }/*from www .j a v a 2 s. c o m*/ if (operation == Operation.REMOVE) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Deleting : {}", aOriginFile.getAbsolutePath()); } removeFile(aSourceResource); } else { Resource aDestination = getDefaultDestination(); if (destinationFactory != null) { aDestinationParams.put(ResourceFactoryConstants.PARAM_SOURCE, aSourceResource); aDestinationParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, sStepExecution); aDestination = destinationFactory.getResource(aDestinationParams); } if ((aDestination != null) && (aDestination.getFile() != null)) { File aDestinationFile = aDestination.getFile(); if (operation == Operation.COPY) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Copying : {} => {}", aOriginFile.getAbsolutePath(), aDestinationFile.getAbsolutePath()); } copyFile(aSourceResource, aDestination); } else if (operation == Operation.MOVE) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Moving : {} => {}", aOriginFile.getAbsolutePath(), aDestinationFile.getAbsolutePath()); } moveFile(aSourceResource, aDestination); } else { throw new FileOperationException("Unknown operation"); } } else { throw new FileOperationException("No destination specified"); } aDestinationFilesList.add(aDestination.getFile().getCanonicalPath()); } if (sContribution != null) { sContribution.incrementWriteCount(1); } } else { throw new FileOperationException("File not found: " + aOriginFile); } return aDestinationFilesList; }
From source file:org.springframework.batch.core.jsr.step.item.JsrChunkProcessor.java
/** * Responsible for the writing portion of the chunking loop. In this implementation, delegates to the * {{@link #doPersist(StepContribution, Chunk)}. * * @param contribution a {@link StepContribution} * @param chunk a {@link Chunk}// w ww .j av a2s .c o m * @throws Exception */ protected void persist(final StepContribution contribution, final Chunk<O> chunk) throws Exception { doPersist(contribution, chunk); contribution.incrementWriteCount(chunk.getItems().size()); }