Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openmole
gate
Commits
7d1a0298
Commit
7d1a0298
authored
7 years ago
by
Julien Perret
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring on mongodb objects (collection, session)
parent
5dbe15d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
Servlet.scala
server/src/main/scala/server/Servlet.scala
+14
-11
No files found.
server/src/main/scala/server/Servlet.scala
View file @
7d1a0298
package
org.openmole.gate.server
import
com.mongodb.
{
MongoCredential
,
ServerAddress
}
import
com.mongodb.
{
DBObject
,
MongoCredential
,
ServerAddress
}
import
com.mongodb.casbah.Imports.
{
MongoCollection
,
MongoDBObject
}
import
com.mongodb.casbah.MongoClient
import
org.openmole.gate.server.Data.User
...
...
@@ -32,19 +32,22 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
tags
.
link
(
tags
.
rel
:=
"stylesheet"
,
tags
.
`type`
:=
"text/css"
,
href
:=
"css/bootstrap.min.css"
),
tags
.
script
(
tags
.
`type`
:=
"text/javascript"
,
tags
.
src
:=
"js/gate.js"
)
)
val
userSession
=
MongoDBObject
(
user
.
login
->
session
.
getId
)
println
(
mongoDB
.
host
+
" => "
+
mongoDB
.
port
)
val
server
=
new
ServerAddress
(
mongoDB
.
host
,
mongoDB
.
port
)
val
credentials
=
MongoCredential
.
createCredential
(
"accountUser"
,
"products"
,
"password"
.
toCharArray
)
val
mongoClient
=
MongoClient
(
server
,
List
(
credentials
))
println
(
mongoDB
.
db
+
" ? "
+
mongoDB
.
dataSet
)
val
mongoCollection
=
mongoClient
(
mongoDB
.
db
)(
mongoDB
.
dataSet
)
case
class
MongoData
(
collection
:
MongoCollection
,
userSession
:
DBObject
)
def
getMongoData
(
user
:
User
)
=
{
val
userSession
=
MongoDBObject
(
user
.
login
->
session
.
getId
)
println
(
mongoDB
.
host
+
" => "
+
mongoDB
.
port
)
val
server
=
new
ServerAddress
(
mongoDB
.
host
,
mongoDB
.
port
)
val
credentials
=
MongoCredential
.
createCredential
(
"accountUser"
,
"products"
,
"password"
.
toCharArray
)
val
mongoClient
=
MongoClient
(
server
,
List
(
credentials
))
println
(
mongoDB
.
db
+
" ? "
+
mongoDB
.
dataSet
)
MongoData
(
mongoClient
(
mongoDB
.
db
)(
mongoDB
.
dataSet
),
userSession
)
}
get
(
"/"
)
{
contentType
=
"text/html"
auth
(
"DB"
)
match
{
case
Some
(
user
)
=>
mongoCollection
.
findOne
(
userSession
)
match
{
val
mongoData
=
getMongoData
(
user
)
mongoData
.
collection
.
findOne
(
mongoData
.
userSession
)
match
{
case
Some
(
x
)
=>
tags
.
html
(
head
,
...
...
@@ -54,7 +57,7 @@ class Servlet(mongoDB: MongoDB) extends ScalatraServlet with AuthenticationSuppo
)
)
case
None
=>
mongo
Collection
+=
userSession
mongo
Data
.
collection
+=
mongoData
.
userSession
tags
.
html
(
head
,
tags
.
body
(
...
...
This diff is collapsed.
Click to expand it.
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