Sunday, October 9, 2011

Generating async version of the GWT remote services

Introduction

Shakespeare would ask: to generate async version of the GWT remote service or to not generate async version of the GWT remote service?

Our answer is: definetelly generated them!

  • It allows you to keep these two files (remote service interface and async remote service interface) in the sync (maybe you have had a hard times with GWT compilation and knows perfectly this kind of error message: Missing asynchronous version of the synchronous method).
  • Thanks to eclipse annotation processing support it is perfectly integrated with your IDE and async remote service interface is automatically regenerated after each change in the remote service interface).

Maven configuration

  • Add following dependency to your pom.xml
    <dependency> <groupId>sk.seges.acris</groupId> <artifactId>acris-async-service-processor </artifactId> <scope>provided</scope> <version>1.2.0</version> </dependency>
  • create .pap file in your project in order to enable annotation processors - see profiles activation wiki

Execution

When your remote service is annotated with one of the following annotation, async interface is automatically generated by the async annotation processor:
  • com.google.gwt.user.client.rpc.RemoteServiceRelativePath
  • sk.seges.acris.core.client.annotation.RemoteServicePath

Example

Remote service:
@RemoteServiceRelativePath("/service")
public interface GWTContentAdministrationServiceRemote 
                            extends RemoteService {
 
     PagedResult> findAll(Page page);
 
     ContentDTO merge(ContentDTO content);
 
     void remove(ContentDTO content);
}
right after the file is saved in the eclipse (or netbeans), async version is generated:
@Generated(value = "sk.seges.acris.pap.service.AsyncServiceProcessor")
public interface GWTContentAdministrationServiceRemoteAsync {
 
     void findAll(Page page,
             AsyncCallback>> callback);
 
     void merge(ContentDTO content, AsyncCallback callback);
 
     void remove(ContentDTO content, AsyncCallback callback);
}
Original article is part of the acris wiki: http://code.google.com/p/acris/wiki/CodeGenerationPlatform_Async

AcrIS 1.2.0 Release

Dear AcrIS developers,

after a delay from estimated date, we are pleased to announce you the release of AcrIS with version 1.2.0. The goal of the release was huge and can be summarized like this:

Features

  • introduced profiles to allow you to quickly start with Processors, GWT client, AppEngine? project development
  • writing Java Annotation Processors from now on will be a piece of cake with AcrIS
    • we implemented Mutable API to be able to easily transform types and write annotation processors in clear way
    • delegated configuration might help you when you don't want to polute existing (or even new) objects with processor-specific annotations
    • there are several prepared annotation processors:
      • for generating portable domain interfaces
      • generating DTOs and convertion layers between server and client layer
      • first sketch of appconstructor - scaffolding platform using annotations
      • GWT service layer processors
  • JSON data migration helps you to transform your data between versions
  • your sites and applications in production environment should be constantly monitored with Asmant monitoring tool deployable to AppEngine?
  • two new widgets to support dynamic layouts:
  • testing became integral part of AcrIS framework so we developed supporting layer for Selenium

Announcements

  • current development was performed on the branch 1.1.x and for future versions will be moved back to the trunk. Current trunk will be moved to 1.0.x branch.
  • beans binding part of AcrIS is discontinued and will be maintained for the purpose of old projects only - we recommend to use GWT's Editor framework. 

So again, don't hesitate and try it !
http://acris.googlecode.com

Sunday, September 4, 2011

JSON data migration

Introduction

JSON data format is simple and still powerful. Nowadays you can encounter more and more web applications communicating using JSON format then couple of years ago. It is simple for a developer to read the format, it is effective for web browser to parse the format and there are databases using it as its primary data format.
But what happens when the data structure changes? You need to migrate.
And that is where acris-json-migration might help you!

Example situation

Let's shed a light into it and assume we have a data like this:

{
        "firstName":"John"
        "secondName":"Doe"
        "street":"Over the rainbow"
        "streetNr":21
}
 
Such data can be represented by following Java domain object:

public class Person {
        String firstName;
        String secondName;
        String street;
        Integer streetNr;

        // ... and getters and setters...
}
 
Well, this seems like data about a person named John Doe. We stored it in database and you can clearly see, that secondName is probably not the field name we really like to have. But a developer made a mistake and in second version of our domain model we are going to fix it:

{
        "firstName":"John"
        "surname":"Doe"
        "street":"Over the rainbow"
        "streetNr":21
}
 
Now you can see the point - thousands of data stored in the format defined by Person class in its version #1 but our program communicating in version #2 with changed secondName to surname in Person class. Clients can wonder why the don't see surnames, can't they? ;)
One thing to remember (for the following context) - the class Person changed and there is only Person class in version #2.

Simple migration script

In this situation I would like to write a script:

public class PersonV1toV2Script extends JacksonTransformationScript<ObjectNode> {

        @Override
        public void process(ObjectNode node) {
                rename(node, "secondName", "surname");
        }
}
 
From the above example it is clear that the script will do the job. And you can do pretty anything with the whole tree of JSON data - adding new nodes, removing existing ones, transforming here and there - all thanks to Jackson's tree model.

How can I execute it?

There is a Transformer abstract class representing a transofmer responsible for passing JSON data to a script and writing it back.
Currently there are tow kinds of transformers:
Jackson-based is the preferred one and is more developed then JSONT-based.
So to execute a transformation on a data set you have to specify only two lines of code:

JacksonTransformer t = new JacksonTransformer(input, output);
t.transform(PersonV1toV2Script.class.getName());
 
... where input and output represent directories. In the input directory all files are treated as files containing JSON data and are transformed and written to the output directory. For a detailed test you can look into TransformerTest in the project.


Conclusion

The script's helper API is evolving and provides you with nice methods like removeIfExists or addNonExistent methods. We would like to hear about your use-cases which are not handled by acris-json-migration yet so the project can generally serve the purpose of JSON data migration.

Monday, July 25, 2011

Dynamic binding of GWT UI components

Introduction

Probably all of you know the chapter in GWT documentation about Declarative Layout with UiBinder. It describes a way how to bind individual components within a panel to its UI representation - written in a HTML-like markup language. It allows you to define the UI layout and compile it, so you don't have to do it in the code of the panel directly and are able to switch the UI anytime with different one.
But what if you need to switch the layout while the application is already running?
That is the point where Dynamic UI binder comes. It allows you to specify the binding information in HTML and GWT panel the same way you do in GWT's UiBinder. The only difference is that you don't need to have the layout template in that time. You can load it later using a service or read it/modify it in the code dynamically.
So let's take a look how you would do that.

Showcase

For those impatient: You can find a showcase of this in acris-showcase-widgets project.
Let's suppose we are going to create a simple calculator of how many ships our space fleet has. We have to "leaders" responsible for their ships. So we will have two text boxes to enter the number and a button to calculate everything:
<div class="dyn-panel">
        <div ui:field="message" class="dyn-message">Status messages are shown here</div>
        <div class="fleet-container">
                <div ui:field="description" class="dyn-description"></div>
                <input type="text" ui:field="ashtarShips" />
                <input type="text" ui:field="ptahShips" />
                <button ui:field="recalculateFleet">Recalculate fleet</button>
        </div>
</div>
As you can see we will output status/error messages and have a link pointing to a description (you may wonder why it is a "div" tag, explanation will follow).
OK, let's construct the panel. We start with binder definition:
public class DynamicallyBoundPanel extends Composite {
        interface DynamicallyBoundPanelUiBinder extends DynamicUiBinder<Widget, DynamicallyBoundPanel> {}

        private static final DynamicallyBoundPanelUiBinder binder = GWT.create(DynamicallyBoundPanelUiBinder.class);

        ...
}
As you can see, the syntax is similar to GWT's one, instead of UiBinder we use DynamicUiBinder.
And the fields will follow:
        @UiField
        protected Label message;

        // this is acris-widget Hyperlink because GWT's misses wrap method!
        @UiField
        protected Hyperlink description;

        @UiField
        protected TextBox ashtarShips;

        @UiField
        protected TextBox ptahShips;

        @UiField
        protected Button recalculateFleet;

Hmm, so now the only piece missing is the glue between the template and the binding:

        public DynamicallyBoundPanel() {
                // load the template e.g. from service ...
                String htmlTemplate = "<div class=\"dyn-panel\"><div ui:field=\"message\" class=\"dyn-message\">Status messages are shown here</div><div class=\"fleet-container\"><div ui:field=\"description\" class=\"dyn-description\"></div><input type=\"text\" ui:field=\"ashtarShips\" /><input type=\"text\" ui:field=\"ptahShips\" /><button ui:field=\"recalculateFleet\">Recalculate fleet</button</div></div>";
                binder.setViewTemplate(htmlTemplate);

                // known from GWT UiBinder - initialize
                initWidget(binder.createAndBindUi(this));
        
                ...
        }

For the purposes of the explanation the HTML template is directly put into the variable "htmlTemplate". Usually you will read it from service.
Every tag that has to be matched to a field-widget in the panel must have corresponding name in the attribute ui:field. The value is the same as a name of the field.
The main difference between GWT's UiBinder and DynamicUiBinder is the template setup. Before you execute binder.createAndBindUi(this), the binder needs to have it. You can consider the binder as a factory of panels, so consecutive calls to the pair of methods setViewTemplate/createAndBindUi can lead to different results (if the template changes). That way you can keep one such binder factory initialized and provide only the template based on businness logic requirements.
With bound fields you can perform ordinary GWT coding, e.g. setting the value of the message:
        message.setText("You accessed " + event.getValue() + ". Thank you for your interest in AcrIS. For more information, please visit http://acris.googlecode.com");

And that's it for the showcase... feel free to check it out at AcrIS pages.

Thursday, June 16, 2011

AcrIS 1.1.2 Release

Dear all,

after a bit of struggling and delay we would like to announce brand new AcrIS 1.1.2 release. Let's list the most important changes:

Features

  • Added shadow theme + new components into the widgets projects (ComboBox, CheckBox based on images
  • New showcases available
  • Added test project for testing cardpay/tatrapay payment methods
  • New APIs/core for annotation processors
  • Added complex selenium/webDriver support with configuration possibilities (with many fixes for doubleclick, etc.)

Improvements

  • 3rd party libraries upgrade - we are now using
    • GWT 2.3.0
    • gwt-log 3.1.2
    • gwt-query 1.0.0
    • Gilead 1.3.3 for GWT 2.3.0
  • More profiles added for easier plugin/depedency configuration(.gwt for GWT based projects, .pap profiles for plugable annotation processor based projects) 

Don't hesitate to visit AcrIS page and use it or ask a question.
AcrIS team

Saturday, May 14, 2011

AcrIS 1.1.1 Release

Dear AcrIS developers,

we are pleased to announce a release of AcrIS with version 1.1.1. The goal of the release was following:


Features

  • Added annotation processing support - part of the sesam & corpis suite. Read more in CodeGenerationPlatform
  • Added more and more showcases
  • Portable architecture introduced and code is continuosuly migrated

Improvements

  • Offline content generator improved, code cleanup and polishing 

AcrIS Binding

In the meantime new GWT version brought Editor framework. Because we favour DRY principles we decided not to continue with aggressive acris-binding development and move to GWT native one. Since now all features which are connected with binding of components, will be commited to GWT code. Only special integrations might be part of AcrIS. Current version of acris-binding will be preserved and maintained.

Don't hesitate and have a look at http://acris.googlecode.com

Monday, December 6, 2010

AcrIS 1.1.0 Released

Dear AcrIS developers,

we are pleased to announce a release of AcrIS with version 1.1.0. This release called Hladný Hadík gives you following advanced JEE features into your hands:

Features
  • Reporting module integrated with JasperServer
    • prepared components to define a set of reports available to your customers with configurable parameters
    • transparent facade to a JasperServer generating required reports
  • Offline generator capable of creating a version of the web searchable by any web crawler
    • have you ever wondered whether you can create crawler-friendly static content of your dynamic application? Now is the time to use offline generator.
    • enables any GWT application to have its static crawlable mirror
  • Security module enhanced with an OpenID authentication integration
Bugfixes
  • Fixes in beans binding (more stable code)
Improvements

  • 3rd party libraries upgrade - Spring 3.0.4.Release, Hibernate 3.6.0-Final, GWT 2.0.4, Gilead 1.3.2
  • from now on AcrIS is using GWT 2.1
  • and of course lot of bugfixes against production code
So don't hesitate and check new release at http://acris.googlecode.com !