@Override public GuidedDecisionTable52 load(final Path path) { try { final String content = ioService.readAllString(Paths.convert(path)); return GuidedDTXMLPersistence.getInstance().unmarshal(content); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public List<ValidationMessage> validate(final Path path, final GuidedDecisionTable52 content) { try { return genericValidator.validate(path, GuidedDTXMLPersistence.getInstance().marshal(content)); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@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 content = ioService.readAllString( Paths.convert( destination ) ); final GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal( content ); //Update table name final String tableName = FileNameUtil.removeExtension( destination, resourceType ); model.setTableName( tableName ); //Save file ioService.write( _destination, GuidedDTXMLPersistence.getInstance().marshal( model ), commentedOptionFactory.makeCommentedOption( "File [" + source.toURI() + "] copied to [" + destination.toURI() + "]." ) ); }
@Before public void setUp() throws Exception { GuidedDTXMLPersistence.getInstance(); }
@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 content = ioService.readAllString( Paths.convert( destination ) ); final GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal( content ); //Update table name final String tableName = FileNameUtil.removeExtension( destination, resourceType ); model.setTableName( tableName ); //Save file ioService.write( _destination, GuidedDTXMLPersistence.getInstance().marshal( model ), commentedOptionFactory.makeCommentedOption( "File [" + source.toURI() + "] renamed to [" + destination.toURI() + "]." ) ); }
@Override public IndexBuilder fillIndexBuilder(final Path path) throws Exception { final String content = ioService.readAllString(path); final GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal(content); final String drl = GuidedDTDRLPersistence.getInstance().marshal(model); return fillDrlIndexBuilder(path, drl); }
@Override public Path create(final Path context, final String fileName, final GuidedDecisionTable52 content, final String comment) { try { final Package pkg = moduleService.resolvePackage(context); final String packageName = (pkg == null ? null : pkg.getPackageName()); content.setPackageName(packageName); final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName); final Path newPath = Paths.convert(nioPath); if (ioService.exists(nioPath)) { throw new FileAlreadyExistsException(nioPath.toString()); } ioService.write(nioPath, GuidedDTXMLPersistence.getInstance().marshal(content), commentedOptionFactory.makeCommentedOption(comment)); return newPath; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Test public void testRoundTrip() { final GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setHitPolicy( GuidedDecisionTable52.HitPolicy.FIRST_HIT ); final String xml = GuidedDTXMLPersistence.getInstance() .marshal( dt ); assertNotNull( xml ); assertTrue( xml.contains( "<hitPolicy>FIRST_HIT</hitPolicy>" ) ); final GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance() .unmarshal( xml ); assertEquals( GuidedDecisionTable52.HitPolicy.FIRST_HIT, dt_.getHitPolicy() ); }
@Override public ResourceConversionResult loadFromInputStream(InputStream is) throws IOException { String xml = new String(IoUtils.readBytesFromInputStream(is), IoUtils.UTF8_CHARSET); GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal(xml); String content = GuidedDTDRLPersistence.getInstance().marshal(model); if (hasDSLSentences(model)) { return new ResourceConversionResult(content, ResourceType.DSLR); } else { return new ResourceConversionResult(content, ResourceType.DRL); } }
@Override public Path save(final Path resource, final GuidedDecisionTable52 model, final Metadata metadata, final String comment) { try { final Package pkg = moduleService.resolvePackage(resource); final String packageName = (pkg == null ? null : pkg.getPackageName()); model.setPackageName(packageName); Metadata currentMetadata = metadataService.getMetadata(resource); ioService.write(Paths.convert(resource), GuidedDTXMLPersistence.getInstance().marshal(model), metadataService.setUpAttributes(resource, metadata), commentedOptionFactory.makeCommentedOption(comment)); fireMetadataSocialEvents(resource, currentMetadata, metadata); return resource; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
dt.setTableName("blah"); String xml = GuidedDTXMLPersistence.getInstance().marshal(dt); System.out.println(xml); assertNotNull(xml); xml.indexOf("GuidedDecisionTable")); GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance().unmarshal(xml); assertNotNull(dt_); assertEquals("blah",
protected void analyze(String resourceName) throws Exception { final String xml = TestUtil.loadResource(resourceName); final GuidedDecisionTable52 table52 = GuidedDTXMLPersistence.getInstance().unmarshal(xml); final Analyzer analyzer = analyzerProvider.makeAnalyser(table52); // First run analyzer.resetChecks(); analyzer.analyze(); }
@Test public void testIndexGuidedDecisionTableActions() throws IOException, InterruptedException { //Add test files final Path path = basePath.resolve("dtable1.gdst"); final GuidedDecisionTable52 model = GuidedDecisionTableFactory.makeTableWithActionCol("org.drools.workbench.screens.guided.dtable.backend.server.indexing", new ArrayList<Import>() {{ add(new Import("org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant")); }}, "dtable1"); final String xml = GuidedDTXMLPersistence.getInstance().marshal(model); ioService().write(path, xml); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); { final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant", ResourceType.JAVA)) .build(); searchFor(index, query, 1, path); } }
protected void analyze(String resourceName) throws Exception { final String xml = TestUtil.loadResource(resourceName); final GuidedDecisionTable52 table52 = GuidedDTXMLPersistence.getInstance().unmarshal(xml); final Analyzer analyzer = analyzerProvider.makeAnalyser(table52); // First run analyzer.resetChecks(); analyzer.analyze(); }
@Test public void testIndexGuidedDecisionTableActions() throws IOException, InterruptedException { //Add test files final Path path = basePath.resolve("dtable1.gdst"); final GuidedDecisionTable52 model = GuidedDecisionTableFactory.makeTableWithActionCol("org.drools.workbench.screens.guided.dtable.backend.server.indexing", new ArrayList<Import>() {{ add(new Import("org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant")); }}, "dtable1"); final String xml = GuidedDTXMLPersistence.getInstance().marshal(model); ioService().write(path, xml); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); { final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant", ResourceType.JAVA)) .build(); searchFor(index, query, 1, path); } }
" </data>\n" + "</decision-table52>"; GuidedDecisionTable52 guidedDTable = GuidedDTXMLPersistence.getInstance().unmarshal(guidedDTableXml); List<List<DTCellValue52>> dataList = guidedDTable.getData(); Assertions.assertThat(dataList).hasSize(1);
@Test public void testIndexGuidedDecisionTableAttributes() throws IOException, InterruptedException { //Add test files final Path path = basePath.resolve("dtable1.gdst"); final GuidedDecisionTable52 model = GuidedDecisionTableFactory.makeTableWithAttributeCol("org.drools.workbench.screens.guided.dtable.backend.server.indexing", new ArrayList<Import>() {{ add(new Import("org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant")); }}, "dtable1"); final String xml = GuidedDTXMLPersistence.getInstance().marshal(model); ioService().write(path, xml); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); //Decision Table defining a RuleFlow-Group named myRuleFlowGroup. This should match dtable1.gdst //This checks whether there is a Rule Attribute "ruleflow-group" and its Value is "myRuleflowGroup" { final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP)) .build(); searchFor(index, query, 1, path); } }
@Test public void testBackwardsCompatibility() throws Exception { final String xml = loadResource( "ExistingDecisionTable.xml" ); final GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance() .unmarshal( xml ); assertNotNull( dt_ ); assertEquals( GuidedDecisionTable52.HitPolicy.NONE, dt_.getHitPolicy() ); }
@Test public void testIndexGuidedDecisionTableAttributes() throws IOException, InterruptedException { //Add test files final Path path = basePath.resolve("dtable1.gdst"); final GuidedDecisionTable52 model = GuidedDecisionTableFactory.makeTableWithAttributeCol("org.drools.workbench.screens.guided.dtable.backend.server.indexing", new ArrayList<Import>() {{ add(new Import("org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant")); }}, "dtable1"); final String xml = GuidedDTXMLPersistence.getInstance().marshal(model); ioService().write(path, xml); Thread.sleep(5000); //wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId()); //Decision Table defining a RuleFlow-Group named myRuleFlowGroup. This should match dtable1.gdst //This checks whether there is a Rule Attribute "ruleflow-group" and its Value is "myRuleflowGroup" { final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP)) .build(); searchFor(index, query, 1, path); } }
@Test public void testFileBaseEntitlementGDST() throws Exception { final String xml = loadResource("Base entitlement.gdst"); final Analyzer analyzer = analyzerProvider.makeAnalyser(GuidedDTXMLPersistence.getInstance() .unmarshal(xml)); analyzer.resetChecks(); analyzer.analyze(); assertTrue(analyzerProvider.getAnalysisReport() .isEmpty()); }