日曜日, 8月 17, 2008

【Groovyコンファレンスデモ】 フローの実装 このエントリーを含むはてなブックマーク



 今回はフローの実装ということで主にsMashアプリの実装について説明する。
 sMashについては、最近、資料がUpされたようなので、詳細についてはこちらを参照していただきたい。

WebSphere sMash Announcement Workshop資料

 さて、sMashのアプリの説明に移る。今回やったことは以下の2つである。


1)JSONインスタンスをそのまま返すテスト用onListサービス
2)userid,monthパラメータを受け取り、iSeriesのリソースを選択し、検索結果をJSONPで返すonRetrieveサービス


とても単純なフローではあるが、当初の目的は十分に果たしている。ポイントは、パラメータに応じて動的にiSeriesのリソースを選択できていること。iSeriesがしっかりJSONで返すことができれば、後はsMash側で煮るなり焼くなりできる。iSeriesというレガシーシステムにアクセスするシステムで、これほどシンプルに特別な変換処理なく実現できることは驚きである。

 最後に、sMash(ZERO)のインストールなどを含めた今回のPMS Demoのインストールについて以下にまとめてあるので、あわせて参照いただきたい。Groovyコンファレンスデモの話はこれくらいでおしまい。 

pmsdemo


import zero.core.connection.Connection;
import zero.core.connection.Connection.Response;

def onList()
{
  // 初期表示&テスト用
  /*
  def  response = [ report : [ activitydetail : [
         ["07/05","10:00","18:00","JavaScript","暑い","80%"],
         ["07/06","10:00","18:00","CSS","寒い","20%"],
         ["07/07","10:00","18:00","HTML","普通","40%"],
         ["07/08","10:00","18:00","JSON","暖かい","70%"],
         ["07/09","10:00","18:00","Ajax","肌寒い","100%"],
         ["07/10","10:00","18:00","JavaScript","暑い","80%"],
         ["07/11","10:00","18:00","CSS","寒い","20%"],
         ["07/12","10:00","18:00","HTML","普通","40%"],
         ["07/13","10:00","18:00","JSON","暖かい","70%"],
         ["07/14","10:00","18:00","Ajax","肌寒い","100%"],
         ["07/15","10:00","18:00","JavaScript","暑い","80%"],
         ["07/16","10:00","18:00","CSS","寒い","20%"],
         ["07/17","10:00","18:00","HTML","普通","40%"],
         ["07/18","10:00","18:00","JSON","暖かい","70%"],
         ["07/19","10:00","18:00","Ajax","肌寒い","100%"],
         ["07/20","10:00","18:00","JavaScript","暑い","80%"],
         ["07/21","10:00","18:00","CSS","寒い","20%"],
         ["07/22","10:00","18:00","HTML","普通","40%"],
         ["07/23","10:00","18:00","JSON","暖かい","70%"],
         ["07/24","10:00","18:00","Ajax","肌寒い","100%"],
         ["07/25","10:00","18:00","JavaScript","暑い","80%"],
         ["07/26","10:00","18:00","CSS","寒い","20%"],
         ["07/27","10:00","18:00","HTML","普通","40%"],
         ["07/28","10:00","18:00","JSON","暖かい","70%"],
         ["07/29","10:00","18:00","Ajax","肌寒い","100%"]
         ],
      assessment   : ["月の評価",
               "よくできました",
                 "2週目評価",
                 "3週目評価",
                 "4週目評価"
                ],
      plan      : ["月のPlan","1週目plan","2週目plan","3週目plan","4週目泉岳寺にいきます"],
      task      : [
               ["週報システム","設計","クラス図","8/1","8/15","5"],
               ["週報システム","設計","クラス図","8/16","8/19","3"],
               ["取引システム","開発","Javaソース","8/20","8/31","2"]
                ],
      userid     : "user01",
      month     : "200808",
      responsecode  : "201",
      createdate   : "Tue Aug 05 16\\:04\\:44 JST 2008",
      ]
    ];
*/
    Connection.Response resp = Connection.doGET("http://localhost:8083/pmsdemo/jp/reflexworks/pms/model/Report?userid=user1&month=200808&json");
    def body = resp.getResponseBodyAsString();
    def respJSON = zero.json.Json.decode(body);

    // JSONで返す例
    print "var jsobj = ";
    request.json.output = respJSON;
    request.view ="JSON";
    render();
}

def onRetrieve()
{

  def userid = request.params.userid[];
  def month = request.params.month[];
  
  def server="";
  
  // ユーザに応じてアクセス先を変える
  if (userid=="user1") server = "http://localhost:8083/";
  if (userid=="user2") server = "http://localhost:8085/";
    
  // リソースにアクセスする
  def Connection.Response resp = Connection.doGET(server +"/pmsdemo/jp/reflexworks/pms/model/Report?json&userid="+userid+"&month="+month);
  
  // リソースをJSONにする
  def body = resp.getResponseBodyAsString();
  def respJSON = zero.json.Json.decode(body);

  // JSONPで返す
  print "callback(";
  request.json.output = respJSON;
  request.view ="JSON";
  render();
  print ");";
}




0 件のコメント:

 
© 2006-2015 Virtual Technology
当サイトではGoogle Analyticsを使ってウェブサイトのトラフィック情報を収集しています。詳しくは、プライバシーポリシーを参照してください。