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

Merge branch '237-uploading-zip-file-from-mac' into 'master'

Resolve "uploading zip file from MAC"

Closes #237

See merge request piotr.gawron/minerva!190
parents 4283ee4b 1331ea0a
No related branches found
No related tags found
1 merge request!190Resolve "uploading zip file from MAC"
Pipeline #
......@@ -114,6 +114,8 @@ public class ComplexZipConverter {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
ZipEntryFile zef = params.getEntry(entry.getName());
logger.debug(entry.getName());
logger.debug(zef);
if (zef instanceof ModelZipEntryFile) {
ModelZipEntryFile modelEntryFile = (ModelZipEntryFile) zef;
InputStream is = zipFile.getInputStream(entry);
......@@ -133,7 +135,7 @@ public class ComplexZipConverter {
// imageEntries.add((ImageZipEntryFile) zef);
} else if (zef instanceof DataMiningZipEntryFile) {
dataMiningSets.add(dataMiningZipEntryToDataMiningSet(zipFile, entry, (DataMiningZipEntryFile) zef));
} else {
} else if (!isIgnoredFile(entry.getName())) {
throw new NotImplementedException("Unknwon entry type: " + zef.getClass());
}
}
......@@ -181,6 +183,19 @@ public class ComplexZipConverter {
}
}
protected boolean isIgnoredFile(String name) {
if (name == null) {
return true;
} else if (name.isEmpty()) {
return true;
} else if (name.startsWith(".DS_Store")) {
return true;
} else if (name.startsWith("__MACOSX")) {
return true;
}
return false;
}
/**
* Process a single reaction in mapping file (transfomring reaction into
* connection between submodels).
......@@ -278,13 +293,12 @@ public class ComplexZipConverter {
String root = null;
String mapping = null;
logger.debug(params.getFilenames());
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
String name = entry.getName();
ZipEntryFile zef = params.getEntry(name);
if (zef == null) {
if (zef == null && !isIgnoredFile(name)) {
throw new InvalidArgumentException("No information found in params about file: " + name);
}
if (zef instanceof ModelZipEntryFile) {
......
......@@ -159,7 +159,7 @@ AddProjectDialog.prototype.createGeneralTabContent = function () {
name: "project-file"
});
fileInput.addEventListener("change", function () {
return self.callListeners("onFileUpload", fileInput.files[0]);
return self.callListeners("onFileUpload", fileInput.files[0]).then(null, GuiConnector.alert);
}, false);
self.addListener("onFileUpload", function (e) {
var file = e.arg;
......@@ -936,6 +936,8 @@ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) {
data.description = "";
}
});
} else if (this.isIgnoredZipEntry(filename)) {
type = undefined;
} else if (filename.indexOf("\\") === -1 && filename.indexOf("/") === -1) {
type = "MAP";
data.root = true;
......@@ -972,7 +974,11 @@ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) {
}
return processingPromise.then(function () {
return new ZipEntry({filename: filename, type: type, data: data});
if (type !== undefined) {
return new ZipEntry({filename: filename, type: type, data: data});
} else {
return null;
}
});
};
......@@ -986,6 +992,15 @@ AddProjectDialog.prototype.setZipEntries = function (entries) {
};
AddProjectDialog.prototype.isIgnoredZipEntry = function (filename) {
var lowercaseString = filename.toLowerCase();
if (lowercaseString.startsWith("__macosx") || lowercaseString.startsWith(".ds_store")) {
return true;
} else {
return false;
}
};
AddProjectDialog.prototype.getEntryByFilename = function (filename) {
var self = this;
var entries = self.getZipEntries();
......
......@@ -172,7 +172,7 @@ describe('AddProjectDialog', function () {
dialog.setProjectId("(invalid id)");
return dialog.checkValidity().then(function () {
assert.notOk("Expected validity to reject");
}).catch(function(error){
}).catch(function (error) {
assert.ok(error instanceof ValidationError);
});
}).then().finally(function () {
......@@ -198,4 +198,38 @@ describe('AddProjectDialog', function () {
});
});
describe('isIgnoredZipEntry', function () {
it('valid entry', function () {
var dialog = new AddProjectDialog({
element: testDiv,
customMap: null
});
assert.notOk(dialog.isIgnoredZipEntry("images/a.png"));
assert.notOk(dialog.isIgnoredZipEntry("main.xml"));
return dialog.destroy();
});
it('invalid MAC OS entry', function () {
var dialog = new AddProjectDialog({
element: testDiv,
customMap: null
});
// noinspection SpellCheckingInspection
assert.ok(dialog.isIgnoredZipEntry("__MACOSX/.desc"));
assert.ok(dialog.isIgnoredZipEntry("__macosx/.desc"));
return dialog.destroy();
});
it('invalid old MAC OS entry', function () {
var dialog = new AddProjectDialog({
element: testDiv,
customMap: null
});
assert.ok(dialog.isIgnoredZipEntry(".DS_Store/.desc"));
assert.ok(dialog.isIgnoredZipEntry(".ds_store/.desc"));
return dialog.destroy();
});
});
});
......@@ -616,4 +616,6 @@ public interface Model {
void addFunction(SbmlFunction sbmlFunction);
SbmlArgument getFunctionById(String id);
void removeReactions(Collection<Reaction> reactions);
}
......@@ -734,4 +734,13 @@ public class ModelFullIndexed implements Model {
}
return null;
}
@Override
public void removeReactions(Collection<Reaction> reactions) {
Set<Reaction> reactionsToRemove = new HashSet<>();
reactionsToRemove.addAll(reactions);
for (Reaction reaction : reactionsToRemove) {
removeReaction(reaction);
}
}
}
......@@ -40,195 +40,197 @@ import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.overlay.ChebiTreeRow;
public class FullAliasViewFactoryTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(FullAliasViewFactoryTest.class);
@Autowired
FullAliasViewFactory fullAliasViewFactory;
@Autowired
private ChebiAnnotator backend;
private Species alias;
private Species alias2;
private Point2D midPoint;
private Reaction reaction;
private Species alias3;
private Model model;
private Compartment compartmentAlias;
@Before
public void setUp() throws Exception {
model = new ModelFullIndexed(null);
model.setWidth(20010);
model.setHeight(20010);
model.setTileSize(256);
model.setZoomLevels(7);
model.addLayout(new Layout());
model.getModelData().setId(-12);
alias = new GenericProtein("AL1");
alias.setName("blablabla");
alias.setNotes("nottttttes");
alias.setX(10.0);
alias.setY(12.0);
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.WIKIPEDIA, "144352"));
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "43345"));
model.addElement(alias);
alias2 = new GenericProtein("AL2");
alias2.setName("blablabla2");
alias2.setX(100.0);
alias2.setY(120.0);
model.addElement(alias2);
midPoint = new Point2D.Double(30, 100);
reaction = new Reaction();
Reactant reactant = new Reactant(alias);
reactant.setLine(new PolylineData(alias.getCenter(), midPoint));
reaction.addReactant(reactant);
Product product = new Product(alias2);
product.setLine(new PolylineData(alias2.getCenter(), midPoint));
reaction.addProduct(product);
model.addReaction(reaction);
alias3 = new GenericProtein("AL3");
alias3.setName("blablabla3");
alias3.setX(200.0);
alias3.setY(120.0);
model.addElement(alias3);
reaction = new NegativeInfluenceReaction(reaction);
reaction.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CAS, "cc"));
model.addReaction(reaction);
compartmentAlias = new Compartment("AL4");
compartmentAlias.setX(10);
compartmentAlias.setY(10);
compartmentAlias.setWidth(10);
compartmentAlias.setHeight(10);
model.addElement(compartmentAlias);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() {
try {
Element alias = new GenericProtein("id");
alias.setName("12");
alias.setModel(new ModelFullIndexed(null));
FullAliasView object = fullAliasViewFactory.create(alias);
String gson = fullAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay2() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias2);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetNotes() throws Exception {
try {
Model model = getModelForFile("testFiles/protein_with_modification.xml", true);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa1");
FullAliasView marker = fullAliasViewFactory.create(alias);
List<?> list = (List<?>) marker.getOther("posttranslationalModifications");
assertNotNull(list);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateChebiTree() throws Exception {
try {
Chebi chebi = backend.getChebiElementForChebiId(new MiriamData(MiriamType.CHEBI, "CHEBI:15377"));
TreeNode root = fullAliasViewFactory.createTreeForChebi(chebi);
Set<String> el = new HashSet<String>();
assertNotNull(root);
Queue<TreeNode> elements = new LinkedList<TreeNode>();
elements.add(root);
while (!elements.isEmpty()) {
TreeNode node = elements.peek();
elements.remove();
el.add(((ChebiTreeRow) node.getData()).getName());
for (TreeNode child : node.getChildren()) {
elements.add(child);
}
}
assertTrue(el.size() > 3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotationsInConversionForChebiTree() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", false);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa4");
assertNotNull(alias);
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result.getOther("chebiTree"));
alias = (Species) model.getElementByElementId("sa3");
result = fullAliasViewFactory.create(alias);
assertNull(result.getOther("chebiTree"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Logger logger = Logger.getLogger(FullAliasViewFactoryTest.class);
@Autowired
FullAliasViewFactory fullAliasViewFactory;
@Autowired
private ChebiAnnotator backend;
private Species alias;
private Species alias2;
private Point2D midPoint;
private Reaction reaction;
private Species alias3;
private Model model;
private Compartment compartmentAlias;
@Before
public void setUp() throws Exception {
model = new ModelFullIndexed(null);
model.setWidth(20010);
model.setHeight(20010);
model.setTileSize(256);
model.setZoomLevels(7);
model.addLayout(new Layout());
model.getModelData().setId(-12);
alias = new GenericProtein("AL1");
alias.setName("blablabla");
alias.setNotes("nottttttes");
alias.setX(10.0);
alias.setY(12.0);
alias.getMiriamData()
.add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.WIKIPEDIA, "144352"));
alias.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.PUBMED, "43345"));
model.addElement(alias);
alias2 = new GenericProtein("AL2");
alias2.setName("blablabla2");
alias2.setX(100.0);
alias2.setY(120.0);
model.addElement(alias2);
midPoint = new Point2D.Double(30, 100);
reaction = new Reaction("re1");
Reactant reactant = new Reactant(alias);
reactant.setLine(new PolylineData(alias.getCenter(), midPoint));
reaction.addReactant(reactant);
Product product = new Product(alias2);
product.setLine(new PolylineData(alias2.getCenter(), midPoint));
reaction.addProduct(product);
model.addReaction(reaction);
alias3 = new GenericProtein("AL3");
alias3.setName("blablabla3");
alias3.setX(200.0);
alias3.setY(120.0);
model.addElement(alias3);
reaction = new NegativeInfluenceReaction(reaction);
reaction.setIdReaction("re2");
reaction.getMiriamData().add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CAS, "cc"));
model.addReaction(reaction);
compartmentAlias = new Compartment("AL4");
compartmentAlias.setX(10);
compartmentAlias.setY(10);
compartmentAlias.setWidth(10);
compartmentAlias.setHeight(10);
model.addElement(compartmentAlias);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateGson() {
try {
Element alias = new GenericProtein("id");
alias.setName("12");
alias.setModel(new ModelFullIndexed(null));
FullAliasView object = fullAliasViewFactory.create(alias);
String gson = fullAliasViewFactory.createGson(object);
assertNotNull(gson);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasOverlay2() throws Exception {
try {
FullAliasView result = fullAliasViewFactory.create(alias2);
assertNotNull(result);
assertEquals(model.getId(), result.getModelId());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetNotes() throws Exception {
try {
Model model = getModelForFile("testFiles/protein_with_modification.xml", true);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa1");
FullAliasView marker = fullAliasViewFactory.create(alias);
List<?> list = (List<?>) marker.getOther("posttranslationalModifications");
assertNotNull(list);
assertEquals(2, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateChebiTree() throws Exception {
try {
Chebi chebi = backend.getChebiElementForChebiId(new MiriamData(MiriamType.CHEBI, "CHEBI:15377"));
TreeNode root = fullAliasViewFactory.createTreeForChebi(chebi);
Set<String> el = new HashSet<String>();
assertNotNull(root);
Queue<TreeNode> elements = new LinkedList<TreeNode>();
elements.add(root);
while (!elements.isEmpty()) {
TreeNode node = elements.peek();
elements.remove();
el.add(((ChebiTreeRow) node.getData()).getName());
for (TreeNode child : node.getChildren()) {
elements.add(child);
}
}
assertTrue(el.size() > 3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotationsInConversionForChebiTree() throws Exception {
try {
Model model = getModelForFile("testFiles/graph_path_example3.xml", false);
model.setTileSize(256);
Species alias = (Species) model.getElementByElementId("sa4");
assertNotNull(alias);
FullAliasView result = fullAliasViewFactory.create(alias);
assertNotNull(result.getOther("chebiTree"));
alias = (Species) model.getElementByElementId("sa3");
result = fullAliasViewFactory.create(alias);
assertNull(result.getOther("chebiTree"));
} catch (Exception e) {
e.printStackTrace();
throw 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