Skip to content
Snippets Groups Projects
Commit 629382de authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'mi-rna-cache-problem' into 'master'

Mi rna cache problem

See merge request piotr.gawron/minerva!263
parents 170c79e8 1989a19b
No related branches found
No related tags found
1 merge request!263Mi rna cache problem
Pipeline #
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment