Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
9a5d7e7b
Commit
9a5d7e7b
authored
Jun 06, 2017
by
Piotr Gawron
Browse files
new api call format for removing overlay
parent
d3e49019
Changes
14
Hide whitespace changes
Inline
Side-by-side
frontend-js/testFiles/apiCalls/
overlay/removeOverlay/POST_
overlay
Id=
17296
&projectId=sample&
token=MOCK_TOKEN_ID&
→
frontend-js/testFiles/apiCalls/
projects/sample/
overlay
s/
17296
/DELETE_
token=MOCK_TOKEN_ID&
View file @
9a5d7e7b
File moved
pom.xml
View file @
9a5d7e7b
...
...
@@ -35,6 +35,9 @@
<jersey.version>
1.18.1
</jersey.version>
<rs-jax.version>
1.1.1
</rs-jax.version>
<jackson.version>
2.8.8
</jackson.version>
<log4j.version>
1.2.17
</log4j.version>
<apache.commons-lang3.version>
3.1
</apache.commons-lang3.version>
...
...
rest-api/.classpath
View file @
9a5d7e7b
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
path=
"src/main/resources"
/>
<classpathentry
kind=
"src"
path=
"src/test/resources"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"org.eclipse.jst.component.nondependency"
value=
""
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
output=
"target/classes"
path=
"src/main/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
output=
"target/test-classes"
path=
"src/test/java"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/classes"
path=
"src/main/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**"
kind=
"src"
output=
"target/test-classes"
path=
"src/test/resources"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"org.eclipse.jst.component.nondependency"
value=
""
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
</classpath>
rest-api/.settings/org.eclipse.core.resources.prefs
View file @
9a5d7e7b
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
rest-api/.settings/org.eclipse.wst.common.component
View file @
9a5d7e7b
...
...
@@ -2,6 +2,5 @@
<wb-module
deploy-name=
"MapViewer-rest-api"
>
<wb-resource
deploy-path=
"/"
source-path=
"/src/main/java"
/>
<wb-resource
deploy-path=
"/"
source-path=
"/src/main/resources"
/>
<wb-resource
deploy-path=
"/"
source-path=
"/src/test/resources"
/>
</wb-module>
</project-modules>
rest-api/pom.xml
View file @
9a5d7e7b
...
...
@@ -48,6 +48,18 @@
<artifactId>
spring-faces
</artifactId>
<version>
${springframework.webflow.version}
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-core
</artifactId>
<version>
${jackson.version}
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
<version>
${jackson.version}
</version>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
...
...
rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java
View file @
9a5d7e7b
...
...
@@ -18,6 +18,9 @@ public abstract class BaseController {
logger
.
error
(
e
,
e
);
if
(
e
instanceof
SecurityException
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Access denied.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
FORBIDDEN
);
}
else
if
(
e
instanceof
ObjectNotFoundException
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Object not found.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
NOT_FOUND
);
}
else
if
(
e
instanceof
QueryException
)
{
return
new
ResponseEntity
<
Object
>(
"{\"error\" : \"Query server error.\",\"reason\":\""
+
e
.
getMessage
()
+
"\"}"
,
new
HttpHeaders
(),
HttpStatus
.
BAD_REQUEST
);
...
...
rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java
View file @
9a5d7e7b
...
...
@@ -26,7 +26,6 @@ public abstract class BaseRestImpl {
protected
Map
<
String
,
Object
>
okStatus
()
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"status"
,
"OK"
);
return
result
;
}
...
...
rest-api/src/main/java/lcsb/mapviewer/api/ObjectNotFoundException.java
0 → 100644
View file @
9a5d7e7b
package
lcsb.mapviewer.api
;
public
class
ObjectNotFoundException
extends
QueryException
{
public
ObjectNotFoundException
(
String
message
)
{
super
(
message
);
}
public
ObjectNotFoundException
(
String
message
,
Exception
reason
)
{
super
(
message
,
reason
);
}
}
rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java
View file @
9a5d7e7b
...
...
@@ -4,17 +4,20 @@ import java.io.IOException;
import
java.util.List
;
import
java.util.Map
;
import
javax.ws.rs.PathParam
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.model.cache.FileEntry
;
...
...
@@ -24,15 +27,19 @@ import lcsb.mapviewer.services.view.LayoutView;
@RestController
public
class
OverlayController
extends
BaseController
{
private
Logger
logger
=
Logger
.
getLogger
(
OverlayController
.
class
);
@Autowired
private
OverlayRestImpl
overlayController
;
private
OverlayRestImpl
overlayRestImp
;
private
ObjectMapper
mapper
=
new
ObjectMapper
();
@RequestMapping
(
value
=
"/projects/{projectId}/overlays/"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
List
<
LayoutView
>
getOverlayList
(
//
@RequestParam
(
value
=
"token"
)
String
token
,
//
@PathVariable
(
value
=
"projectId"
)
String
projectId
//
)
throws
SecurityException
,
QueryException
{
return
overlay
Controller
.
getOverlayList
(
token
,
projectId
);
return
overlay
RestImp
.
getOverlayList
(
token
,
projectId
);
}
@RequestMapping
(
value
=
"/projects/{projectId}/overlays/{overlayId}/"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
...
...
@@ -41,7 +48,7 @@ public class OverlayController extends BaseController {
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@PathVariable
(
value
=
"overlayId"
)
String
overlayId
//
)
throws
SecurityException
,
QueryException
{
return
overlay
Controller
.
getOverlayById
(
token
,
projectId
,
overlayId
);
return
overlay
RestImp
.
getOverlayById
(
token
,
projectId
,
overlayId
);
}
@RequestMapping
(
value
=
"/projects/{projectId}/overlays/{overlayId}/models/{modelId}/bioEntities/"
,
method
=
{
RequestMethod
.
GET
},
...
...
@@ -51,7 +58,7 @@ public class OverlayController extends BaseController {
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@PathVariable
(
value
=
"overlayId"
)
String
overlayId
,
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
)
throws
SecurityException
,
QueryException
{
return
overlay
Controller
.
getOverlayElements
(
token
,
projectId
,
Integer
.
valueOf
(
overlayId
),
columns
);
return
overlay
RestImp
.
getOverlayElements
(
token
,
projectId
,
Integer
.
valueOf
(
overlayId
),
columns
);
}
@RequestMapping
(
value
=
"/projects/{projectId}/overlays/{overlayId}/models/{modelId}/bioEntities/reactions/{reactionId}/"
,
method
=
{
RequestMethod
.
GET
},
...
...
@@ -64,7 +71,7 @@ public class OverlayController extends BaseController {
@PathVariable
(
value
=
"reactionId"
)
String
reactionId
,
//
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
//
)
throws
SecurityException
,
QueryException
{
return
overlay
Controller
return
overlay
RestImp
.
getOverlayElement
(
token
,
projectId
,
Integer
.
valueOf
(
modelId
),
Integer
.
valueOf
(
overlayId
),
Integer
.
valueOf
(
reactionId
),
"REACTION"
,
columns
);
}
...
...
@@ -78,7 +85,7 @@ public class OverlayController extends BaseController {
@PathVariable
(
value
=
"elementId"
)
String
reactionId
,
//
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
//
)
throws
SecurityException
,
QueryException
{
return
overlay
Controller
return
overlay
RestImp
.
getOverlayElement
(
token
,
projectId
,
Integer
.
valueOf
(
modelId
),
Integer
.
valueOf
(
overlayId
),
Integer
.
valueOf
(
reactionId
),
"ALIAS"
,
columns
);
}
...
...
@@ -92,12 +99,22 @@ public class OverlayController extends BaseController {
@RequestParam
(
value
=
"filename"
)
String
filename
,
//
@RequestParam
(
value
=
"type"
,
defaultValue
=
""
)
String
type
//
)
throws
SecurityException
,
QueryException
,
IOException
{
return
overlayController
.
addOverlay
(
token
,
projectId
,
name
,
description
,
content
,
filename
,
type
);
return
overlayRestImp
.
addOverlay
(
token
,
projectId
,
name
,
description
,
content
,
filename
,
type
);
}
@RequestMapping
(
value
=
"/projects/{projectId}/overlays/{overlayId}"
,
method
=
{
RequestMethod
.
DELETE
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
Map
<
String
,
Object
>
removeOverlay
(
//
@RequestBody
String
body
,
//
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@PathVariable
(
value
=
"overlayId"
)
String
overlayId
//
)
throws
SecurityException
,
QueryException
,
IOException
{
ObjectNode
node
=
mapper
.
readValue
(
body
,
ObjectNode
.
class
);
return
overlayRestImp
.
removeOverlay
(
node
.
get
(
"token"
).
asText
(),
projectId
,
overlayId
);
}
@RequestMapping
(
value
=
"/overlay/getOverlayTypes"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
List
<
Map
<
String
,
Object
>>
getOverlayTypes
(
@RequestParam
(
value
=
"token"
)
String
token
)
throws
SecurityException
,
QueryException
{
return
overlay
Controller
.
getOverlayTypes
(
token
);
return
overlay
RestImp
.
getOverlayTypes
(
token
);
}
@RequestMapping
(
value
=
"/overlay/updateOverlay"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
PUT
,
RequestMethod
.
POST
},
...
...
@@ -105,21 +122,14 @@ public class OverlayController extends BaseController {
public
Map
<
String
,
Object
>
updateOverlay
(
@RequestParam
(
value
=
"token"
)
String
token
,
@RequestParam
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"overlayId"
)
String
overlayId
,
@RequestParam
(
value
=
"name"
)
String
name
,
@RequestParam
(
value
=
"description"
)
String
description
)
throws
SecurityException
,
QueryException
{
return
overlayController
.
updateOverlay
(
token
,
projectId
,
overlayId
,
name
,
description
);
}
@RequestMapping
(
value
=
"/overlay/removeOverlay"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
DELETE
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
Map
<
String
,
Object
>
removeOverlay
(
@RequestParam
(
value
=
"token"
)
String
token
,
@RequestParam
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"overlayId"
)
String
overlayId
)
throws
SecurityException
,
QueryException
,
IOException
{
return
overlayController
.
removeOverlay
(
token
,
projectId
,
overlayId
);
return
overlayRestImp
.
updateOverlay
(
token
,
projectId
,
overlayId
,
name
,
description
);
}
@RequestMapping
(
value
=
"/overlay/getOverlaySource"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
ResponseEntity
<
byte
[]>
getOverlaySource
(
@RequestParam
(
value
=
"token"
)
String
token
,
@RequestParam
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"overlayId"
)
String
overlayId
)
throws
SecurityException
,
QueryException
{
FileEntry
file
=
overlay
Controller
.
getOverlaySource
(
token
,
projectId
,
overlayId
);
FileEntry
file
=
overlay
RestImp
.
getOverlaySource
(
token
,
projectId
,
overlayId
);
MediaType
type
=
MediaType
.
TEXT_PLAIN
;
if
(
file
.
getOriginalFileName
().
endsWith
(
"xml"
))
{
type
=
MediaType
.
APPLICATION_XML
;
...
...
@@ -130,20 +140,20 @@ public class OverlayController extends BaseController {
}
/**
* @return the overlay
Controller
* @see #overlay
Controller
* @return the overlay
RestImp
* @see #overlay
RestImp
*/
public
OverlayRestImpl
getOverlay
Controller
()
{
return
overlay
Controller
;
public
OverlayRestImpl
getOverlay
RestImp
()
{
return
overlay
RestImp
;
}
/**
* @param overlay
Controller
* the overlay
Controller
to set
* @see #overlay
Controller
* @param overlay
RestImp
* the overlay
RestImp
to set
* @see #overlay
RestImp
*/
public
void
setOverlay
Controller
(
OverlayRestImpl
overlay
Controller
)
{
this
.
overlay
Controller
=
overlayController
;
public
void
setOverlay
RestImp
(
OverlayRestImpl
overlay
RestImp
)
{
this
.
overlay
RestImp
=
overlayRestImp
;
}
}
\ No newline at end of file
rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java
View file @
9a5d7e7b
...
...
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.transaction.annotation.Transactional
;
import
lcsb.mapviewer.api.BaseRestImpl
;
import
lcsb.mapviewer.api.ObjectNotFoundException
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.model.cache.FileEntry
;
...
...
@@ -194,17 +195,17 @@ public class OverlayRestImpl extends BaseRestImpl {
AuthenticationToken
authenticationToken
=
userService
.
getToken
(
token
);
Model
model
=
modelService
.
getLastModelByProjectId
(
projectId
,
authenticationToken
);
if
(
model
==
null
)
{
throw
new
Query
Exception
(
"Project with given id doesn't exist"
);
throw
new
ObjectNotFound
Exception
(
"Project with given id doesn't exist"
);
}
try
{
Integer
id
=
Integer
.
valueOf
(
overlayId
);
LayoutView
layout
=
layoutService
.
getLayoutById
(
model
,
id
,
authenticationToken
);
if
(
layout
==
null
)
{
throw
new
QueryException
(
"Invalid overlay id
"
);
throw
new
ObjectNotFoundException
(
"Overlay doesn't exist
"
);
}
layoutService
.
removeLayout
(
layout
,
null
);
}
catch
(
NumberFormatException
e
)
{
throw
new
QueryException
(
"Invalid overlay id
"
);
throw
new
QueryException
(
"Invalid overlay id
: "
+
overlayId
);
}
return
okStatus
();
}
...
...
rest-api/src/test/java/lcsb/mapviewer/api/projects/AllProjectTests.java
View file @
9a5d7e7b
...
...
@@ -5,9 +5,11 @@ import org.junit.runners.Suite;
import
org.junit.runners.Suite.SuiteClasses
;
import
lcsb.mapviewer.api.projects.models.AllModelsTests
;
import
lcsb.mapviewer.api.projects.overlays.AllOverlaysTests
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AllModelsTests
.
class
,
//
AllOverlaysTests
.
class
,
//
ModelMetaDataTest
.
class
,
//
ProjectRestImplTest
.
class
})
public
class
AllProjectTests
{
...
...
rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/AllOverlaysTests.java
0 → 100644
View file @
9a5d7e7b
package
lcsb.mapviewer.api.projects.overlays
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
OverlayControllerTest
.
class
})
public
class
AllOverlaysTests
{
}
rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayControllerTest.java
0 → 100644
View file @
9a5d7e7b
package
lcsb.mapviewer.api.projects.overlays
;
import
static
org
.
junit
.
Assert
.
fail
;
import
org.junit.After
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lcsb.mapviewer.api.RestTestFunctions
;
import
lcsb.mapviewer.services.InvalidTokenException
;
public
class
OverlayControllerTest
extends
RestTestFunctions
{
OverlayController
controller
=
new
OverlayController
();
@Autowired
OverlayRestImpl
overlayRestImp
;
@AfterClass
public
static
void
tearDownAfterClass
()
throws
Exception
{
}
@Before
public
void
setUp
()
throws
Exception
{
controller
.
setOverlayRestImp
(
overlayRestImp
);
}
@After
public
void
tearDown
()
throws
Exception
{
}
@Test
public
void
testTokenParsing
()
throws
Exception
{
String
body
=
"{\"token\":\""
+
token
+
"\"}"
;
try
{
controller
.
removeOverlay
(
body
,
"p_id"
,
"-1"
);
fail
(
"Exception expected"
);
}
catch
(
InvalidTokenException
e
)
{
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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