Wednesday, August 27, 2008

Don't forget about StringUtil!

StringUtil is yet another great useful utility class that does some nice work for you if used correctly.

Here some examples:

List myList
= StringUtil.detokenizeStringAsList("ABC, DEF, AVC, EWR, ASD" , ",", true);

This gives you a nice list of all the items in the given string and does a trim() on them.


Here the API info:

detokenizeStringAsList
public static java.util.List detokenizeStringAsList(java.lang.String input,
java.lang.String separator,
boolean trimsItems)

Given an input String and a separator String, this method returns a String List of tokens based on tokenizing with the String separator.

Parameters:input - String
separator - String
trimsItems - whether each item will be trimmed
Returns:
String array of tokens


Yes there is more then that, check out the API docs for more details: com.workbrain.util.StringUtil

Some versions ago the changed the name of the class
   StringHelper -> StringUtil

Friday, August 22, 2008

Workbrain / App Server versions

Here is something that I always wanted to know. An easy way to find out what version of Workbrain I'm using/working with and what server is it running on. It's as simple as one mouse click to find out. Go to the login screen of your Workbrain app, and click the "About" link in the lower right hand corner of the login box. See images below:






Wednesday, August 20, 2008

How to get time code id given a time code name

You can use CodeMapper to lookup a time code ID.

First create an instance of CodeMapper, it takes a DBConnection as a parameter.

CodeMapper mapper = CodeMapper.createCodeMapper(conn);

If you happen to be writing a Rule, you can simply get CodeMapper from the WBData parameter.

CodeMapper mapper = wbData.getCodeMapper();

Next, lookup the TimeCodeData using the CodeMapper instance and the time code name as a parameter.

TimeCodeData timeCode = mapper getTimeCodeByName(timeCodeName);

int id = timeCode .getTcodeId();

RuleHelper is your Friend

Here a few tips when working on/with Rules:

Use the RuleHelper whenever you can, it saves you a lot of work!

eg.:

public static boolean isCodeInList(java.lang.String sList, java.lang.String sCode)

Method checks if a token belongs to a comma-separated list. If the list is empty it has the special meaning of "contains everything".

Parameters:
sList - the comma-separated list
sCode - the token
Returns:
true / false

sample code:
String paramTCodes = "WRK, TRN, MEAL"; // I would get it from a param field or so..

if (RuleHelper.isCodeInList(paramTCodes, WorkDetailData.getWrkdTcodeName())) {
// do your thing...
}

**********

If the rule requires parameters you need as for the time codes, remember to return the parameter list insted of new ArrayList(); Doh! Yes I did that this morning... ops..

public List getParameterInfo(DBConnection dBConnection) {
List parametersList = new ArrayList();

RuleParameterInfo rpiEligibleTimeCodes = new RuleParameterInfo(WORK_TIME_CODES, RuleParameterInfo.STRING_TYPE, false);

parametersList.add(rpiEligibleTimeCodes);
RuleParameterInfo rpiEligibleHourTypes = new RuleParameterInfo(HOLIDAY_HOUR_TIME_CODE, RuleParameterInfo.STRING_TYPE, false);

parametersList.add(rpiEligibleHourTypes);

return new ArrayList(); // <- OPS!!! should of returned the parametersList
}

Tuesday, August 19, 2008

Welcome to Workbrain Coders Blog!

Well it's finally here... I was looking for one myself for quite some time now to help me with my job, however I was unable to find anything related to Workbrain development at all. So here you go. Let me try to run one and hope that I/we can help others that are in the same boat as me/us. Please feel free to email me any ideas or code examples, configuration solutions or anything that we can talk about on here that's related to Workbrain.

Thanks!