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
4b24a5bb
Commit
4b24a5bb
authored
Aug 19, 2020
by
Piotr Gawron
Browse files
documentation for image conversion API end points
parent
a5178600
Changes
5
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/convert/ConvertController.java
View file @
4b24a5bb
...
...
@@ -69,12 +69,12 @@ public class ConvertController extends BaseController {
}
@RequestMapping
(
value
=
"/"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
Map
<
String
,
Object
>
getInformation
()
{
public
Map
<
String
,
?
>
getInformation
()
{
return
convertController
.
getInformation
();
}
@RequestMapping
(
value
=
"/image/"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
Map
<
String
,
Object
>
getInformationImage
()
{
public
Map
<
String
,
?
>
getInformationImage
()
{
return
convertController
.
getInformationImage
();
}
...
...
rest-api/src/main/java/lcsb/mapviewer/api/convert/ConvertRestImpl.java
View file @
4b24a5bb
...
...
@@ -148,17 +148,17 @@ public class ConvertRestImpl extends BaseRestImpl {
return
new
ByteArrayInputStream
(
out
.
toByteArray
());
}
public
Map
<
String
,
Object
>
getInformation
()
{
Map
<
String
,
Object
>
info
=
new
LinkedHashMap
<>();
public
Map
<
String
,
List
<
Map
<
String
,
List
<
String
>>>
>
getInformation
()
{
Map
<
String
,
List
<
Map
<
String
,
List
<
String
>>>
>
info
=
new
LinkedHashMap
<>();
List
<
Object
>
converters
=
new
ArrayList
<>();
List
<
Map
<
String
,
List
<
String
>>
>
converters
=
new
ArrayList
<>();
for
(
Converter
converter
:
getModelConverters
())
{
List
<
String
>
names
=
new
ArrayList
<>();
names
.
add
(
removeWhiteSpaces
(
converter
.
getCommonName
()));
names
.
add
(
converter
.
getClass
().
getCanonicalName
());
Map
<
String
,
Object
>
names_item
=
new
LinkedHashMap
<>();
Map
<
String
,
List
<
String
>
>
names_item
=
new
LinkedHashMap
<>();
names_item
.
put
(
"available_names"
,
names
);
converters
.
add
(
names_item
);
}
...
...
@@ -168,10 +168,10 @@ public class ConvertRestImpl extends BaseRestImpl {
return
info
;
}
public
Map
<
String
,
Object
>
getInformationImage
()
{
Map
<
String
,
Object
>
info
=
getInformation
();
public
Map
<
String
,
List
<
Map
<
String
,
List
<
String
>>>
>
getInformationImage
()
{
Map
<
String
,
List
<
Map
<
String
,
List
<
String
>>>
>
info
=
getInformation
();
List
<
Object
>
generators
=
new
ArrayList
<>();
List
<
Map
<
String
,
List
<
String
>>
>
generators
=
new
ArrayList
<>();
ImageGenerators
igs
=
new
ImageGenerators
();
for
(
Pair
<
String
,
Class
<?
extends
AbstractImageGenerator
>>
generator
:
igs
.
getAvailableImageGenerators
())
{
...
...
@@ -179,7 +179,7 @@ public class ConvertRestImpl extends BaseRestImpl {
names
.
add
(
igs
.
getExtension
(
generator
.
getRight
()));
names
.
add
(
generator
.
getRight
().
getCanonicalName
());
Map
<
String
,
Object
>
names_item
=
new
LinkedHashMap
<>();
Map
<
String
,
List
<
String
>
>
names_item
=
new
LinkedHashMap
<>();
names_item
.
put
(
"available_names"
,
names
);
generators
.
add
(
names_item
);
}
...
...
rest-api/src/test/java/lcsb/mapviewer/api/convert/ConvertRestImplTest.java
View file @
4b24a5bb
...
...
@@ -44,7 +44,7 @@ public class ConvertRestImplTest extends RestTestFunctions {
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testGetInformation
()
throws
Exception
{
Map
<
String
,
Object
>
result
=
convertRestImpl
.
getInformationImage
();
Map
<
String
,
?
>
result
=
convertRestImpl
.
getInformationImage
();
assertTrue
(
result
.
keySet
().
size
()
==
2
);
assertNotNull
(
result
.
get
(
"inputs"
));
assertNotNull
(
result
.
get
(
"outputs"
));
...
...
@@ -59,7 +59,7 @@ public class ConvertRestImplTest extends RestTestFunctions {
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testGetInformationImage
()
throws
Exception
{
Map
<
String
,
Object
>
result
=
convertRestImpl
.
getInformationImage
();
Map
<
String
,
?
>
result
=
convertRestImpl
.
getInformationImage
();
assertTrue
(
result
.
keySet
().
size
()
==
2
);
assertNotNull
(
result
.
get
(
"inputs"
));
assertNotNull
(
result
.
get
(
"outputs"
));
...
...
@@ -162,7 +162,7 @@ public class ConvertRestImplTest extends RestTestFunctions {
}
@SuppressWarnings
(
"unchecked"
)
private
List
<
String
>
extractIdsFromOutputs
(
Map
<
String
,
Object
>
infoObject
)
{
private
List
<
String
>
extractIdsFromOutputs
(
Map
<
String
,
?
>
infoObject
)
{
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
Map
<
String
,
List
<
String
>>
o
:
(
List
<
Map
<
String
,
List
<
String
>>>)
infoObject
.
get
(
"outputs"
))
{
ids
.
add
(
o
.
get
(
"available_names"
).
get
(
0
));
...
...
@@ -174,8 +174,8 @@ public class ConvertRestImplTest extends RestTestFunctions {
throws
SBMLException
,
SecurityException
,
InvalidInputDataExecption
,
InconsistentModelException
,
IOException
,
ConverterException
,
XMLStreamException
,
DrawingException
,
QueryException
{
Map
<
String
,
Object
>
info
=
convertRestImpl
.
getInformation
();
Map
<
String
,
Object
>
infoImage
=
convertRestImpl
.
getInformationImage
();
Map
<
String
,
?
>
info
=
convertRestImpl
.
getInformation
();
Map
<
String
,
?
>
infoImage
=
convertRestImpl
.
getInformationImage
();
List
<
String
>
targets
=
new
ArrayList
<>();
...
...
web/src/main/asciidoc/converter.adoc
View file @
4b24a5bb
...
...
@@ -27,8 +27,23 @@ include::{snippets}/converter/format_conversion/curl-request.adoc[]
==== Path Parameters
include::{snippets}/converter/format_conversion/path-parameters.adoc[]
== Convert network from an input format to an output image
=== List available formats
==== CURL sample
include::{snippets}/converter/list_image_formats/curl-request.adoc[]
==== Response Fields
include::{snippets}/converter/
format_conversion
/response-fields.adoc[]
include::{snippets}/converter/
list_image_formats
/response-fields.adoc[]
==== Sample Response
include::{snippets}/converter/list_image_formats/response-body.adoc[]
=== Convert network from an input format to an output image
==== CURL sample
include::{snippets}/converter/image_conversion/curl-request.adoc[]
==== Path Parameters
include::{snippets}/converter/image_conversion/path-parameters.adoc[]
web/src/test/java/lcsb/mapviewer/web/ConvertControllerIntegrationTest.java
View file @
4b24a5bb
...
...
@@ -2,8 +2,10 @@ package lcsb.mapviewer.web;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.*;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.*;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
get
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
post
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
fieldWithPath
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
responseFields
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
parameterWithName
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
pathParameters
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -11,16 +13,20 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.util.*
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
lcsb.mapviewer.api.convert.ConvertRestImpl
;
import
lcsb.mapviewer.converter.ConverterParams
;
import
lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser
;
import
lcsb.mapviewer.model.map.model.Model
;
...
...
@@ -29,6 +35,9 @@ import lcsb.mapviewer.model.map.species.Element;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
ConvertControllerIntegrationTest
extends
ControllerIntegrationTest
{
@Autowired
private
ConvertRestImpl
converterRestImpl
;
Logger
logger
=
LogManager
.
getLogger
();
@Test
...
...
@@ -130,7 +139,7 @@ public class ConvertControllerIntegrationTest extends ControllerIntegrationTest
File
file
=
new
File
(
"src/test/resources/convert/cd-sample.xml"
);
String
content
=
FileUtils
.
readFileToString
(
file
,
StandardCharsets
.
UTF_8
);
RequestBuilder
request
=
post
(
"/convert/{inputFormat}:{outputFormat}"
,
"CellDesigner_SBML"
,
"GPML"
)
.
header
(
"post-filename"
,
"input_file.xml"
)
.
header
(
"post-filename"
,
"input_file.xml"
)
.
content
(
content
.
getBytes
(
"UTF-8"
))
.
characterEncoding
(
"UTF-8"
);
...
...
@@ -138,10 +147,67 @@ public class ConvertControllerIntegrationTest extends ControllerIntegrationTest
.
andDo
(
document
(
"converter/format_conversion"
,
pathParameters
(
parameterWithName
(
"inputFormat"
)
.
description
(
"input format
(list of
available
formats be obtained from the /convert/ API)"
),
.
description
(
"input format
,
available
options: "
+
getConverters
()
),
parameterWithName
(
"outputFormat"
)
.
description
(
"output format
(list of
available
formats be obtained from the /convert/ API)"
))))
.
description
(
"output format
,
available
options: "
+
getConverters
()
))))
.
andExpect
(
status
().
is2xxSuccessful
());
}
@Test
public
void
testListAvailableImageFormats
()
throws
Exception
{
RequestBuilder
request
=
get
(
"/convert/image/"
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is2xxSuccessful
())
.
andDo
(
document
(
"converter/list_image_formats"
,
responseFields
(
fieldWithPath
(
"inputs"
)
.
description
(
"list of available input formats"
)
.
type
(
"Array"
),
fieldWithPath
(
"inputs[].available_names"
)
.
description
(
"list of names that could be used for specific format"
)
.
type
(
"Array<String>"
),
fieldWithPath
(
"outputs"
)
.
description
(
"list of available input formats"
)
.
type
(
"Array"
),
fieldWithPath
(
"outputs[].available_names"
)
.
description
(
"list of names that could be used for specific format"
)
.
type
(
"Array<String>"
))));
}
@Test
public
void
convertCellDesignerToSvg
()
throws
Exception
{
File
file
=
new
File
(
"src/test/resources/convert/cd-sample.xml"
);
String
content
=
FileUtils
.
readFileToString
(
file
,
StandardCharsets
.
UTF_8
);
RequestBuilder
request
=
post
(
"/convert/image/{inputFormat}:{outputFormat}"
,
"CellDesigner_SBML"
,
"png"
)
.
header
(
"post-filename"
,
"input_file.xml"
)
.
content
(
content
.
getBytes
(
"UTF-8"
))
.
characterEncoding
(
"UTF-8"
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"converter/image_conversion"
,
pathParameters
(
parameterWithName
(
"inputFormat"
)
.
description
(
"input format, available options: "
+
getConverters
()),
parameterWithName
(
"outputFormat"
)
.
description
(
"output format, available options: "
+
getImageConverters
()))))
.
andExpect
(
status
().
is2xxSuccessful
());
}
private
String
getConverters
()
{
List
<
String
>
converters
=
new
ArrayList
<>();
for
(
Map
<
String
,
List
<
String
>>
entry
:
converterRestImpl
.
getInformation
().
get
(
"inputs"
))
{
converters
.
addAll
(
entry
.
get
(
"available_names"
));
}
return
StringUtils
.
join
(
converters
,
", "
);
}
private
String
getImageConverters
()
{
List
<
String
>
converters
=
new
ArrayList
<>();
for
(
Map
<
String
,
List
<
String
>>
entry
:
converterRestImpl
.
getInformation
().
get
(
"outputs"
))
{
converters
.
addAll
(
entry
.
get
(
"available_names"
));
}
return
StringUtils
.
join
(
converters
,
", "
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment