Posts

Showing posts from 2015

utility to extract date from text with java

Image
A date pattern recognition algorithm to not only identify date pattern but also fetches probable date in Java date format. This algorithm is very fast and lightweight. The processing time is linear and all dates are identified in a single pass. Algorithm resolves date using tree traverse mechanism. Tree data structures are custom created to build supported date, time and month patterns. Following Trees are used (Note: ^ sign denotes complete pattern) DATE PATTERN TREE Month Pattern Tree (Jan and January both are valid, identified using ^ sign) Time pattern (Identified as suffix to Date, $ sign indicates SPACE character) Tree structures are used in the following algorithm.  Date Part Identification algorithm flowchart Time part identification algorithm flowchart These flow charts are self-explanatory in most part. --> sign is used to denote next match in respective tree structures. The algorithm also acknowledges multipl

java convert date from one timezone to another

Use Case: Suppose you receive time string from one machine in  PST zone as "04-30-2015 07:00:00" , the machine on which you receive this string data is in CST and you want to convert the time in EST . If we use java.util.Date it will change the string into Date with reference to local machine timezone which is CST. i.e. it will look something like " 04-30-2015 07:00:00 CST ", so the conversion will something like below. What will Happen Time is EST  will be calculated as " 04-30-2015 09:00:00 EST " What is the perceived output Time is EST  should be  " 04-30-2015 10:00:00 EST " Why It happens java.util.Date does not take in reference of the timezone, for it time is absolute and Timezone is only interpreted as display property, and offset is applied on absolute time to print the timezone accordingly. Solution Use Joda time. If you are using maven include the following dependency.  <dependency>             <groupId>

org.apache.wink.server.internal.RequestProcessor logException ObjectCreationException (500 - Internal Server Error) occurred during the handlers chain invocation

As the name suggests this error is created while apache wink tries to create an object and it fails. The error is not clear but if you log the debug statements present in wink libraries, the thing will become crystal clear to you. Here what happens when you start logging wink activities. This clearly shows that you are missing class "org.apache.poi.ss.usermodel.Workbook". This is contained in Apache poi library and you are missing this jar file. Apache wink depends on few more libraries, so if you see this error, enable logging on wink and find out the missing jar, org.apache.wink.server.internal.RequestProcessor logException ObjectCreationException (500 - Internal Server Error) occurred during the handlers chain invocation                                  org.apache.wink.common.internal.lifecycle.ObjectCreationException: java.lang.NoClassDefFoundError: org.apache.poi.ss.usermodel.Workbook     at org.apache.wink.common.internal.lifecycle.CreationUtils.createObject(Creati

hbm2ddl -- the problems and remedy

For a project I had to create ddl from the hibernate mapping files (hbm.xml). I started with following configuration. Remember you need not have database details of hibernate.cfg.xml file hibernate.cfg.xml <hibernate-configuration>   <session-factory>     <mapping resource="com/gvt/sch/hibernate/ApplicationEnvironment.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/UserRole.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/Application.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/TaskType.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/WorkStatus.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/Users.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/Roles.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/Contacts.hbm.xml"/>     <mapping resource="com/gvt/sch/hibernate/EnvType.hbm.xml&qu