Saturday, July 23, 2011

Thoughts about Business Process Management

Here is my random thought's list about Business Process Management. Please don't expect it to be complete, new thoughts always comes and at random time and in random order. I will try to update it as new thoughts will come.

In general some person or group of the persons in the organization understands the full business process. When business process is automated then people are starting to rely on the business process executed by the Information System. At some point the system becomes too complicated and people starts trust business processes executed by the system. Employees leaves and new comes and at some time it's obvious that nobody fully understand what was intention of currently running business process, or some parts of it. Once you have reached that state, people is starting to be scared to change anything and keeps doing work in the same, sometimes inefficient way. Business conditions are changing permanently, but Business Process are not changing as fast and they should. My points are:
* business processes should be well understood by people who are working with system and organization's management.
* they should be collected out of smaller easier to understand subprocesses (if that can be achieved).
* all business processes should be graphically presented and documented in simple terms and short sentences.
* business language should be used to describe process, technical terms should be avoided as much as it could be.
* should be regularly revisited and updated as needed, without a fear of changes.

In my humble opinion, It's better to have a well understood, easy to change and maybe not perfect business process instead of huge, sophisticated process and be dependent on it without understanding what is going on and why organization is following some steps.

Worst possible Business Process or Workflow Management system is an embedded system. Embedded system will be considered and used by this one system and probably will not be able to work with other Applications and Information Systems or external data. Business Process and Workflow management system most of the time acts and integration tool between different systems and should be deployed ad used as such. It's better to have one scalable, performant system and integrate with other tools and systems used in the organization.

Wednesday, January 7, 2009

EJB 3.1 embeddable container and end of life for spring framework.

Just amazing what can be found in borring JCP document. All this story started once I decided to do some research regarding EJB 3.1 specification.

I will print only a few sentences from JSR-318 and will add some thought and comments about only one tiny part of it, just what is related with Embedded EJB container.

Enterprise JavaBeansTM 3.1 and what is said about Embedded Container.

Embeddable usage allows client code and its corresponding EJB 3.1 to run within the same JVM and class loader. This provides better support for testing, offline processing (e.g. batch), and the use of the EJB programming model in desktop applications.

The client uses a spec-defined bootstrapping API to start the container and identify the set of enterprise bean components for execution. The embeddable EJB container provides a managed environment with support for the same basic services that exist within a Java EE runtime : injection, access to a component environment, container-managed transactions, etc. In general, enterprise bean components are unaware of the kind of managed environment in which they are running. This allows maximum reusability of enterprise components across a wide range of testing and deployment scenarios without significant rework.

My comments and thoughts.

What makes me happy, this is an ability to have an EJB in desktop applications or regular java web application packaged as war and running in tomcat or other servlet container. Idea of having an EJB in tomcat is not absolutely new, OpenEJB does exactly that, but to be used in desktop application, for me it's a mind blowing idea. I like it very much.
Most of the people are using spring for their desktop applications and it helps a lot. Everyone knows that there are more frameworks following dependency injection pattern such as google-guice, pico container and others. Some of them have better performance, others are easier to use, but all, all of them without exceptions makes you dependent on them, you can not throw them out or replace by something more suitable later, or remove from runtime. Yes application is always dependent on execution environment and in this case dependent on spring or some other DI or EJB container. The point is an EJB container is a specification and it can be replaced by another more suitable for current task or environment, but spring can be replaced only by a newer version of spring.

What is most amazing, even full blown EJB containers such as Glassfish already are close to or almost at the same level of performance as spring framework and is easier to write and configure. Feel shocked, trust me or read these blog posts.

And here are some other interesting blog posts, for example I will list a few of them with some comments:
* Simplest possible EJB 3.1 shows what effort it takes to write an EJB 3.1 compliant bean, no xml, no interfaces, nothing what you ever could call boilerplate code.
* Some interesting thoughts about EJB vs POJO.
* EJB vs POJO performance
* EJB3 memory consumption.


And now the last thoughts. Everyone knows that spring framework is going to become application server, scary, yeah that's right a Java EE Application Server. Don't you think that spring has no option anymore, EJB's already becoming more effective in some cases and it's not a vendor lock in. Only option for spring is to become another option in list of options. What irony I see, is that spring lost his enemy, spring always was an opposition to EE, and now it becomes an EE by himself. That automatically makes it less appealing choice for new projects.

Have fun feature are bright

Regards Remigijus Bauzys

Monday, January 5, 2009

RESTful Web Services with Jersey JSR-311

Currently I'm excited about RESTful web services. REST is a kind of buzzword at this time and there are some good reasons for buzz. I do believe that REST for web services will stay for long time or hopefully even as long as web will exist. And today I'll try to do my first RESTful web service based on jersey.

Project Jersey is a reference implementation for JSR-311 for building RESTful Web services. As this specification states "it defines a set of Java APIs for the development of Web services built according to the 3
Representational State Transfer (REST) architectural style".

I was watching this project for quite long time, saw some presentations and red quite a lot about it and did a little bit of RESTful web services. So all this staff is not very new to me. Nevertheless this is my first try on JSR-311 and Jersey.

First impressions

At the beginning I thought and hoped that jersey will be something very or reasonably lightweight, few jars and servlet configuration for web.xml. These expectations comes from the stripes framework which I currently use and enjoy it very much. In general it has a very similar annotation based mapping between URI and handler methods and can be used with little bit adoption for similar things. But as you already guessed it is different, actually it has a lot of dependencies and comes even with grizzly or light weight http server, all JAXB jars if you a still on Java SE 5, ASM and other jars as optional. Documentation on jersey site scared me a little bit, it was not easy to understand what do I need for minimal start. I guess if I would be a maven friend everything could be easier.

At some point, when I was close to getting angry, about insane documentation I made decision to start with NetBeans. For the beginning I created a new Hello World (RESTful) Web Services project from one of the NetBeans samples project, after what I got a new project what was running and ready to go. This is the easiest way to get started. From that point everything went very smooth I knew what REST is and what I like to get at the end. Of course in order to understand what I should expect form Jersey and how can it differ from traditional RESTful I downloaded JSR-311 documentation in PDF form and JavaDocs.

JSR documentation is very short, only 49 pages and easy to read and understand. I'm true believer in the KISS, so I liked simplicity of this JSR.

The source code of my application is in one file. Application is just a simple test case where I want to have a catalog of the products and vendors. For this time I did most of the CRUD operations for vendor, they are : list vendors, add new vendor, and delete vendor. Update operation for vendor I didn't do because just for simplicity vendor has only one field which is a vendor's title and that makes unreasonable to do update operation.


package helloworld;

import java.util.ArrayList;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

/**
*
* @author remis
*/
@Path("/catalog")
public class CatalogResource {

private static ArrayList vendors = new ArrayList();

@GET
public String getCatalog() {
return "catalog index";
}

/**
* On HTTP GET method for /catalog/vendor returns full list of vendors.
* @return string with full list of vendors separated by semicolon.
*/
@GET
@Path("vendor")
public Response getVendors() {
StringBuilder sb = new StringBuilder();
for (String vendor : vendors) {
sb.append(vendor).append(";");
}
return Response.ok(sb.toString()).build();
}

/**
* On HTTP GET method for /catalog/vendor/{title} returns
* data of the specified vendor.
* @return string with title of found vendor. In case if such vendor
* does not exist
*/
@GET
@Produces("text/plain")
@Path("vendor/{title}")
public Response getVendor(@PathParam("title") String title) {
Response result = null;
if (! hasVendor(title)) {
result = Response.ok(title).build();
} else {
result = Response.noContent().build();
}
return result;
}

private boolean hasVendor(String vendor) {
return (vendor != null && vendors.contains(vendor));
}

@DELETE
@Produces("text/plain")
@Path("vendor/{title}")
public Response deleteVendor(@PathParam("title") String title) {
Response result = null;
if (hasVendor(title)) {
vendors.remove(title);
result = Response.ok().build();
}
return result;
}

@POST
@Produces("text/plain")
@Path("vendor/{title}")
public Response addVendor(@PathParam("title") String title) {
Response result = null;
if (! hasVendor(title)) {
vendors.add(title);
result = Response.ok().build();
}
return result;
}

@GET
@Path("product")
public String getProducts() {
return "product list is not implemented yet";
}

@GET
@Path("feature")
public String getFeatures() {
return "feature list";
}

@GET
@Path("tag")
public String getTags() {
return "tag list";
}

@GET
@Produces("text/plain")
public String getList() {
return "catalog list";
}
}


And here is result of my solution. There is a set of steps, with command curl -d "" URI I adding three vendors step by step. Three HTTP post methods are used to add 3 new vendors: SONY, PANASONIC and PHILIPS. Last HTTP GET command is used to retrieve all added vendors.


remis$ curl -X POST http://localhost:8080/restHello/resources/catalog/vendor/SONY
remis$ curl -X POST http://localhost:8080/restHello/resources/catalog/vendor/PANASONIC
remis$ curl -X POST http://localhost:8080/restHello/resources/catalog/vendor/PHILIPS
remis$ curl -X GET http://localhost:8080/restHello/resources/catalog/vendor
remis$ curl -X DELETE http://localhost:8080/restHello/resources/catalog/vendor/PANASONIC
remis$ curl -X GET http://localhost:8080/restHello/resources/catalog/vendor


How does it works? Simple, on every http request jersey does the matching between URI and path annotation, then based on the http method issued, corresponding handler method is executed. In case if method has additional parameter, which in my case is retrieved from URI path, this parameter is passed to the method and method uses parameter for business logic.

The list of curl commands listed above does the following commands line by line. Adds new vendor SONY, then another vendor PANASONIC and PHILIPS, later it prints out a full list of vendors and removes PANASONIC vendor. At the end of the list another command which outputs full list of vendors, but in this case it will enter only two vendors, because PANASONIC vendor was removed by previous command.

You can use a regular web browser in order to get an output for HTTP GET method, but it will be much harder to do HTTP POST and DELETE methods. If you know any easier and more user friendly way to issue HTTP POST and DELETE methods be very kind and enlighten my.

Maybe, I will update this blog entry later or even will write another story about Jersey, but for now it's enough. I have tried Jersey, I got my own opinion about it and next time decisions will be based on real experience.

As conclusion I would like to say, I haven't seen nothing easier that this Web Service API. It is easy to understand, clean, very productive and looks very fresh as fresh as spring. I haven't tested performance of it, but I guess hardly anything will beat it. As the last word I think I will look at other JSR-311 implementations, maybe they will be easier to start and lighter on dependencies.

Saturday, January 3, 2009

Google app engine templates and custom filters.

Last month I was messing with google app engine. That's right GAE (google app engine) and python. 

Still hardly can find any productivity gains from switching to python or as other will say "dynamic programming language" from java, but I still hope to see a "light at the end of the tunnel". With hope to experience some new, more dynamic and less restrictive thinking and software development, I'm still keep going by this new path.

Here is a new tiny challenge I got and how I'm going to deal with it. GAE uses template engine for view generation, what is greatly welcomed. Template engine and most of other code are borrowed from django, which is a high-level Python web framework. So this is a reason why I going to refer to django. Django Template engine has a nice feature which is called a template filter. Template filters are used to modify variables for display, this means that before variable value will be written to the output it can be formatted or modified in any way as it's needed.

For beginning I used this blog post as my starting point. It has a list of steps what is needed to get started. In order to get solution I like to dig a little dipper and understand what is going on. Here is a few questions what I wold like to know before I will do what I need.

# What are the differences between GAE and django template engine?
# How can I add my custom filters?
# What is a default set of filters in GAE?

Ok here are some my questions and answers to them.

What are the differences between GAE and django template engine?

First difference is a minor one. Location of Template class in django and GAE differs. Django uses django.template.Template class and GAE has it's own appengine.ext.template.Template class and it is just a simple wrapper class for the django Template class. This wrapper class handles all differences between django and app engine and makes programmers work easier.

How can I add my custom filters?

Google app engine and django uses different steps for custom filter registration. I had to create a new package, in my case I created a new package "common" and templatefilters.py file in it with content listed bellow. In case you want to look how can it be done in django here is a source of this file.

import urllib
from google.appengine.ext import webapp

def truncate(value,maxsize,stopper = '...'):
""" truncates a string to a given maximum
size and appends the stopper if needed """
stoplen = len(stopper)
if len(value) > maxsize and maxsize > stoplen:
return value[:(maxsize-stoplen)] + stopper
else:
return value[:maxsize]

def rb_quote_plus(value):
""" Replace special characters in string using
the %xx escape. Letters, digits, and the
characters '_.-' are never quoted. Also
replaces spaces by plus signs, as required
for quoting HTML form values. """

return urllib.quote_plus(value)

# get registry, we need it to register our filter later.
register = webapp.template.create_template_register()
register.filter(truncate)
register.filter(rb_quote_plus)


One last step is needed in your main.py file or any other fail with main method at the top level you have to add code listed bellow. This will instruct app engine to register new teplate filters from common.templatefilters.py file.

webapp.template.register_template_library('common.templatefilters')


Here are default list of filters in django template. In case if it's not enough and you need some more information what can be done with filters, information is provided in django documentation custom template tags and filters. This reference is for django version 1.0 and I guess something will not work because GAE uses 0.96 version as basis.

Conclusions
I was not able to find information in form I liked. This blog post is consequence of that. In general I liked how easy it's to extend and customize templates. I'm impressed how easy to get additional power in view layer without mixing business and UI logic in one place. Some features what I haven't tried yet, and I think they could not work in GAE, such as decorator @register.filter makes me excited. Once I found what and how filters can be added, I should say, this is an easiest way to add custom features to templates.

Sunday, July 20, 2008

Hibernate or JPA

Back to java. Busy time in future?

I have some works to be finished, new project what just starting for my new client and waiting for new huge projects, from few new customers. It looks I will be very, very busy.

Better solution in less time

Everyone is using hibernate for ORM, but not me. Yes I was ignoring it, since I have tried it first time 4 or even 5 years back. I always thought, why do I have to add another technology layer, introduce another dependency and make my applications dependent on technology which could not be easily removed or replaced. All my software is layered in the UI, BO and DAO layers and I never had a problem to write DAO layer classes for data manipulation with JDBC. I always felt I have more power, flexibility and options by doing it on my own.

It's still possible to write another implementation of DAO class and to have an option to replace JDBC implementation class with hibernate, but it's not as easy to do as easy to say. If you have big number of entities and relations between them, Hibernate does a lot of nice work by handling relations and lazy loading, this is a really nice feature, I like it and it's handled automatically. Problem is, once you accept features from Hibernate and start to use them, it's no way ho I can do that with JDBC. How can I make a lazy loading of linked list, I became dependent on Hibernate? The irony is, if taking hibernate road I have to change my way of thinking and application design. By doing that I'm loosing a way back, I will never be back.

The same dependency upon technology I see with spring framework. They call it Dependency Injection pattern and say that you components are loosely coupled, that's fine. But you have to be very careful, it's just amazing how fast you can be dependent on spring. The technology that is sold as a way to make you components independent makes yours application design dependent on spring. What is a difference, to have independent class and dependent application. Fine, I know there are some benefits but they can write in red "By making your classes and components independent on each other you making your application dependent on spring. And you are in danger to make yourself dependent on Spring. Please don't overuse it".

JPA may be a better choice

Lately since I moved my development to Glassfish and EJB3 I'm started to use JPA yes the same thing, but with important differences. The choice was obvious either JPA or CMB. CMB is too old, inefficient and technology dead end. JPA still new but annotation base with different implementations and it's specification based, jsr.

Why now?

I'm going to sacrifice somthing in order to get a better productivity, time spend on project development. I'm not happy how much time I spend on DAO layer. Yes the main reason is time, no less, no more just time. I hope I will get some advantages and will be able to improve time.

I still have to make some decisions where to go JPA or Hibernate. It looks that JPA could be better for me, but still have to decide.

Saturday, July 19, 2008

Busy time, a log changes

Busy time, a lot of changes

I've been quite busy last month. Had to spend some time with my family, changed my job and I'm again a freelancer. And I'm on the way to even bigger changes in my personal and professional life. I'm looking to move to new country, I'm very open with new opportunity and looking to move to any EU country or to UAE, Dubai. Where I would like to base my personal IT business. Hope some offers and decisions will come and I will be able to accept them.

Back to java. Busy time in future?

I have some works to be finished, new project what just starting for my new client and waiting for new huge projects, from few new customers. It looks I will be very, very busy.

Sunday, May 4, 2008

Time to share even more ideas

Intro

The biggest source of nice ideas on swing UI I got from JGoodies. The Author of Jgoodies libraries, Karsten Lentzsch, I could proudly call my inspirational guru. First time I visited jgoodies.com site was 5 years back and used it in my first Java Applet. Later I reused all that code in desktop application. I liked its look, layout manager, form builders and simplicity, I also saw clear deep understanding of UI design and usability issues.

My personal experience
Now I'm using all his libraries: jgoodies-forms, jgoodies-looks, jgoodies-validation and jgoodies-binding. He was one of the first people who showed and said how swing application can and should look and behave, that was before anyone started to talk about these problems in loud.

Six years ago, once again I went on freelance. Major focus for my service was and still is on Java Web applications for business. As always happens from time to time I had to do some swing programming. I and my company (now I'm running small software development business) did 4 applications on swing, all of them was based on jgoodies. All these applications are functioning perfectly, customers are happy, and have best opinion about desktop software developed on swing. All of them like application's look, usability, easy of use and performance. Looks like great success story.

Now Karsten Lentzsch, author of JGoodies is on JCP-295 Beans Binding and JCP-296 Swing Application Framework expert group list. I hope that will come to great specifications and products.

Some points

IMHO good code is a code which is easy to read, understand and follows natural way of thinking. It has be easy to understand by the person who will come after me and will have to extend, modify or support it. Another important point that UI should be consistent and elegant.

As wiki or blog editor does not care about HTML, CSS, HTTP or all other technical stuff you don't have to care about SWING components. In case you know what you are doing you can mess with swing, but you should do that only where it's needed, not everywhere. So we need some abstraction layer, layer which seats between end user and swing components.

How do we use swing components? Simple answer is inefficient! Every time I have to add a new record such as Customer, Product or whatever, we are dealing with JTextField, JDialog, JButtom, JAction, different action listeners. But this way is too deep, takes too much time and is hugely inefficient, everything I want is a common add, edit or delete form, where I have a list of required and optional fields and Ok, Cancel buttons. It would be nice to have some help or hints and validation of entered data.

And at last there is some Domain Specific Languages, this is where I'm leading. I'm not going to go through Domain language definition, everything is on wikipedia domain specific languages. This Domain Specific Language, or UI abstraction layer should hide unneeded details and hide complexity, but without introducing new limitations. I mean, if I need a deeper control and still want to deal with swing controls, I still can do that and don't want to have another Domain language which I have different syntax to learn and maintain.

Just to tease you here is a window's screenshot from one of my application. All these windows are consistent across all application, they follow common UI guidelines. There is one small but, I have to remove these classes from my old applications, do some little cleaning, update them a little bit and make them available as open source package.



In order to collect all requirements and update I need some opinion from outside.

What we can expect to get at the end:
  • less lines of code - better productivity, less bugs
  • source code have to be easy to read, understand and maintain
  • UI - must be consistent and with no surprises
  • UI - should be nice and pleasant to work with
  • software developer have to be able to change UI as he likes, UI does not have to be forced by framework
  • It does not have to meet everyones expectation. Bloated library is the worst thing can be.
As result of that you will gain pleased and happy developers and customers. All new requests from customer will be easy to achieve and customer will almost never hear answer no or it's under budget.