Tuesday, February 9, 2010

Customization of webflows

With the new 1.7 release of sculptor the possibilities to customize flows for the web client is much better.
With our Library example here is what you can do.
For example, lets say you want to implement filter functionality for the library list feature. Here is the steps to do that:

1) Specify that you want gap-files for the list library feature, so in your model.guidesign:

gui Library for Library {
Module for media {
ListTask for Library {
gap
}
}
}

Now you have a bunch of files for the feature:
  • src/generated/java/org...library/ListLibraryActionBase.java
  • src/main/java/org...library/ListLibraryAction.java -> gap
  • src/generated/java/org...library/ListLibraryForm.java
  • src/WEB-INF/generated/flows/media/listLibrary/listLibrary-base.xml
  • src/WEB-INF/generated/flows/media/listLibrary/list_include.xhtml
  • src/WEB-INF/flows/media/listLibrary/listLibrary-flow.xml -> gap
  • src/WEB-INF/flows/media/listLibrary/list.xhtml -> gap

2) Edit the media/listLibrary flow:


<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance"
ns0:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
parent="media/listLibraryBase">
<view-state id="list">
<transition on="filterLibrary" to="listByFilter" />
</view-state>
<view-state id="listByFilter" model="listLibraryForm"
view="/WEB-INF/flows/media/listLibrary/list.xhtml" parent="media/listLibraryBase#list">
<on-render>
<evaluate
expression="listLibraryAction.findByFilter(flowRequestContext)" />
</on-render>
</view-state>
</flow>

3) Edit the ListLibraryAction, add the method:


public String findByFilter(RequestContext ctx) {
getRepository().clear();

List<library> allLibraries = getLibraryService().findAll(ServiceContextStore.get());
List<library> filtered = new ArrayList<library>();
String filter = ctx.getRequestParameters().get("libraryFilter");
for (Library library : allLibraries) {
if (library.getName().startsWith(filter)) {
filtered.add(library);
}
}
formObject(ctx).setAllLibraries(filtered);
return "success";
}

4) Add a simple form with a text field and a button to the media/listLibrary/list.xhtml-file:


<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jstl/core"
xmlns:a="ApplicationTaglib">
<body>
<ui:composition template="/WEB-INF/common/template.xhtml">
<ui:define name="content">
<h1>
<h:outputFormat value="#{msg['list.header']}">
<f:param
value="#{msgMedia['model.DomainObject.Library.plural']}" />
</h:outputFormat>
</h1>
<h:form xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jstl/core"
xmlns:a="ApplicationTaglib">
<div>
<label for="_libraryFilter">#{msgMedia['model.DomainObject.Library.filter']}: </label>
<input type="text" value="#{requestParameters.libraryFilter}" name="libraryFilter" id="_libraryFilter"/>
<h:commandButton value="#{msgMedia['model.DomainObject.Library.filterButton']}" action="filterLibrary" />
</div>
</h:form>
<ui:include
src="/WEB-INF/generated/flows/media/listLibrary/list_include.html" />
</ui:define>
</ui:composition>
</body>
</html>

Note that the default generated table showing the list result is used by including the generated file. In case you need to modify the generated content you can either overwrite the code generation templates in WebSpecialCases.xpt or simply copy the generated file and maintain it manually

That's it.

Tuesday, February 2, 2010

Two Success Stories from Factory4Solutions

Introduction
I work as architect at company Factory4Solutions (www.f4s.sk). Our
primary customers are banks, insurance companies, telecommunication
sector. We was using MDA approach long before. We started around 1997
with our own home made solution based on RationalRose, XML and custom
generator. Than we switched to AndroMDA. Tool was nice but stalled in
development around 2007. Then I start investigate another MDA tools.
We were looking for tool based on open technologies, universal and able
to generate JEE code. After playing little bit with proof of concept
projects we got first real project in which we could apply it.

Insurance company
Decision was not easy. We have to migrate existing portal with huge
amount of existing data to new portal. Persistent layer was hand
written in Oracle TopLink and front-end was in JSPs. I expected many
problems because hand written persistent layer is usually full of
nonstandard approaches which are hard to achieve in generic MDA tool.

However for me as an architect it was important to achieve
standardization because we had complicated deployment mode. Because of
security, portal was split to two. First was 3 tier extranet deployed
on WebLogic cluster and internal part which had similar functionality
but was running only on single server. Both portals were using same
database. For easier development I decided go with only one code base.
At build time we split the application and created more WAR files (Full
intranet, Extranet service tier, Extranet web tier).

I was really afraid about MDA approach. I started with SQL DDL and
created first version of model design file for Sculptor. Then I started
to tweak model file to fit existing database. After 2 days I was ready
with our model and first version of important services.

Thanks to strict Domain Driven Design which Sculptor follow I moved
code to developers to finish services and develop web frontend. Thanks
to Spring Remoting it took just 1 day to develop build procedure for 3
different WAR files. Except some small problems when developer used
some utility methods from frontend on backend. The architecture is stable,
system is maintainable and extendable. Today we still use one code
base also for demo system, batch processing system and Web Service
layer. Flexibility of Sculptor is endless. When you reach the border
with what Sculptor allow, you are still free to override parts of
generated code thanks to Xpand language.

Project facts:
  • 6 developers + 0.5 architect + 1 project manager + 0.5 auality assurance + 0.5 analyst for 9 month
  • 108.000 lines of java code, 34.000 lines of JSP code
  • Processing big reports from customers take 5-6 minutes (10 MB XML)
  • 20.000 reports a day are send in peaks

Investment company
We had advantage that we should start from scratch. Now project
consist of 40 entities and 26 services. Very complex security and
entity processing by complicated business processes involving bank,
customers, internal users, stock exchange, e-mail processing and
advisor networks. It was developed fully with Sculptor for entity and
service tier.

This is our first project where we used Sculptor also for generating
web frontend. We used smartclient (Sculptor allow to generate different
frontends). We are satisfied with speed of development and nice GUI
which users appreciate.

We also used very unique concept of waving rule engine - Drools
in front of service tier. This way we validate objects, sending
announcement, sending business alerts and also for complex price
list processing which consist of 8 different payment tables applied
at complex conditions. Result is very robust system which allow at
one side dynamic change but on other side very stable.

We are now running User Acceptance Tests at client side.

Project facts:
  • 2 developers + 0.5 architect + 0.5 quality assurance during 6 month
  • 9.000 lines of hand written code, 3.600 lines of test code, 49.000 lines of generated code

Conclusion
Today we are using Sculptor for all our projects. We master it to nice
extend and we now participate in development of new versions. I'm very
happy with new 1.7 release. This brings some nice features.
Specifically it's Smartclient frontend, hints for custom generation of
code and condition criteria builder with nice Java DSL (type and name
checking and IDE autocompletion).

This story was written by Pavel Tavoda, Factory4Solutions

An Old Success Story

It was a completely new project started from scratch. The main goal of a project was processing of a big files and then generates reports. Despite the fact that installation of a product includes configuration for personal and network use, we choose choose architecture of app that includes Tomcat and Hibernate. After some investigation I found Sculptor. It uses well known (by me) technologies and best practices for that moment. When main functionality was implemented in a draft state Sculptor helped to start with a simple domain model. It was not really big model. This model includes about 50 entities and services (Users, Reports, Settings, Schedule, Directory objects, ...). It was implemented by a team with a different experience in JEE technologies. And almost all of them started to use Sculptor model very quickly.

Our team used SCRUM as a development process. So, it was really exciting "Agile" process implementation. Even Domain Model was agile! There were several serious refactorings that includes changes in Domain Model and Sculptor framework supported this in several ways. First, It requires tests implementation, so our changes was tested just after applying. Second, the way Sculptor uses to separate generated and hand-written code doesn't prevent refactorings. Sure, there were some minor problems, e.g. with using "lazy" initialization. But they were successfully solved and now product is on the market.

Regards,
Vladimir
December 2008

Sculptor 1.7.0 - GAE, Smartclient, EclipseLink, DataNucleus, JEE

Sculptor 1.7.0 has been released. In this version the list of supported technologies has grown with several popular alternatives.

Sculptor has many built in customization options to pick and choose from. The major new target implementation options in this release:
  • Google App Engine
  • EclipseLink and DataNucleus JPA Provider
  • Smartclient GWT
  • Pure EJB3 (without Spring)
  • Web Services with JAX-WS
Sculptor also has good possibilities for extensibility if you prefer a design or framework that is not supported out-of-the-box. Sculptor is using openArchitectureWare code generation platform, which makes it possible to change the code generation templates using Aspect-Oriented Programming (AOP) features.

The Pure EJB3 implementation, one of the new features in 1.7.0, has already been successfully used in several projects, i.e. it is well tested and production ready. This means that not only Spring users can gain the productivity and quality benefits of Sculptor, but also those who develop on the standard JEE stack.


Thursday, January 28, 2010

Enable scala in your appengine/sculptor project

I've recently started to interest myself in the Scala language. It is a language that runs on the jvm. It's very rich in its syntax and it has a very pleasant mix of OO- and functional programming.
But since I always starts my explorations with the solid foundation of maven the first problem I encountered was how to integrate scala in my build process in a project that already mixes GAE and Sculptor. I.e. I start off from a project that has been created with our maven appengine archetype. So this is a log of my steps for making this happen.

1) In your pom, add a property for the version of Scala:


<scala.version>2.7.7</scala.version>


2) In your pom, add repository for scala:


<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>


3) In your pom , add pluginRepository:


<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>


4) In your pom, add dependency:


<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>


5) In your pom, add entry in maven-dependency-plugin in the build section:


<artifactItem>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<outputDirectory>war/WEB-INF/lib</outputDirectory>
</artifactItem>


6) In your pom, add dependency to specs-library (if you want it):


<dependency>
<groupId>org.specs</groupId>
<artifactId>specs</artifactId>
<version>1.4.3</version>
<scope>test</scope>
</dependency>


7) In your pom, add the scala-plugin to the build section:


<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
</args>
</configuration>
</plugin>


8) In your project file structure, add a simple scala file: src/main/scala/org/foo/App.scala


package org.foo

/**
* Hello world!
*
*/
object App extends Application {
println( "Hello World!" )
}

9) In your project file structure, add a simple scala test: src/test/scala/org/foo/AppTest.scala


package org.foo

import org.junit._
import Assert._

@Test
class AppTest {

@Test
def testOK() = assertTrue(true)

}

10) In the root of your project file structure, run mvn install to see that everything builds ok

Tuesday, January 26, 2010

How to Remove Sculptor

When taking the decision to try a tool, such as Sculptor, it is important to know what it takes to stop using it if doesn't turn out as expected. Therefore I will in this post explain how to remove Sculptor. You don't have to do all steps and you don't have to do everything at once.

Step 1
The first step is to remove the code generation. This will take you less than 10 minutes.

a) In the maven pom.xml you remove the following:
  • plugin fornax-oaw-m2-plugin
  • plugin maven-clean-plugin
  • plugin fornax-checksum-m2-plugin
  • dependency fornax-cartridges-sculptor-generator
b) Remove these files in src/main/resources:
  • model files, .btdesign, .guidesign
  • sculptor-generator.properties
  • templates/SpecialCases.xpt
  • extensions/SpecialCases.ext
c) Move generated files
  • src/generated/java -> src/main/java
  • src/generated/resources -> src/main/resources
  • src/test/generated/java -> src/test/java
  • src/test/generated/resources -> src/test/resources
d) Run mvn eclipse:eclipse to generate eclipse project without generated source directories

Step 2
You don't need to do more right away, but later you would probably like to refactor the gap classes. Separation of generated and manually written code is done by a generated base class and manually written subclass. E.g. Person and PersonBase. You would probably like to collapse those into one class. To do this you can use the 'Push Down' refactoring in Eclipse, or simply copy paste the code from the base class to the subclass, and remove the extension.

This takes a few minutes per class, so you should be able to do a whole project within a few hours. It is a trivial and safe refactoring.

Step 3
Sculptor is a development tool, but it also has a small runtime library, with classes of utility and general character. This blog post explains why we have a runtime library. You can continue to use those classes as is. If you feel uncomfortable with that you can copy the source and remove classes that you don't use. The runtime library is not advanced at all, and you will have no problems to understan, maintain and change it as you need.

Thursday, January 21, 2010

Why we Combine Code Generator with Runtime Library

Sculptor is a development tool, but it also has a small runtime library. Some people find it scaring to bring in yet another library in their software stack.

It contains classes of utility and general character. It is not advanced at all. We could have generated those also and have no runtime dependency at all. Instead, we try to only generate things that must be variable, such as application specific structure and glue code. Static content should not be generated.

If we would have decided to not use a runtime library I think it would be a high risk that we would have generated code with bad design, such as repeated, duplicated code. We think in terms of DRY for the generated code. We always try to produce code as if we would have written it by hand, without a code generator. There are some exceptions to this rule, for example separation of generated and hand written code in separate classes.

It is interesting to compare Spring Roo and Sculptor. I see a lot of similarities, but also differences. One difference related to this topic is that Roo doesn't have a runtime library (except ordinary Spring Framework). They generate everything. They are using this as a selling point, but I think they have fallen into the trap of generating duplicated code. Take a look at the persistence methods in the ITD for an Entity.
   @Transactional 
public void Planet.remove() {
if (this.entityManager == null) this.entityManager = entityManager();
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
Planet attached = this.entityManager.find(Planet.class, this.id);
this.entityManager.remove(attached);
}
}
What happens if you decide to remove Roo? Then you will have to maintain a lot of duplicated code, that was generated initially. I think it illustrates how easy it is to forget or not bother about ordinary design principles when you solve everything with code generation. DRY should of course be used even when you have a code generator in your hands.

In Sculptor we have placed the general persistence operations in parameterized access objects, in the runtime library.