jbpm-examples その3

HumanTask

もう少し複雑なHuman Taskのサンプル。

ContentDataというクラスを使って、Task越しにデータをやりとりする。なんか面倒くさいんですけど、、、ヘルパークラスつくればいいか。

渡す

       Map<String, Object> results = new HashMap<String, Object>();
       results.put("comment", "Agreed, existing laptop needs replacing");
       results.put("outcome", "Accept");
       ContentData contentData = new ContentData();
       contentData.setAccessType(AccessType.Inline);
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       ObjectOutputStream out;
       try {
               out = new ObjectOutputStream(bos);
               out.writeObject(results);
               out.close();
               contentData = new ContentData();
               contentData.setContent(bos.toByteArray());
               contentData.setAccessType(AccessType.Inline);
       } catch (IOException e) {
               e.printStackTrace();
       }
       taskClient.complete(task1.getId(), "sales-rep", contentData,
taskOperationHandler);

読み出す

       ByteArrayInputStream bis = new ByteArrayInputStream(content.getContent());
       ObjectInputStream in;
       try {
               in = new ObjectInputStream(bis);
               Object result = in.readObject();
               in.close();
               Map<?, ?> map = (Map<?, ?>) result;
               for (Map.Entry<?, ?> entry: map.entrySet()) {
                       System.out.println(entry.getKey() + " = " + entry.getValue());
               }
       } catch (IOException e) {
               e.printStackTrace();
       } catch (ClassNotFoundException e) {
               e.printStackTrace();
       }

さて、このサンプルは HumanTaskExample の main 実行以外にも、jbpm-consoleからテストできる。jbpm-consoleから呼び出すためには一度Guvnorにアップロードして、パッケージをビルドする必要がある。

インストーラディレクトリで

ant start.demo

すれば、Guvnor がデプロイされた JBoss AS7 が立ち上がる。

立ち上がったら Eclipse 側で、[Window] -> [Open Perspective] -> [Other] から 'Guvnor Repository Exploring'パースペクティブに変更、「Guvnor Repositories」ビューのアイコンから、リポジトリを追加します。URLのコンテキストパスはコミュニティ坂なら drools-guvnor、エンタープライズ版なら jboss-brms なので注意。そして「Navigator」ビューから src/main/resources/humantask 以下のファイルを全て選択し、右クリックから [Guvnor]->[Add] でGuvnorへアップロードします。パッケージは defaultPackageで。アップロードされたら今度はGuvnor側で [Knowledge Base]->[defaultPackage] で開き、 [Edit]タブで「Build Package」。

続いて、 http://localhost:8080/jbpm-console にアクセス。ログインは admin/admin。で、[Process Overview]にいくとエラー!

java.lang.NoSuchMethodError:
org.apache.commons.codec.binary.Base64.encodeBase64String([B)Ljava/lang/String;

jbpm 5.2 のインストーラの不具合で、commons-codecのいらんバージョンが入ってしまったようです。5.3では直っているはず。
https://issues.jboss.org/browse/JBPM-3482

$JBOSS_HOME/standalone/deployments/jbpm-gwt-console-server.war/WEB-INF/lib/org.apache.commons.codec_1.3.0.v201101211617.jar

を削除してください。

気を取り直して、再度jbpm-consoleにアクセスすると、[Process Overview]に "Human Task" が見えるはずです。あとはプロセスをスタート、タスクをClaimなどなど。