Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
No replies
SystemAdmin
SystemAdmin
6042 Posts
ACCEPTED ANSWER

Pinned topic Problem Updating Decision Tables and Saving back to .dta file

‏2013-01-10T15:58:36Z |
I get the following error when executing RuleflowReport.ilrResourceManager.saveElement(decisionTable);
(the last line of the following code):

Runtime error:
...../Bus Card Dual Non Orig.dta is not synchronized in the workspace. You cannot modify it.

Running the following code:

if (element instanceof IlrDecisionTable) {
IlrDecisionTable decisionTable = (IlrDecisionTable) element;
// decisionTable.setName("1 timestamp = " +
// System.currentTimeMillis());

// 1 get model from DT
IlrDTModel dtModel = decisionTable.getDTController().getDTMEditor();
IlrDTExpressionManager expressionManager = dtModel.getExpressionManager();

// 2. get controller from model DT
IlrDTController ilrDTController = ((IlrDecisionTable) (dtModel.getDTRuleElement())).getDTController();

// 3. display condition definitions BEFORE adding condition
// definition
List<DTConditionDefinition> dtConditionDefinitions = dtModel.getConditionDefinitionList();

for (DTConditionDefinition conditionDefinition : dtConditionDefinitions) {
System.out.println("conditionDefinition.getId() " + conditionDefinition.getId());
System.out.println("conditionDefinition.getExpressionDefinition().getExpressionText() "
+ conditionDefinition.getExpressionDefinition().getExpressionText());
System.out.println("conditionDefinition.getPlaceHolderCount() " + conditionDefinition.getPlaceHolderCount());
}

// 4. add condition definition
IlrDTExpressionDefinition ageExpressionDefinition = expressionManager.newExpressionDefinition(
"the age of 'my customer' is between and ", null);
IlrDTPartitionDefinition ageConditionDefinition = dtModel.newPartitionDefinition(ageExpressionDefinition);
IlrDTPropertyHelper.setDefinitionTitle(ageConditionDefinition, "Customer age");
dtModel.addPartitionDefinition(dtModel.getPartitionDefinitionCount(), ageConditionDefinition);

// 5. display condition definitions AFTER adding condition
// definition
dtConditionDefinitions = dtModel.getConditionDefinitionList();

for (DTConditionDefinition conditionDefinition : dtConditionDefinitions) {
System.out.println("conditionDefinition.getId() " + conditionDefinition.getId());
System.out.println("conditionDefinition.getExpressionDefinition().getExpressionText() "
+ conditionDefinition.getExpressionDefinition().getExpressionText());
System.out.println("conditionDefinition.getPlaceHolderCount() " + conditionDefinition.getPlaceHolderCount());
}

// 6. get model properties and display BEFORE adding locking
// properties
Map properties = dtModel.getProperties();

Set<String> keys = properties.keySet();

for (String key : keys) {
System.out.println("key = " + key + " value = " + properties.get(key));
}

Map<String, Boolean> newProperties = new HashMap<String, Boolean>(4);
newProperties.put("Lock.ApplyLocking", true);
newProperties.put("Lock.EditCondExpr", true);
newProperties.put("Lock.EditPartitionValues", true);
newProperties.put("Lock.EditPartitions", true);

dtModel.addProperties(newProperties);

// 7. get model properties and display AFTER adding locking
// properties
properties = dtModel.getProperties();
keys = properties.keySet();

for (String key : keys) {
System.out.println("key = " + key + " value = " + properties.get(key));
}

// 7a add one lock property to model DT properties & display
// ((IlrDecisionTable)
// (dtModel.getDTRuleElement())).setPropertyValue("Lock.ApplyLocking",
// true);

// 8. set model name to timestamp in ms
// ((IlrDecisionTable)
// (dtModel.getDTRuleElement())).setName("1 timestamp = " +
// System.currentTimeMillis());

// 9. save model DT back to .dta file
// IlrResourceManager ilrResourceManager =
// RuleflowReport.ilrResourceManager;

// RuleflowReport.ilrResourceManager.saveElement(decisionTable);//
// RJE

// 9a save DT to .dta file
RuleflowReport.ilrResourceManager.saveElement(decisionTable);