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

when invalid file is passed proper errors is thrown by rest api

parent 6dce94b4
No related branches found
No related tags found
1 merge request!681Resolve "Gene mapping upload progress counter freezes at 0 until upload finishes"
......@@ -159,8 +159,9 @@ public abstract class AbstractReferenceGenomeConnector extends CachableInterface
* {@link #referenceGenome}
* @param name
* {@link #name}
* @throws ReferenceGenomeConnectorException
*/
private DownloadGeneMappingGenomeVersionTask(ReferenceGenome referenceGenome, String name, String url, IProgressUpdater updater) {
private DownloadGeneMappingGenomeVersionTask(ReferenceGenome referenceGenome, String name, String url, IProgressUpdater updater) throws ReferenceGenomeConnectorException {
this.url = url;
this.referenceGenome = referenceGenome;
this.name = name;
......@@ -173,36 +174,38 @@ public abstract class AbstractReferenceGenomeConnector extends CachableInterface
}
};
}
}
@Override
public Void call() throws Exception {
getDbUtils().createSessionForCurrentThread();
try {
ReferenceGenome referenceGenome = getReferenceGenomeDao().getById(this.referenceGenome.getId());
for (ReferenceGenomeGeneMapping mapping : referenceGenome.getGeneMapping()) {
if (mapping.getName().equals(name)) {
throw new ReferenceGenomeConnectorException("Gene mapping with name: \"" + name + "\" already exists.");
}
}
if (!url.toLowerCase().endsWith("bb")) {
throw new ReferenceGenomeConnectorException("Only big bed format files are supported but found: \"" + url + "\".");
}
ReferenceGenome referenceGenome = getReferenceGenomeDao().getById(this.referenceGenome.getId());
for (ReferenceGenomeGeneMapping mapping : referenceGenome.getGeneMapping()) {
if (mapping.getName().equals(name)) {
throw new ReferenceGenomeConnectorException("Gene mapping with name: \"" + name + "\" already exists.");
}
}
if (!url.toLowerCase().endsWith("bb")) {
throw new ReferenceGenomeConnectorException("Only big bed format files are supported but found: \"" + url + "\".");
}
ReferenceGenomeGeneMapping mapping = new ReferenceGenomeGeneMapping();
mapping.setReferenceGenome(referenceGenome);
mapping.setName(name);
mapping.setSourceUrl(url);
referenceGenome.addReferenceGenomeGeneMapping(mapping);
getReferenceGenomeGeneMappingDao().add(mapping);
getReferenceGenomeGeneMappingDao().flush();
getReferenceGenomeDao().update(referenceGenome);
getReferenceGenomeDao().commit();
getReferenceGenomeDao().flush();
logger.debug(0);
getBigFileCache().downloadFile(url, false, new IProgressUpdater() {
@Override
public void setProgress(double progress) {
logger.debug(progress);
if (updater != null) {
updater.setProgress(progress);
}
// we have to get the object because it's in separate thred
// we have to get the object because it's in separate thread
ReferenceGenomeGeneMapping temp = getReferenceGenomeGeneMappingDao().getById(mapping.getId());
temp.setDownloadProgress(progress);
getReferenceGenomeGeneMappingDao().update(temp);
......
......@@ -244,7 +244,7 @@ public class ReferenceGenomeRestImpl extends BaseRestImpl {
try {
referenceGenomeService.addReferenceGenome(genomeType, organism, version, url);
return okStatus();
} catch(ReferenceGenomeExistsException e) {
} catch (ReferenceGenomeExistsException e) {
throw new ObjectExistsException(e);
} catch (URISyntaxException e) {
throw new QueryException("Problem wih given uri", e);
......@@ -262,6 +262,10 @@ public class ReferenceGenomeRestImpl extends BaseRestImpl {
ReferenceGenome genome = referenceGenomeService.getReferenceGenomeById(id, token);
String name = getFirstValue(formData.get("name"));
String url = getFirstValue(formData.get("url"));
if (!url.toLowerCase().endsWith("bb")) {
throw new QueryException("Only big bed format files are supported but found: \"" + url + "\".");
}
referenceGenomeService.addReferenceGenomeGeneMapping(genome, name, url);
return okStatus();
} catch (URISyntaxException e) {
......
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