Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
unstable
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PROINFODATA
unstable
Commits
4d3e5c97
Commit
4d3e5c97
authored
11 years ago
by
Eduardo L. Buratti
Browse files
Options
Downloads
Patches
Plain Diff
Add controller to handle le-save-config
parent
e0b3af31
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
web/app/controllers/SaveConfig.java
+104
-0
104 additions, 0 deletions
web/app/controllers/SaveConfig.java
web/conf/routes
+7
-0
7 additions, 0 deletions
web/conf/routes
with
111 additions
and
0 deletions
web/app/controllers/SaveConfig.java
0 → 100644
+
104
−
0
View file @
4d3e5c97
package
controllers
;
import
java.io.*
;
import
java.util.ArrayList
;
import
play.*
;
import
play.mvc.*
;
import
play.data.*
;
import
play.mvc.Http.MultipartFormData
;
import
play.mvc.Http.MultipartFormData.FilePart
;
import
models.*
;
public
class
SaveConfig
extends
Controller
{
private
static
String
TMP_DIR
=
"/tmp/"
;
public
static
Result
get
(
String
inep
,
String
macaddr
)
{
try
{
if
(!
School
.
checkMachineBelongsToSchool
(
inep
,
macaddr
))
return
forbidden
();
}
catch
(
java
.
sql
.
SQLException
e
)
{
e
.
printStackTrace
();
return
internalServerError
();
}
String
filename
=
"config_"
+
inep
+
".bz2"
;
File
f
=
new
File
(
TMP_DIR
+
filename
);
if
(
f
.
exists
())
{
response
().
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
filename
);
return
ok
(
f
);
}
else
return
notFound
();
}
public
static
Result
put
(
String
inep
,
String
macaddr
)
{
try
{
if
(!
School
.
checkMachineBelongsToSchool
(
inep
,
macaddr
))
return
forbidden
();
}
catch
(
java
.
sql
.
SQLException
e
)
{
e
.
printStackTrace
();
return
internalServerError
();
}
String
filename
=
"config_"
+
inep
+
".bz2"
;
File
f
=
new
File
(
TMP_DIR
+
filename
);
InputStream
src
=
null
;
OutputStream
dst
=
null
;
try
{
if
(!
f
.
exists
())
{
f
.
createNewFile
();
}
MultipartFormData
body
=
request
().
body
().
asMultipartFormData
();
FilePart
uploadPart
=
body
.
getFile
(
"config"
);
if
((
uploadPart
==
null
)
||
(
uploadPart
.
getFile
()
==
null
))
throw
new
Exception
(
"failed to get file"
);
src
=
new
FileInputStream
(
uploadPart
.
getFile
());
dst
=
new
FileOutputStream
(
f
);
byte
[]
buf
=
new
byte
[
4096
];
int
len
;
while
((
len
=
src
.
read
(
buf
))
>
0
)
{
dst
.
write
(
buf
,
0
,
len
);
}
src
.
close
();
dst
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
internalServerError
();
}
return
ok
(
"config saved"
);
}
public
static
Result
exists
(
String
inep
,
String
macaddr
)
{
try
{
if
(!
School
.
checkMachineBelongsToSchool
(
inep
,
macaddr
))
return
forbidden
();
}
catch
(
java
.
sql
.
SQLException
e
)
{
e
.
printStackTrace
();
return
internalServerError
();
}
String
filename
=
"config_"
+
inep
+
".bz2"
;
File
f
=
new
File
(
TMP_DIR
+
filename
);
if
(
f
.
exists
())
return
ok
(
"true"
);
else
return
ok
(
"false"
);
}
}
This diff is collapsed.
Click to expand it.
web/conf/routes
+
7
−
0
View file @
4d3e5c97
...
...
@@ -58,6 +58,13 @@ GET /attendance/network/:project/:region/:state/:city/ controllers.Attendan
GET /attendance/os/:project/ controllers.Attendance.osBrasil(project: String)
POST /le-save-config/:inep/:macaddr/ controllers.SaveConfig.put(inep: String, macaddr: String)
POST /le-save-config/:inep/:macaddr controllers.SaveConfig.put(inep: String, macaddr: String)
GET /le-save-config/:inep/:macaddr/ controllers.SaveConfig.get(inep: String, macaddr: String)
GET /le-save-config/:inep/:macaddr controllers.SaveConfig.get(inep: String, macaddr: String)
GET /le-save-config/:inep/:macaddr/exists/ controllers.SaveConfig.exists(inep: String, macaddr: String)
GET /le-save-config/:inep/:macaddr/exists controllers.SaveConfig.exists(inep: String, macaddr: String)
# Map routes for ajax requests
GET /routes.js controllers.Application.jsRoutes()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment