use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class GuidedDecisionTreeEditorCopyHelper method postProcess.
@Override
public void postProcess(final Path source, final Path destination) {
// Load existing file
final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination);
final String drl = ioService.readAllString(Paths.convert(destination));
final String baseFileName = FileNameUtil.removeExtension(source, resourceType);
final PackageDataModelOracle oracle = dataModelService.getDataModel(source);
final GuidedDecisionTree model = GuidedDecisionTreeDRLPersistence.getInstance().unmarshal(drl, baseFileName, oracle);
// Update tree name
final String treeName = FileNameUtil.removeExtension(destination, resourceType);
model.setTreeName(treeName);
// Save file
ioService.write(_destination, GuidedDecisionTreeDRLPersistence.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] copied to [" + destination.toURI() + "]."));
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class GuidedDecisionTreeEditorServiceImpl method loadDataModel.
@Override
public PackageDataModelOracleBaselinePayload loadDataModel(final Path path) {
try {
final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
// There are no classes to pre-load into the DMO when requesting a new Data Model only
DataModelOracleUtilities.populateDataModel(oracle, dataModel, new HashSet<String>());
return dataModel;
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class GuidedDecisionTreeEditorServiceImpl method constructContent.
@Override
protected GuidedDecisionTreeEditorContent constructContent(Path path, Overview overview) {
final GuidedDecisionTree model = load(path);
final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
// Get FQCN's used by model
final GuidedDecisionTreeModelVisitor visitor = new GuidedDecisionTreeModelVisitor(model);
final Set<String> consumedFQCNs = visitor.getConsumedModelClasses();
// Get FQCN's used by Globals
consumedFQCNs.addAll(oracle.getPackageGlobals().values());
DataModelOracleUtilities.populateDataModel(oracle, dataModel, consumedFQCNs);
// Signal opening to interested parties
resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
return new GuidedDecisionTreeEditorContent(model, overview, dataModel);
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImpl method load.
@Override
public RuleModel load(final Path path) {
try {
final String drl = ioService.readAllString(Paths.convert(path));
final List<String> globals = utilities.loadGlobalsForPackage(path);
final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
RuleModel ruleModel = null;
if (dslrResourceType.accept(path)) {
final String[] dsls = utilities.loadDslsForPackage(path);
ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, oracle, persistenceExtensions, dsls);
} else {
ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, oracle, persistenceExtensions);
}
return ruleModel;
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImplTest method checkConstructContentPopulateProjectCollectionTypesAndDSLSentences.
@Test
public void checkConstructContentPopulateProjectCollectionTypesAndDSLSentences() throws Exception {
final Path path = mock(Path.class);
final Overview overview = mock(Overview.class);
final ModuleDataModelOracle projectDataModelOracle = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(List.class).addClass(Set.class).addClass(Collection.class).addClass(Integer.class).build();
final PackageDataModelOracle oracle = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectDataModelOracle).addExtension(DSLActionSentence.INSTANCE, Collections.singletonList(dslSentence)).addExtension(DSLConditionSentence.INSTANCE, Collections.singletonList(dslSentence)).build();
when(path.toURI()).thenReturn("default://project/src/main/resources/mypackage/rule.rdrl");
when(dataModelService.getDataModel(any())).thenReturn(oracle);
final GuidedEditorContent content = service.constructContent(path, overview);
assertEquals(3, content.getDataModel().getCollectionTypes().size());
assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Collection"));
assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.List"));
assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Set"));
assertTrue(content.getDataModel().getPackageElements(DSLActionSentence.INSTANCE).contains(dslSentence));
assertTrue(content.getDataModel().getPackageElements(DSLConditionSentence.INSTANCE).contains(dslSentence));
}
Aggregations