use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project drools-wb by kiegroup.
the class FromAccumulateCompositeFactPatternWidgetTest method setUp.
@Before
public void setUp() throws Exception {
// listBox is used for verification fo added available fact types into UI
GwtMockito.useProviderForType(ListBox.class, aClass -> listBox);
// Mock partially the AsyncPackageDataModelOracle
validatorInstance = new MockInstanceImpl<>();
oracle = spy(new AsyncPackageDataModelOracleImpl(new CallerMock<>(incrementalDataModelService), validatorInstance));
// Mock partially the AsyncPackageDataModelOracleFactory and ensure oracle will contain data form payload below
doReturn(syncBeanDef).when(syncBeanManager).lookupBean(AsyncPackageDataModelOracle.class);
doReturn(oracle).when(syncBeanDef).getInstance();
doReturn(oracle).when(ruleModeller).getDataModelOracle();
// Prepare base payload that simulates two Facts in the package, Person and Car
dataModelPayload = new PackageDataModelOracleBaselinePayload();
dataModelPayload.setModelFields(new HashMap<String, ModelField[]>() {
{
final String fqnPerson = REDHAT_PACKAGE + "." + FACT_TYPE_PERSON;
final String fqnCar = REDHAT_PACKAGE + "." + FACT_TYPE_CAR;
final String fqnNumber = Number.class.getName();
put(fqnPerson, new ModelField[] { modelField(DataType.TYPE_THIS, fqnPerson) });
put(fqnCar, new ModelField[] { modelField(DataType.TYPE_THIS, fqnCar) });
put(fqnNumber, new ModelField[] { modelField(DataType.TYPE_THIS, fqnNumber) });
}
});
// Prevent NPE in FromAccumulateCompositeFactPatternWidget constructor
when(pattern.useFunctionOrCode()).thenReturn(FromAccumulateCompositeFactPattern.USE_FUNCTION);
fromAccumulateWidget = new FromAccumulateCompositeFactPatternWidget(ruleModeller, eventBus, pattern);
ruleModelWithImportedNumber = new RuleModel() {
{
setImports(new Imports() {
{
addImport(new Import(Number.class));
}
});
}
};
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project drools-wb by kiegroup.
the class GuidedRuleTemplateEditorServiceImpl method constructContent.
@Override
protected GuidedTemplateEditorContent constructContent(Path path, Overview overview) {
final TemplateModel model = load(path);
final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
// Get FQCN's used by model
final GuidedRuleModelVisitor visitor = new GuidedRuleModelVisitor(model);
final Set<String> consumedFQCNs = visitor.getConsumedModelClasses();
// Get FQCN's used by Globals
consumedFQCNs.addAll(oracle.getPackageGlobals().values());
// Get FQCN's of collections defined in project settings
// they can be used in From Collect expressions
consumedFQCNs.addAll(oracle.getModuleCollectionTypes().entrySet().stream().filter(entry -> entry.getValue()).map(entry -> entry.getKey()).collect(Collectors.toSet()));
DataModelOracleUtilities.populateDataModel(oracle, dataModel, consumedFQCNs);
// Signal opening to interested parties
resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
return new GuidedTemplateEditorContent(model, overview, dataModel);
}
use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project drools-wb by kiegroup.
the class GuidedRuleTemplateEditorPresenter method getModelSuccessCallback.
private RemoteCallback<GuidedTemplateEditorContent> getModelSuccessCallback() {
return new RemoteCallback<GuidedTemplateEditorContent>() {
@Override
public void callback(final GuidedTemplateEditorContent content) {
// Path is set to null when the Editor is closed (which can happen before async calls complete).
if (versionRecordManager.getCurrentPath() == null) {
return;
}
resetEditorPages(content.getOverview());
addSourcePage();
addPage(new PageImpl(dataView, GuidedTemplateEditorConstants.INSTANCE.Data()) {
@Override
public void onFocus() {
dataView.setContent(model, oracle, eventBus, isReadOnly);
}
@Override
public void onLostFocus() {
// Nothing to do here
}
});
addImportsTab(importsWidget);
model = content.getModel();
final PackageDataModelOracleBaselinePayload dataModel = content.getDataModel();
oracle = oracleFactory.makeAsyncPackageDataModelOracle(versionRecordManager.getCurrentPath(), model, dataModel);
view.setContent(model, oracle, ruleNamesService, eventBus, isReadOnly);
importsWidget.setContent(oracle, model.getImports(), isReadOnly);
createOriginalHash(model);
view.hideBusyIndicator();
}
};
}
Aggregations