• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Should I use Filters for this?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Hope I get some responses to this question.

Our system uses Struts 1.2. It deals with insurance applications. Let me give you a brief description of an issue we are facing.

We have a requirement to only allow one user to be able to modify an insurance application at a given time - hence if a user A opens application 123, then user B cannot modify it. So user A locks the application for a given time. If this user does not perform any actions (i.e. leaves the application idle) for more than 20 minutes, then we must release the lock (times out) and allow other users to open and modify the application.

We have created a DB table to hold details of the locked applications and their associated users. Every time a user performs an action on these applications, we update a timestamp in this table so that the lock does not time out. So basically any action on the application will require a database call to check the validity (and if necessary) update the lock record.

So, I was wondering - could I use filters to basically intercept a set of actions - so that we look-up/update this database table and then delegate control to the associated controller/action classes?

Or am I better off having a base action class that basically does the above work and then have all the other relevant action classes extend this base class?

If any of the above is not clear, please let me know. I'm also open to any other suggestions/advice. Thanks very much!

Andrew
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Struts Action classes are part of the Controller, in MVC terms. The requirements that you describe are part of the application (in MVC terms, the Model).

The requirement of checking to see if something can be done or not should go in the application (Model), especially if it deals with checking a database table. Business logic should not be coded in the Struts Action classes or any of the filters associated with the HttpRequest.

Check out the Business Delegate design pattern for more information.

Create a "lock utility" class that will monitor the users behavior and check the database table. A Business Delegate can use this class to regulate the application.
[ November 09, 2008: Message edited by: James Clark ]
 
Andrew McMillan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James - thanks for the reply.

Yes, I am aware that we shouldn't be making database calls from the controller/filter. I will simply be looking up the relevant locking service/lock utility from within my action class - it is the service that will then check the table and make any updates, etc.

Since I will be monitoring a number of user actions, I was wondering what the best strategy would be to check what action/link they clicked on so as to then call my lock service. i.e. if filters would be appropriate or simply creating a base class whereby any of its children will then have to check the database (via the service).

Hope that makes sense.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the best bet would be to create a Base Action class and then have all the relevant Action classes of the the application extend this Base Action class.

You could then add a private method in the Base Action class which will connect to the service. And you could then call this method from whichever Action you want

The Base Action will extend the Struts Action class.
reply
    Bookmark Topic Watch Topic
  • New Topic