ユーザー変更項目に対するJavaメソッドの作成例
既存のシステム変更項目として定義されていないアプリケーション文書で取得された属性値を使用するには、このトピックのサンプル・コードを基にして作成されたJavaメソッドから値を取得するユーザー変更項目を作成できます。
このトピックでは、Javaメソッド作成時の参考になるコメントを含む2つのサンプル・メソッドを示します。 これらのメソッドのJava変更項目値の提供元は、データベースの表およびビュー・オブジェクト(VO)によって異なります。
Javaユーザー変更項目が文書ヘッダーVO(契約ヘッダーVOやPOヘッダーVOなど)の属性の場合は、1番目のメソッドを使用します。 Javaユーザー変更項目が文書ヘッダーVOの子表の属性の場合は、2番目のメソッドを使用します。
サンプルJavaメソッド1
このサンプルでは、CurrencyCode
はPOヘッダーVOの属性であるものとします。 この契約エキスパートJava変更項目は、文書作成時にヘッダー情報が保存されなくても機能します。 このシナリオで、getCurrencyCode()
は変更項目定義ページでユーザー定義のJava変更項目と関連付けられているメソッド名です。
-
Oracle JDeveloperを使用して、アプリケーションを作成し、そのアプリケーション内にプロジェクトを作成します。
-
プロジェクト内に、Javaユーザー変更項目用のメソッドのJavaファイルを作成します。
-
一時フォルダを作成し、fusionapps/jlibディレクトリからこのフォルダに
ContractsTermsLibraryPublicModel
JARファイルをコピーします。 -
Oracle JDeveloperでプロジェクトを右クリックし、「プロジェクト・プロパティ」で右クリックします。
-
ライブラリとクラスパスを選択します。
-
一時フォルダから
ContractsTermsLibraryPublicModel
JARを追加します。
-
-
プロジェクトを右クリックし、「プロジェクト・プロパティ」、「デプロイメント・プロファイル」の順に選択して、現在のプロジェクトのJARを作成します。
-
この新しいJARを、ディレクトリmw_home_standalone/user_projects/domains/fusion_domain/servers/AdminServer/upload/ContractManagementApp/V2.0/app/ContractManagementApp/APP-INF/libにコピーします。
-
サーバーをバウンスします。
次に示すのは、Javaユーザー変更項目を実装するサンプルのJavaクラスです。 構成するには、クラス名(MyPurchaseUDV
)を変更します。 インポート文は変更または削除しないでください。
/**
*/
MyPurchaseUDV.java
package oracle.apps.contracts.termsLibrary.publicModel.Attributes.model.java;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import oracle.apps.contracts.termsLibrary.publicModel.variables.model.java.ProgrammaticUDV;
/**
This class extends the abstract class ProgrammaticUDV.
TO CONFIGURE: Change the Class name only (MyPurchaseUDV).
*/
public class MyPurchaseUDV extends ProgrammaticUDV {
/**
CASE 1: For achieving CASE 1 use the methods registerAttributes() and getCurrencyCode().
*/
/**
The following method registers the Java variable present in the Header VO. The name of the variable should be the same as the name of the attribute in the Header VO.
TO CONFIGURE: Change only the VO attribute name of the variable (in this case CurrencyCode) to match the attribute name in the Header VO.
Do not change the method name or scope of the method. The only thing can be changed is the VO attribute name of the user variable.
*/
protected void registerAttributes() {
registerAttribute("CurrencyCode");
}
/**
The following method obtains the value of java variable used in the Header VO. The attribute name of the java variable used in this method is CurrencyCode. This method returns the value of the CurrencyCode. The value of the variable which we are trying to get using this method (getCurrencyCode) should be registered in the previous method registerAttributes().
TO CONFIGURE: Change the name of the method (getCurrencyCode()). Do not change the scope of the method.
The return type can be changed. To get the value of the variable we have to use the getAttributeValue() method only.
*/
public String getCurrencyCode() throws Exception {
String retVal = null;
retVal = getAttributeValue("CurrencyCode");
return retVal;
}
サンプルJavaメソッド2
次のメソッドは、SQL問合せを使用してJava変更項目の値を取得するために使用します。 このシナリオでは、契約に販売実績がある場合に契約条件に条項を追加します。 販売実績情報は、契約ヘッダーとは別の表に格納されています。 このシナリオを処理するには、契約エキスパートを呼び出す前に文書を保存する必要があります。 この場合に使用するJava変更項目はSales Credit
です。 Javaユーザー変更項目が文書ヘッダーVOの子表の属性の場合は、getSalesCredit()
メソッドを使用します。
構成するには、getSalesCredit()
メソッドの名前およびメソッドの戻り値の型を変更します。 問合せの実行時に必要になる可能性のある文書IDや文書タイプなどの他の属性値は、getメソッドgetDocumentId()
、getDocumentType()
、getDocumentVersion()
で取得できます。
executeQuery
メソッドは次のように機能します。
-
結果セットの1行目の1列目でスカラー値を常に返します。
-
文字列値を常に返します。
-
整数値を期待する場合は、値を返す前に変換を行う必要があります。
-
文字列を期待する場合は変換する必要はありません。
-
次の例では、YesまたはNoの値セットの値のID値は、契約に販売実績エントリがあるかどうかに基づいて返されます。
*/
public int getSalesCredit() throws SQLException, Exception {
int retVal = 0;
int value = 0;
String s1 = null;
BigDecimal id = getDocumentId();
s1 = executeQuery("SELECT to_char(count(*)) FROM OKC_K_SALES_CREDITS where dnz_chr_id = " + id);
value = Integer.parseInt(s1);
if(value > 0) {
retVal = 271230; // Value Set id for "YES"
} else {
retVal = 271229; // Value Set id for "NO"
}
return retVal;
}
}
/*****************************************************
The following file content is provided here only for reference.
DO NOT INCLUDE THE FOLLOWING CODE IN ANY USER METHOD.
*****************************************************/
ProgrammaticUDV.java
package oracle.apps.contracts.termsLibrary.publicModel.variables.model.java;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import oracle.jbo.server.DBTransaction;
public abstract class ProgrammaticUDV {
private HashMap attributesData;
private DBTransaction dBTransaction;
private Statement statement;
protected BigDecimal documentId;
protected String documentType;
protected BigDecimal documentVersion;
private ArrayList<String> attributeNamesUsed = new ArrayList<String>();
public ProgrammaticUDV(){
registerAttributes();
}
protected abstract void registerAttributes();
protected void registerAttribute(String attributeName) {
attributeNamesUsed.add(attributeName);
}
protected String getAttributeValue(String attributeName) throws Exception {
if(attributesData.get(attributeName) == null){
throw new Exception("Attribute name '" + attributeName + "' is either invalid or not registered.");
}
return (String)attributesData.get(attributeName);
}
public HashMap getAttributesData() {
return attributesData;
}
public void setAttributesData(HashMap variableData) {
this.attributesData = variableData;
}
public ArrayList getAttributesUsed() {
return attributeNamesUsed;
}
public void setDBTransaction(DBTransaction dBTransaction) {
this.dBTransaction = dBTransaction;
}
protected String executeQuery(String query) throws SQLException {
ResultSet rs = null;
String s =null;
if (statement != null) {
statement.close();
}
statement = dBTransaction.createStatement(0);
rs = statement.executeQuery(query);
if(rs.next()){
s = rs.getString(1);
}
statement.close();
return s;
}
protected void closeQuery() throws SQLException {
if (statement != null) {
statement.close();
statement = null;
}
}
public void setDocumentId(BigDecimal documentId) {
this.documentId = documentId;
}
public void setDocumentType(String documentType) {
this.documentType = documentType;
}
public void setDocumentVersion(BigDecimal documentVersion) {
this.documentVersion = documentVersion;
}
public BigDecimal getDocumentId() {
return documentId;
}
public String getDocumentType() {
return documentType;
}
public BigDecimal getDocumentVersion() {
return documentVersion;
}
}