doc/ja/AddNewService

サービスの追加方法

1.XMLファイルに定義を追記する

- XMLファイルの場所  inox  Century 21 Broker Properti Jual Beli Sewa Rumah Indonesia

/postlbs-main/src/main/webapp/WEB-INF/data

- ファンクション - functions.xml
サービスで使用するファンクションを定義する。

  <function name="transform">
    <description>transform geometry</description>
    <parameterList>
      <parameter name="geom" type="string" required="true"/>
      <parameter name="crs" type="string" required="true"/>
    </parameterList>
    <formatList>
	  <format name="geojson" template="transform_geojson.st" mimeType="application/json" />
	  <format name="wkt" mimeType="text/plain"/>
    </formatList>
  </function>
</functionList>

- リソース - resources.xml
サービスで使用するリソースを定義する。

<!--例:リソースがpostgisの場合-->
  <resource name="route">
    <type>postgis</type>
    <connection>
      <url>192.168.1.xxx</url>
      <port>5432</port>
      <user>postgres</user>
      <password></password>
      <db>routing</db>
    </connection>
    <characterSet>UTF8</characterSet>
  </resource>

- サービス - services.xml
サービスを定義する。

  <service name="transform" function="transform" resource="none">
    <description>transform wkt geometry</description>
    <formatList>
      <format>geojson</format>
      <format>wkt</format>
    </formatList>
  </service>

- バスケット- baskets.xml
作成したサービスを利用するバスケットに定義を追加する。

<!--例:basicバスケットにtransformサービスを追加する場合-->
  <basket name="basic">
    <description>basic</description>
    <availableServices>
       <config service="transform">
        <description>transform</description>
        <!-- service properties --> 
        <propertyList>
          <property name="test_property">5000</property>
        </propertyList>
        <!-- default parameters -->
        <parameterList>
          <parameter name="crs">EPSG:4326, EPSG:4326</parameter>
        </parameterList>
        <!-- available format -->
        <formatList>
          <format>geojson</format>
          <format>wkt</format>
        </formatList>
      </config>
       <config service="route">
          ・・・
       </config>
    </availableServices>
  </basket>

-- システム設定- configuration.xml
servicePackagesに作成したサービスのパッケージ名を追加する。

  <servicePackages>org.postlbs.samples.service, org.postlbs.core.service</servicePackages>

2.パターンクラスを作成する

- 1.クラスを作成する。
org.postlbs.core.service.AbstractServiceを継承してクラスを作成する。
クラス名は「xxxxService」とすること。

public class TransformService extends AbstractService{
}

- 2.コンストラクタを作成する。
以下のような引数をもつコンストラクタを定義する。
処理は抽象クラスで定義されているので親のコンストラクタを呼ぶだけでよい。 stal

public TransformService(Function function, Resource resource, Map<String, String> propertyMap, Format format) {
	super(function, resource, propertyMap, format);
}

- 3.getResultメソッドを作成する。
このメソッドに結果を取得する処理を実装する。

@Override
protected AbstractFormatMaterial getResult(Map<String, Parameter> parameters) throws ServiceException, DataAccessException {

	// 結果を取得する処理
        ・・・

	// 結果からフォーマット用のデータを作成
	Map<String, Object> valueMap = new HashMap<String, Object>();
        AbstractFormatMaterial  material = new TemplateMaterial(valueMap);

	return valueMap ;
}