Thursday, December 6, 2007

@ofbizUrl tag = your ticket to hell

You are doing development locally and everything looks good, so you plop your code on the dev server and everything goes to shit. Request parameters are all empty when they should be full. You double check all the svn diffs and you didn't miss any code.

Could you be using a mixture of http and https urls? Could be, if you are using the @ofbizUrl tag to build your URLs. Try doing your URLs without this tag. Things might magically start working for you.

Friday, November 2, 2007

Using JDBC to take advantage of Database technology

abandoned the entity engine and Jumped into JDBC to do this.

  • Joins two views in a left outer join, meaning that it gets values from the first view even if there is no matching value in the second view.
  • Uses the COALESCE function of postgres to fill in default values (zero in this case) when values in the second view (the right hand view) are missing



SELECT query1.DIVID,TotalSub,COALESCE(TotalPassed,0) AS TotalPassed,COALESCE(100*(TotalPassed/TotalSub),0) as PERCENT
FROM
(SELECT DIVID, COUNT(t1.PARTY_ID) AS TotalSub
FROM (public.USERS t1 INNER JOIN public.TABLE2 sub ON t1.PARTY_ID = sub.PARTY_ID)
INNER JOIN public.TABLE3 t3 ON sub.PRODUCT_ID = t3.T_ID
WHERE (sub.from_date + (days_to_complete||' days')::INTERVAL > '2007-08-01' AND sub.product_id = 'testCourseOne')
GROUP BY t1.div_num) AS query1
LEFT OUTER JOIN
(SELECT DIVID, COUNT(t1.PARTY_ID) AS TotalPassed
FROM (public.USERS t1 INNER JOIN public.TABLE2 sub ON t1.PARTY_ID = sub.PARTY_ID)
INNER JOIN public.TABLE3 t3 ON sub.PRODUCT_ID = t3.T_ID
WHERE (sub.from_date + (days_to_complete||' days')::INTERVAL > '2007-08-01'
AND sub.product_id = 'testCourseOne' AND sub.completed_date IS NOT NULL)
GROUP BY t1.div_num) AS query2
ON query1.DIVID = query2.DIVID

Thursday, August 23, 2007

adjust allowed login attempts

How do I adjust the number of allowed login attempts in ofbiz?

Edit the value for "max.failed.logins" in the file security.properties

If a user is already locked out, you can unlock them in webtools-->find-->[enter user login] --> Lookup Party--> find disabled account -->edit

How do I turn this feature off altogether?

Setting max.failed.logins to zero should disable this feature.

Wednesday, August 22, 2007

Mixing AND and OR conditions in entityConditionList

How does one make a query using findByCondition that has both OR and AND clauses?

hint: do a search on .OR in your ofbiz code. This will lead you to
the file lookupBulkAddProducts.bsh

with the following code:


conditionList.add(new EntityExpr("productTypeId", EntityOperator.NOT_EQUAL, "AGGREGATED"));
than isVirtual != "Y".
// we consider those products to be non-virtual and hence addable to the order in bulk
orConditionList.add(new EntityExpr("isVirtual", EntityOperator.NOT_EQUAL, "Y"));
orConditionList.add(new EntityExpr("isVirtual", EntityOperator.EQUALS, "N"));
orConditionList.add(new EntityExpr("isVirtual", EntityOperator.EQUALS, null));

orConditions = new EntityConditionList(orConditionList, EntityOperator.OR);
conditions = new EntityConditionList(conditionList, EntityOperator.AND);

mainConditionList.add(orConditions);
mainConditionList.add(conditions);
mainConditions = new EntityConditionList(mainConditionList, EntityOperator.AND);

productList = delegator.findByCondition("Product", mainConditions, UtilMisc.toList("productId", "brandName", "internalName"), UtilMisc.toList("productId"));



pretty self-explanatory. Group the OR statements in their own entityConditionList, the AND statements in their own, and combine the two in a master EntityConditionList (using the EntityOperator.AND)
so, the above would result in something like WHERE (a OR b OR c) AND d

Saturday, August 4, 2007

how to iterate maps in FTL

instead of <#list> ... </#list>

you can try
<#assign mList=courseMap.keySet()/>

<#list mList as key>
...
</#list>

and to address members of the map:

<#list mList as key>

${courseMap[key]}

</#list>

FTL date formats

Here is a page of information on how to format dates in FTL:

Thursday, August 2, 2007

Postgresql Timestamp + interval

Jumping into SQL with EntityWhereString, I was trying to do some date arithmetic. I had a timestamp and an integer number of days. I wanted to add the number of days to the timestamp and work with the resulting timestamp.

the Postgresql syntax for this is
SELECT timestamp '2001-09-28 01:00' + interval '23 hours' from myReports

so I got this far:

select tx_stamp + interval '23 days' from myReports

and that worked but when I tried using my integer column "days_to_complete" for the interval, the syntax wasn't clear.

It turns out I needed to concatenate cast my days_to_complete into a string:

days_to_complete||' days'
and then cast the resulting string into an INTERVAL:

select tx_stamp + (days_to_complete||' days')::INTERVAL from myReports
and that worked.