List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:net.opentsdb.contrib.tsquare.support.TsWebApplicationContextInitializer.java
private TsdbConfigPropertySource loadTsdbConfig(final ResourcePatternResolver resolver) throws IOException { Resource configResource = null; for (final String location : OVERRIDE_SEARCH_LOCATIONS) { final String fullLoc = String.format("%s%s", location, CONFIG_FILENAME); log.debug("Searching for TSDB config in {}", fullLoc); final Resource res = resolver.getResource(fullLoc); if (res != null && res.exists()) { configResource = res;//w w w .j a va 2 s .co m log.info("Found TSDB config file using {} ", fullLoc); break; } } if (configResource == null) { return new TsdbConfigPropertySource(PROPERTY_SOURCE_NAME, new Config(true)); } else if (configResource.isReadable()) { return new TsdbConfigPropertySource(PROPERTY_SOURCE_NAME, new Config(configResource.getFile().getAbsolutePath())); } else { throw new IllegalStateException("Unable to locate any TSDB config files!"); } }
From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTasklet.java
private int splitFile(Resource sSourceResource, ChunkContext sChunkContext) throws Exception { Map<String, Object> aDestinationParams = new HashMap<String, Object>(); aDestinationParams.put(ResourceFactoryConstants.PARAM_SOURCE, sSourceResource); aDestinationParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, ((sChunkContext != null) && (sChunkContext.getStepContext() != null)) ? sChunkContext.getStepContext().getStepExecution() : null);/*from w w w .ja va 2s. co m*/ Resource aDestination = null; int aResult = 0; PDDocumentContainer aDocumentContainer = null; try { aDocumentContainer = documentFactory.getDocument(sSourceResource.getFile()); List<PDDocument> documents = aDocumentContainer.getParts(); for (int i = 0; i < documents.size(); i++) { PDDocument doc = documents.get(i); // Output file factory int aTryCount = 10; do { aDestination = destinationFactory.getResource(aDestinationParams); aTryCount--; } while (!forceReplace && (aTryCount > 0) && (aDestination != null) && aDestination.exists()); if ((aTryCount == 0) && !forceReplace) { throw new SplitPDFException("Cannot create a new destination filename"); } if (aDestination != null) { if (aDestination.exists() && LOGGER.isWarnEnabled()) { LOGGER.warn("Replacing {}", aDestination.getFile().getAbsolutePath()); } writeDocument(doc, aDestination.getFile().getAbsolutePath()); doc.close(); } else { throw new SplitPDFException("No destination specified"); } aResult++; } } finally { if (aDocumentContainer != null) { aDocumentContainer.close(); } } return aResult; }
From source file:com.apdplat.platform.compass.APDPlatLocalCompassBean.java
/** * Sets an optional connection based on Spring <code>Resource</code> * abstraction. Will be used if none is set as part of other possible * configuration of Compass connection.//from w ww . j a v a2s . c om * <p/> * Will use <code>Resource#getFile</code> in order to get the absolute * path. */ public void setConnection(Resource connection) { //this.connection = connection; //compass //??? Resource resource = new FileSystemResource(IndexManager.getIndexDir()); this.connection = resource; try { log.info("apdplatcompass1 :? " + connection.getFile().getPath() + " ?? " + this.connection.getFile().getAbsolutePath() + ""); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.epam.catgenome.manager.ProjectManagerTest.java
@Test @Transactional(propagation = Propagation.REQUIRED) public void testLoadReferenceGenes() throws IOException { Resource resource = context.getResource("classpath:templates/genes_sorted.gtf"); FeatureIndexedFileRegistrationRequest geneRequest = new FeatureIndexedFileRegistrationRequest(); geneRequest.setReferenceId(referenceId); geneRequest.setName("genes"); geneRequest.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(geneRequest); referenceGenomeManager.updateReferenceGeneFileId(referenceId, geneFile.getId()); geneRequest.setName("genes1"); GeneFile geneFile1 = gffManager.registerGeneFile(geneRequest); Project project = new Project(); project.setName(TEST_PROJECT_NAME);// w w w . j a v a 2 s . co m project.setItems(Arrays.asList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())), new ProjectItem(geneFile1))); projectManager.saveProject(project); Project loadedProject = projectManager.loadProject(project.getId()); Reference projectReference = (Reference) loadedProject.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.REFERENCE) .map(ProjectItem::getBioDataItem).findFirst().get(); GeneFile projectGeneFile = (GeneFile) loadedProject.getItems().stream() .filter(i -> i.getBioDataItem().getId().equals(geneFile1.getId())).map(ProjectItem::getBioDataItem) .findFirst().get(); Assert.assertEquals(projectGeneFile.getPath(), projectReference.getGeneFile().getPath()); Assert.assertEquals(projectGeneFile.getFormat(), projectReference.getGeneFile().getFormat()); Assert.assertEquals(projectGeneFile.getType(), projectReference.getGeneFile().getType()); Assert.assertEquals(projectGeneFile.getReferenceId(), projectReference.getGeneFile().getReferenceId()); Assert.assertEquals(projectGeneFile.getCreatedBy(), projectReference.getGeneFile().getCreatedBy()); Assert.assertNotNull(projectReference.getGeneFile().getId()); Assert.assertNotNull(projectReference.getGeneFile().getName()); Assert.assertNotNull(projectReference.getGeneFile().getCreatedDate()); }
From source file:com.epam.catgenome.manager.ProjectManagerTest.java
@Test @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) public void testMoveProjectToParent() throws FeatureIndexException, InterruptedException, VcfReadingException, NoSuchAlgorithmException, IOException { Project parent = new Project(); parent.setName("testParent"); parent.setItems(Collections/*from ww w . j a va 2 s . co m*/ .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); parent = projectManager.saveProject(parent); Project child1 = new Project(); child1.setName("testChild1"); child1.setItems(Collections .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); child1 = projectManager.saveProject(child1, parent.getId()); parent = projectManager.loadProject(parent.getId()); Assert.assertFalse(parent.getNestedProjects().isEmpty()); Assert.assertEquals(child1.getId(), parent.getNestedProjects().get(0).getId()); Project child2 = new Project(); child2.setName("testChild2"); child2.setItems(Collections .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); child2 = projectManager.saveProject(child2); projectManager.moveProjectToParent(child2.getId(), parent.getId()); parent = projectManager.loadProject(parent.getId()); Assert.assertEquals(parent.getNestedProjects().size(), 2); Assert.assertEquals(child1.getId(), parent.getNestedProjects().get(0).getId()); Assert.assertEquals(child2.getId(), parent.getNestedProjects().get(1).getId()); parent = projectManager.loadProject(parent.getId()); Assert.assertEquals(parent.getNestedProjects().size(), 2); Assert.assertEquals(child1.getId(), parent.getNestedProjects().get(0).getId()); Assert.assertEquals(child2.getId(), parent.getNestedProjects().get(1).getId()); List<Project> topLevel = projectManager.loadTopLevelProjectsForCurrentUser(); Assert.assertEquals(1, topLevel.size()); // test loading tree Project child11 = new Project(); child11.setName("tesChild11"); child11.setItems(Collections .singletonList(new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); projectManager.saveProject(child11, child1.getId()); addVcfFileToProject(parent.getId(), "testVcf", TEST_VCF_FILE_PATH); Resource resource = context.getResource("classpath:templates/genes_sorted.gtf"); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setName("genes"); request.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(request); projectManager.addProjectItem(child1.getId(), geneFile.getBioDataItemId()); referenceGenomeManager.updateReferenceGeneFileId(referenceId, geneFile.getId()); projectManager.addProjectItem(parent.getId(), geneFile.getBioDataItemId()); topLevel = projectManager.loadProjectTree(null); Assert.assertFalse(topLevel.isEmpty()); Assert.assertFalse(topLevel.stream().anyMatch(p -> p.getNestedProjects().isEmpty())); Assert.assertTrue(topLevel.stream().anyMatch(p -> p.getItems().stream() .anyMatch(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.GENE))); Assert.assertFalse(topLevel.stream().anyMatch(p -> p.getItems().isEmpty())); Assert.assertFalse(topLevel.get(0).getNestedProjects().stream() .allMatch(p -> CollectionUtils.isEmpty(p.getNestedProjects()))); Assert.assertFalse( topLevel.get(0).getNestedProjects().stream().allMatch(p -> CollectionUtils.isEmpty(p.getItems()))); }
From source file:de.ingrid.admin.Config.java
public Properties getOverrideProperties() throws IOException { Resource override = getOverrideConfigResource(); InputStream is = new FileInputStream(override.getFile().getAbsolutePath()); Properties props = new Properties(); props.load(is);//from w w w . java 2s . c om return props; }
From source file:com.epam.catgenome.manager.GffManagerTest.java
@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testDeleteGeneWithIndex() throws IOException, InterruptedException, FeatureIndexException, NoSuchAlgorithmException, GeneReadingException { Resource resource = context.getResource(GENES_SORTED_GTF_PATH); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(resource.getFile().getAbsolutePath()); GeneFile geneFile = gffManager.registerGeneFile(request); Assert.assertNotNull(geneFile);/* w ww .ja v a 2s.c om*/ Assert.assertNotNull(geneFile.getId()); try { referenceGenomeManager.updateReferenceAnnotationFile(referenceId, geneFile.getBioDataItemId(), false); geneFileManager.deleteGeneFile(geneFile); //expected exception } catch (IllegalArgumentException e) { //remove file correctly as expected referenceGenomeManager.updateReferenceAnnotationFile(referenceId, geneFile.getBioDataItemId(), true); geneFileManager.deleteGeneFile(geneFile); } }