List of usage examples for org.springframework.batch.item ItemStreamException ItemStreamException
public ItemStreamException(Throwable nested)
From source file:uk.ac.ebi.intact.task.mitab.index.OntologyEnricherItemProcessor.java
public BinaryInteraction process(BinaryInteraction item) throws Exception { if (enricher == null) { if (ontologiesSolrUrl == null) { throw new ItemStreamException("ontologiesSolrUrl is null"); }//from w ww . j av a 2 s.c o m HttpSolrServer ontologiesSolrServer = createSolrServer(); OntologySearcher ontologySearcher = new OntologySearcher(ontologiesSolrServer); enricher = new OntologyCrossReferenceEnricher(ontologySearcher); } if (!processOnlyInteractors) { enricher.enrich(item); } else { if (item.getInteractorA() != null) { enricher.enrich(item.getInteractorA()); } if (item.getInteractorB() != null) { enricher.enrich(item.getInteractorB()); } } return item; }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReader.java
/** * Tries to extract all files in the archives and adds them as resources to * the normal MultiResourceItemReader. Overwrites the Comparator from * the super class to get it working with itemstreams. * * @param executionContext/* w w w . ja v a 2 s. c om*/ * @throws ItemStreamException */ @Override public void open(ExecutionContext executionContext) throws ItemStreamException { // really used with archives? if (archives != null) { // overwrite the comparator to use description // instead of filename, the itemStream can only // have that description this.setComparator(new Comparator<Resource>() { /** Compares resource descriptions. */ @Override public int compare(Resource r1, Resource r2) { return r1.getDescription().compareTo(r2.getDescription()); } }); // get the inputStreams from all files inside the archives zipFiles = new ZipFile[archives.length]; List<Resource> extractedResources = new ArrayList<Resource>(); try { for (int i = 0; i < archives.length; i++) { // find files inside the current zip resource zipFiles[i] = new ZipFile(archives[i].getFile()); extractFiles(zipFiles[i], extractedResources); } } catch (Exception ex) { throw new ItemStreamException(ex); } // propagate extracted resources this.setResources(extractedResources.toArray(new Resource[extractedResources.size()])); } super.open(executionContext); }
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReader.java
/** * Tries to extract all files in the archives and adds them as resources to * the normal MultiResourceItemReader. Overwrites the Comparator from * the super class to get it working with itemstreams. * * @param executionContext//from w ww . j a v a 2 s .c om * @throws ItemStreamException */ @Override public void open(ExecutionContext executionContext) throws ItemStreamException { // really used with archives? if (archives != null) { // overwrite the comparator to use description instead of filename this.setComparator(new Comparator<Resource>() { /** Compares resource descriptions. */ @Override public int compare(Resource r1, Resource r2) { return r1.getDescription().compareTo(r2.getDescription()); } }); // get the inputStreams from all files inside the archives wrappedArchives = new TFile[archives.length]; List<Resource> extractedResources = new ArrayList<Resource>(); try { for (int i = 0; i < archives.length; i++) { wrappedArchives[i] = new TFile(archives[i].getFile()); // iterate over each TFile and get the file list // extract only the files, ignore directories List<TFile> fileList = new ArrayList<TFile>(); runNestedDirs(wrappedArchives[i], fileList, filenameFilter); for (TFile tFile : fileList) { extractedResources .add(new InputStreamResource(new TFileInputStream(tFile), tFile.getName())); LOG.info("using extracted file:" + tFile.getName()); } } } catch (Exception ex) { throw new ItemStreamException(ex); } // propagate extracted resources this.setResources(extractedResources.toArray(new Resource[extractedResources.size()])); } super.open(executionContext); }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReader.java
/** * Calls super.close() and tries to close all used zip files. * * @throws ItemStreamException /*from w w w.j a v a2 s . com*/ */ @Override public void close() throws ItemStreamException { super.close(); // try to close all used zipfiles if (zipFiles != null) { for (int i = 0; i < zipFiles.length; i++) { try { zipFiles[i].close(); } catch (IOException ex) { throw new ItemStreamException(ex); } } } }
From source file:org.beanio.spring.BeanIOFlatFileItemWriter.java
public void update(ExecutionContext executionContext) throws ItemStreamException { if (stream == null) { throw new ItemStreamException("ItemStream not open or already closed."); }/* ww w .j a v a 2 s.c o m*/ if (saveState) { stream.update(executionContext); } }
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReader.java
/** * Calls super.close() and tries to unmount all used archive files afterwards. * * @throws ItemStreamException //from ww w . j av a 2s . c o m */ @Override public void close() throws ItemStreamException { super.close(); if (wrappedArchives != null) { for (int i = 0; i < wrappedArchives.length; i++) { // release all try { TFile.umount(wrappedArchives[i]); } catch (FsSyncException ex) { throw new ItemStreamException(ex); } } } }
From source file:fr.acxio.tools.agia.alfresco.AlfrescoNodeReader.java
@Override public void open(ExecutionContext sExecutionContext) throws ItemStreamException { String aFullPath = null;/* w w w .j av a2 s.c o m*/ try { baseURI = new URI(getAlfrescoService().getWebappAddress()).resolve(WEBDAV_PATH); aFullPath = getWebDavDirectoryURI(baseURI.getPath() + path).getPath(); } catch (URISyntaxException e) { throw new ItemStreamException(e); } currentDirPath = sExecutionContext.getString(CONTEXT_KEY_CURRENTPATH, aFullPath); Object aCurrentIndexes = sExecutionContext.get(CONTEXT_KEY_CURRENTINDEXES); if (aCurrentIndexes == null) { currentIndexes = new ArrayDeque<Integer>(); currentIndexes.addFirst(0); } else { Integer[] aArray = (Integer[]) aCurrentIndexes; currentIndexes = new ArrayDeque<Integer>(Arrays.asList(aArray)); } sardine = getAlfrescoService().startWebDavSession(); }
From source file:fr.acxio.tools.agia.file.ExtendedMultiResourceItemReader.java
/** * Figure out which resource to start with in case of restart, open the * delegate and restore delegate's position in the resource. */// w w w.j a v a 2 s . c o m public void open(ExecutionContext executionContext) throws ItemStreamException { Assert.isTrue((resources != null) || (resourcesFactory != null), "Resources and ResourcesFactory must not be both null"); try { if ((resources == null) && (resourcesFactory != null)) { Map<String, Object> aSourceParams = new HashMap<String, Object>(); aSourceParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, stepExecution); resources = resourcesFactory.getResources(aSourceParams); isResourcesSet = false; } } catch (ResourceCreationException e) { throw new ItemStreamException(e); } noInput = false; if ((resources == null) || (resources.length == 0)) { if (strict) { throw new IllegalStateException( "No resources to read. Set strict=false if this is not an error condition."); } else { LOGGER.warn("No resources to read. Set strict=true if this should be an error condition."); noInput = true; return; } } Arrays.sort(resources, comparator); if (executionContext.containsKey(executionContextUserSupport.getKey(RESOURCE_KEY))) { currentResource = executionContext.getInt(executionContextUserSupport.getKey(RESOURCE_KEY)); // context could have been saved before reading anything if (currentResource == -1) { currentResource = 0; } delegate.setResource(resources[currentResource]); delegate.open(executionContext); } else { currentResource = -1; } }
From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java
@Override public ExitStatus afterStep(StepExecution stepExecution) { if (!(stepExecution.getStatus() == BatchStatus.COMPLETED)) { return ExitStatus.EXECUTING; }/*from w w w .j av a 2 s .co m*/ long expecting = localState.getExpecting(); boolean timedOut; try { logger.debug("Waiting for results in step listener..."); timedOut = !waitForResults(); logger.debug("Finished waiting for results in step listener."); } catch (RuntimeException e) { logger.debug("Detected failure waiting for results in step listener.", e); stepExecution.setStatus(BatchStatus.FAILED); return ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": " + e.getMessage()); } finally { for (StepContribution contribution : getStepContributions()) { stepExecution.apply(contribution); } } if (timedOut) { stepExecution.setStatus(BatchStatus.FAILED); throw new ItemStreamException("Timed out waiting for back log at end of step"); } return ExitStatus.COMPLETED.addExitDescription("Waited for " + expecting + " results."); }