Decision Center API の使用

Decision Center API を使用することで、プロジェクトとベースラインの管理、パッケージとルールの作成、リポジトリーの検索、およびプロジェクト・エレメントのロック、アンロック、およびコミットを行うことができます。

IlrSession は Decision Center へのメインのエントリー・ポイントです。 以下のコードは、Decision Center セッションを開く方法を示しています。

// Open the <product> session
IlrSessionFactory factory = new IlrRemoteSessionFactory();
factory.connect(login, password, serverUrl, datasource);
IlrSession session = factory.getSession();
try {
	// Do something
} finally {
	session.close();
}

このクラスを使用して、以下を行います。

プロジェクトの取得、削除、または作成

以下のコードは、Decision Center でのプロジェクトの取得、削除、および作成の方法を示しています。

// Get the project by name
String projectName = "testProject";
IlrRuleProject testProject = (IlrRuleProject) IlrSessionHelper.getProjectNamed(session, projectName);
if (testProject != null) {
    // Erase a project
       session.eraseProject(testProject);
       System.out.println("Project Deleted");
}
// Create a project
testProject = (IlrRuleProject) IlrSessionHelper.createRuleProject(session, projectName);

ベースラインの管理

以下のコードは、Decision Center で現行のベースラインを開く方法と、新規ベースラインを作成する方法を示しています。

// Open current baseline
IlrBaseline currentBaseline = IlrSessionHelper.getCurrentBaseline(session, testProject);
session.setWorkingBaseline(currentBaseline);

// Create a new baseline
Date today = new Date();
String baselineName = "testBaseline " + today.toString();
IlrBaseline newBaseline = session.createBaselineFromCurrentState(baselineName);

パッケージとルールの作成

以下のコードは、Decision Center でのパッケージとルールの作成方法を示しています。

// Create a package at the root level
String packageName = "testPackage";
IlrRulePackage testPackage = IlrSessionHelper.createRulePackage(session, null, packageName);

// Create a rule
String ruleName = "testRule";
IlrSessionHelper.createActionRule(session, testPackage, ruleName, "then print ¥"hello¥";");

Decision Center リポジトリーの検索

以下のコードは、Decision Center リポジトリーの照会方法を示しています。

{
	// Query with BQL
	String query = new String("Find all business rules such that the name of each business rule is ¥"testRule¥"");
	IlrDefaultSearchCriteria criteria = new IlrDefaultSearchCriteria(query.toString());
	List summaries = session.findElements(criteria, IlrModelConstants.ELEMENT_SUMMARY);
	for (int i = 0; i < summaries.size(); i++) {
		IlrElementSummary ruleSummary = (IlrElementSummary) summaries.get(i);
		System.out.println(ruleSummary.getName());
	}
}

{
	// Query by code: find rule by name
	String name = "testRule";
	IlrBrmPackage metaModel = session.getBrmPackage();
	IlrDefaultSearchCriteria criteria = new IlrDefaultSearchCriteria(metaModel.getActionRule(), Arrays.asList(metaModel.getModelElement_Name()), Arrays.asList(name));
	List details = session.findElements(criteria, IlrModelConstants.ELEMENT_DETAILS);
	for (int i = 0; i < details.size(); i++) {
		IlrActionRule rule = (IlrActionRule) details.get(i);
		System.out.println(rule.getName());
	}
}

プロジェクト・エレメントのロック、アンロック、およびコミット

以下のコードは、Decision Center でのプロジェクト・エレメントのロック、アンロック、およびコミットの方法を示しています。

// Lock element
session.lockElement(rule);

// Unlock element
session.unlockElement(rule);

// Modify a property and commit
rule.setRawValue(metaModel.getRule_Priority(), "2");
session.commit(rule);

// Modify an aggregated element and commit
IlrDefinition definition = rule.getDefinition();
definition.setRawValue(metaModel.getDefinition_Body(), "then print ¥"helloooo¥";");
IlrCommitableObject co = new IlrCommitableObject(rule);
co.addModifiedElement(metaModel.getRuleArtifact_Definition(), definition);
session.commit(co);