この章では、リポジトリ拡張性フレームワーク(REX)アーキテクチャについて説明し、OpenAPIを有効にしてWSDLを使用する方法について解説します。
この章の内容は次のとおりです。
REXは、プログラムでOracle API Catalogに統合するWebサービスAPIです。これは、業界で認められた標準に基づいており、相互運用性とプラットフォームの独立性に重点を置いて設計されています。REXでは、Web Services Description Language (WSDL v1.1)で記述された、リモート・プロシージャ・コール(RPC) Webサービスを使用します。これにより、クライアントで、任意のプラットフォームやWebサービスをサポートする任意の実装言語を使用して、Oracle API Catalogと相互に動作できます。たとえば、Oracle API CatalogはJ2EEアプリケーションですが、REXを使用して.NETクライアントとプログラムで相互に動作できます。
|
注意: flashlineおよびregistryというインスタンスが、特にJavaパッケージ構造およびREXクラス名としてこのドキュメントで使用されています。 |
Oracle API CatalogがSiteminderで保護されるように構成されているか、今後構成される場合、次のURLを無視するか、または保護しないようにポリシー・サーバーを構成して、OpenAPI統合が正しく機能できるようにする必要があります。
http://appserver.example.com/oer/services/
|
注意: このドキュメントで使用している例は説明用であり、Oracle API Catalog WSDLのバージョン間のパッケージ構造の違いのためにコンパイルされません。使用しているバージョンのOracle API Catalogに合うように、パッケージ構造を変更する必要があります。 |
REXの詳細は、Oracle Fusion Middleware Oracle API Catalog拡張性フレームワーク(REX)のREX Javadocを参照してください。
|
注意: REXの全機能がOracle API Catalogに適用されるわけではありません。REX Javadocで説明されているのは、Oracle Enterprise Repositoryでサポートされている機能であり、Oracle API Catalogではありません。このドキュメントに記載したREX機能のみ使用するようにお薦めします。Oracle API Catalogのライセンスには、REXパッケージ・セット全体のサブセットのみの使用権が含まれます。 |
図5-1に、REXのアーキテクチャを示します。
Oracle API CatalogおよびREXの高度なアーキテクチャは、次の高度な目標を考慮して設計されています。
柔軟性
SOAP、WSDLおよびHTTPなどの業界で認められた標準に準拠しているクライアント・プラットフォームは、REXインタフェースを介してOracle API Catalogと相互に動作できます。一般的なクライアント・プラットフォームとAPIが適切に連携することが検証されています。
拡張性
新機能がOracle API Catalogに追加された際に、その機能にアクセスするためのサブシステムの追加プロセスが、Oracle API Catalogの階層化アーキテクチャにより単純化されます。詳細は、第5.2.4項「Oracle API Catalog REXのバージョンの考慮事項」を参照してください。
簡潔性
エンドユーザーは、REXで使用可能な拡張機能を簡単に利用できます。
Oracle API CatalogのREXを使用すると、様々なサブシステムにアクセスできます。これらのサブシステムは、システムの機能を論理的なカテゴリ(動作するエンティティのタイプとほぼ同様)に大まかにグループ化しています。このドキュメントの大部分は、これらのサブシステムに基づいた項で構成されています。
REXメソッドは、様々なサブシステムに基づいたスキームを使用して、名前が付けられています。このプロセスで使用されるアルゴリズムの詳細は、第5.2.2項「CRUD-Q命名規則」を参照してください。REXで定義されているサブシステムは、次のとおりです。
アセット
部門
インポート/エクスポート
ユーザー
オープンAPIメソッドのネーミングで使用されているスキームは、CRUD-Qニーモニックに基づいています。CRUD-Qは、次の5つの操作を表しています。
C: 作成(Create)
R: 読取り(Read)
U: 更新(Update)
D: 削除(Delete)
Q: 問合せ(Query)
各メソッドは、次の例のように、そのメソッドが属するサブシステムの名前で始まり、次にそのサブシステム内で実行される操作の説明が続きます。
<サブシステム><操作>
たとえば、アセット・サブシステムで作成の操作を実行するメソッド名は、次のようになります。
assetCreate(...)
この命名規則を使用すると、次のような名前も考えられます。
assetRead(...) assetUpdate(...) assetDelete(...) assetQuery(...)
サブシステムにはCRUD-Qセット以外の操作が含まれていることがあります。また、CRUD-Qの操作をすべて含んでいるわけではありません。たとえば、ユーザーを削除できないので、userDeleteメソッドはありませんが、userDeactivateメソッドはあります。表5-1に、サブシステムがCRUD-Q操作以外に含めることのできる操作の詳細なリストを示します。
表5-1 サブシステムとCRUD-Q規則の関係
| 作成 | 読取り | 更新 | 削除 | 問合せ | その他の機能 | |
|---|---|---|---|---|---|---|
|
アセット |
はい |
はい |
はい |
はい |
はい |
|
|
部門 |
はい |
はい |
はい |
いいえ |
はい |
|
|
ユーザー |
はい |
はい |
はい |
いいえ |
はい |
アクティブ化、非アクティブ化、ロックアウト、未承認 |
REXでは、次の基本的なWSDLデータ型およびWSDLで定義された複合の型が使用されています。
これらの型の配列が返されます。
xsd:int
xsd:long
xsd:string
xsd:boolean
xsd:dateTime
次のURLのIDEまたはWebサービス・ツールキットを指して、REX WSDLを使用することにより、APIスタブを動的に生成できます。
http://appserver/oer/services/FlashlineRegistry?WSDL
Oracle BPM 11gからOERとのカスタム統合を作成する場合は、その代わりに次のURLを使用します。
http://appserver/oer/services/RexAPI?wsdl
Oracle API Catalog REX WSDLのためのJavaスタブは、AXIS WSDL2javaユーティリティを使用して作成できます。
java -cp .;axis.jar; xerces.jar; commons-discovery.jar; commons-logging.jar; jaxen-full.jar; jaxrpc.jar; saaj.jar;wsdl4j.jar; xalan.jar org.apache.axis.wsdl.WSDL2Java
この変換プロセスの完了に必要なJARファイルは、次のとおりです。
axis.jar
xerces.jar
commons-discovery.jar
commons-logging.jar
jaxen-full.jar
jaxrpc.jar
saaj.jar
wsdl4j.jar
xalan.jar
|
注意: URL内のappserverは、Oracle API Catalogがインストールされているサーバーの名前で置き換えてください。 |
Oracle API Catalog REXはOracle API Catalogと同様に発展します。このプロセスの結果として、REXの新旧バージョン間で非互換が起こることがあります。すべてのバージョン間の互換性の実現を目標としていますが、下位互換性が実現されるかどうかは予測できない場合もあります。したがって、制限が避けられない可能性があります。Oracle API Catalog REXには、次の後方互換性を持つ拡張が含まれています。
Oracle API Catalog Weサービスへの新しいメソッドの追加
WSDLでの新しい複合型の定義
これらの下位互換性への変更に関して、新機能を利用する必要がある場合にかぎり、クライアント・プロキシの再生成が必要になります。
非互換の変更を回避できない場合にかぎり、サービスのネームスペースが変更されます。このような変更の例には、既存の複合型の変更や、サービスのメソッドの署名における変更があります。この場合、最低限のコード変更があるので、クライアント・プロキシの再生成が必要です。以前のバージョンのREXから生成されたクライアント・プロキシでは、新しいサービスに接続できません。
複合型のネームスペースは変更されません。
この項では、オープンAPIの有効化およびWSDLの使用の開始方法などのREXの基本的な概念について説明します。
この手順は、Oracle API Catalogの「管理」画面で実行します。
「システム設定」をクリックします。
新しいシステム設定の有効化テキスト・ボックスにプロパティcmee.extframework.enabledを入力します。
「有効化」をクリックします。オープンAPIセクションが表示されます。
cmee.extframework.enabledプロパティにTrueが設定されていることを確認します。
「保存」をクリックします。これで、REXがOracle API Catalogインスタンス内で有効になりました。
REXを使用するための最初の手順は、Oracle API Catalogサーバーとの通信に必要なクライアント側スタブの生成です。これは、通常、特定のWebサービス・ツールキットで提供されている自動ツールを使用して実行されます。この項では、様々な統合開発環境およびツールキットを使用して、クライアント・スタブを生成する方法について説明します。
認証と認可
REXを使用するための最初の手順は、サーバーでの認証です。authTokenCreateメソッドを使用して認証が実行されます。このメソッドは、Oracle API Catalogでの認証で使用する際に、ユーザーIDとパスワードを引数として取ります。IDとパスワードの認証が成功すると、認証トークンが返されます。このトークンは、後続のすべてのREXの呼出しで使用する必要があります。
有効なAuthTokenがすべてのREXメソッドに含まれていない場合、OpenAPIExceptionがスローされます。これは、authTokenCreateおよびauthTokenDelete以外のすべてのメソッドに適用されます。
次の例は、AuthTokenを取得してこれを後続のREX呼出しで使用する方法を示しています。
例5-1 AuthTokenを取得してREX呼出しで使用する方法
package com.example.flashlineclient;
//The imports below are assumed for any of the included examples
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Asset;
public class FlexTest {
public FlexTest () {
}
public static void main(String[] pArgs)throws OpenAPIException, RemoteException, ServiceException {
try {
FlashlineRegistry lRegistry = null;
AuthToken lAuthToken = null;
URL lURL = null;
lURL = new URL("http://www.example.com/appname/services/FlashlineRegistry");
//"www.example.com" should be your server address
//"appname" is the application name of the location that the Registry is running
on
//These two things must be changed to the proper values in every example
lRegistry = new FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
lAuthToken = lRegistry.authTokenCreate("username", "password");
System.out.println(lAuthToken.getToken());
//displaying the authtoken as a string to the screen
Asset lAsset = lRegistry.assetRead(lAuthToken, 559);
//reading asset number 559
System.out.println(lAsset.getName());
//displaying the name of asset 559 to the screen
} catch(OpenAPIException lEx) {
System.out.println("ServerCode = "+ lEx.getServerErrorCode());
System.out.println("Message = "+ lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
System.out.println("execution completed");
System.exit(0);
}
}
認可
REXでは、Oracle API Catalogアプリケーションと同じ認可ルールが実行されます。認可に使用するユーザーIDとパスワードでは、REXでユーザーに使用できる権限が判定されます。たとえば、プロジェクトに割り当てられた編集権限を持たない認証済のユーザーがprojectCreate REXメソッドを使用してプロジェクトを作成しようとした場合、OpenAPIExceptionがスローされます。
例外処理
オープンAPIはSOAPフォルトでサーバー・エラーをクライアントに通知します。SOAPフォルトが処理される方法は、使用している言語とSOAPツールキットによって異なります。
この項では、一般的なプラットフォームとツールキットの組合せを使用して、クライアント・コード内でオープンAPIが生成した例外を検出して処理する方法を示します。
JavaとAXIS
オープンAPIがスローした例外は、SOAPフォルトとして転送されてから、AXISクライアント・ツールキットでJava例外としてデシリアライズされます。つまり、AXISは、SOAPフォルトを対応するクライアント側OpenAPIExceptionクラスにマップしようとします。サーバー側エラーは、com.flashline.registry.openapi.OpenAPIExceptionインスタンスとしてクライアントに示されます。したがって、クライアント・コードは、前述のコードから、次に示したコードで例外を取得できます。
try {
lAsset = lRegistry.assetCreate(..);
} catch(OpenAPIException lEx) {
System.out.println("ServerCode = "+ lEx.getServerErrorCode());
System.out.println("Message = "+ lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
検証
エンティティをOracle API Catalogに保存しようとする際に、入力内容の検証が試行されます。欠落しているデータや無効なデータがあると、サーバーは、フィールドのリストとそれぞれのエラーが含まれるOpenAPIExceptionをスローします。
詳細は、「例外処理」を参照してください。
REXにおける問合せの考慮事項
基準オブジェクトは、現在、用語とグループ化のさらに柔軟性の高い表現に移行しています。このオブジェクトが発生すると、これらの変更は、基準オブジェクトを使用して問合せを実行する場合に、特定のAPI機能を使用できるかどうかに影響します。サブシステムでは、対応する基準オブジェクトのみ直接評価されます。このドキュメントで説明しないかぎり、基礎となるSearchTermGroupの拡張機能は使用されません。
バイナリ・データの送信(添付ファイル)
様々なREXメソッドでは、クライアントとサーバー間で大量のバイナリ・データの送受信を必要とする場合があります。たとえば、インポート/エクスポート・サブシステムでは、インポート元からペイロードを送信するメソッドやエクスポート済アセットを表すペイロードを受信するメソッドが提供されています。
通常、バイナリ・データは、WebサービスのRPC起動によって、Dynamic Internet Message Exchange (DIME)、SOAP with Attachments (SwA)またはBase-64エンコーディングを介して、転送されます。それぞれに長所と短所がありますが、3つすべてを直接サポートしているクライアントは少数です。
Oracle API CatalogのオープンAPIは、バイナリ・データの転送に3つのメカニズムすべてをサポートしています。詳細は、次の項を参照してください。バイナリ・データの転送に提供されているメソッドには3つのバージョンがあり、それぞれが異なる転送メカニズムをサポートしています。たとえば、エクスポート結果を取得するには、ユーザーは次のメソッドのいずれかを選択できます。
importGetResultsB64
base-64エンコーディング形式でエクスポート結果を取得します。これは、あまり一般的ではありませんが、クライアントがbase-64データをエンコードまたはデコードできる場合は、どのプラットフォームでも使用できます。
importGetResultsDIME
DIMEプロトコルを使用して、エクスポート結果を添付ファイルとして取得します。これは、ほとんどの.NETクライアントに優先される選択肢です。
importGetResultsSwA
SOAP with Attachments (SwA)プロトコルを使用して、エクスポート結果を添付ファイルとして取得します(MIMEベース)。
.NETとMicrosoft Web Services Enhancement (WSE)キットでのDIME添付ファイルの使用
Microsoftでは、標準の.Net Webサービス・ツールキットの拡張を提供しています。Microsoft Web Services Enhancement (WSE)キットでは、Dynamic Internet Messaging Exchange (DIME)プロトコルを使用して、Webサービスを介した添付ファイルの送受信などの拡張機能を提供しています。
次のコード・スニペットは、DIME添付ファイルによるデータ送信の例を示しています。
例5-2 DIME添付ファイルによるデータ送信の例
// relax the requirement for the server to understand ALL headers. This MUST be
// done, or the call with the attachment fails. After the call, if you wish,
// you can set this back to "true"
registry.RequestSoapContext.Path.EncodedMustUnderstand= "false";
// clear the attachments queue
registry.RequestSoapContext.Attachments.Clear();
registry.RequestSoapContext.Attachments.Add(
new Microsoft.Web.Services.Dime.DimeAttachment("0", "application/zip",
Microsoft.Web.Services.Dime.TypeFormatEnum.MediaType, "c:\\tmp\\import.zip"));
// start an import running on the server
registry.importExecute(lAuthToken, "flashline", null, "FEA Flashpack Import",
null);
// do some polling (calls to importStatus) to monitor the import progress,
// if you wish
次のコード・スニペットは、DIME添付ファイルによるデータ受信の例を示しています。
例5-3 DIME添付ファイルによるデータ受信の例
// relax the requirement for the server to understand ALL headers. This MUST be
// done, or the call with the attachment fails. After the call, if you wish,
// you can set this back to "true"
registry.RequestSoapContext.Path.EncodedMustUnderstand= "false";
// clear the attachments queue
registry.RequestSoapContext.Attachments.Clear();
// start an export
flashline.ImpExpJob lJob =
registry.exportExecute(lAuthToken, "flashline", null, "Complete Export",
"flashline",
"<entitytypes>
<entitytype type=\"acceptableValueList\">
<entities>
<entity id=\"100\"/>
</entities>
</entitytype>
</entitytypes>");
// do some polling (calls to exportStatus) to watch the progress of the
// export, if you wish...
// this call blocks until either the method returns (or an exception is
thrown),
// or the call times out.
registry.exportGetResultsDIME(lAuthToken, lJob);
// check to see if the call resulted in attachments being returned...
if(registry.ResponseSoapContext.Attachments.Count > 0)
{
Stream lStream = registry.ResponseSoapContext.Attachments[0].Stream;
// write the data out somewhere...
}
添付ファイルとJava AXISクライアントでのSOAPの使用
Axisクライアントでは、SOAP添付ファイルをJavaで処理する機能が提供されています。詳細は、http://www-106.ibm.com/developerworks/webservices/library/ws-soapatt/を参照してください。
次のコード・スニペットは、データ受信の例を示しています。
byte[] lResults = null;
ImpExpJob lExportJob =
mFlashlineRegistrySrc.exportExecute(mAuthTokenSrc,"flashline",null,
"Export Assets","default", createAssetQuery().toString());
lExportJob =
mFlashlineRegistrySrc.exportStatus(mAuthTokenSrc, lExportJob);
lResults =
mFlashlineRegistrySrc.exportGetResultsB64(mAuthTokenSrc, lExportJob);
// write the results out to disk in a temp file
File lFile = null;
String lTempDirectory =
System.getProperty("java.io.tmpdir");
lFile = new File(lTempDirectory + File.separator + "impexp.zip");
FileOutputStream lOS = new FileOutputStream(lFile);
BufferedOutputStream lBOS = new BufferedOutputStream(lOS);
lBOS.write(lResults);
lBOS.flush();
lBOS.close();
lOS.close();
次のコード・スニペットは、DIME添付ファイルによるデータ送信の例を示しています。
// open file and attach as data source InputStream lIS = new FileInputStream(lFile); ((Stub)mFlashlineRegistryDest)._setProperty (Call.ATTACHMENT_ENCAPSULATION_FORMAT, Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME); ByteArrayDataSource lDataSource = new ByteArrayDataSource(lIS, "application/x-zip-compressed"); DataHandler lDH = new DataHandler(lDataSource); // add the attachment ((Stub)mFlashlineRegistryDest).addAttachment(lDH); ImpExpJob lJob = mFlashlineRegistryDest.importExecute(mAuthTokenDest, "flashline", null, "Import Assets Test", null);
この項では、REX APIの説明とユースケースを示します。
|
注意: REXの全機能がOracle API Catalogに適用されるわけではありません。REX Javadocで説明されているのは、Oracle Enterprise Repositoryでサポートされている機能であり、Oracle API Catalogではありません。このドキュメントに記載したREX機能のみ使用するようにお薦めします。 |
この項では、アセットAPIについて説明し、アセットAPIのユースケースを示します。このユースケースで、アセットの作成または変更、アセットの検索の作成、およびアセット・ステータスとアセット・タブの操作を行う方法について解説します。
アセットは、Oracle API Catalogのコア・エンティティです。このドキュメントには、アセット・サブシステムのアクションの作成、読込み、更新、削除および問合せについて記述されています。また、次の項目の更新についても記述されています。
アセットのアクティブ・ステータス:
アクティブ化
非アクティブ化
リタイア
アセットの登録ステータス:
発行
承認
登録
未発行
未許可
登録解除
アセットの割当てステータス:
割当て
未割当て
REXを使用してOracle API Catalogのアセットを操作する場合、いくつかの問題を考慮する必要があります。メモリー消費におけるトレードオフとパフォーマンスについて、よく検討する必要があります。
メモリーの消費
アセットおよびそのメタデータは、REXサーバーとREXを使用するクライアント・ソフトウェアの両方で、かなりの量のメモリーを消費します。REXを使用してOracle API Catalogを検索する場合、多数のアセットが返される可能性があります。サービス拒否によるシステムの中断を回避するために、管理者は、REXメソッドのassetQueryのコールで返される結果の最大数を制限します。システム設定のcmee.extframework.assets.maxでは、問合せの結果として返される検索結果の最大数を制御します。問合せに一致する結果の数が最大数を超えると、REXによって例外が生成されます。
多数のアセットが問合せに一致する可能性がある場合、assetQuerySummaryメソッドをお薦めします。Oracle API Catalogに問合せを実行する別の方法では、assetQueryへのコールとして同じアセットと完全一致させますが、完全なアセット・オブジェクトではなく、軽量アセット・サマリー・オブジェクトを返します。これらのサマリー・オブジェクトのメモリーの消費量は少ないので、問合せの結果としてリソースを使い果す可能性はほとんどありません。
サマリー問合せが実行された後、assetReadまたはassetReadArrayFromSummaryのいずれかを使用して、完全なアセット・オブジェクトを対象アセットのために取得できます。複数のアセットが必要な場合、assetReadArrayFromSummaryメソッドを使用することをお薦めします。このメソッドの使用方法の詳細は、APIのドキュメントを参照してください。
パフォーマンス
REXは、標準的なWebサービス・テクノロジに基づいており、柔軟性と移植性において多数の利点があります。ただし、あらゆるWebサービスに基づいたテクノロジと同様に、特にデータ量が多い状況(多数のアセットを操作する場合など)で、パフォーマンスがあまりよくないことがあります。REXでは、想定されるパフォーマンスの問題を開発者が回避できるオプションがあります。
反復する読込み
Webサービス・テクノロジの主なオーバーヘッドは、ネットワーク転送と組み合せた、XMLを使用するシリアライズとデシリアライズで起こります。このようなオーバーヘッドの多くは、多数のアセットが読み込まれる状況で回避できます。たとえば、REXを使用して、50個のアセットをOracle API Catalogから取得する場合、assetReadが50回コールされます。よりよい方法として、必要なアセットのIDを単一の引数として渡す、assetReadArrayメソッドを使用する方法を採用するとします。これを使用すると、1回のコールですべての50個のアセットが取得されるので、パフォーマンスがかなり向上します。
リスト表示操作
エンドユーザーにリスト表示するために、REXからデータを取得することがあります。この場合、アセットをよく検査して選択する必要があります。このような場合、完全なアセット・メタデータは、サマリー・リストの生成に必要ありません。前述のメモリーに関する項で説明したとおり、REXで提供されたサマリー・メソッドを使用することを検討してください。
アクセス制御
REXのユーザーに表示されるアセットおよびこれらのアセットの情報は、アクセス設定によって、ある程度制御されます。Web GUIを介してシステムにアクセスするユーザーのために存在する、同様のアクセス制限もREXアセット・サブシステムに適用されます。
問合せの制限: assetQueryまたはassetReadをコールする場合、ユーザーが取得できるのは、表示権限のあるアセットのみです。
更新の制限: ユーザーが更新できるのは、編集権限のあるアセットのみです。
ファイルの制限: ユーザーが表示できるのは、各ファイルに適用済のファイル・タイプのカスタム・アクセス設定で設定されているように、ダウンロード権限のあるファイルのみです。つまり、ユーザーはアセットを表示できますが、アセットのファイルの中には表示できないものもあるということです。各ファイルには、アセットの権限とは別に、そのファイル用の権限があります。特定のファイル・タイプの権限がファイルに適用されていない場合、これらの権限はそのファイルが属するアセットの権限から継承されます。
この項では、次の項目の定義について説明します。
IDおよびUUID
IDは、単一のOracle API Catalogインスタンス内でアセットを一意に特定するために内部で使用される一意の識別子(数値)です。
UUIDは、Oracle API Catalogのインスタンスで一意にアセットを特定するためにユニバーサルに使用される識別子(16進数で表される128ビットの数値)です。各アセットのUUIDは、主に読込みと検索用に表示されます。REXを使用してこのフィールドを変更しないことを強くお薦めします。ただし、管理者がアセットのUUIDを変更することを選択した場合、フォーマットは一貫している必要があります(00000000-0000-0000-0000-000000000000)。また、UUIDは、ターゲットのOracle API Catalogインスタンス内で一意である必要があります。これ以外の場合、変更操作は失敗します。
名前およびバージョン
アセットを一意に特定するために結合した文字列のフィールド。
カスタム・データ
アセットのカスタマイズ可能なメタデータは、この文字列内にXML構造で保存されています。サンプル・コードでは、カスタム・データ・メソッドを記述しています。
例5-4 カスタム・データ・メソッドのサンプル・コード
package com.flashline.sample.assetapi;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.xml.rpc.ServiceException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class UpdateCustomData {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException, ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
////////////////////////////////////////////////////////////
// Login to OER
////////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
//////////////////////////////////////////
// assetUpdateCustomDataString
//////////////////////////////////////////
// Find and Modify a custom data field value with a value supplied on the
command line
Long currentLicenses = new
Long(repository.assetReadCustomDataString(authToken, 589, "/
_-total-licenses-owned"));
currentLicenses = new Long(currentLicenses.intValue() + 1);
// save the modifications
// NOTICE: A leading slash is required to specify the appropriate path to
the element being updated.
repository.assetUpdateCustomDataString(authToken, 589, "/
_-total-licenses-owned", currentLicenses.toString());
//////////////////////////////////////////
// assetUpdateCustomDataStringArray
//////////////////////////////////////////
// Add a custom data field value with a value supplied on the command line
Format formatter = new SimpleDateFormat("yyyyMMdd");
String dateFormat = formatter.format(new Date());
// NOTICE: for the following method, there is no leading slash for the
elements being updated.
String[] versionHistory = {"version-history/version-history/version-number",
"version-history/version-history/production-date-yyyymmdd-",
"version-history/version-history/comments"};
String[] versionHistoryValues = {currentLicenses.toString(), dateFormat,
"Updated version History: " + dateFormat};
// save the modifications
repository.assetUpdateCustomDataStringArray(authToken, 589, versionHistory,
versionHistoryValues);
//////////////////////////////////////////
// assetUpdateCustomDataNode
//////////////////////////////////////////
//The following updates a specific custom data element called
"document-name" that is a child of "document",
//which is a child of "documentation"
XPath lXPath = null;
List lElms = null;
//First read the Node "documentation" of the specific asset
String lXMLDocumentation = repository.assetReadCustomDataNode(authToken,
589, "documentation");
//Using DOM, convert the XML to a Document
Document lDoc = null;
SAXBuilder lBuilder = new SAXBuilder();
StringReader lReader = null;
lReader = new StringReader(lXMLDocumentation);
lBuilder.setValidation(false);
lBuilder.setIgnoringElementContentWhitespace(true);
lDoc = lBuilder.build(lReader);
lXPath = XPath.newInstance("documentation/document");
lElms = lXPath.selectNodes(lDoc);
//Cycle through the "document" elements until we find the one we want. Then
update it.
for (int i=0;i<lElms.size();i++) {
Element lElm = (Element)lElms.get(i);
List lChildElms = lElm.getChildElements();
for (int x=0;x<lChildElms.size();x++) {
Element lChildElm = (Element)lChildElms.get(x);
if (lChildElm.getName().equals("document-name") &&
lChildElm.getValue().equals("API")) {
lChildElm.setText("API KHAN");
} else {
lChildElm.setText(lChildElm.getValue());
}
}
}
//Convert the Document back to an XML string and update the asset's custom
data.
repository.assetUpdateCustomDataNode(authToken, 589, "documentation", new
XMLOutputter().outputString(lDoc));
//////////////////////////////////////////
// assetUpdateCustomDataNodeArray
//////////////////////////////////////////
try {
//The following updates multiple custom data elements. One is called
"document-name" that is a child of "document",
//which is a child of "documentation"
//The other is the element called "also-known-as"
lXPath = null;
lElms = null;
//First read the Node "documentation" of the specific asset
lXMLDocumentation = repository.assetReadCustomDataNode(authToken, 589,
"documentation");
//Using DOM, convert the XML to a Document
lDoc = null;
lBuilder = new SAXBuilder();
lReader = null;
lReader = new StringReader(lXMLDocumentation);
lBuilder.setValidation(false);
lBuilder.setIgnoringElementContentWhitespace(true);
lDoc = lBuilder.build(lReader);
lXPath = XPath.newInstance("documentation/document");
lElms = lXPath.selectNodes(lDoc);
//Cycle through the "document" elements until we find the one we want.
Then update it.
for (int i=0;i<lElms.size();i++) {
Element lElm = (Element)lElms.get(i);
List lChildElms = lElm.getChildElements();
for (int x=0;x<lChildElms.size();x++) {
Element lChildElm = (Element)lChildElms.get(x);
if (lChildElm.getName().equals("document-name") &&
lChildElm.getValue().equals("API")) {
lChildElm.setText("API KHAN");
} else {
lChildElm.setText(lChildElm.getValue());
}
}
}
String lDoc1 = new XMLOutputter().outputString(lDoc);
//Get the next element
lXMLDocumentation = repository.assetReadCustomDataNode(authToken, 589,
"also-known-as");
lDoc = null;
lBuilder = new SAXBuilder();
lReader = null;
lReader = new StringReader(lXMLDocumentation);
lBuilder.setValidation(false);
lBuilder.setIgnoringElementContentWhitespace(true);
lDoc = lBuilder.build(lReader);
lXPath = XPath.newInstance("also-known-as");
lElms = lXPath.selectNodes(lDoc);
//Get the also-known-as element
for (int i=0;i<lElms.size();i++) {
Element lElm = (Element)lElms.get(i);
lElm.setText("Modified Alias");
}
String lDoc2 = new XMLOutputter().outputString(lDoc);
//Convert the Document back to an XML string and update the asset's custom
data.
repository.assetUpdateCustomDataNodeFromStringArray(authToken, 589, new
String[] {"documentation", "also-known-as"}, new String[] {lDoc1, lDoc2});
} catch (Exception e) {
e.printStackTrace();
}
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
この項では、アセットAPIで使用される次の関連サブシステムについて説明します。
AssetType
すべてのアセットには、アクティブで有効なアセット・タイプが必要です。このアセット・タイプは、アセット用のカスタム・データに保存できるメタデータを定義します。
ベンダー
必要に応じて、アセットをベンダーにリンクできます。リンクはベンダーID別に行います。
許容値
アセットを作成または編集する場合、許容値リストに含まれる許容値は、アセット・タイプ用に定義されたメタデータ要素のオプションとして使用します。許容値リストの許容値を使用するには、アセット(Asset.GetCustomData())のカスタム・データを変更して、許容値のIDを参照します。
リレーションシップ・タイプ
リレーションシップ・タイプは、アセット間に存在できるリレーションシップの種類を定義します。
カテゴリ分けタイプ
カテゴリ分けタイプは、アセット・タイプに追加された最上位レベルのグループのカテゴリ分けです。カテゴリ分けは、アセットを記述します。
プロジェクト
アセットは、プロジェクト別に作成できます。アセット用にプロジェクトを作成すると、IDの配列で格納されます。
ユーザー
ユーザーはアセットに割り当てることができます。メタデータの操作の担当者です。
この項では、アセットAPIを使用するユースケースについて説明します。内容は次のとおりです。
説明
新しいアセットを作成し、Oracle API Catalogに入れます。
サンプル・コード
例5-5 ユースケース: 新しいアセットの作成
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class CreateNewAsset {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////
// Login to OER
///////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
///////////////////////////////////
// Create new asset
///////////////////////////////////
Asset myAsset = repository.assetCreate(authToken,
"My Asset Name108", "My Version
"+Calendar.getInstance().getTimeInMillis(), 144);
////////////////////////////////////////////
//The following demonstrates how to modify a custom data Date element on an
asset.
//This date must be in a specific format and the name of the element must by
known.
//In this example, the name of the element is "testdate". This element must
have been created in the
//asset type as a Date element
//Update the testdate field to January 1, 2007
//Note: the format of the date should match the system setting for Short
Date.
repository.assetUpdateCustomDataString(authToken, myAsset.getID(),
"testdate", "2007-1-1");
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
アセットのXML表現から新しいアセットを作成することもできます。スキーマを使用してアセットのXMLを検証してから、作成します。アセット・タイプのスキーマは、例5-6に示されているように、オープンAPIで使用できます。
個別に検証を実行する必要はありません。作成の前に、アセットのXMLが内部で検証されるためです。個別に検証を実行する場合、Xerces 2.0などの検証用のXMLパーサーを見つける必要があります。
サンプル・コード
例5-6 ユースケース: XMLからの新しいアセットの作成
package com.flashline.sample.assetapi;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.rpc.ServiceException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class CreateNewAssetFromXML {
public static void main(String pArgs[]) throws ServiceException,
ParserConfigurationException, SAXException, IOException {
String SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
SAXParserFactory lSaxParserFactory = null;
SAXParser lSaxParser = null;
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////
// Login to OER
///////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
// Anonymous class to handle validation errors
DefaultHandler lDefaultHandler = new DefaultHandler() {
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
};
//////////////////////////////////////////////////////////////////////
// Define the asset you want to create in XML
//////////////////////////////////////////////////////////////////////
// This is the XML of the asset we're creating. Typically it would
// come from a GUI or other asset creation mechanism. It is hard
// coded for this example.
/////////////////////////////////////////////////////////////////////
String assetXML = "<asset id=\"0\">"
+ " <asset-type id=\"145\" icon=\"component.gif\"
lastSavedDate=\"17 Jul 2007 12:00:00 AM\">Component</asset-type>"
+ " <mandatory-data>"
+ " <name>NewComponent</name>"
+ "
<version>"+Calendar.getInstance().getTimeInMillis()+"</version>"
+ " <description><![CDATA[My Description]]></description>"
+ " <keywords/>"
+ " <notification-email/>"
+ " <applied-policies/>"
+ " <vendor id=\"0\"/>"
+ " <file-informations/>"
+ " <hash-informations/>"
+ " <producing-projects/>"
+ " <submission-files/>"
+ " <applied-compliance-templates/>"
+ " <contacts/>"
+ " <relationships/>"
+ " <categorization-types/>"
+ " </mandatory-data>"
+ " <admin-data>"
+ " </admin-data>"
+ " </asset>";
//////////////////////////////////////////////////////////////////////
// This returns the Schema for the asset type of the asset we're
// creating
//////////////////////////////////////////////////////////////////////
String schema = repository.assetTypeSchemaRead(authToken, 144);
//////////////////////////////////////////////////////////////////////
// This block of code shows validating the asset XML against
// the schema
//////////////////////////////////////////////////////////////////////
lSaxParserFactory = SAXParserFactory.newInstance();
lSaxParserFactory.setNamespaceAware(true);
lSaxParserFactory.setValidating(true);
lSaxParser = lSaxParserFactory.newSAXParser();
lSaxParser.setProperty(SCHEMA_LANGUAGE, XML_SCHEMA);
lSaxParser.setProperty(SCHEMA_SOURCE, new InputSource(new StringReader(
schema)));
lSaxParser.parse(new InputSource(new StringReader(assetXML)),
lDefaultHandler);
//////////////////////////////////////////////////////////////////////
// If no exception was thrown the asset XML validates and
// the creation should not fail due to XML formatting errors.
//////////////////////////////////////////////////////////////////////
repository.assetCreateFromXML(authToken, assetXML);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
既存のアセットのメタデータを変更します。
サンプル・コード
例5-7 ユースケース: アセットの変更
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Categorization;
import com.flashline.registry.openapi.entity.CategorizationType;
import com.flashline.registry.openapi.query.CategorizationTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class ModifyExistingAsset {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
////////////////////////////////////////////////////////////
// Login to OER
////////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
////////////////////////////////////////////////////////////
// Read the asset you want to modify
////////////////////////////////////////////////////////////
Asset myAsset = repository.assetRead(authToken, 559);
// 559 is the example asset number
////////////////////////////////////////////////////////////
// Modify the name, version, description, and notification
// email
////////////////////////////////////////////////////////////
myAsset.setName("New Name");
myAsset.setVersion("New Version");
myAsset.setDescription("New Description");
myAsset.setNotificationEmail("user@example.com");
////////////////////////////////////////////////////////////
// Modify Categorizations on the asset
////////////////////////////////////////////////////////////
// Setup arrays used for assigning categorizations
CategorizationType[] lAllCatTypes = null;
Categorization[] lAllCats = null;
CategorizationType[] lCatTypes = new CategorizationType[1];
Categorization[] lCats = new Categorization[1];
////////////////////////////////////////////////////////////
// Search for all categorizations that are asset assignable
////////////////////////////////////////////////////////////
CategorizationTypeCriteria categorizationTypeCriteria = new
CategorizationTypeCriteria();
categorizationTypeCriteria.setNameCriteria("");
lAllCatTypes = repository.categorizationTypeQuery(authToken,
categorizationTypeCriteria);
////////////////////////////////////////////////////////////
// Find all the categorizations to be assigned to the asset
////////////////////////////////////////////////////////////
for (int i = 0; i < lAllCatTypes.length; i++) {
CategorizationType lCatType = repository.categorizationTypeRead(
authToken, lAllCatTypes[i].getID());
lAllCats = repository.categorizationReadByType(authToken,
lCatType, true, true);
if (lAllCats.length > 0) {
lCatTypes[0] = lCatType;
// when we find the first one, use it
break;
}
}
lCats[0] = lAllCats[0];
////////////////////////////////////////////////////////////
// Modify the asset to use the categorizations
////////////////////////////////////////////////////////////
myAsset.setCategorizations(lCats);
myAsset.setCategorizationTypes(lCatTypes);
////////////////////////////////////////////////////////////
// Modify the custom access settings for the asset
////////////////////////////////////////////////////////////
String[] lCasTypes = repository.customAccessSettingTypesGet(authToken);
String[] lCustomAccessSettings = null;
if (lCasTypes!=null && lCasTypes.length>0) {
lCustomAccessSettings = repository.customAccessSettingNamesGet(authToken,
lCasTypes[0]);
}
if (lCustomAccessSettings!=null && lCustomAccessSettings.length>0) {
String[] myCustomAccessSettings = { lCustomAccessSettings[0] };
myAsset.setCustomAccessSettings(myCustomAccessSettings);
}
////////////////////////////////////////////////////////////
// Add producing projects to the asset
////////////////////////////////////////////////////////////
long[] producingProjectsIDs = new long[1];
producingProjectsIDs[0] = 50000;
myAsset.setProducingProjectsIDs(producingProjectsIDs);
////////////////////////////////////////////////////////////
// save the modifications
////////////////////////////////////////////////////////////
repository.assetUpdate(authToken, myAsset);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
複数のユーザーを1つのアセットに割り当てることができます。
サンプル・コード
例5-8 ユースケース: アセットへのユーザーの割当て
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AssignedUser;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RegistryUser;
import com.flashline.registry.openapi.query.UserCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssignUsers {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
//////////////////////////////////////////////////////////
// Login to OER
//////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
//////////////////////////////////////////////////////////
// Retrieve desired asset
//////////////////////////////////////////////////////////
Asset myAsset = repository.assetRead(authToken, 559);
// 559 is the example asset number
//////////////////////////////////////////////////////////
// Create array of AssignedUser objects
//////////////////////////////////////////////////////////
AssignedUser[] lUsers = new AssignedUser[3];
//////////////////////////////////////////////////////////
// NOTE:
//
// The AssignedUser object has two methods:
// setUserID(long)
// setAssignedDate(Calendar).
// (Specifies the date the user was assigned to the
// asset. If no date is specified, the current date
// is used.)
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// Add AssignedUser objects to the array
//////////////////////////////////////////////////////////
AssignedUser lUser = new AssignedUser();
lUser.setUserID(99); // 99 is the admin user id
lUsers[0] = lUser;
lUser = new AssignedUser();
RegistryUser lRegistryUser1 = createRegistryUser(repository, authToken);
lUser.setUserID(lRegistryUser1.getID());
lUsers[1] = lUser;
lUser = new AssignedUser();
RegistryUser lRegistryUser2 = createRegistryUser(repository, authToken);
lUser.setUserID(lRegistryUser2.getID());
lUsers[2] = lUser;
//////////////////////////////////////////////////////////
// Add array to the asset that is being updated
//////////////////////////////////////////////////////////
myAsset.setAssignedUsers(lUsers);
//////////////////////////////////////////////////////////
// save the modifications
//////////////////////////////////////////////////////////
repository.assetUpdate(authToken, myAsset);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
protected static RegistryUser createRegistryUser(FlashlineRegistry repository,
AuthToken authToken) throws OpenAPIException, RemoteException {
RegistryUser lRet = null;
String lUserName = "user"+Calendar.getInstance().getTimeInMillis();
lRet = repository.userCreate(authToken, lUserName, "", lUserName,
lUserName+"@example.com", lUserName, false, false, false);
return lRet;
}
}
説明
特定の条件を満たすアセットをすべて検索します。
サンプル・コード
例5-9 ユースケース: アセットの検索の作成
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AssetSummary;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.query.DateRangeSearchTerm;
import com.flashline.registry.openapi.query.SearchTerm;
import com.flashline.registry.openapi.query.TabStatusSearchTerm;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class FindAssets {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
////////////////////////////////////////////////////////////
// Login to OER
////////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
////////////////////////////////////////////////////////////
// Search for all assets
////////////////////////////////////////////////////////////
AssetCriteria criteria = new AssetCriteria();
AssetSummary[] assets = repository.assetQuerySummary(authToken, criteria);
////////////////////////////////////////////////////////////
// try a general search which includes Name, version,
// description, and keywords
////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
criteria.setGeneralCriteria("My Asset");
assets = repository.assetQuerySummary(authToken, criteria);
////////////////////////////////////////////////////////////
// Search for assets that contain a specific search string
// in one particular field.
////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
criteria.setNameCriteria("My Name");
criteria.setVersionCriteria("My version");
criteria.setDescriptionCriteria("My Description");
assets = repository.assetQuerySummary(authToken, criteria);
////////////////////////////////////////////////////////////
// Implementing a Search through the AssetCriteria Object
// --------------------------------------------------
// If no operator is specified when implementing a search
// using the setSearchTerms method in the AssetCriteria
// object, the system defaults to the operator EQUALS.
// The operator LIKE must be specified if required for the
// search.
////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
SearchTerm lSearchTerm = new SearchTerm();
lSearchTerm.setKey("name");
lSearchTerm.setOperator("LIKE");
lSearchTerm.setValue("Test");
SearchTerm[] lTerms = new SearchTerm[1];
lTerms[0] = lSearchTerm;
criteria.setSearchTerms(lTerms);
assets = repository.assetQuerySummary(authToken, criteria);
//Search for assets where a specific DATETIME field is a given age
//////////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
//Not specifying an operator defaults to 'equals'.
DateRangeSearchTerm lTerm = new DateRangeSearchTerm();
/////////////////////////
//date-range is the query key. registereddate is the date field we are
searching on
//Allowable fields to search on:
//submitteddate
//registereddate
//accepteddate
//createddate
//updateddate
//To do a search for all assets that were registered more than 5 days ago
lTerm.setKey("date-range");
//Set the value to a day 5 days older than the current date. Assume today's
date is 1/10/2007
//The format defaults to OER's system setting for Short Date Format.
//The format can be set to any valid date format using setDateFormat() and
passing the date format.
lTerm.setDateFormat("yyyy-MM-dd");
lTerm.setBeginDate("2007-1-5");
lTerm.setBeginOperator("lt");
lTerm.setDateField("registereddate");
lTerms = new SearchTerm[1];
lTerms[0] = lTerm;
criteria.setSearchTerms(lTerms);
assets = repository.assetQuerySummary(authToken, criteria);
//Search for assets where a given date field is within a date range
//////////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
lTerm = new DateRangeSearchTerm();
/////////////////////////
//date-range is the query key. registereddate is the date field we are
searching on
//Allowable fields to search on:
//submitteddate
//registereddate
//accepteddate
//createddate
//updateddate
//The following SearchTerm translates to "Assets where the registereddate is
greater than or equal to Jan. 1, 2007
lTerm.setKey("date-range");
//The format defaults to OER's system setting for Short Date Format.
//The format can be set to any valid date format using setDateFormat() and
passing the date format.
lTerm.setDateField("registereddate");
lTerm.setDateFormat("yyyy-MM-yy");
lTerm.setBeginDate("2007-01-01");
lTerm.setBeginOperator("gte");
lTerm.setEndDate("2007-01-10");
lTerm.setEndOperator("lte");
//The following SearchTerm translates to "Assets where the registereddate is
less than or equal to Jan. 10, 2007
criteria.setSearchTerms(new SearchTerm[] {lTerm});
//This query returns all assets that were registered between January 1 and
January 10, including those days.
assets = repository.assetQuerySummary(authToken, criteria);
//Search for assets where a given tab has been approved or unapproved
//////////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
TabStatusSearchTerm lTabTerm = new TabStatusSearchTerm();
//tabstatus is the type of search we want to do. overview is the name of
the tab we want to search on
lTabTerm.setKey("tabstatus");
lTabTerm.setTabNames(new String[] {"overview"});
lTabTerm.setApproved(true);
criteria.setSearchTerms(new SearchTerm[] {lTabTerm});
//This query returns all assets with the Overview tab being approved
assets = repository.assetQuerySummary(authToken, criteria);
//You may also search by a date range.
lTabTerm.setKey("tabstatus");
lTabTerm.setTabNames(new String[] {"overview"});
lTabTerm.setApproved(false);
lTabTerm.setBeginDate("2007-1-01");
lTabTerm.setBeginOperator("lte");
criteria.setSearchTerms(new SearchTerm[] {lTabTerm});
//The following returns all assets that have the Overview tab unapproved
since or before January 1, 2007
assets = repository.assetQuerySummary(authToken, criteria);
//Search for assets where a custom field date has a specific value.
//This test returns all assets that have a testdate of January 1, 2007.
//The testdate field is a custom data date element.
//////////////////////////////////////////////////////////////////
criteria = new AssetCriteria();
DateRangeSearchTerm lDateRangeTerm = new DateRangeSearchTerm();
//Test Equals
lDateRangeTerm.setKey("/asset/custom-data/testdate");
lDateRangeTerm.setBeginDate("2007-01-1");
lDateRangeTerm.setBeginOperator("eq");
criteria.setSearchTerms(new SearchTerm[] {lDateRangeTerm});
assets = repository.assetQuerySummary(authToken, criteria);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
アセットのステータス・レベルを未発行から、発行済、承認済、登録済に変更します。
サンプル・コード
例5-10 ユースケース: アセット・ステータスのアップグレード
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.KeyValuePair;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class PromoteAsset {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////////////////////////////
// Login to OER
///////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
long lAssetID = 559;
// -------------------------------------------------------
// asset with id 559 would have to be unsubmitted for this to work
AssetCriteria lAssetCriteria = new AssetCriteria();
lAssetCriteria.setIDCriteria(lAssetID);
KeyValuePair lKeyValuePair = repository.assetEvaluate(authToken,
lAssetCriteria, "Registration Status");
if (!lKeyValuePair.getValue().equalsIgnoreCase("unsubmitted")) {
unregisterAsset(repository, authToken, lAssetID);
}
///////////////////////////////////////////////////////////
// promote the asset from unsubmitted to submitted
///////////////////////////////////////////////////////////
repository.assetSubmit(authToken, lAssetID);
// asset 559 would have to be unsubmitted for this to work
///////////////////////////////////////////////////////////
// promote the asset from submitted to accepted
///////////////////////////////////////////////////////////
repository.assetAccept(authToken, lAssetID);
// asset 561 would have to be submitted for this to work
///////////////////////////////////////////////////////////
// promote the asset from accepted to registered
///////////////////////////////////////////////////////////
repository.assetRegister(authToken, lAssetID);
// asset 563 would have to be accepted for this to work
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
protected static void unregisterAsset(FlashlineRegistry repository, AuthToken
authToken, long pAssetID) {
try {
repository.assetUnRegister(authToken, pAssetID);
} catch (Exception e) {
}
try {
repository.assetUnAccept(authToken, pAssetID);
} catch (Exception e) {
}
try {
repository.assetUnSubmit(authToken, pAssetID);
} catch (Exception e) {
}
}
}
説明
前述のユースケースとは反対に、アセットのステータス・レベルを登録済から、承認済、発行済、未発行に変更します。
サンプル・コード
例5-11 ユースケース: アセット・ステータスのダウングレード
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.KeyValuePair;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class DemoteAsset {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////////////////////////////
// Login to OER
///////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
long lAssetID = 559;
// -------------------------------------------------------
// asset with id 559 would have to be registered for this to work
AssetCriteria lAssetCriteria = new AssetCriteria();
lAssetCriteria.setIDCriteria(lAssetID);
KeyValuePair lKeyValuePair = repository.assetEvaluate(authToken,
lAssetCriteria, "Registration Status");
if (!lKeyValuePair.getValue().equalsIgnoreCase("registered")) {
registerAsset(repository, authToken, lAssetID);
}
///////////////////////////////////////////////////////////
// demote the asset from registered to accepted
///////////////////////////////////////////////////////////
repository.assetUnRegister(authToken, lAssetID);
///////////////////////////////////////////////////////////
// demote the asset from accepted to submitted
///////////////////////////////////////////////////////////
repository.assetUnAccept(authToken, lAssetID);
///////////////////////////////////////////////////////////
// demote the asset from submitted to unsubmitted
///////////////////////////////////////////////////////////
repository.assetUnSubmit(authToken, lAssetID);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
protected static void registerAsset(FlashlineRegistry repository, AuthToken
authToken, long pAssetID) {
try {
repository.assetSubmit(authToken, pAssetID);
} catch (Exception e) {
}
try {
repository.assetAccept(authToken, pAssetID);
} catch (Exception e) {
}
try {
repository.assetRegister(authToken, pAssetID);
} catch (Exception e) {
}
}
}
説明
コンプライアンス・テンプレートのプロジェクトへの追加およびプロジェクトからの削除を行うことができます。
|
注意: アセットがプロジェクトに適用されていて、そのアセットがコンプライアンス・テンプレートでない場合、OpenAPIExceptionが発生します。 |
サンプル・コード
例5-12 ユースケース: プロジェクトからのコンプライアンス・テンプレートの適用および削除
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AssetType;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Project;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.query.AssetTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AddRemoveTemplate {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
URL lURL = null;
lURL = new URL(pArgs[0]);
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////////////////////////////
// Login to OER
///////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],
pArgs[2]);
///////////////////////////////////////////////////////////
// Read or Create a Compliance Template Type and Asset
///////////////////////////////////////////////////////////
AssetType ctType = null;
AssetTypeCriteria lAssetTypeCriteria = new AssetTypeCriteria();
lAssetTypeCriteria.setArcheTypeCriteria("Compliance Template Type");
AssetType[] lAssetTypes =
repository.assetTypeQuery(authToken, lAssetTypeCriteria);
if (lAssetTypes!=null && lAssetTypes.length>0) {
ctType = lAssetTypes[0];
} else {
ctType = repository.assetTypeCreateComplianceTemplate(authToken,
"My Compliance Template
Type"+Calendar.getInstance().getTimeInMillis());
}
Asset lComplianceTemplateAsset = null;
AssetCriteria lAssetCriteria = new AssetCriteria();
lAssetCriteria.setAssetTypeCriteria(ctType.getID());
Asset[] lAssets = repository.assetQuery(authToken, lAssetCriteria);
if (lAssets!=null && lAssets.length>0) {
lComplianceTemplateAsset = lAssets[0];
} else {
lComplianceTemplateAsset = repository.assetCreate(authToken, "My
Compliance Template",
""+Calendar.getInstance().getTimeInMillis(), ctType.getID());
}
///////////////////////////////////////////////////////////
// Create a String array of Project IDs that the Compliance
// Template is applied to.
///////////////////////////////////////////////////////////
String[] lProjectIDs = { "50000" };
// /////////////////////////////////////////////////////////
// Apply template to the projects.
// /////////////////////////////////////////////////////////
repository.assetApplyToProjects(authToken, lProjectIDs,
lComplianceTemplateAsset);
///////////////////////////////////////////////////////////
// Retrieve an array of Projects that this template is
// applied to.
///////////////////////////////////////////////////////////
Project[] lProjects = repository.assetReadAppliedToProjects(
authToken, lComplianceTemplateAsset);
String lMsg = "Compliance Template '" + lComplianceTemplateAsset.getName();
lMsg += "' applied to Project(s): ";
for (int i=0; lProjects!=null && i<lProjects.length; i++) {
lMsg += ""+lProjects[i].getName()+(i+1==lProjects.length ? "." : ", ");
}
System.out.println(lMsg);
///////////////////////////////////////////////////////////
// Create a String array of Project IDs that the Compliance
// Template is removed from.
///////////////////////////////////////////////////////////
String[] lRemoveProjectIDs = { "50000" };
///////////////////////////////////////////////////////////
// Remove template from the projects.
///////////////////////////////////////////////////////////
repository.assetRemoveAppliedToProjects(authToken,
lRemoveProjectIDs, lComplianceTemplateAsset);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
リポジトリを更新して、新しいバージョンのアセットを使用できるようにし、以前のバージョンのアセットをリタイアします。
サンプル・コード
例5-13 ユースケース: 新しいバージョンのアセットの作成
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RelationshipType;
import com.flashline.registry.openapi.query.RelationshipTypeCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class CreateNewVersionOfAsset {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////////////////////////////
// Login to OER
///////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
///////////////////////////////////////////////////////////
// Read old asset.
// Update metadata as necessary.
// Save as new asset.
///////////////////////////////////////////////////////////
Asset myAsset = repository.assetRead(authToken, 561);
///////////////////////////////////////////////////////////
// Find the "next-version" relationship for the asset
///////////////////////////////////////////////////////////
RelationshipType[] allRelationshipTypes =
getAllRelationshipTypes(repository, authToken);
for (int i = 0; i < allRelationshipTypes.length; i++) {
if (allRelationshipTypes[i].getName().equals("next-version")) {
///////////////////////////////////////////////////////////
// This is the relationship type, modify the assets that are related
// using it
///////////////////////////////////////////////////////////
RelationshipType myRelationshipType = allRelationshipTypes[i];
///////////////////////////////////////////////////////////
// Add the old version to list of previous versions of the
// newly created asset
///////////////////////////////////////////////////////////
long[] oldSecondaryIDs = myRelationshipType.getSecondaryIDs();
long[] newSecondaryIDs = new long[oldSecondaryIDs.length + 1];
for (int j = 0; j < oldSecondaryIDs.length; j++) {
newSecondaryIDs[j] = oldSecondaryIDs[j];
}
newSecondaryIDs[newSecondaryIDs.length - 1] = 561;
myRelationshipType.setSecondaryIDs(newSecondaryIDs);
}
}
Asset myNewAsset = repository.assetCreate(authToken,
myAsset.getName(), ""+Calendar.getInstance().getTimeInMillis(),
myAsset.getTypeID());
myNewAsset.setRelationshipTypes(allRelationshipTypes);
///////////////////////////////////////////////////////////
// Update the new asset
///////////////////////////////////////////////////////////
myNewAsset = repository.assetUpdate(authToken, myNewAsset);
///////////////////////////////////////////////////////////
// retire the old asset
///////////////////////////////////////////////////////////
repository.assetRetire(authToken, 561);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
/**
* This method returns every relationship type in the repository
* @param repository
* @param authToken
* @return
* @throws RemoteException
*/
public static RelationshipType[] getAllRelationshipTypes(FlashlineRegistry
repository, AuthToken authToken) throws RemoteException {
//Create an empty relationship type criteria object
RelationshipTypeCriteria criteria = new RelationshipTypeCriteria();
criteria.setNameCriteria("");
RelationshipType[] allRelationshipTypes =
repository.relationshipTypeQuery(authToken, criteria);
return allRelationshipTypes;
}
}
説明
リポジトリに属さないアセットのグループを削除します。
サンプル・コード
例5-14 ユースケース: リポジトリからの不要なアセットの削除
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class DeleteAssets {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////////////////////////////
// Login to OER
///////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(
pArgs[1],pArgs[2]);
///////////////////////////////////////////////////////////
// find the assets to delete
///////////////////////////////////////////////////////////
AssetCriteria criteria = new AssetCriteria();
criteria.setGeneralCriteria("delete me");
Asset[] assets = repository.assetQuery(authToken, criteria);
///////////////////////////////////////////////////////////
// Iterate through assets, deleting them one at a time.
///////////////////////////////////////////////////////////
for (int i = 0; i < assets.length; i++) {
repository.assetDelete(authToken, assets[i].getID());
}
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
短所:
アセットは完全に削除されます。オープンAPIでは、削除したアセットをリストアするメソッドがありません。
回避するメソッド:
次のメソッドはオープンAPIのコンテキストでは意味がないので、使用しないでください。
setAcceptedByID
setAcceptedByName
setAcceptedByDate
setActiveStatus
setAssigned
setAssignedToID
setAssignedDate
setCategorizationTypes
setCreatedByID
setCreatedByName
setCreatedByDate
setDeleted
setEntityType
setExtractable
setFullAsset
setInactive
setKey
setLoadedDate
setLongName
setNotifyUpdatedRelationships
setRegisteredByID
setRegisteredByName
setRegisteredDate
setRegistrationStatus
setRegistrationStatusBaseName
setRegistrationStatusRegistered
setRegistrationStatusRejected
setRegistrationStatusSubmittedPendingReview
setRegistrationStatusSubmittedUnderReview
setRegistrationStatusUnsubmitted
setRejectionReason
setRetired
setSubmittedByID
setSubmittedByName
setSubmittedDate
setTypeIcon
setTypeName
setUpdatedDate
setVendorName
setVisible
一般的なミスの回避
アセットのルール
アセットは、アクティブで有効なアセット・タイプに割り当てる必要があります。
アセットの名前/バージョンの文字列は一意のペアである必要があります。
新しいアセットのIDは0にする必要があります。
新しいアセットのアクティブなステータスはアクティブである必要があります。
提供されていない機能
カスタム・データを変更するためのヘルパー・メソッド
追加の検証
アセットを保存する場合、Oracle API Catalogでは、現在、次の内容を検証しています。
アセット・タイプが有効でアクティブであること
名前/バージョンが一意であること
アセットを作成する場合、アクティブなステータスが有効であること
アセットを更新する場合、アセットがすでに存在すること
コンタクトが重複していないこと
カテゴリ分けが有効であること
今後のバージョンのリポジトリの検証内容
カスタム・データが正しいフォーマットのXMLであること
カスタム・データにはアセット・タイプに基づいて有効なXMLが含まれていること
説明
特定のカスタム・データ値ですべてのアセットの検索を実行し、これらのアセットのそれぞれについてカスタム・データの一部を更新します。注意: assetUpdateCustomDataNodeメソッドを使用する場合、アセットは自動的に保存されます。
サンプル・コード
例5-15 ユースケース: アセットの検索およびカスタム・データのアップグレード
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AssetSummary;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.query.AssetCriteria;
import com.flashline.registry.openapi.query.SearchTerm;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class UpdateAssetTestResults {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException, ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
///////////////////////////////////////////////////////////
// Login to OER
///////////////////////////////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],
pArgs[2]);
///////////////////////////////////////////////////////////
// create a criteria object searching for all assets with a
// custom-data element for test-frequency equal to 'DAILY'
///////////////////////////////////////////////////////////
SearchTerm[] searchTermArray = new SearchTerm[1];
SearchTerm term = new SearchTerm();
term.setKey("/asset/custom-data/test-frequency");
term.setValue("DAILY");
searchTermArray[0] = term;
AssetCriteria criteria = new AssetCriteria();
criteria.setSearchTerms(searchTermArray);
///////////////////////////////////////////////////////////
// perform search, getting back summary objects. loop through
// objects and perform an action on each one
///////////////////////////////////////////////////////////
AssetSummary[] assets = repository.assetQuerySummary(authToken,
criteria);
///////////////////////////////////////////////////////////
// Loop through search results
///////////////////////////////////////////////////////////
for (int i = 0; i < assets.length; i++) {
long assetID = assets[i].getID();
String testResult = null;
///////////////////////////////////////////////////////////
// Update value in the asset
///////////////////////////////////////////////////////////
repository.assetUpdateCustomDataNode(
authToken, assetID, "/asset/custom-data/test-result", testResult);
}
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
アセットのタブを読み込みます。
サンプル・コード
例5-16 ユースケース: アセットのタブの読込み
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.TabBean;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssetReadTabs {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
TabBean[] lTabBeans = null;
///////////////////////////////////
// Login to OER
///////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
///////////////////////////////////
// read an asset's tabs
///////////////////////////////////
lTabBeans = repository.assetTabsRead(authToken, 559);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
タブ・タイプ別に特定のアセット・タブを取得します。
サンプル・コード
例5-17 ユースケース: タブ・タイプに基づいたアセットのタブの取得
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.TabBean;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssetGetTabByType {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
Asset lAsset = null;
TabBean lTabBean = null;
///////////////////////////////////
// Login to OER
///////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
///////////////////////////////////
// read an asset
///////////////////////////////////
lAsset = repository.assetRead(authToken, 559);
///////////////////////////////////
// get an asset's tab by tabbeantype
///////////////////////////////////
lTabBean = repository.assetTabRead(authToken, lAsset.getID(), 458);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
アセットのタブを承認するか、または未承認にします。
サンプル・コード
例5-18 ユースケース: タブの承認および未承認
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class ApproveUnapproveTab {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
///////////////////////////////////
// Login to OER
///////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
///////////////////////////////////
// approve an asset tab
///////////////////////////////////
repository.assetTabApprove(authToken, 559, 1864);
///////////////////////////////////
// unapprove an asset tab
///////////////////////////////////
repository.assetTabUnapprove(authToken, 559, 1864);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
説明
特定のタブに基づいたアセットのメタデータを読み込みます。
サンプル・コード
例5-19 ユースケース: 特定のタブ用のアセットのメタデータの読込み
package com.flashline.sample.assetapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.Asset;
import com.flashline.registry.openapi.entity.AssetMetadataElement;
import com.flashline.registry.openapi.entity.AssetMetadataTableElement;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AssetGetMetadataByTab {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
Asset lAsset = null;
///////////////////////////////////
// Login to OER
///////////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
///////////////////////////////////
// read an asset
///////////////////////////////////
lAsset = repository.assetRead(authToken, 589);
///////////////////////////////////
// Get the metadata elements based
// on the asset ID and the tab name
///////////////////////////////////
AssetMetadataElement[] lElements =
repository.assetReadTabMetadata(authToken, lAsset.getID(), "Overview");
//An AssetMetadataElement represents a custom or mandatory data element of an asset
for (AssetMetadataElement lElement : lElements) {
//This represents a TABLE element type
if (lElement.getValue() instanceof AssetMetadataTableElement) {
AssetMetadataTableElement lTable =
(AssetMetadataTableElement)lElement.getValue();
System.out.println(lElement.getDisplayName());
//A TABLE can have multiple elements
for (AssetMetadataElement lTableElement : lTable.getElements()) {
//An element of a TABLE can be another TABLE
if (lTableElement.getValue() instanceofAssetMetadataTableElement) {
System.out.println(((AssetMetadataTableElement)lTableElement.getValue()).getDisplayName());
for (AssetMetadataElement lChildElement :
((AssetMetadataTableElement)lTableElement.getValue()).getElements()) {
System.out.println(lChildElement.getDisplayName() + " : " +
lChildElement.getValue());
}
} else {
//Or an element of a TABLE can be a regular value
System.out.println(lTableElement.getDisplayName() + " : " +
lTableElement.getValue());
}
}
//This represents a MULTIPLE ITEM LIST
} else if (lElement.getValue() instanceof String[]) {
System.out.println(lElement.getDisplayName());
for (String lString : (String[])lElement.getValue()) {
System.out.println(lString);
}
//This represents a SINGLE ITEM
} else {
System.out.println(lElement.getDisplayName() + " : " +
lElement.getValue());
}
}
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
この項では、部門APIのユースケースについて説明します。このユースケースで、Oracle API Catalogの部門の作成、更新、問合せおよび削除を行う方法について解説します。
部門の作成、読込み、問合せおよび変更を行うことができます。これらの操作は、次のとおりです。部門の作成後は削除できないことに注意してください。部門の2つの属性(名前と説明)のみがユーザーに有効です。
追加で必要なインポート
import com.flashline.registry.openapi.entity.Department;
説明
次のサンプル・コードは、Oracle API Catalogの部門の操作が含まれる典型的なタスクを示します。これには、作成、更新、問合せおよび削除が含まれます。
サンプル・コード
例5-20 ユースケース: 部門の操作
package com.flashline.sample.departmentapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Department;
import com.flashline.registry.openapi.query.DepartmentCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class Departments {
public static void main(String pArgs[]) throws java.rmi.RemoteException,
OpenAPIException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
// //////////////////////////////
// Authenticate with OER
// //////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],
pArgs[2]);
// //////////////////////////////
// Create a new department
// Each Department requires a unique name. Descriptions are optional.
// //////////////////////////////
Department dept = repository.departmentCreate(authToken,
"My Dept "+Calendar.getInstance().getTimeInMillis(), "A New
Department");
// //////////////////////////////
// Read a department
// To read a Department you must have the Department name.
// //////////////////////////////
Department dept2 = repository.departmentRead(authToken,
"ADepartment");
// //////////////////////////////
// Query for a department
//
// To query for a Department you must fill out a
// DepartmentCriteria object with an array of SearchTerms. A SearchTerm
// is a key/value pair. Currently the only valid key is "name".
//
// A query for name is a match if the value for the name term
// occurs anywhere in the name of the department. For example,
// a search for fred matches fred, alfred, and fredrick.
// //////////////////////////////
DepartmentCriteria criteria = new DepartmentCriteria();
criteria.setNameCriteria("DepartmentName");
Department[] depts = repository.departmentQuery(authToken,
criteria);
// //////////////////////////////
// Update a department
//
// To update a Department you need only to modify a Department
// reference and call departmentUpdate...
// //////////////////////////////
String lOldName = dept.getName();
String lNewName = "New " + dept.getName();
Department dept3 = repository.departmentRead(authToken, lOldName);
dept3.setName(lNewName);
repository.departmentUpdate(authToken, dept3);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
この項では、REXクライアントのローカライズのユースケースについて説明します。このユースケースで、Oracle API CatalogのREX例外およびREX監査メッセージのローカライズ済のメッセージを作成する方法について解説します。
ステータスは、OpenAPIExceptionまたはAuditMsgオブジェクトのいずれかとして、REXクライアントに渡されます。OpenAPIExceptionオブジェクトは例外用に使用されますが、AuditMsgオブジェクトは非同期的に実行されるプロセス用に使用されます。これらのオブジェクトの両方がREXクライアントにテキストのエラー・メッセージを返します。
両方のオブジェクトのインタフェースがエラー・コードおよびメッセージの引数のリストを含めるために拡張されたため、REXクライアントは別の言語でエラー・メッセージやステータス・メッセージを表示できます。クライアントは標準のエラー・メッセージを使用し続けるか、またはメッセージを無視し、エラー・コードとメッセージ引数を使用して専用のエラー・メッセージを作成できます。
たとえば、REXを使用するアプリケーションをローカライズする場合、最初に、想定されるすべてのエラー・メッセージを表示するプロパティ・ファイルを取得します。メッセージは次のようになります。
ERR_9008 = Error updating project with ID = [{0}].
次に、必要に応じて、すべてのメッセージを次のように翻訳する必要があります。
ERR_9008 = Errorway updatingay ojectpray ithway IDway = [{0}].
クライアント・コードはプロジェクトをID=123で変更しようとして、その変更が失敗した場合、エンドユーザーに例外が発生し、次のエラー・メッセージが表示されます。
Error updating project with ID = [123].
このエラーをローカルの言語(ピッグ・ラテン語など)で表示する場合、エラー・コード9008を選択し、これを翻訳済ファイルで検索して文字列"Errorway updatingay ojectpray ithway IDway = [{0}]."を取得します。次に、メッセージ引数を使用して、トークンを置き換えます。この場合、123という文字列が1つのみ検索されるので、メッセージ引数を1つ見つけることができます。
次のように、エンドユーザー用にカスタムのエラー・メッセージを作成できます。
Errorway updatingay ojectpray ithway IDway = [123].
説明
OpenAPIExceptionから、サーバー・エラー・コードとメッセージ引数を取得します。
クライアント・ロケールに適切なOpenAPIExceptionsのリソース・バンドルを取得します。
エラー・コードに関連付けられた文字列を取得し、トークンをメッセージ引数で置き換えます。
サンプル・コード
例5-21 ユースケース: REX例外からのローカライズ済のメッセージの作成
package com.flashline.sample.localization;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.Project;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class SyncTest {
private static final int INVALID_PROJECT_ID = 8672609;
public static void main(String[] args) throws Exception {
URL lURL = new
URL("http://localhost:9080/registry/services/FlashlineRegistry");
FlashlineRegistry reg = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
AuthToken token = reg.authTokenCreate("admin", "n0pa55w0rd");
try {
Project project = reg.projectRead(token,INVALID_PROJECT_ID);
} catch (OpenAPIException ex) {
String msg =
createMessage(ex.getServerErrorCode(),ex.getMessageArguments());
System.out.println(msg);
}
}
private static String createMessage(int pServerErrorCode, Object[] pArgs) {
ResourceBundle mResourceBundle =
ResourceBundle.getBundle("com.flashline.sample.localization.sync_error
_messages");
return MessageFormat.format(mResourceBundle.getString("ERR
_"+pServerErrorCode), pArgs);
}
}
説明
AuditMsgとImpExpJobから、サーバー・エラー・コードとメッセージ引数を取得し、AuditMsgからメッセージ引数を取得します。
クライアント・ロケールに適切な監査メッセージのリソース・バンドルを取得します。
エラー・コードに関連付けられた文字列を取得し、トークンをメッセージ引数で置き換えます。
サンプル・コード
例5-22 REX監査メッセージからのローカライズ済のメッセージの作成
package com.flashline.sample.localization;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import javax.activation.DataHandler;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Stub;
import org.apache.soap.util.mime.ByteArrayDataSource;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.ImpExpJob;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class AsyncTest {
public void run() throws MalformedURLException, ServiceException,
OpenAPIException, RemoteException{
URL lURL = new
URL("http://localhost:9080/registry/services/FlashlineRegistry");
FlashlineRegistry reg = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
AuthToken token = reg.authTokenCreate("admin", "n0pa55w0rd");
try {
File lFile = new
File("samples/com/flashline/sample/localization/asynctest.zip");
//Import the file and save to db
InputStream lIS = new FileInputStream(lFile);
ByteArrayDataSource lDataSource = new ByteArrayDataSource(lIS,
"application/x-zip-compressed");
DataHandler lDH = new DataHandler(lDataSource);
// add the attachment
((Stub)reg).addAttachment(lDH);
ImpExpJob lJob = reg.importExecute(token, "flashline", null, "Import Assets
Test", null);
boolean lPassed = false;
for(int i=0; i<1000; i++){
lJob = reg.importStatus(token, lJob);
System.out.println("Import Job ["+lJob.getID()+"] - State:
"+lJob.getState());
String msg =
createMessage(lJob.getAuditMsg().getSummaryID(),lJob.getAuditMsg().getSummaryArgs
());
System.out.println(msg);
if( lJob.getState().equals("completed")){
lPassed = true;
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (lPassed){
System.out.println("Import Completed");
}
} catch (OpenAPIException ex) {
String msg =
createMessage(ex.getServerErrorCode(),ex.getMessageArguments());
System.out.println(msg);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args
* @throws ServiceException
* @throws RemoteException
* @throws MalformedURLException
* @throws OpenAPIException
*/
public static void main(String[] args) throws OpenAPIException,
MalformedURLException, RemoteException, ServiceException {
AsyncTest test = new AsyncTest();
test.run();
}
private static String createMessage(int pServerErrorCode, Object[] pArgs) {
ResourceBundle mResourceBundle =
ResourceBundle.getBundle("com.flashline.sample.localization.async_error
_messages");
return MessageFormat.format(mResourceBundle.getString("ERR
_"+pServerErrorCode), pArgs);
}
private String readZip(String pFileName) throws IOException {
int lNumRead = 0;
char[] lBuf = new char[2048];
StringBuffer lQuery = new StringBuffer();
InputStreamReader lReader = new
InputStreamReader(getClass().getResourceAsStream(pFileName));
while( (lNumRead=lReader.read(lBuf)) != -1){
lQuery.append(lBuf, 0, lNumRead);
}
return lQuery.toString();
}
}
この項では、システム設定APIのユースケースについて説明します。このユースケースで、Oracle API Catalogのシステム設定について問合せを行う方法について解説します。
Oracle API Catalogのシステム設定セクションで、管理者は基本的な操作を構成して、特定の機能を有効または無効にできます。システム設定APIでは、これらのシステム設定を問い合せるメカニズムを提供します。
|
注意: ユーザーは、システム設定の値を問い合せることのみを許可されています。REXでは、システム設定を設定または変更することはできません。 |
システム設定を問い合せるには、次のパッケージ・インポートが必要です。
import com.flashline.registry.openapi.entity.SettingValue; import com.flashline.registry.openapi.entity.AuthToken; import com.flashline.registry.openapi.query.SystemSettingsCriteria;
予約済メソッド
systemSettingsAddBundleメソッドは、今後の使用のために予約されています。一般的な用途向けではありません。
説明
REXでシステム設定を問い合せます。
サンプル・コード
例5-23 ユースケース: システム設定の問合せ
package com.flashline.sample.systemsettingsapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.SettingValue;
import com.flashline.registry.openapi.query.SystemSettingsCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class SystemSettings {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new
FlashlineRegistryServiceLocator().getFlashlineRegistry(lURL);
// //////////////////////////////
// Authenticate with OER
// //////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],pArgs[2]);
// //////////////////////////////
// Set Application Token on AuthToken object. This is supplied by OER
//authToken.setApplicationToken("TokenString");
// //////////////////////////////////////
//Read all available system settings
//Create an empty Criteria object. No criteria returns all settings.
SystemSettingsCriteria lCriteria = new SystemSettingsCriteria();
lCriteria.setNameCriteria("enterprise.defaults.displayname.field");
SettingValue[] lValues = repository.systemSettingsQuery(authToken,
lCriteria);
for (int i=0;i<lValues.length;i++) {
SettingValue lValue = lValues[i];
System.out.println("Setting Name: " + lValue.getDescriptor().getName());
System.out.println("Setting Value: " + lValue.getValue());
}
// /////////////////////////////////////
//Read a specific setting
lCriteria.setNameCriteria("cmee.server.companyname");
lValues = repository.systemSettingsQuery(authToken, lCriteria);
for (int i=0;i<lValues.length;i++) {
SettingValue lValue = lValues[i];
System.out.println("Setting Name: " + lValue.getDescriptor().getName());
System.out.println("Setting Value: " + lValue.getValue());
}
// /////////////////////////////////////
//Read a specific section
lCriteria.setSectionCriteria("general");
lValues = repository.systemSettingsQuery(authToken, lCriteria);
for (int i=0;i<lValues.length;i++) {
SettingValue lValue = lValues[i];
System.out.println("Setting Name: " + lValue.getDescriptor().getName());
System.out.println("Setting Value: " + lValue.getValue());
}
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}
この項では、ユーザーAPIのユースケースについて説明します。このユースケースで、ユーザーの作成、取得、更新および非アクティブ化を行う方法、またはユーザーについて問い合せる方法について解説します。
ユーザー・サブシステムは、Oracle API Catalogのユーザー・アカウントの作成、読込み、更新、問合せまたは操作に使用する、Webサービス・ベースのメカニズムを提供します。
追加で必要なインポート
import com.flashline.registry.openapi.entity.RegistryUser; import com.flashline.registry.openapi.query.UserCriteria;
説明
新規ユーザーを作成します。
既存のユーザーを取得します。
ユーザーを更新します。
ユーザーを非アクティブ化します。
ユーザーについて問い合せます。
サンプル・コード
例5-24 ユースケース: ユーザーの操作
package com.flashline.sample.userapi;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.flashline.registry.openapi.base.OpenAPIException;
import com.flashline.registry.openapi.entity.AuthToken;
import com.flashline.registry.openapi.entity.RegistryUser;
import com.flashline.registry.openapi.query.UserCriteria;
import com.flashline.registry.openapi.service.v300.FlashlineRegistry;
import
com.flashline.registry.openapi.service.v300.FlashlineRegistryServiceLocator;
public class Users {
public static void main(String pArgs[]) throws OpenAPIException,
RemoteException,
ServiceException {
try {
///////////////////////////////////////////////////////////
// Connect to Oracle API Catalog
///////////////////////////////////////////////////////////
URL lURL = null;
lURL = new URL(pArgs[0]);
FlashlineRegistry repository = new FlashlineRegistryServiceLocator()
.getFlashlineRegistry(lURL);
// //////////////////////////////
// Authenticate with OER
// //////////////////////////////
AuthToken authToken = repository.authTokenCreate(pArgs[1],
pArgs[2]);
// -----------------------------------------
// Create a new user
String lUserName = "testUserCreate
_"+Calendar.getInstance().getTimeInMillis();
String lFirstName = "testUserCreate_FirstName";
String lLastName = "testUserCreate_LastName";
String lEmail = lUserName+"@example.com";
String lPassword = "testUserCreate_Password";
boolean lMustChangePassword = false;
boolean lPasswordNeverExpires = false;
boolean lAssignDefafultRoles = true;
RegistryUser RbacRegistrySecUser = repository.userCreate(
authToken, lUserName, lFirstName, lLastName, lEmail, lPassword,
lMustChangePassword, lPasswordNeverExpires, lAssignDefafultRoles);
// -----------------------------------------
// Read a User
long lId = 50000; // user id must exist in OER
RegistryUser lUser1 = repository.userRead(authToken,
lId);
// -----------------------------------------
// Update a User
lUser1.setActiveStatus(10);
lUser1.setUserName("xxx");
lUser1.setPhoneNumber("412-521-4914");
lUser1.setMustChangePassword(true);
lUser1.setPasswordNeverExpires(false);
lUser1.setPassword("changed_password");
lUser1.setEmail("newaddress@bea.com");
try {
lUser1 = repository.userUpdate(authToken,
lUser1);
} catch (OpenAPIException e) {
e.printStackTrace();
}
// -----------------------------------------
// Deactivate a User
RegistryUser lUser2 = null;
try {
lUser2 = repository.userDeactivate(authToken, lId);
} catch (OpenAPIException e) {
e.printStackTrace();
}
// -----------------------------------------
// Query for Users
RegistryUser lUsers[] = null;
UserCriteria lUserCriteria = null;
lUserCriteria = new UserCriteria();
lUserCriteria.setNameCriteria("testname");
lUsers = repository.userQuery(authToken,
lUserCriteria);
} catch (OpenAPIException lEx) {
System.out.println("ServerCode = " + lEx.getServerErrorCode());
System.out.println("Message = " + lEx.getMessage());
System.out.println("StackTrace:");
lEx.printStackTrace();
} catch (RemoteException lEx) {
lEx.printStackTrace();
} catch (ServiceException lEx) {
lEx.printStackTrace();
} catch (MalformedURLException lEx) {
lEx.printStackTrace();
}
}
}