quarta-feira, 22 de outubro de 2014

webMethods Utilities Boolean Service to check a date is within range

Bellow a java service to check if a date is within a certain range.


package common.date;
import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import java.util.*;
import java.text.*;
public final class booleanDateInRange_SVC
{
/**
* The isWithinRange service is implemented to be used with webmethods Integration Server
* and it should be java version agnostic.
* The service receives six inputs if date is on the default format yyyy-MM-dd
* only the startDateTime, testDateTime, endDateTime are required.
*
* @author Luis Mesquita
* @version 1.0
* @since 22-Oct-2014
*
* The primary method for the Java service
*
* @param pipeline
* The IData pipeline
* @throws ServiceException
*/
public static final void booleanDateInRange(IData pipeline)
throws ServiceException {
// pipeline input
IDataCursor pipelineCursor = pipeline.getCursor();
pipelineCursor.first( "startDateTime" );
String startDateTime = (String) pipelineCursor.getValue();
pipelineCursor.first( "testDateTime" );
String testDateTime = (String) pipelineCursor.getValue();
pipelineCursor.first( "endDateTime" );
String endDateTime = (String) pipelineCursor.getValue();
String startDateFormat;
if (pipelineCursor.first("startDateFormat"))
{
startDateFormat = (String) pipelineCursor.getValue();
}
else
{
startDateFormat = "yyyy-MM-dd";
}
String testDateFormat;
if (pipelineCursor.first("endDateFormat"))
{
testDateFormat = (String) pipelineCursor.getValue();
}
else
{
testDateFormat = "yyyy-MM-dd";
}
String endDateFormat;
if (pipelineCursor.first("endDateFormat"))
{
endDateFormat = (String) pipelineCursor.getValue();
}
else
{
endDateFormat = "yyyy-MM-dd";
}
// local var for output
Boolean isInRange = false;
// All data retrieved from the pipeline at this point
pipelineCursor.destroy();
try {
SimpleDateFormat sdf = new SimpleDateFormat(startDateFormat);
Date sdt = sdf.parse(startDateTime);
SimpleDateFormat tdf = new SimpleDateFormat(testDateFormat);
Date tdt = tdf.parse(testDateTime);
SimpleDateFormat edf = new SimpleDateFormat(endDateFormat);
Date edt = edf.parse(endDateTime);
// calculate is in range
if(!(tdt.before(sdt) || tdt.after(edt)))
isInRange=true;
// pipeline output
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "isInRange", isInRange );
pipelineCursor_1.destroy();
} catch (ParseException e) {
throw new ServiceException("Error parsing the date time: " + e);
}
}
// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
private static boolean isNullOrBlank(String s) {
return (s==null || s.trim().equals(""));
}
// --- <<IS-END-SHARED-SOURCE-AREA>> ---
/**
}
view raw gistfile1.java hosted with ❤ by GitHub

Sem comentários:

Enviar um comentário