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
51bd86b3
Commit
51bd86b3
authored
Jul 20, 2021
by
Piotr Gawron
Browse files
create plugin data entry moved to service
parent
89a494d5
Changes
4
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/plugins/PluginController.java
View file @
51bd86b3
package
lcsb.mapviewer.api.plugins
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -142,7 +143,7 @@ public class PluginController extends BaseController {
@PathVariable
(
value
=
"key"
)
String
key
,
@RequestParam
(
value
=
"value"
,
defaultValue
=
""
)
String
value
)
throws
QueryException
{
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
return
pluginRest
.
createPluginDataEntry
(
hash
,
user
,
key
,
value
);
return
createPluginDataEntry
(
hash
,
user
,
key
,
value
);
}
@DeleteMapping
(
value
=
"/{hash}/data/users/{key}"
)
...
...
@@ -159,7 +160,7 @@ public class PluginController extends BaseController {
@PathVariable
(
value
=
"hash"
)
String
hash
,
@PathVariable
(
value
=
"key"
)
String
key
,
@RequestParam
(
value
=
"value"
,
defaultValue
=
""
)
String
value
)
throws
QueryException
{
return
pluginRest
.
createPluginDataEntry
(
hash
,
null
,
key
,
value
);
return
createPluginDataEntry
(
hash
,
null
,
key
,
value
);
}
@DeleteMapping
(
value
=
"/{hash}/data/global/{key}"
)
...
...
@@ -215,4 +216,38 @@ public class PluginController extends BaseController {
result
.
put
(
"status"
,
"ok"
);
return
result
;
}
private
PluginDataEntry
createPluginDataEntry
(
String
hash
,
User
user
,
String
key
,
String
value
)
throws
QueryException
{
Plugin
plugin
=
pluginService
.
getByHash
(
hash
);
if
(
plugin
==
null
)
{
throw
new
ObjectNotFoundException
(
"Plugin doesn't exist"
);
}
int
length
=
0
;
if
(
value
!=
null
)
{
try
{
length
=
value
.
getBytes
(
"UTF-8"
).
length
;
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
e
,
e
);
}
}
if
(
length
>=
1024
*
1024
)
{
throw
new
QueryException
(
"Data entry value too big ("
+
length
+
"; max length = "
+
1024
*
1024
+
")"
);
}
PluginDataEntry
entry
=
pluginService
.
getEntryByKey
(
plugin
,
key
,
user
);
if
(
entry
==
null
)
{
entry
=
new
PluginDataEntry
();
entry
.
setKey
(
key
);
entry
.
setPlugin
(
plugin
);
entry
.
setUser
(
user
);
entry
.
setValue
(
value
);
pluginService
.
add
(
entry
);
}
else
{
entry
.
setValue
(
value
);
pluginService
.
update
(
entry
);
}
return
entry
;
}
}
\ No newline at end of file
rest-api/src/main/java/lcsb/mapviewer/api/plugins/PluginRestImpl.java
View file @
51bd86b3
...
...
@@ -39,39 +39,6 @@ public class PluginRestImpl extends BaseRestImpl {
this
.
pluginDataEntryDao
=
pluginDataEntryDao
;
}
public
PluginDataEntry
createPluginDataEntry
(
String
hash
,
User
user
,
String
key
,
String
value
)
throws
QueryException
{
Plugin
plugin
=
pluginDao
.
getByHash
(
hash
);
if
(
plugin
==
null
)
{
throw
new
ObjectNotFoundException
(
"Plugin doesn't exist"
);
}
int
length
=
0
;
if
(
value
!=
null
)
{
try
{
length
=
value
.
getBytes
(
"UTF-8"
).
length
;
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
e
,
e
);
}
}
if
(
length
>=
1024
*
1024
)
{
throw
new
QueryException
(
"Data entry value too big ("
+
length
+
"; max length = "
+
1024
*
1024
+
")"
);
}
PluginDataEntry
entry
=
pluginDataEntryDao
.
getByKey
(
plugin
,
key
,
user
);
if
(
entry
==
null
)
{
entry
=
new
PluginDataEntry
();
entry
.
setKey
(
key
);
entry
.
setPlugin
(
plugin
);
entry
.
setUser
(
user
);
entry
.
setValue
(
value
);
pluginDataEntryDao
.
add
(
entry
);
}
else
{
entry
.
setValue
(
value
);
pluginDataEntryDao
.
update
(
entry
);
}
return
entry
;
}
public
Plugin
updatePlugin
(
String
hash
,
Map
<
String
,
Object
>
data
)
throws
QueryException
{
Plugin
plugin
=
pluginDao
.
getByHash
(
hash
);
if
(
plugin
==
null
)
{
...
...
service/src/main/java/lcsb/mapviewer/services/impl/PluginService.java
View file @
51bd86b3
...
...
@@ -57,7 +57,9 @@ public class PluginService implements IPluginService {
@Override
public
PluginDataEntry
getEntryByKey
(
Plugin
plugin
,
String
key
,
User
user
)
{
PluginDataEntry
result
=
pluginDataEntryDao
.
getByKey
(
plugin
,
key
,
user
);
Hibernate
.
initialize
(
result
.
getUser
());
if
(
result
!=
null
)
{
Hibernate
.
initialize
(
result
.
getUser
());
}
return
result
;
}
...
...
@@ -75,4 +77,14 @@ public class PluginService implements IPluginService {
public
void
add
(
Plugin
plugin
)
{
pluginDao
.
add
(
plugin
);
}
@Override
public
void
add
(
PluginDataEntry
entry
)
{
pluginDataEntryDao
.
add
(
entry
);
}
@Override
public
void
update
(
PluginDataEntry
entry
)
{
pluginDataEntryDao
.
add
(
entry
);
}
}
service/src/main/java/lcsb/mapviewer/services/interfaces/IPluginService.java
View file @
51bd86b3
...
...
@@ -22,4 +22,8 @@ public interface IPluginService {
void
add
(
Plugin
plugin
);
void
add
(
PluginDataEntry
entry
);
void
update
(
PluginDataEntry
entry
);
}
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