Nullpointer problem

1
0
-1

Hi everyone!

I'm having an issue with a code. And I can't get where is the problem. The problem is that at the execution it throws me a 'Nullpointer' error. And nothing else. The code is in the following text bloc:

import groovy.sql.Sql

def sqlw = BonitaSql.newInstance("jdbc:sqlserver://172.16.0.36;databasename=base", "user", "pass", new com.microsoft.sqlserver.jdbc.SQLServerDriver())
def dt_inicio = ""
def dt_fim = ""

sqlw.eachRow 'select DATEADD(DAY, DATEDIFF(DAY, 0, (GETDATE()-2)),0) as tempo', {dt_inicio = it.tempo.toString()}
sqlw.eachRow "select DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()-2), '23:59:59') as tempoz", {dt_fim = it.tempoz.toString()}
sqlw.close()

def sql = BonitaSql.newInstance("jdbc:sqlserver://172.16.0.36;databasename=base", "user", "pass", new com.microsoft.sqlserver.jdbc.SQLServerDriver())
def queryc = "create table ##tempoh(empresa varchar(10), cliente varchar(10), produto varchar(20), quantidade decimal(14,4),valor int, movimento char(2), documento varchar(20), unidade char(2), movimento_b char(1), cc varchar(10), sistema datetime, data_movimento datetime, ano_movimento int, lote int, ano_lote char(4), usuario char(10), lote_prod char(10), data_prod nvarchar(10), ordem int, ano_op int, item_movim varchar(10), dt_gerado datetime, dt_atuest datetime, dt_atucus datetime) insert into ##tempoh EXEC P_PRODUCAO_SAIDA '${dt_inicio}', '${dt_fim}' "
sql.execute(queryc)
def queryB = "create table ##totaisb(linha bigint, produto varchar(20), ano_movimento int, cc varchar(10), data_prod nvarchar(10), quantidade decimal(14,4)) insert into ##totaisb Select row_number() over(order by produto) as linha, produto, cc, ano_movimento, max(data_prod) as data_producao , sum(quantidade) as total from ##tempoh where movimento_b = 'E' group by produto, ano_movimento, cc order by produto"
sql.execute(queryB)

for (int i=1; i<= 100; i++){
def aux = i
def produto = ""
def ano_movimento = 0
def data_prod = ""
def quantidade = 0
def nr_lanmov = ""
def vl_estatual = 0
def cci = ""
def cc = 0

sql.eachRow "select produto from ##totaisb where linha= '${aux}' ", {produto += it.produto}
sql.eachRow "select ano_movimento from ##totaisb where linha= '${aux}' ", {ano_movimento += it.ano_movimento}
sql.eachRow "select data_prod from ##totaisb where linha= '${aux}' ", {data_prod += it.data_prod}
sql.eachRow "select quantidade from ##totaisb where linha= '${aux}' ", {quantidade += it.quantidade}
sql.eachRow "select cc as cci from ##totaisb where linha= '${aux}' ", {cci += it.cci}
cc = cci.toInteger()

Sql sqlb = BonitaSql.newInstance("jdbc:oracle:thin:@192.168.0.18:1521:base", "user", "pass",new oracle.jdbc.OracleDriver())
sqlb.eachRow "select max(nr_lanmov) + 1 as nr_lanmov from base.cemovime where ch_produt = '${produto}' ", {nr_lanmov +=it.nr_lanmov}
sqlb.eachRow "select max(vl_estatual) as vl_estatual from base.cemovime where ch_produt = '${produto}'", {vl_estatual += it.vl_estatual}
vl_estatual = vl_estatual+quantidade
def query = "INSERT INTO base.CEMOVIME VALUES(100,null,'${produto}',${quantidade},0,21,000000,72,null,'E',99999999,9999,'9',2008,sysdate,sysdate-1,${vl_estatual},0,null,null,null,null,null,'${ano_movimento}',null,null,null,null,${nr_lanmov},null,1,'L',null,sysdate-1,null,null,null,1,null,null,null,null,null,null,null,null,null,null,sysdate,sysdate,sysdate)"
sqlb.execute(query)
sqlb.close()

}

I'm accepting any tip.

Thanks in advance.

2 answers

1
+1
-1

Hi Rafael,

the groovy interpreter, as called by the BonitaSoft engine is not the ideal medium for running complex tasks - i usually recommend that long or complex groovy be written in an external console, which has better debugging capability.

That is not always easy/possible, however, when we have bonita process variables or built in values / variables, or sometimes libraries that are a part of the script. When that happens, we can resort to the ancient debugging methods of writing to the log file, e.g.

import java.util.logging.Logger;

Logger log = Logger.getLogger(this.getClass().toString());

log.severe(activityInstance.getUUID().toString() + "DEBUG myVarName value: " + myVarName);

or including error handling via try catch loops in the code. If you add some debug lines of code to your script, you will be able to view those log messages in the bonita.log of the application server, and that will help you locate which groovy object is not being instantiated properly.

-Declan

1
0
-1

Hi Declan!

Thanks for your answer.

I kinda realized that groovy interpreter is ~limitated~ at some points. So I just changed my code and some operations. However, I'll try to add some debug code to see what is wrong and what can be done to improve that.

Thanks a lot for your answer.

Notifications