Created
April 18, 2017 16:14
-
-
Save kryton/70573bdb534fa1996356b3b9fe902d03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def importFile = Action.async{ implicit request => | |
user.isAdmin(LDAPAuth.getUser()).map { | |
case true =>Ok(views.html.person.importFile()) | |
case false => Unauthorized(views.html.page_403( "You don't have access to import SAP files")) | |
} | |
} | |
def doImport = Action.async(parse.multipartFormData) { implicit request => | |
user.isAdmin(LDAPAuth.getUser()).map { | |
case false => Future.successful(Unauthorized(views.html.page_403("You don't have access to import SAP files")) ) | |
case true => | |
request.body.file("importFile").map { picture => | |
val filename = picture.filename | |
val path: Path = picture.ref.path | |
SAPImport.importFile(path).map { | |
employees => | |
SAPImport.validate(employees) match { | |
case Nil => employeeRepo.repopulate(employees).map { x => | |
Future.successful(Ok(views.html.person.importFileResult(x._1.toList.sortBy(_.login), x._2, x._3.toList))) | |
} | |
case x: Seq[String] => Future.successful(Future.successful(InternalServerError(s"Failed to Validate:\n ${x.mkString("\n")}"))) | |
} | |
}.flatMap(identity).flatMap(identity) | |
}.getOrElse { | |
Future.successful(Redirect(routes.PersonController.importFile()).flashing( | |
"error" -> "Missing file")) | |
} | |
}.flatMap(identity) | |
} | |
} | |
-- templates | |
@()(implicit request: Request[_], webJarAssets: WebJarAssets, assets: AssetsFinder) | |
@import helper._ | |
@implicitFieldConstructor = { | |
FieldConstructor(twitterBootstrapInput.f) | |
} | |
@main("Import SAP Extract file") { | |
<!-- Begin page content --> | |
<div class="row"> | |
<div class="col-md-12 col-sm-12 col-xs-12"> | |
<div class="x_panel"> | |
<div class="x_title"> | |
<h2>Import SAP Extract file</h2> | |
<div class="clearfix"></div> | |
</div> | |
<div class="x_content"> | |
@form(action = routes.PersonController.doImport(), 'enctype -> "multipart/form-data") { | |
@CSRF.formField | |
<label for="importFile">The export file from SAP:</label> | |
<input id="importFile" type="file" name="importFile"> | |
<p> | |
Do Import <input type="submit"> | |
</p> | |
} | |
</div> | |
</div> | |
</div> | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment