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
754b1808
Commit
754b1808
authored
Jan 27, 2017
by
Piotr Gawron
Browse files
rest api for adding/removing/modifying overlays
parent
6904198b
Changes
6
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java
View file @
754b1808
package
lcsb.mapviewer.api
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.log4j.Logger
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -24,4 +27,5 @@ public abstract class BaseController {
}
}
}
rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java
0 → 100644
View file @
754b1808
package
lcsb.mapviewer.api
;
import
java.util.HashMap
;
import
java.util.Map
;
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/comment/CommentRestImpl.java
View file @
754b1808
...
...
@@ -12,6 +12,7 @@ import org.apache.log4j.Logger;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
lcsb.mapviewer.api.BaseRestImpl
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.map.Comment
;
...
...
@@ -30,7 +31,7 @@ import lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierTy
import
lcsb.mapviewer.services.view.AuthenticationToken
;
@Transactional
(
value
=
"txManager"
)
public
class
CommentRestImpl
{
public
class
CommentRestImpl
extends
BaseRestImpl
{
Logger
logger
=
Logger
.
getLogger
(
CommentRestImpl
.
class
);
...
...
@@ -355,10 +356,7 @@ public class CommentRestImpl {
}
commentService
.
addComment
(
name
,
email
,
content
,
model
,
pointCoordinates
,
commentedObject
,
pinned
,
submodel
);
// TODO Auto-generated method stub
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"status"
,
"OK"
);
return
result
;
return
okStatus
();
}
}
rest-api/src/main/java/lcsb/mapviewer/api/overlay/OverlayController.java
View file @
754b1808
package
lcsb.mapviewer.api.overlay
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -10,11 +11,13 @@ 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
org.springframework.web.multipart.MultipartFile
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.model.cache.FileEntry
;
import
lcsb.mapviewer.services.SecurityException
;
import
lcsb.mapviewer.services.utils.data.ColorSchemaType
;
import
lcsb.mapviewer.services.view.LayoutView
;
@RestController
...
...
@@ -24,19 +27,42 @@ public class OverlayController extends BaseController {
@Autowired
private
OverlayRestImpl
overlayController
;
@RequestMapping
(
value
=
"/getOverlayList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
@RequestMapping
(
value
=
"/getOverlayList"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
List
<
LayoutView
>
getOverlayList
(
@RequestParam
(
value
=
"token"
)
String
token
,
@RequestParam
(
value
=
"projectId"
)
String
projectId
)
throws
SecurityException
,
QueryException
{
return
overlayController
.
getOverlayList
(
token
,
projectId
);
}
@RequestMapping
(
value
=
"/getOverlayById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
@RequestMapping
(
value
=
"/getOverlayById"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
LayoutView
getOverlayById
(
@RequestParam
(
value
=
"token"
)
String
token
,
@RequestParam
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"overlayId"
)
String
overlayId
)
throws
SecurityException
,
QueryException
{
return
overlayController
.
getOverlayById
(
token
,
projectId
,
overlayId
);
}
@RequestMapping
(
value
=
"/getOverlaySource"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
@RequestMapping
(
value
=
"/updateOverlay"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
PUT
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
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
=
"/addOverlay"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
Map
<
String
,
Object
>
addOverlay
(
@RequestParam
(
value
=
"token"
)
String
token
,
@RequestParam
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"name"
)
String
name
,
@RequestParam
(
value
=
"description"
)
String
description
,
@RequestParam
(
value
=
"content"
)
String
content
,
@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
);
}
@RequestMapping
(
value
=
"/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
);
}
@RequestMapping
(
value
=
"/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
{
...
...
rest-api/src/main/java/lcsb/mapviewer/api/overlay/OverlayRestImpl.java
View file @
754b1808
package
lcsb.mapviewer.api.overlay
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
lcsb.mapviewer.api.BaseRestImpl
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.model.cache.FileEntry
;
import
lcsb.mapviewer.model.map.layout.InvalidColorSchemaException
;
import
lcsb.mapviewer.model.map.layout.Layout
;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.persist.dao.map.LayoutDao
;
import
lcsb.mapviewer.services.SecurityException
;
import
lcsb.mapviewer.services.interfaces.ILayoutService
;
import
lcsb.mapviewer.services.interfaces.ILayoutService.CreateLayoutParams
;
import
lcsb.mapviewer.services.interfaces.IModelService
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
import
lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierType
;
import
lcsb.mapviewer.services.search.layout.LightLayoutAliasView
;
import
lcsb.mapviewer.services.search.layout.LightLayoutReactionView
;
import
lcsb.mapviewer.services.utils.data.ColorSchemaType
;
import
lcsb.mapviewer.services.view.AuthenticationToken
;
import
lcsb.mapviewer.services.view.LayoutView
;
@Transactional
(
value
=
"txManager"
)
public
class
OverlayRestImpl
{
public
class
OverlayRestImpl
extends
BaseRestImpl
{
Logger
logger
=
Logger
.
getLogger
(
OverlayRestImpl
.
class
);
@Autowired
private
IUserService
userService
;
...
...
@@ -34,6 +48,9 @@ public class OverlayRestImpl {
@Autowired
private
ILayoutService
layoutService
;
@Autowired
private
LayoutDao
layoutDao
;
public
List
<
LayoutView
>
getOverlayList
(
String
token
,
String
projectId
)
throws
SecurityException
,
QueryException
{
AuthenticationToken
authenticationToken
=
userService
.
getToken
(
token
);
Model
model
=
modelService
.
getLastModelByProjectId
(
projectId
,
authenticationToken
);
...
...
@@ -141,7 +158,7 @@ public class OverlayRestImpl {
if
(
layout
==
null
)
{
throw
new
QueryException
(
"Invalid overlay id"
);
}
//lazy initialization issue
//
lazy initialization issue
layout
.
getInputData
().
getFileContent
();
return
layout
.
getInputData
();
}
catch
(
NumberFormatException
e
)
{
...
...
@@ -149,4 +166,99 @@ public class OverlayRestImpl {
}
}
public
Map
<
String
,
Object
>
updateOverlay
(
String
token
,
String
projectId
,
String
overlayId
,
String
name
,
String
description
)
throws
QueryException
,
SecurityException
{
AuthenticationToken
authenticationToken
=
userService
.
getToken
(
token
);
Model
model
=
modelService
.
getLastModelByProjectId
(
projectId
,
authenticationToken
);
if
(
model
==
null
)
{
throw
new
QueryException
(
"Project with given id doesn't exist"
);
}
try
{
Integer
id
=
Integer
.
valueOf
(
overlayId
);
Layout
layout
=
layoutService
.
getLayoutDataById
(
id
,
authenticationToken
);
if
(
layout
==
null
)
{
throw
new
QueryException
(
"Invalid overlay id"
);
}
layout
.
setDescription
(
description
);
layout
.
setTitle
(
name
);
layoutDao
.
update
(
layout
);
}
catch
(
NumberFormatException
e
)
{
throw
new
QueryException
(
"Invalid overlay id"
);
}
return
okStatus
();
}
public
Map
<
String
,
Object
>
removeOverlay
(
String
token
,
String
projectId
,
String
overlayId
)
throws
QueryException
,
SecurityException
,
IOException
{
AuthenticationToken
authenticationToken
=
userService
.
getToken
(
token
);
Model
model
=
modelService
.
getLastModelByProjectId
(
projectId
,
authenticationToken
);
if
(
model
==
null
)
{
throw
new
QueryException
(
"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"
);
}
layoutService
.
removeLayout
(
layout
,
null
);
}
catch
(
NumberFormatException
e
)
{
throw
new
QueryException
(
"Invalid overlay id"
);
}
return
okStatus
();
}
/**
* @return the layoutDao
* @see #layoutDao
*/
public
LayoutDao
getLayoutDao
()
{
return
layoutDao
;
}
/**
* @param layoutDao
* the layoutDao to set
* @see #layoutDao
*/
public
void
setLayoutDao
(
LayoutDao
layoutDao
)
{
this
.
layoutDao
=
layoutDao
;
}
public
Map
<
String
,
Object
>
addOverlay
(
String
token
,
String
projectId
,
String
name
,
String
description
,
String
content
,
String
filename
,
String
type
)
throws
SecurityException
,
QueryException
,
IOException
{
AuthenticationToken
authenticationToken
=
userService
.
getToken
(
token
);
User
user
=
userService
.
getUserByToken
(
token
);
if
(
Configuration
.
ANONYMOUS_LOGIN
.
equals
(
user
.
getLogin
()))
{
throw
new
SecurityException
(
"You have no privileges to add layout"
);
}
Model
model
=
modelService
.
getLastModelByProjectId
(
projectId
,
authenticationToken
);
if
(
model
==
null
)
{
throw
new
QueryException
(
"Project with given id doesn't exist"
);
}
ColorSchemaType
colorSchemaType
=
ColorSchemaType
.
GENERIC
;
logger
.
debug
(
"TYPE: \'"
+
type
+
"\'"
);
if
(
type
!=
null
&&
!
type
.
equals
(
""
))
{
try
{
colorSchemaType
=
ColorSchemaType
.
valueOf
(
type
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
QueryException
(
"Invalid type of overlay: "
+
type
,
e
);
}
}
try
{
InputStream
stream
=
new
ByteArrayInputStream
(
content
.
getBytes
(
StandardCharsets
.
UTF_8
));
LayoutView
layout
=
layoutService
.
createLayout
(
new
CreateLayoutParams
()
.
async
(
false
).
colorInputStream
(
stream
).
description
(
description
).
layoutFileName
(
filename
).
model
(
model
).
name
(
name
).
user
(
user
)
.
colorSchemaType
(
colorSchemaType
).
directory
(
"."
));
Map
<
String
,
Object
>
result
=
okStatus
();
result
.
put
(
"overlayId"
,
layout
.
getIdObject
());
return
result
;
}
catch
(
InvalidColorSchemaException
e
)
{
throw
new
QueryException
(
e
.
getMessage
(),
e
);
}
}
}
service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java
View file @
754b1808
...
...
@@ -1039,6 +1039,9 @@ public class LayoutService implements ILayoutService {
@Override
public
LayoutView
getLayoutById
(
Model
model
,
int
overlayId
,
AuthenticationToken
token
)
throws
SecurityException
{
Layout
layout
=
getLayoutById
(
overlayId
,
token
);
if
(
layout
==
null
)
{
return
null
;
}
return
layoutViewFactory
.
create
(
layout
);
}
...
...
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