Commit 9f5e98c4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when there is a problem with creating fir throw exception

parent ca1a6ad4
......@@ -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
......
......@@ -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;
......
......@@ -45,38 +45,30 @@
"litemol": "github:dsehnal/LiteMol#a5419c696faa84530dd93acd55b747cf8136902b"
},
"dependencies": {
"ProtVista": {
"version": "git://github.com/davidhoksza/protvista.git#4e4bb737ba1e183291505bd25f8bae2e651ce21e",
"dev": true,
"requires": {
"d3": "3.5.17",
"file-saver": "1.3.3",
"jquery": "2.2.4",
"jszip": "3.1.4",
"underscore": "1.8.3"
},
"dependencies": {
"jquery": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz",
"integrity": "sha1-LInWiJterFIqfuoywUUhVZxsvwI=",
"dev": true
}
}
},
"jquery": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz",
"integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==",
"dev": true
},
"litemol": {
"version": "github:dsehnal/LiteMol#a5419c696faa84530dd93acd55b747cf8136902b",
"dev": true,
"requires": {
"@types/react": "15.6.14",
"@types/react-dom": "15.5.7"
}
}
}
},
"ProtVista": {
"version": "git://github.com/davidhoksza/protvista.git#4e4bb737ba1e183291505bd25f8bae2e651ce21e",
"dev": true,
"requires": {
"d3": "3.5.17",
"file-saver": "1.3.3",
"jquery": "2.2.4",
"jszip": "3.1.4",
"underscore": "1.8.3"
},
"dependencies": {
"jquery": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz",
"integrity": "sha1-LInWiJterFIqfuoywUUhVZxsvwI=",
"dev": true
}
}
},
......@@ -2058,6 +2050,14 @@
"immediate": "3.0.6"
}
},
"litemol": {
"version": "github:dsehnal/LiteMol#a5419c696faa84530dd93acd55b747cf8136902b",
"dev": true,
"requires": {
"@types/react": "15.6.14",
"@types/react-dom": "15.5.7"
}
},
"lodash": {
"version": "4.17.4",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment