OSDN Git Service

Asynchronous implements
authoruyaji <yuichiro.uyama@gmail.com>
Wed, 28 May 2014 03:06:31 +0000 (12:06 +0900)
committeruyaji <yuichiro.uyama@gmail.com>
Wed, 28 May 2014 03:06:31 +0000 (12:06 +0900)
PartsList/PartsList/app/controllers/PartsListController.scala
PartsList/PartsList/app/controllers/services/PartsList.scala
PartsList/PartsList/app/views/partslistshow.scala.html
PartsList/PartsList/conf/routes

index fbf1ce6..a9bb6b2 100644 (file)
@@ -21,6 +21,8 @@ import com.google.inject._
 import modules._
 import scala.io.Source
 import java.io.FileInputStream
+import scala.concurrent.Future
+import play.api.libs.concurrent.Execution.Implicits._
 
 object PartsListController extends Controller{
   val inject = Guice.createInjector(new ServiceModules)
@@ -59,21 +61,21 @@ object PartsListController extends Controller{
       }
     }
    
-       def downLoad(opt:Int, page:Int, key:String, relationKey:String) = AuthAction {
+       def downLoadFuture(opt:Int, page:Int, key:String, relationKey:String) = AuthAction {
      Action { implicit request =>
       if(request == null) {
          Ok(views.html.errors.errorNotAuthentication())
        } else {
-         inTransaction{
-           val partsBuffer = PartsList().getPartsBuffer(opt, page, key, relationKey)
-           var totalCost:Long =0
-           for(partBuffer <- partsBuffer) {
-             totalCost += partBuffer.cost
-             }
-           val attachment = "attachment; filename=" + key + "_download.csv"
-           Ok(views.html.partsListsCsv(partsBuffer)).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv")
+         val futureOfPartsBuffer: Future[Seq[PartsListShowBean]] = Future {
+           PartsList().getPartsBuffer(opt, page, key, relationKey)
+         }
+         val attachment = "attachment; filename=" + key + "_download.csv"
+         Async {
+           futureOfPartsBuffer.map { fpb =>
+             Ok(views.html.partsListsCsv(fpb)).withHeaders(CONTENT_DISPOSITION -> attachment).as("text/csv")
            }
-        }
+         }
+       }
       }
     }
 
index 667e688..af712ae 100644 (file)
@@ -1,11 +1,13 @@
 package controllers.services
 import scala.collection.immutable.Map
 import scala.collection.immutable.Seq
+import org.squeryl.PrimitiveTypeMode._
 import beans._
 import models._
 import models.services._
 case class PartsList() {
        def getPartsBuffer(opt:Int, page:Int, key:String, relationKey:String):Seq[PartsListShowBean] = {
+         inTransaction {
                var partsBuffer = Seq[PartsListShowBean]()
                val targetParts = PartManager().getByName(key)
                if(targetParts.size != 0) {
@@ -14,6 +16,7 @@ case class PartsList() {
                  }
                }
                return partsBuffer
+         }
        }
 
        def getMatrixPartsList(partsListBeans: Seq[Seq[PartsListShowBean]], allChildren: Seq[Part]): Map[Part, Seq[MultiPartsListBean]] = {
index a1763ee..54e6f0a 100644 (file)
            </div>
            
                <div id="action2">
-                       @helper.form(action=routes.PartsListController.downLoad(opt, page, key, relationKey)) {
+                       @helper.form(action=routes.PartsListController.downLoadFuture(opt, page, key, relationKey)) {
                                <input type="hidden" name="opt" value="@opt">
                                <input type="hidden" name="key" value="@key">
                                <input type="hidden" name="relationKey" value="@relationKey">
index 4b69c9e..94d320f 100644 (file)
@@ -5,7 +5,7 @@
 # Home page
 GET     /                                                               controllers.Application.index
 GET     /single_partslist           controllers.PartsListController.index(opt:Int=0, page:Int, key:String, relationKey:String)
-GET     /single_partslist_download  controllers.PartsListController.downLoad(opt:Int, page:Int, key:String, relationKey:String)
+GET     /single_partslist_download_future  controllers.PartsListController.downLoadFuture(opt:Int, page:Int, key:String, relationKey:String)
 GET             /multi_partslist                                controllers.PartsListController.index(opt:Int=1, page:Int, key:String, relationKey:String)
 POST    /multi_partslist                                controllers.PartsListController.index(opt:Int=1, page:Int, key:String, relationKey:String)
 GET             /matrix_partslists                      controllers.PartsListController.matrixPartList(project:String)