Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
f47be7d8
Commit
f47be7d8
authored
Sep 29, 2017
by
Piotr Gawron
Browse files
frontend for add zip projects
parent
d074a0b8
Changes
38
Hide whitespace changes
Inline
Side-by-side
.idea/modules.xml
View file @
f47be7d8
...
...
@@ -2,7 +2,28 @@
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/CellDesigner-plugin/CellDesigner-plugin.iml"
filepath=
"$PROJECT_DIR$/CellDesigner-plugin/CellDesigner-plugin.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/annotation/annotation.iml"
filepath=
"$PROJECT_DIR$/annotation/annotation.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/commons/commons.iml"
filepath=
"$PROJECT_DIR$/commons/commons.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/comparison/comparison.iml"
filepath=
"$PROJECT_DIR$/comparison/comparison.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/console/console.iml"
filepath=
"$PROJECT_DIR$/console/console.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/converter/converter.iml"
filepath=
"$PROJECT_DIR$/converter/converter.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/converter-CellDesigner/converter-CellDesigner.iml"
filepath=
"$PROJECT_DIR$/converter-CellDesigner/converter-CellDesigner.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/converter-SBGNML/converter-SBGNML.iml"
filepath=
"$PROJECT_DIR$/converter-SBGNML/converter-SBGNML.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/converter-graphics/converter-graphics.iml"
filepath=
"$PROJECT_DIR$/converter-graphics/converter-graphics.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/editor/editor.iml"
filepath=
"$PROJECT_DIR$/editor/editor.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/frontend-js/frontend-js.iml"
filepath=
"$PROJECT_DIR$/frontend-js/frontend-js.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/minerva.iml"
filepath=
"$PROJECT_DIR$/.idea/minerva.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/model/model.iml"
filepath=
"$PROJECT_DIR$/model/model.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/model-command/model-command.iml"
filepath=
"$PROJECT_DIR$/model-command/model-command.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/parent.iml"
filepath=
"$PROJECT_DIR$/parent.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/pathvisio/pathvisio.iml"
filepath=
"$PROJECT_DIR$/pathvisio/pathvisio.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/persist/persist.iml"
filepath=
"$PROJECT_DIR$/persist/persist.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/quadTrees/quadTrees.iml"
filepath=
"$PROJECT_DIR$/quadTrees/quadTrees.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/reactome/reactome.iml"
filepath=
"$PROJECT_DIR$/reactome/reactome.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/rest-api/rest-api.iml"
filepath=
"$PROJECT_DIR$/rest-api/rest-api.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/service/service.iml"
filepath=
"$PROJECT_DIR$/service/service.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/web/web.iml"
filepath=
"$PROJECT_DIR$/web/web.iml"
/>
</modules>
</component>
</project>
\ No newline at end of file
converter/src/main/java/lcsb/mapviewer/converter/OverviewParser.java
View file @
f47be7d8
...
...
@@ -13,6 +13,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.zip.ZipFile
;
import
javax.imageio.ImageIO
;
...
...
@@ -90,17 +91,17 @@ public class OverviewParser {
private
static
final
Integer
BUFFER_SIZE
=
1024
;
/**
* String identifing {@link OverviewModelLink} connections.
* String identif
y
ing {@link OverviewModelLink} connections.
*/
private
static
final
String
MODEL_LINK_TYPE
=
"MODEL"
;
/**
* String identifing {@link OverviewImageLink} connections between images.
* String identif
y
ing {@link OverviewImageLink} connections between images.
*/
private
static
final
String
IMAGE_LINK_TYPE
=
"IMAGE"
;
/**
* String identifing {@link OverviewSearchLink} connections.
* String identif
y
ing {@link OverviewSearchLink} connections.
*/
private
static
final
String
SEARCH_LINK_TYPE
=
"SEARCH"
;
...
...
@@ -125,7 +126,7 @@ public class OverviewParser {
* @throws InvalidOverviewFile
* thrown when the zip file contains invalid data
*/
public
List
<
OverviewImage
>
parseOverviewLinks
(
Set
<
Model
>
models
,
List
<
ImageZipEntryFile
>
files
,
String
outputDirectory
)
throws
InvalidOverviewFile
{
public
List
<
OverviewImage
>
parseOverviewLinks
(
Set
<
Model
>
models
,
List
<
ImageZipEntryFile
>
files
,
String
outputDirectory
,
ZipFile
zipFile
)
throws
InvalidOverviewFile
{
if
(
outputDirectory
!=
null
)
{
File
f
=
new
File
(
outputDirectory
);
if
(!
f
.
exists
())
{
...
...
@@ -151,14 +152,14 @@ public class OverviewParser {
// copy file to file system
if
(
outputDirectory
!=
null
)
{
imageFile
=
new
File
(
outputDirectory
+
"/"
+
filename
);
}
else
{
// or temp file
}
else
{
// or temp
orary
file
imageFile
=
File
.
createTempFile
(
"temp-file-name"
,
".png"
);
imageFile
.
deleteOnExit
();
}
FileOutputStream
fos
=
new
FileOutputStream
(
imageFile
);
byte
[]
bytes
=
new
byte
[
BUFFER_SIZE
];
int
length
;
InputStream
is
=
entry
.
getInputStream
();
InputStream
is
=
zipFile
.
getInputStream
(
zipFile
.
getEntry
(
entry
.
getFilename
())
);
while
((
length
=
is
.
read
(
bytes
))
>=
0
)
{
fos
.
write
(
bytes
,
0
,
length
);
}
...
...
@@ -175,7 +176,7 @@ public class OverviewParser {
StringBuilder
sb
=
new
StringBuilder
(
""
);
byte
[]
buffer
=
new
byte
[
BUFFER_SIZE
];
int
read
=
0
;
InputStream
is
=
entry
.
getInputStream
();
InputStream
is
=
zipFile
.
getInputStream
(
zipFile
.
getEntry
(
entry
.
getFilename
())
);
while
((
read
=
is
.
read
(
buffer
))
>=
0
)
{
sb
.
append
(
new
String
(
buffer
,
0
,
read
));
}
...
...
converter/src/main/java/lcsb/mapviewer/converter/ProjectFactory.java
View file @
f47be7d8
...
...
@@ -58,7 +58,7 @@ public class ProjectFactory {
if
(
imageEntries
.
size
()
>
0
)
{
OverviewParser
parser
=
new
OverviewParser
();
project
.
addOverviewImages
(
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
params
.
getVisualizationDir
()));
project
.
addOverviewImages
(
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
params
.
getVisualizationDir
()
,
zipFile
));
}
return
project
;
}
...
...
converter/src/main/java/lcsb/mapviewer/converter/zip/ImageZipEntryFile.java
View file @
f47be7d8
package
lcsb.mapviewer.converter.zip
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.Serializable
;
/**
...
...
@@ -15,67 +12,31 @@ import java.io.Serializable;
*/
public
class
ImageZipEntryFile
extends
ZipEntryFile
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* Default constructor.
*/
public
ImageZipEntryFile
()
{
}
/**
* Default constructor.
*
* @param filename
* {@link ZipEntryFile#filename}
* @param inputStream
* input stream with the data for this entry.
* @see #baos
* @throws IOException
* thrown when there is a problem with accessing input stream
*/
public
ImageZipEntryFile
(
String
filename
)
{
super
(
filename
);
}
/**
* Size of the buffer used to copy input streams.
*/
private
static
final
int
BUFFER_SIZE
=
1024
;
/**
* Copy of the {@link InputStream} of the file.
*/
private
byte
[]
bytes
;
/**
* Default constructor.
*/
public
ImageZipEntryFile
()
{
}
/**
* Default constructor.
*
* @param filename
* {@link ZipEntryFile#filename}
* @param inputStream
* input stream with the data for this entry.
* @see #baos
* @throws IOException
* thrown when there is a problem with accessing input stream
*/
public
ImageZipEntryFile
(
String
filename
,
InputStream
inputStream
)
throws
IOException
{
super
(
filename
);
setInputStream
(
inputStream
);
}
/**
* @return the inputStream
* @see #inputStream
*/
public
InputStream
getInputStream
()
{
return
new
ByteArrayInputStream
(
bytes
);
}
/**
* @param inputStream
* the inputStream to set
* @throws IOException
* thrown when there is aproblem with accessing inputStream
* @see #inputStream
*/
public
void
setInputStream
(
InputStream
inputStream
)
throws
IOException
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
BUFFER_SIZE
];
int
len
;
while
((
len
=
inputStream
.
read
(
buffer
))
>
-
1
)
{
baos
.
write
(
buffer
,
0
,
len
);
}
baos
.
flush
();
bytes
=
baos
.
toByteArray
();
}
}
converter/src/main/java/lcsb/mapviewer/converter/zip/LayoutZipEntryFile.java
View file @
f47be7d8
...
...
@@ -11,70 +11,72 @@ import java.io.Serializable;
*/
public
class
LayoutZipEntryFile
extends
ZipEntryFile
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* Name of the layout.
*/
private
String
name
=
""
;
/**
* Name of the layout.
*/
private
String
name
=
""
;
/**
* Description of the layout.
*/
private
String
description
=
""
;
/**
* Description of the layout.
*/
private
String
description
=
""
;
/**
* Default constructor.
*/
public
LayoutZipEntryFile
()
{
/**
* Default constructor.
*/
public
LayoutZipEntryFile
()
{
}
}
/**
* Default constructor.
*
* @param filename
* {@link ZipEntryFile#filename}
*/
public
LayoutZipEntryFile
(
String
filename
)
{
super
(
filename
);
}
/**
* Default constructor.
*
* @param filename
* {@link ZipEntryFile#filename}
*/
public
LayoutZipEntryFile
(
String
filename
,
String
name
,
String
description
)
{
super
(
filename
);
this
.
name
=
name
;
this
.
description
=
description
;
}
/**
* @return the name
* @see #name
*/
public
String
getName
()
{
return
name
;
}
/**
* @return the name
* @see #name
*/
public
String
getName
()
{
return
name
;
}
/**
* @param name
* the name to set
* @see #name
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* @param name
* the name to set
* @see #name
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* @return the description
* @see #description
*/
public
String
getDescription
()
{
return
description
;
}
/**
* @return the description
* @see #description
*/
public
String
getDescription
()
{
return
description
;
}
/**
* @param description
* the description to set
* @see #description
*/
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
/**
* @param description
* the description to set
* @see #description
*/
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
converter/src/main/java/lcsb/mapviewer/converter/zip/ZipEntryFileFactory.java
View file @
f47be7d8
...
...
@@ -165,7 +165,7 @@ public class ZipEntryFileFactory {
}
return
zesf
;
}
else
if
(
directory
.
equals
(
IMAGES_DIRECTORY
))
{
ImageZipEntryFile
result
=
new
ImageZipEntryFile
(
entry
.
getName
()
,
zipFile
.
getInputStream
(
entry
)
);
ImageZipEntryFile
result
=
new
ImageZipEntryFile
(
entry
.
getName
());
return
result
;
}
else
if
(
directory
.
equals
(
LAYOUT_DIRECTORY
))
{
LayoutZipEntryFile
result
=
createLayoutZipEntryFile
(
entry
.
getName
(),
zipFile
.
getInputStream
(
entry
));
...
...
converter/src/test/java/lcsb/mapviewer/converter/OverviewParserTest.java
View file @
f47be7d8
...
...
@@ -10,9 +10,12 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.log4j.Logger
;
...
...
@@ -28,226 +31,237 @@ import lcsb.mapviewer.model.map.model.Model;
import
lcsb.mapviewer.model.map.model.ModelFullIndexed
;
public
class
OverviewParserTest
{
Logger
logger
=
Logger
.
getLogger
(
OverviewParserTest
.
class
);
OverviewParser
parser
=
new
OverviewParser
();
@Before
public
void
setUp
()
throws
Exception
{
}
@After
public
void
tearDown
()
throws
Exception
{
}
@Test
public
void
testParsingValidFile
()
throws
Exception
{
try
{
Set
<
Model
>
models
=
createValidTestMapModel
();
List
<
ImageZipEntryFile
>
imageEntries
=
createImageEntries
(
"testFiles/valid_overview"
);
List
<
OverviewImage
>
result
=
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
null
);
assertNotNull
(
result
);
assertEquals
(
1
,
result
.
size
());
OverviewImage
img
=
result
.
get
(
0
);
assertEquals
(
"test.png"
,
img
.
getFilename
());
assertEquals
((
Integer
)
639
,
img
.
getHeight
());
assertEquals
((
Integer
)
963
,
img
.
getWidth
());
assertEquals
(
2
,
img
.
getLinks
().
size
());
OverviewLink
link
=
img
.
getLinks
().
get
(
0
);
List
<
Point2D
>
polygon
=
link
.
getPolygonCoordinates
();
assertEquals
(
4
,
polygon
.
size
());
assertTrue
(
link
instanceof
OverviewModelLink
);
OverviewModelLink
mLink
=
(
OverviewModelLink
)
link
;
Model
mainModel
=
models
.
iterator
().
next
();
assertEquals
(
mainModel
.
getModelData
(),
mLink
.
getLinkedModel
());
assertEquals
((
Integer
)
10
,
mLink
.
getxCoord
());
assertEquals
((
Integer
)
10
,
mLink
.
getyCoord
());
assertEquals
((
Integer
)
3
,
mLink
.
getZoomLevel
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
private
List
<
ImageZipEntryFile
>
createImageEntries
(
String
string
)
throws
IOException
{
List
<
ImageZipEntryFile
>
result
=
new
ArrayList
<
ImageZipEntryFile
>();
for
(
final
File
fileEntry
:
new
File
(
string
).
listFiles
())
{
if
(!
fileEntry
.
isDirectory
())
{
result
.
add
(
new
ImageZipEntryFile
(
fileEntry
.
getName
(),
new
FileInputStream
(
fileEntry
)));
}
}
return
result
;
}
@Test
public
void
testParsingValidFile2
()
throws
Exception
{
try
{
Set
<
Model
>
models
=
createValidTestMapModel
();
String
tmpDir
=
"tmp"
;
new
File
(
tmpDir
).
mkdirs
();
List
<
ImageZipEntryFile
>
imageEntries
=
createImageEntries
(
"testFiles/valid_overview"
);
List
<
OverviewImage
>
result
=
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
tmpDir
);
assertTrue
(
new
File
(
tmpDir
+
"/test.png"
).
exists
());
assertNotNull
(
result
);
assertEquals
(
1
,
result
.
size
());
OverviewImage
img
=
result
.
get
(
0
);
assertEquals
(
"test.png"
,
img
.
getFilename
());
new
File
(
tmpDir
).
delete
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testParsingInvalidFile1
()
throws
Exception
{
try
{
List
<
ImageZipEntryFile
>
imageEntries
=
createImageEntries
(
"testFiles/invalid_overview_1"
);
Set
<
Model
>
models
=
createValidTestMapModel
();
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
null
);
fail
(
"Exception expected"
);
}
catch
(
InvalidOverviewFile
e
)
{
assertTrue
(
e
.
getMessage
().
contains
(
"Unknown image filename"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testParsingInvalidFile2
()
throws
Exception
{
try
{
List
<
ImageZipEntryFile
>
imageEntries
=
createImageEntries
(
"testFiles/invalid_overview_2"
);
Set
<
Model
>
models
=
createValidTestMapModel
();
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
null
);
fail
(
"Exception expected"
);
}
catch
(
InvalidOverviewFile
e
)
{
assertTrue
(
e
.
getMessage
().
contains
(
"Unknown model"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testParsingInvalidFile3
()
throws
Exception
{
try
{
List
<
ImageZipEntryFile
>
imageEntries
=
createImageEntries
(
"testFiles/invalid_overview_3"
);
Set
<
Model
>
models
=
createValidTestMapModel
();
parser
.
parseOverviewLinks
(
models
,
imageEntries
,
null
);
fail
(
"Exception expected"
);
}
catch
(
InvalidOverviewFile
e
)
{
assertTrue
(
e
.
getMessage
().
contains
(
"coordinates outside image"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
private
Set
<
Model
>
createValidTestMapModel
()
{
Set
<
Model
>
result
=
new
HashSet
<>();
Model
model
=
new
ModelFullIndexed
(
null
);
model
.
setName
(
"main"
);
result
.
add
(
model
);
return
result
;
}
/**
* Test coordinates that overlap (exception is expected).
*
* @throws Exception
*/
@Test
public
void
testParseInvalidCoordinates
()
throws
Exception
{
try
{
String
invalidCoordinates
=
"test.png 10,10 100,10 100,100 10,10 main.xml 10,10 3\n"
+
//
"test.png 10,10 10,400 400,400 400,10 main.xml 10,10 4"
;
Set
<
Model
>
models
=
createValidTestMapModel
();
List
<
OverviewImage
>
images
=
new
ArrayList
<
OverviewImage
>();
OverviewImage
oi
=
new
OverviewImage
();
oi
.
setFilename
(
"test.png"
);
oi
.
setWidth
(
1000
);
oi
.
setHeight
(
1000
);
images
.
add
(
oi
);
parser
.
processCoordinates
(
models
,
images
,
invalidCoordinates
);
fail
(
"Exception expected"
);
}
catch
(
InvalidOverviewFile
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testParseValidCoordinates
()
throws
Exception
{
try
{
String
invalidCoordinates
=
"FILE POLYGON LINK_TARGET MODEL_COORDINATES MODEL_ZOOM_LEVEL LINK_TYPE\n"
+
//
"test.png 10,10 100,10 100,100 10,10 main.xml 10,10 3 MODEL\n"
+
//
"test.png 200,200 200,400 400,400 400,200 main.xml 10,10 4 MODEL"
;
Set
<
Model
>
models
=
createValidTestMapModel
();
List
<
OverviewImage
>
images
=
new
ArrayList
<
OverviewImage
>();
OverviewImage
oi
=
new
OverviewImage
();
oi
.
setFilename
(
"test.png"
);
oi
.
setWidth
(
1000
);
oi
.
setHeight
(
1000
);
images
.
add
(
oi
);
parser
.
processCoordinates
(
models
,
images
,
invalidCoordinates
);
assertEquals
(
2
,
oi
.
getLinks
().
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testParseValidComplexCoordinates
()
throws
Exception
{
try
{
String
invalidCoordinates
=
FileUtils
.
readFileToString
(
new
File
(
"testFiles/coordinates.txt"
));
Set
<
Model
>
models
=
createValidTestMapModel
();
List
<
OverviewImage
>
images
=
new
ArrayList
<>();
OverviewImage
oi
=
new
OverviewImage
();
oi
.
setFilename
(
"test.png"
);
oi
.
setWidth
(
1000
);
oi
.
setHeight
(
1000
);
images
.
add
(
oi
);
OverviewImage
oi2
=
new
OverviewImage
();
oi2
.
setFilename
(
"test2.png"
);
oi2
.
setWidth
(
1000
);
oi2
.
setHeight
(
1000
);
images
.
add
(
oi2
);
parser
.
processCoordinates
(
models
,
images
,
invalidCoordinates
);
assertEquals
(
2
,
oi
.
getLinks
().
size
());
assertEquals
(
1
,
oi2
.
getLinks
().
size
());
}
catch
(
Exception
e
)
{