@Test public void testRDSLRFile() { final Path pathSource = mock(Path.class); final Path pathDestination = mock(Path.class); when(pathSource.toURI()).thenReturn("file: when(pathDestination.toURI()).thenReturn("file: when(pathDestination.getFileName()).thenReturn("MyNewFile.rdslr"); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenReturn(dslr); helper.postProcess(pathSource, pathDestination); final ArgumentCaptor<String> drlArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), drlArgumentCaptor.capture(), any(CommentedOption.class)); final String newDrl = drlArgumentCaptor.getValue(); assertNotNull(newDrl); assertTrue(newDrl.contains("MyNewFile")); }
@Override public void postProcess(final Path source, final Path destination) { final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination); final String drl = ioService.readAllString(_destination); final String[] dsls = utilities.loadDslsForPackage(destination); final List<String> globals = utilities.loadGlobalsForPackage(destination); RuleModel model = null; String ruleName = null; if (drlResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions); ruleName = FileNameUtil.removeExtension(destination, drlResourceType); } else if (dslrResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions, dsls); ruleName = FileNameUtil.removeExtension(destination, dslrResourceType); } if (model != null) { model.name = ruleName; ioService.write(_destination, RuleModelDRLPersistenceImpl.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] renamed to [" + destination.toURI() + "].")); } }
GuidedRuleEditorRenameHelper implements RenameHelper { @Override public void postProcess(final Path source, final Path destination) { final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination); final String drl = ioService.readAllString(_destination); final String[] dsls = utilities.loadDslsForPackage(destination); final List<String> globals = utilities.loadGlobalsForPackage(destination); RuleModel model = null; String ruleName = null; if (drlResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions); ruleName = FileNameUtil.removeExtension(destination, drlResourceType); } else if (dslrResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions, dsls); ruleName = FileNameUtil.removeExtension(destination, dslrResourceType); } if (model != null) { model.name = ruleName; ioService.write(_destination, RuleModelDRLPersistenceImpl.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] renamed to [" + destination.toURI() + "].")); } } }
GuidedRuleEditorRenameHelper implements RenameHelper { @Override public void postProcess(final Path source, final Path destination) { final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination); final String drl = ioService.readAllString(_destination); final String[] dsls = utilities.loadDslsForPackage(destination); final List<String> globals = utilities.loadGlobalsForPackage(destination); RuleModel model = null; String ruleName = null; if (drlResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions); ruleName = FileNameUtil.removeExtension(destination, drlResourceType); } else if (dslrResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions, dsls); ruleName = FileNameUtil.removeExtension(destination, dslrResourceType); } if (model != null) { model.name = ruleName; ioService.write(_destination, RuleModelDRLPersistenceImpl.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] renamed to [" + destination.toURI() + "].")); } } GuidedRuleEditorRenameHelper(); @Inject  GuidedRuleEditorRenameHelper(final @Named("ioStrategy") IOService ioService,
                                        final GuidedRuleDRLResourceTypeDefinition drlResourceType,
                                        final GuidedRuleDSLRResourceTypeDefinition dslrResourceType,
                                        final GuidedRuleEditorServiceUtilities utilities,
                                        final CommentedOptionFactory commentedOptionFactory,
                                        final DataModelService dataModelService,
                                        final Instance<RuleModelIActionPersistenceExtension> persistenceExtensionInstance); }
GuidedRuleEditorRenameHelper implements RenameHelper { @Override public void postProcess(final Path source, final Path destination) { final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination); final String drl = ioService.readAllString(_destination); final String[] dsls = utilities.loadDslsForPackage(destination); final List<String> globals = utilities.loadGlobalsForPackage(destination); RuleModel model = null; String ruleName = null; if (drlResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions); ruleName = FileNameUtil.removeExtension(destination, drlResourceType); } else if (dslrResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions, dsls); ruleName = FileNameUtil.removeExtension(destination, dslrResourceType); } if (model != null) { model.name = ruleName; ioService.write(_destination, RuleModelDRLPersistenceImpl.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] renamed to [" + destination.toURI() + "].")); } } GuidedRuleEditorRenameHelper(); @Inject  GuidedRuleEditorRenameHelper(final @Named("ioStrategy") IOService ioService,
                                        final GuidedRuleDRLResourceTypeDefinition drlResourceType,
                                        final GuidedRuleDSLRResourceTypeDefinition dslrResourceType,
                                        final GuidedRuleEditorServiceUtilities utilities,
                                        final CommentedOptionFactory commentedOptionFactory,
                                        final DataModelService dataModelService,
                                        final Instance<RuleModelIActionPersistenceExtension> persistenceExtensionInstance); @Override boolean supports(final Path destination); @Override void postProcess(final Path source,
                            final Path destination); }
GuidedRuleEditorRenameHelper implements RenameHelper { @Override public void postProcess(final Path source, final Path destination) { final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination); final String drl = ioService.readAllString(_destination); final String[] dsls = utilities.loadDslsForPackage(destination); final List<String> globals = utilities.loadGlobalsForPackage(destination); RuleModel model = null; String ruleName = null; if (drlResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions); ruleName = FileNameUtil.removeExtension(destination, drlResourceType); } else if (dslrResourceType.accept(destination)) { model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, dataModelService.getDataModel(destination), persistenceExtensions, dsls); ruleName = FileNameUtil.removeExtension(destination, dslrResourceType); } if (model != null) { model.name = ruleName; ioService.write(_destination, RuleModelDRLPersistenceImpl.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] renamed to [" + destination.toURI() + "].")); } } GuidedRuleEditorRenameHelper(); @Inject  GuidedRuleEditorRenameHelper(final @Named("ioStrategy") IOService ioService,
                                        final GuidedRuleDRLResourceTypeDefinition drlResourceType,
                                        final GuidedRuleDSLRResourceTypeDefinition dslrResourceType,
                                        final GuidedRuleEditorServiceUtilities utilities,
                                        final CommentedOptionFactory commentedOptionFactory,
                                        final DataModelService dataModelService,
                                        final Instance<RuleModelIActionPersistenceExtension> persistenceExtensionInstance); @Override boolean supports(final Path destination); @Override void postProcess(final Path source,
                            final Path destination);  }