dasのデータの管理に、googleのデータストアを使う。
googleのデータストアからデータがとれるとして、
新しく必要だったのはハンドラー。チュートリアルだと、MyPluginにあたるとこ。
http://www.biojava.org/wiki/Dazzle:writeplugin
まずは、チュートリアルどおりにMyPluginを作ってみて動くことを確認。
多少でてくるデータを変えたりしたりした。
データをいれるところを作る。その前に。
次のとこ見たら簡単なことは大体できる。
Datastore Java API Overview - Google App Engine - Google Code
日本語
http://code.google.com/intl/ja/appengine/docs/java/datastore/
英語
http://code.google.com/intl/en/appengine/docs/java/datastore/overview.html
登録したデータを確認したいので、コンソールがあったなぁと思って探したが
javaではどうやってみていいのかわからず、ちょと困ったが
python版の方ですぐみつかった
Python 開発用サーバー - Google App Engine - Google Code
http://code.google.com/intl/ja/appengine/docs/python/tools/devserver.html
管理コンソール
http://localhost:8888/_ah/admin
データをいれるところを作る。
とりあえず、/das/dsnは、いまんとこコンフィグに書いたのでよいので、
entry_pointsに表示するようなデータを扱えるようにする。
さっきのデータストア関係の文書をみてEntryPoint.javaというのをつくってみた
Employee.javaってのがgoogleのデータストアのサンプルにあったので、
それのフィールド名を変更して、あとはeclipseにgetter/setterとコンストラクタとか
作ってもらった。
EntryPoint.java
package com.example.myproject.plugin; import java.util.Date; import javax.jdo.annotations.IdGeneratorStrategy; import javax.jdo.annotations.IdentityType; import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.Persistent; import javax.jdo.annotations.PrimaryKey; @PersistenceCapable(identityType = IdentityType.APPLICATION) public class EntryPoint { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private String name; @Persistent private String type; @Persistent private Long start; @Persistent private Long end; @Persistent private String orientation; public EntryPoint(){ } public EntryPoint(String name, String type, Long start, Long end, String orientation) { super(); this.name = name; this.type = type; this.start = start; this.end = end; this.orientation = orientation; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Long getStart() { return start; } public void setStart(Long start) { this.start = start; } public Long getEnd() { return end; } public void setEnd(Long end) { this.end = end; } public String getOrientation() { return orientation; } public void setOrientation(String orientation) { this.orientation = orientation; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((end == null) ? 0 : end.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((orientation == null) ? 0 : orientation.hashCode()); result = prime * result + ((start == null) ? 0 : start.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; EntryPoint other = (EntryPoint) obj; if (end == null) { if (other.end != null) return false; } else if (!end.equals(other.end)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (orientation == null) { if (other.orientation != null) return false; } else if (!orientation.equals(other.orientation)) return false; if (start == null) { if (other.start != null) return false; } else if (!start.equals(other.start)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; return true; } }
を作ってみた。
実際に追加とかしてみる。
データの作成、取得、削除 - Google App Engine - Google Code
http://code.google.com/intl/ja/appengine/docs/java/datastore/creatinggettinganddeletingdata.html
ここに、作成と取得についてかいてあった。
まずは、アクセスしたらランダムにデータ乎入れるように作ってみて、追加できることを確認した。
ハンドラーを作る
基本的にMyPluginのメソッドの中身を変更するだけ。
もとのソースのコメントに、「ここでデータベースからデータ取得」とか書いてあるのでそのまま指示にしたがう。
GAEPlugin.java
package com.example.myproject.plugin; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; import java.util.TreeSet; import javax.jdo.PersistenceManager; import org.biojava.bio.seq.ProteinTools; import org.biojava.bio.seq.Sequence; import org.biojava.bio.symbol.IllegalSymbolException; import org.biojava.servlets.dazzle.Segment; import org.biojava.servlets.dazzle.datasource.AbstractGFFFeatureSource; import org.biojava.servlets.dazzle.datasource.DataSourceException; import org.biojava.servlets.dazzle.datasource.DazzleReferenceSource; import org.biojava.servlets.dazzle.datasource.GFFFeature; import com.example.myproject.data.EntryPoint; import com.example.myproject.data.PMF; public class GAEPlugin extends AbstractGFFFeatureSource implements DazzleReferenceSource{ public GFFFeature[] getFeatures(String reference) throws DataSourceException{ System.out.println("got a features request for " + reference); return new GFFFeature[0]; } //@Override public GFFFeature[] getFeatures(Segment seg, String[] types) throws DataSourceException { if(types!=null){ for(String type : types){ System.out.println("type="+type); } } PersistenceManager pm = PMF.get().getPersistenceManager(); EntryPoint ep = new EntryPoint(); ep.setName(seg.getReference()); try { //pm.makePersistent(ep); String query = "select from " + EntryPoint.class.getName() + " where name == '"+seg.getReference()+"'"; List<EntryPoint> eps = (List<EntryPoint>) pm.newQuery(query).execute(); ep = eps.get(0); } finally { pm.close(); } List<GFFFeature> features = new ArrayList<GFFFeature>(); // This is up to YOU: // get your data from somewhere, e.g. a database, parse a flat file // whatever you like. // then with your data we fill the GFFFeature objects // GFFFeature is a simple Java-bean GFFFeature gff = new GFFFeature(); gff.setType(ep.getType()); gff.setLabel(ep.getName()); // start and end are strings to support e.g. PDB -file residue // numbering, which can contain insertion codes gff.setStart(Long.toString(ep.getStart())); gff.setEnd(Long.toString(ep.getEnd())); gff.setName("the name of my feature"); gff.setMethod("the dazzle plugin tutorial"); gff.setLink("http://www.biojava.org/wiki/Dazzle:writeplugin"); gff.setNote("the note field contains the actual annotation!"); // see the documentation for GFFFeature for all possible fields features.add(gff); //System.out.println("got a features request for " + reference); System.out.println("hello getFeatures seg="+seg.toString()); return (GFFFeature[]) features.toArray(new GFFFeature[features.size()]); } public Set getEntryPoints() { Set<String> s = new TreeSet<String> (); // this example has only one feature. // for your real data you might want to add a SQL query here. //s.add("123"); PersistenceManager pm = PMF.get().getPersistenceManager(); try { //pm.makePersistent(ep); String query = "select from " + EntryPoint.class.getName();// + " where start > 1"; List<EntryPoint> eps = (List<EntryPoint>) pm.newQuery(query).execute(); for(EntryPoint ep: eps){ s.add(ep.getName()); } } finally { pm.close(); } return s; } public Sequence getSequence(String ref) throws NoSuchElementException, DataSourceException { String seq = "ECNEUQESECNEUQESECNEUQESECNEUQESECNEUQES"; try { Sequence prot = ProteinTools.createProteinSequence(seq, ref); return prot; } catch ( IllegalSymbolException e){ throw new DataSourceException(e.getMessage()); } } }
これで、entry_pointsが使えるようになった。
コンフィグに、自分のデータを表示できるように加える。
データを追加する部分を作る。
とりあえずフォームを用意して投稿できるようにしようとおもった。
あとで、dsnのところとかも追加できるようにしたいので、とりあえず認証をつけてみるテスト。
Google アカウント Java API 概要 - Google App Engine - Google Code
http://code.google.com/intl/ja/appengine/docs/java/users/overview.html
ここのコードをそのまま使ったらうまく動いた。
次
せっかくデータを登録とかできるが、entry_pointsに詳細データがでないので、
それを表示できるようにしてみたい。
どんどんクリックしていったら、feature_idを処理できなかったので、
インターフェースを追加して、処理できるようにしてみたい。
あとは、githubにコードを登録しよう。