Customize function by using JavaDSL - citrus-framework

I would like to know how can I create a customize function in java code instead of XML? I know how to add my function in the XML function library. But is there another way to add to the library in code?

You can add function libraries as Spring Beans to the application context. This is all you have to do in order to use your custom functions in Citrus:
#Bean
public FunctionLibrary customFunctionLib() {
FunctionLibrary functionLibrary = new FunctionLibrary();
functionLibrary.setPrefix("foolib:");
functionLibrary.setName("fooFunctionLibrary");
functionLibrary.getMembers().put("fooFunction", new FooFunction());
return functionLibrary;
}
After that you should be able to call the function with foolib:fooFunction().

Related

Changing jasper report parameters in runtime

I know, but we really need it.
We have a clear division of labor.
They create templates, I fill them in runtime according to some rules.
Can't teach my business to insert something like this and be sure they really did it ok(so can't move any logic to templates):
$P{risk_types}.get($F{risk_type}) ?: "UNDEFINED"
Also can not fill from files hardcoded in some adapter hadwritten by god-knows-who and unchangeable in runtime. It's a web app. Best option is to find a way to replace that file source from adapter to a ByteArrayStream.
SO:
Need to substitute contents of parameters(also default ones) at runtime.
example:
need to set JSON_INPUT_STREAM
Like this unsolved thread.
https://community.jaspersoft.com/questions/516611/changing-parameter-scriptlet
Really hope not to work on xml level, but xml also can't solve my problem as far as I tried.
Thank you!
The easiest and cleanest way we did this(bypassing usage of tons of deprecated documentation and unfinished bugged undocumented static antipatterned new features):
Create context with repository extension
SimpleJasperReportsContext jasperReportsContext = new SimpleJasperReportsContext();
jasperReportsContext.setExtensions(RepositoryService.class, Collections.singletonList(new MyRepositoryService(jasperReportsContext, yourOptionalParams)));
Fill this way(after compile and other usual actions)
JasperPrint print = JasperFillManager.getInstance(jasperReportsContext).fill(compiled, new HashMap<>());
Now your repository must extend default one to be hack-injected(cause of hodgie coded "isAssignableFrom") successfully
public class PrintFormsRepositoryService extends DefaultRepositoryService {
#Override
public InputStream getInputStream(RepositoryContext context, String uri) {
// return here your own good simple poj inputStream even from memory if you found source
// or pass to another repository service(default one probably)
return null;
}
}

How to find references to a Spring converter in Eclipse?

I'm working on a Java web app which utilises Spring's ConversionService API.
Converters look like this:
public class MyCustomConverter implements Converter<MySourceClass, MyTargetClass> {
#Override
public MyTargetClass convert(final MySourceClass source) {
// ...conversion code...
return myTargetClass;
}
}
and are registered in the application config, e.g:
#PostConstruct
public void addConverters() {
genericConversionService.addConverter(myCustomConverter);
// ...others...
}
A conversion can then be applied like this:
MyTargetClass result = conversionService.convert(mySource, MyTarget.class);
The problem I'm having is finding usage within the code of a particular converter (such as the example directly above). Am using Eclipse IDE - could anyone suggest a way to do this?
If you want to see all the references made to the method ConversionService.convert, you can highlight the convert method and use the Eclipse short-cut Ctrl + Shift + G. This will search the method inside your entire workspace. To search only in the project, you can right-click on the method and select References > Project.
To restrict the references search with a specific method parameter, see this answer : https://stackoverflow.com/a/11836545/1743880.

How to extract parts of a GWT application into a library of separate dialogs

I'm trying to extract parts of a GWT application into many separate dialogs that can be invoked from php.
Existing state:
We have a GWT appplication that is deployed to JBoss as a WAR.
The app has a single module with a signle entry point.
The main JSP sets up the environment and then has some JS that loads the .nocache.js using document.write();
The entry point's onModuleLoad() creates a panel to fill the browser and adds it to the root using RootPanel.get("root").add();
When some event happens (e.g., user presses button) we pop up a DialogBox by instatiating a subclass and calling center() or setVisible()
Desired state:
We want a php app with multiple pages, to be able to invoke various DialogBox subclasses.
I think that the php side should use JS function calls that use document.write();
As for the GWT side, the options I see are:
One module with multiple entry points.
Multiple modules.
Does anyone have any experience or understanding of what would be the best practice here?
If I've understood right, you need to call GWT methods from Javascript.
You can use JSNI.
But I think you should try gwt-exporter on the GWT side. Overview. Tutorial.
It's simple GWT module to create JS_API for your GWT modules.
Not pretending to be the best practices, just quick example.
On the server-side you include an existing GWT module with DialogBoxes on every page.
You need to modify this GWT module or create new like this.
public class GwtModule implements EntryPoint {
#Override
public void onModuleLoad() {
// exportable class
DialogBoxManager dbm = new DialogBoxManager();
// export all Exportable classes of module
ExporterUtil.exportAll();
// needed cause JS_API will be available only after the GWT is loaded
onLoad();
}
// call when GWT module loaded
private native void onLoad() /*-{
$wnd.loaded();
}-*/;
DialogBoxManager looks like this
#Export
#ExportPackage("pkg")
public class DialogBoxManager implements ClickHandler, Exportable {
private DialogBox db;
public DialogBoxManager() {
this.db = new DialogBox();
}
#Export("showDB")
public void showDialog() {
db.setVisible(true);
db.center();
db.show();
}
#Override
public void onClick(ClickEvent event) {
showDialog();
}
}
String values in #Export("show"), #ExportPackage("pkg"), etc. annotations will be used in our JS_API calls for annotated GWT methods (you can export also fields).
You can use just #Export (as I did for DialogBoxManager).
When GWT module is loaded in your JS library you can realize initialization of JS_API member or what you need
var dbManager = null;
...
function loaded() {
dbManager = new pkg.DialogBoxManager();
}
and then just call JS_API like this
function showDB() {
if (dbManager != null) {
dbManager.showDB();
}
}

Extend symfony task in plugin

I am working with a plugin in symfony 1.4, and would like to add a listener for a task from another plugin. When the user does php symfony doctrine:build I want my plugin to run a task of its own. Where/how do I register the listener? I did not have any success with http://www.symfony-project.org/gentle-introduction/1_4/en/17-Extending-Symfony
Thank you!
Actually you can hook your code to any symfony task. Have a look at sfBaseTask::doRun method. Any task, when is executed, emits 2 events: command.pre_command and command.post_command.
Create a class to store you code, for example:
class toolkitEvents
{
static public function commandPostEventHook(sfEvent $event)
{
$task = $event->getSubject();
if ($task->getFullName() === 'doctrine:build')
{
//do stuff or call another task
}
}
and connect this method to a dispatcher when initializing your plugin:
class yourPluginConfiguration extends sfPluginConfiguration
{
public function initialize()
{
$this->dispatcher->connect('command.post_command', array('toolkitEvents', 'commandPostEventHook'));
}
I don't think there is a suitable event for this (like the cache clear one).
My suggestion would be either to accept that it needs to be two tasks, or if you use build that often, create a wrapper task to call one first then the other - doctrine:build is a good example of how to do this. Or a bash/batch script!

Eclipse RCP: How to access internal classes of plugins?

I want to use the default XML editor (org.eclipse.wst.xml.ui) of Eclipse in an RCP application. I need to read the DOM of the xml file currently open. The plugin doesn't offer any extension point, so I'm trying to access the internal classes. I am aware that the I should not access the internal classes, but I don't have another option.
My approach is to create a fragment and an extension point to be able to read data from the plugin. I'm trying not to recompile the plugin, that's why I thought that a fragment was necessary. I just want to load it and extract the data at runtime.
So, my question is: is there another way to access the classes of a plugin? if yes, how?
Any tutorial, doc page or useful link for any of the methods is welcome.
Since nobody answered my question and I found the answer after long searches, I will post the answer for others to use if they bump into this problem.
To access a plugin at runtime you must create and extension point and an extension attached to it into the plugin that you are trying to access.
Adding classes to a plugin using a fragment is not recommended if you want to access those classes from outside of the plugin.
So, the best solution for this is to get the plugin source from the CVS Repository and make the modifications directly into the source of the plugin. Add extension points, extensions and the code for functionality.
Tutorials:
Getting the plugin from the CVS Repository:
http://www.eclipse.org/webtools/community/tutorials/DevelopingWTP/DevelopingWTP.html
Creating extensions and extension points and accessing them:
http://www.vogella.de/articles/EclipseExtensionPoint/article.html
http://www.eclipsezone.com/eclipse/forums/t97608.rhtml
I ended up extending XMLMultiPageEditorPart like this:
public class MultiPageEditor extends XMLMultiPageEditorPart implements
IResourceChangeListener {
#Override
public void resourceChanged(IResourceChangeEvent event) {
// TODO Auto-generated method stub
setActivePage(3);
}
public Document getDOM() {
int activePageIndex = getActivePage();
setActivePage(1);
StructuredTextEditor fTextEditor = (StructuredTextEditor) getSelectedPage();
IDocument document = fTextEditor.getDocumentProvider().getDocument(
fTextEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager()
.getExistingModelForRead(document);
Document modelDocument = null;
try {
if (model instanceof IDOMModel) {
// cast the structured model to a DOM Model
modelDocument = (Document) (((IDOMModel) model).getDocument());
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
setActivePage(activePageIndex);
return modelDocument;
}
}
This is not a clean implementation, but it gets the job done.