diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/cache/BigFileCache.java b/annotation/src/main/java/lcsb/mapviewer/annotation/cache/BigFileCache.java index eacd0a8c15f8e16b99eab1b15eb33ccf65877b94..c81f8cf544c97a843ed3f687c01e9cc7bed56cbe 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/cache/BigFileCache.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/cache/BigFileCache.java @@ -32,7 +32,6 @@ import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.IProgressUpdater; -import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.model.cache.BigFileEntry; import lcsb.mapviewer.model.user.ConfigurationElementType; @@ -227,8 +226,9 @@ public class BigFileCache { * @return new {@link BigFileEntry} for given url * @throws URISyntaxException * thrown when url is invalid + * @throws IOException */ - private BigFileEntry createEntryForBigFile(String url) throws URISyntaxException { + private BigFileEntry createEntryForBigFile(String url) throws URISyntaxException, IOException { String localPath = configurationDao.getValueByType(ConfigurationElementType.BIG_FILE_STORAGE_DIR); BigFileEntry entry = new BigFileEntry(); entry.setDownloadDate(Calendar.getInstance()); @@ -237,7 +237,12 @@ public class BigFileCache { bigFileEntryDao.add(entry); localPath = entry.getLocalPath() + "/" + entry.getId() + "/"; - new File(Configuration.getWebAppDir() + localPath).mkdirs(); + File dirFile = new File(Configuration.getWebAppDir() + localPath); + + if (!dirFile.mkdirs()) { + throw new IOException("Cannot create directory: " + dirFile.getAbsolutePath()); + } + localPath += getFileName(url); entry.setLocalPath(localPath); @@ -461,6 +466,9 @@ public class BigFileCache { output.close(); return null; + } catch (Exception e) { + logger.error(e, e); + throw e; } finally { bigFileEntryDao.commit(); // close the transaction for this thread @@ -838,7 +846,6 @@ public class BigFileCache { File f = new File(Configuration.getWebAppDir() + entry.getLocalPath()); if (!f.exists()) { logger.warn("File is supposed to be cached but it's not there... " + sourceUrl); - bigFileEntryDao.delete(entry); return false; } } diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/MiRNAParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/MiRNAParser.java index 57b69010ec01f7dc63d4eb4975e1908cbc2ea1ff..c8e1642248c4d3ec155e24ed1bc21a9dd2e9759c 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/MiRNAParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/MiRNAParser.java @@ -133,7 +133,7 @@ public class MiRNAParser extends CachableInterface implements IExternalService { */ @Autowired private BigFileCache bigFileCache; - + @Autowired private ProjectDao projectDao; @@ -187,7 +187,7 @@ public class MiRNAParser extends CachableInterface implements IExternalService { } List<String> list = getSuggestedQueryListWithoutCache(project); result = StringUtils.join(list, "\n"); - } else { + } else { result = super.refreshCacheQuery(query); } } else { @@ -229,6 +229,9 @@ public class MiRNAParser extends CachableInterface implements IExternalService { if (!idsToFind.isEmpty()) { // logger.debug("MiRNAParser.getMiRNA Start:"+new Date()); List<MiRNA> fromDBList = this.getMiRnasByNameFromDb(idsToFind); + for (MiRNA mirna : fromDBList) { + super.setCacheValue(MI_RNA_PREFIX + mirna.getName().toLowerCase(), miRnaSerializer.objectToString(mirna)); + } // logger.debug("MiRNAParser.getMiRNA End:"+new Date()); // Add them to result miRNAs.addAll(fromDBList); diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/cache/BigFileCacheTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/cache/BigFileCacheTest.java index fef9e3780344364b4741803c8e97a8f7691894e0..3f2e61fb1f31aa679bdef5a5aae26d330a42bcdf 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/cache/BigFileCacheTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/cache/BigFileCacheTest.java @@ -32,6 +32,7 @@ import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.AnnotationTestFunctions; +import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidStateException; @@ -140,6 +141,23 @@ public class BigFileCacheTest extends AnnotationTestFunctions { } } + @Test + public void testSavingToInvalidDirectory() throws Exception { + try { + String url = httpUrl + "?invalid"; + Configuration.setWebAppDir("/"); + bigFileCache.downloadFile(url, false, null); + fail("Exception expected"); + } catch (IOException e) { + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + Configuration.setWebAppDir("./"); + } + } + private void waitForDownload() throws InterruptedException { while (bigFileCache.getDownloadThreadCount() > 0) { logger.debug("Waiting for download to finish"); @@ -457,9 +475,6 @@ public class BigFileCacheTest extends AnnotationTestFunctions { public void testRemoveFileThatDoesntExist() throws Exception { try { bigFileCache.removeFile("unexisting file"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - assertTrue(e.getMessage().contains("Cannot remove file. File wasn't downloaded")); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java b/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java index 772b913f5dd287625a68668d02290754498e5888..380de5359833e754b56d9c6edc6cbe49b9581631 100644 --- a/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java +++ b/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java @@ -6,6 +6,8 @@ import javax.annotation.PostConstruct; import javax.faces.bean.ApplicationScoped; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; +import javax.faces.context.FacesContext; +import javax.servlet.ServletContext; import org.apache.log4j.Logger; @@ -64,6 +66,10 @@ public class StartupBean { @PostConstruct public void init() { logger.debug("Application startup script starts"); + ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() + .getContext(); + Configuration.setWebAppDir(servletContext.getRealPath(".") + "/../"); + setInterruptedProjectsStatuses(); modifyXFrameDomain(); removeInterruptedReferenceGenomeDownloads();