0% found this document useful (0 votes)
183 views9 pages

Z Ws Object Send

This Python script contains functions for sending work order status updates and data to an external system via web services. The functions populate message header and detail objects, set field values, and invoke message sending services.

Uploaded by

Bernardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views9 pages

Z Ws Object Send

This Python script contains functions for sending work order status updates and data to an external system via web services. The functions populate message header and detail objects, set field values, and invoke message sending services.

Uploaded by

Bernardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

#ZWSOBJECTSEND.

SAVE
from com.ibm.tivoli.maximo.interaction.process import InteractionProcesser
def importScript():
script = None
from psdi.server import MXServer
mxserver = MXServer.getMXServer()
sysuser = mxserver.getSystemUserInfo()
impSet = mxserver.getMboSet("AUTOSCRIPT",sysuser)
impSet.setWhere("AUTOSCRIPT='IMPORTS'")
imp = impSet.moveFirst()
if imp != None:
script = imp.getString("SOURCE")
impSet.close()
return script
exec(importScript())
def zwoesristatus(wonum, status, ldstatus):
esristatusSet = getMboSet("ZWOESRISTATUS")
esristatusSet.setWhere(toSQL("WONUM='?'",wonum))
esristatus = esristatusSet.moveFirst()
if esristatus == None:
esristatus = esristatusSet.add()
esristatus.setValue("WONUM",wonum,2)
esristatus.setValue("STATUS", status, 2)
esristatus.setValue("STATUS_LONGDESCRIPTION", ldstatus, 2)
saveClose(esristatusSet)
def sendWOStatus(log,wo):
ztype = wo.getMboSet("ZTYPES").moveFirst()
ztypewo = wo.getMboSet("ZTYPESWO").moveFirst()
from java.text import SimpleDateFormat
xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")

wsSet = wo.getMboSet('ZWSWO1')
header = wsSet.add()
header.setValue("TRACKINGID",str(Date().getTime()),11)
header.setValue("CREATIONTIME", xmlDate.format(Date()),11)
header.setValue("LOGIN", wo.getString("CHANGEBY"), 11)
history = header.getMboSet("ZWSWO3").add()
#TIBCO
history.setValue("OWNER", wo.getString("CHANGEBY"), 11)
history.setValue("DOMAIN", 'APP_MAXIMO', 11)
history.setValue("TYPE", 'Interfaces', 11)
history.setValue("SERVICENAME",'ZWOESRISTATUS.STATUS.ACTION', 11)
history.setValue("ACTION", 'ACTION', 11)
history.setValue("VERSION", '1.0', 11)
history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11)
history.setValue("COMPONENT", 'ZWOTRACK', 11)
history.setValue("TRANSPORT", '', 11)
history.setValue("SUBJECT", '', 11)
history.setValue("STEP", '1', 11)
history.setValue("APPLICATION", 'MAXIMO', 11)
history.setValue("TRACKINGID", header.getString("TRACKINGID"), 11)
#WORKORDER
ot = header.getMboSet("ZWSWO16").add()
if not wo.isNull("ZCODEMPRESA"):

ot.setValue("EMPRESA_CODEMPRESA", wo.getString("ZCODEMPRESA"), 11)


ot.setValue("ZWSWO16_CODORDEMTRABALHO", wo.getString("WONUM"), 11)
if not wo.isNull("ZCODIGOORDEM"):
ot.setValue("ZWSWO16_CODORDEMTRABALHO", wo.getString("ZCODIGOORDEM"), 11
)
ot.setValue("ZWSWO16_DESCRICAO", wo.getString("DESCRIPTION"), 11)
ot.setValue("ZWSWO16_DATACRIACAO", xmlDate.format(wo.getDate("REPORTDATE")),
11)
ot.setValue("ZWSWO16_CODSTATUS", wo.getString("STATUS"), 11)
ot.setValue("ZWSWO16_TIPOOBJETO", wo.getString("ZTYPE"), 11)
ot.setValue("ZWSWO16_TIPOORDEMTRABALHO", wo.getString("WORKTYPE"), 11)
ot.setValue("ZWSWO16_FLAGMULTIPLO", "0", 11)
if ztype != None and ztype.getBoolean("ESRIMULTISELECT"):
ot.setValue("ZWSWO16_FLAGMULTIPLO", "1", 11)
ot.setValue("ZWSWO16_FLAGEDICAO", "0", 11)
if ztypewo != None and ztypewo.getBoolean("ESRIEDICAO"):
ot.setValue("ZWSWO16_FLAGEDICAO", "1", 11)
if wo.getString("STATUS") == 'APPR':
ot.setValue("ZWSWO16_CODATIVIDADE", 'JB007',11)
ot.setValue("ZWSWO16_CODACAO", 'AV002', 11)
if wo.getString("STATUS") == 'EXEC':
ot.setValue("ZWSWO16_CODATIVIDADE", 'JB008',11)
ot.setValue("ZWSWO16_CODACAO", 'AV001', 11)
ot.setValue("ZWSWO16_MEDIDAINICIO", str(wo.getDouble("LINEARRELATED.STARTMEA
SURE")), 11)
ot.setValue("ZWSWO16_MEDIDAFIM", str(wo.getDouble("LINEARRELATED.ENDMEASURE"
)), 11)
ot.setValue("ZWSWO16_IDCARTA", wo.getString("LOCATION.ZCARTA.ZCODSIGAS"), 11
)
ot.setValue("ZWSWO16_DATAACAO", xmlDate.format(wo.getDate("STATUSDATE")), 11
)
ot.setValue("ZWSWO16_DIAMETRORAMAL", wo.getString("ZDIAMETRO"), 11)
ot.setValue("ZWSWO16_MATERIALRAMAL", wo.getString("ZMATERIAL"), 11)
ot.setValue("ZWSWO16_COMPRIMENTORAMAL", str(wo.getInt("ZCOMPRIMENTO")), 11)
ot.setValue("ZWSWO16_COMENTARIOS", wo.getString("ZCOMENTARIOS"), 11)
#ver o comentrio se vale a pena enviar
#procura os ativos na MULTIASSETLOCCI
ativos = []
for mulci in MboSetIterator(wo.getMboSet("MULTIASSETLOCCI")):
if not mulci.isNull("ZCODSIGAS"):
ativos.append(mulci.getString("ZCODSIGAS"))
if len(ativos) == 0 and not wo.isNull("ZCODSIGAS"):
ativos.append(wo.getString("ZCODSIGAS"))
codigoAtivoSet = ot.getMboSet("ZWSWO17")
for ativosItr in ativos:
if ativosItr != '':
codigoAtivo = codigoAtivoSet.add()
codigoAtivo.setValue("ZWSWO17_CODATIVO", ativosItr, 11)
interaction = InteractionProcesser('ZWSWO')
close(wsSet)
log.start()
interaction.invokeservice(wo)
log.stop()
def sendWOFat(log,wo):
from java.text import SimpleDateFormat

xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")

wsSet = wo.getMboSet('ZWSPC1')
header = wsSet.add()
header.setValue("TRACKINGID",str(Date().getTime()),11)
header.setValue("CREATIONTIME", xmlDate.format(Date()),11)
header.setValue("LOGIN", wo.getString("CHANGEBY"), 11)
#TIBCO
history = header.getMboSet("ZWSPC3").add()
history.setValue("OWNER", wo.getString("CHANGEBY"), 11)
history.setValue("DOMAIN", 'APP_MAXIMO', 11)
history.setValue("TYPE", 'Interfaces', 11)
history.setValue("SERVICENAME",'ZWSPC', 11)
history.setValue("ACTION", 'ACTION', 11)
history.setValue("VERSION", '1.0', 11)
history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11)
history.setValue("COMPONENT", 'ZWOTRACK', 11)
history.setValue("TRANSPORT", '', 11)
history.setValue("SUBJECT", '', 11)
history.setValue("STEP", '1', 11)
history.setValue("APPLICATION", 'MAXIMO', 11)
history.setValue("TRACKINGID", header.getString("TRACKINGID"), 11)

#WORKORDER
ot = header.getMboSet("ZWSPC16").add()
ot.setValue("EMPRESA_CODEMPRESA", wo.getString("ZCODEMPRESA"), 11)
ot.setValue("ZWSPC16_CODATIVIDADE", 'JB002', 11) #recepcao do resultado da f
atibilidade
ot.setValue("ZWSPC16_CODPROCESSOCONS7441", wo.getString("ZCODPROCESSOCONSTRU
CAOPAI"), 11)
ot.setValue("ZWSPC16_CODAPRECIACAO", wo.getString("ZSRFATIBILIDADE.ZRESULTAD
O"), 11)
ot.setValue("ZWSPC16_COMENTARIOS", None, 11)
interaction = InteractionProcesser('ZWSPC')
close(wsSet)
interaction.invokeservice(wo)
def sendAtivoReply(log,zp_eai_header):
from java.text import SimpleDateFormat
xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")

ci = getMbo("CI","1=1")
ciSet = ci.getMboSet('ZWSATIVOREPLAY1')
header = ciSet.add()
header.setValue("TRACKINGID",str(Date().getTime()),11)
header.setValue("CREATIONTIME", xmlDate.format(Date()),11)
header.setValue("LOGIN", wo.getString("CHANGEBY"), 11)
#TIBCO
history = header.getMboSet("ZWSATIVOREPLAY3").add()
history.setValue("OWNER", 'MAXADMIN', 11)
history.setValue("DOMAIN", 'APP_MAXIMO', 11)
history.setValue("TYPE", 'Interfaces', 11)
history.setValue("SERVICENAME",'ZWSPC', 11)
history.setValue("ACTION", 'ACTION', 11)
history.setValue("VERSION", '1.0', 11)
history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11)
history.setValue("COMPONENT", 'ZWOTRACK', 11)

history.setValue("TRANSPORT", '', 11)


history.setValue("SUBJECT", '', 11)
history.setValue("STEP", '1', 11)
history.setValue("APPLICATION", 'MAXIMO', 11)
history.setValue("TRACKINGID", zp_eai_header.getString("TRACKINGID"), 11)
interaction = InteractionProcesser('ZWSATIVOREPLAY')
close(ciSet)
interaction.invokeservice(ci)
def sendWOAva(log,wo):
from java.text import SimpleDateFormat
xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
wsSet = wo.getMboSet('ZWSPC1')
header = wsSet.add()
header.setValue("TRACKINGID",str(Date().getTime()),11)
header.setValue("CREATIONTIME", xmlDate.format(Date()),11)
#TIBCO
history = header.getMboSet("ZWSPC3").add()
history.setValue("OWNER", wo.getString("CHANGEBY"), 11)
history.setValue("DOMAIN", 'APP_MAXIMO', 11)
history.setValue("TYPE", 'Interfaces', 11)
history.setValue("SERVICENAME",'ZWSPC', 11)
history.setValue("ACTION", 'ACTION', 11)
history.setValue("VERSION", '1.0', 11)
history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11)
history.setValue("COMPONENT", 'ZWOTRACK', 11)
history.setValue("TRANSPORT", '', 11)
history.setValue("SUBJECT", '', 11)
history.setValue("STEP", '1', 11)
history.setValue("APPLICATION", 'MAXIMO', 11)
history.setValue("TRACKINGID", header.getString("TRACKINGID"), 11)
#WORKORDER
ot = header.getMboSet("ZWSPC16").add()
ot.setValue("EMPRESA_CODEMPRESA", wo.getString("ZCODEMPRESA"), 11)
ot.setValue("ZWSPC16_CODATIVIDADE", 'JB005', 11) #recepcao do resultado da f
atibilidade
#
ot.setValue("ZWSPC16_CODPROCESSOCONS7441", wo.getString("ZCODPROCESSOCONSTR
UCAOPAI"), 11)
ot.setValue("ZWSPC16_CODPROCESSOCONS", wo.getString("ZCODPROCESSOCONSTRUCAO"
), 11)
ot.setValue("ZWSPC16_CODAPRECIACAO", wo.getString("ZSRAVA.ZRESULTADO"), 11)
ot.setValue("ZWSPC16_COMENTARIOS", None, 11)
close(wsSet)
interaction = InteractionProcesser('ZWSPC')
log.start()
interaction.invokeservice(wo)
log.stop()
def sentExpReplay(log,zp_eai_header):
from java.text import SimpleDateFormat
xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
keySet = zp_eai_header.getMboSet("ZP_EAI_LOG_KEYS")
keySet.setWhere("FIELD='ZWS_EXP_SYNCID'")

keySet.reset()
keyvalue = keySet.moveFirst()
close(keySet)
if keyvalue == None:
return
zws_exp_sync = getMbo("ZWS_EXP_SYNC",toSQL("ZWS_EXP_SYNCID=?",keyvalue.getSt
ring("VALUE")))
close(zws_exp_sync)
if zws_exp_sync == None:
return

wo = getMbo("WORKORDER","1=1")
wsSet = wo.getMboSet('ZWSPCREPLY1')
header = wsSet.add()
header.setValue("TRACKINGID",str(Date().getTime()),11)
header.setValue("CREATIONTIME", xmlDate.format(Date()),11)
header.setValue("LOGIN", wo.getString("CHANGEBY"), 11)
#TIBCO
history = header.getMboSet("ZWSPCREPLY3").add()
history.setValue("OWNER", wo.getString("CHANGEBY"), 11)
history.setValue("DOMAIN", 'APP_MAXIMO', 11)
history.setValue("TYPE", 'Interfaces', 11)
history.setValue("SERVICENAME",'ZWSPC', 11)
history.setValue("ACTION", 'ACTION', 11)
history.setValue("VERSION", '1.0', 11)
history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11)
history.setValue("COMPONENT", 'ZWOTRACK', 11)
history.setValue("TRANSPORT", '', 11)
history.setValue("SUBJECT", '', 11)
history.setValue("STEP", '1', 11)
history.setValue("APPLICATION", 'MAXIMO', 11)
history.setValue("TRACKINGID", zp_eai_header.getString("TRACKINGID"), 11)

ot = header.getMboSet("ZWSPCREPLY16").add()
ot.setValue("ZWSPCREPLY16_CODSTATUS", zp_eai_header.getString("NCODE"), 11)
ot.setValue("ZWSPCREPLY16_DESCSTATUS", zp_eai_header.getString("NDESCRIPTION
"), 11)
ot.setValue("EMPRESA_CODEMPRESA", zws_exp_sync.getString("CODEMPRESA"), 11)
ot.setValue("ZWSPCREPLY16_CODPROCESS9592", zws_exp_sync.getString("CODPROCES
SOCONSTRUCAOPAI"), 11)
ot.setValue("ZWSPCREPLY16_CODPROCESS", zws_exp_sync.getString("CODPROCESSOCO
NSTRUCAO"), 11)
interaction = InteractionProcesser('ZWSPCREPLY')
close(wsSet)
close(wo)
log.start()
interaction.invokeservice(wo)
log.stop()
def sentOtReplay(log,zp_eai_header):
from java.text import SimpleDateFormat
xmlDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
keySet = zp_eai_header.getMboSet("ZP_EAI_LOG_KEYS")
keySet.setWhere("FIELD='ZWS_OT_SYNCID'")
keySet.reset()
keyvalue = keySet.moveFirst()
close(keySet)

if keyvalue == None:
return
zws_ot_sync = getMbo("ZWS_OT_SYNC",toSQL("ZWS_OT_SYNCID=?",keyvalue.getStrin
g("VALUE")))
close(zws_ot_sync)
if zws_ot_sync == None:
return

wo = getMbo("WORKORDER","1=1")
wsSet = wo.getMboSet('ZWSWOREPLY1')
header = wsSet.add()
header.setValue("TRACKINGID",str(Date().getTime()),11)
header.setValue("CREATIONTIME", xmlDate.format(Date()),11)
header.setValue("LOGIN", wo.getString("CHANGEBY"), 11)
#TIBCO
history = header.getMboSet("ZWSWOREPLY3").add()
history.setValue("OWNER", wo.getString("CHANGEBY"), 11)
history.setValue("DOMAIN", 'APP_MAXIMO', 11)
history.setValue("TYPE", 'Interfaces', 11)
history.setValue("SERVICENAME",'ZWSPC', 11)
history.setValue("ACTION", 'ACTION', 11)
history.setValue("VERSION", '1.0', 11)
history.setValue("TIMESTAMP", header.getString("CREATIONTIME"), 11)
history.setValue("COMPONENT", 'ZWOTRACK', 11)
history.setValue("TRANSPORT", '', 11)
history.setValue("SUBJECT", '', 11)
history.setValue("STEP", '1', 11)
history.setValue("APPLICATION", 'MAXIMO', 11)
history.setValue("TRACKINGID", zp_eai_header.getString("TRACKINGID"), 11)

ot = header.getMboSet("ZWSWOREPLY16").add()
ot.setValue("ZWSWOREPLY16_CODSTATUS", zp_eai_header.getString("NCODE"), 11)
ot.setValue("ZWSWOREPLY16_DESCSTATUS", zp_eai_header.getString("NDESCRIPTION
"), 11)
ot.setValue("PROCESSOCONSTRUCAO_CODP1113", zws_ot_sync.getString("CODEXPEDIE
NTEPAI"), 11)
ot.setValue("PROCESSOCONSTRUCAO_CODP", zws_ot_sync.getString("CODEXPEDIENTER
AMAL"), 11)
ot.setValue("ZWSWOREPLY16_CODORDEMTR", zws_ot_sync.getString("CODIGOORDEM"),
11)
ot.setValue("EMPRESA_CODEMPRESA", zws_ot_sync.getString("CODEMPRESA"), 11)
interaction = InteractionProcesser('ZWSWOREPLY')
close(wsSet)
close(wo)
log.start()
interaction.invokeservice(wo)
log.stop()
objectname = mbo.getString("OBJECTNAME")
objectid = mbo.getString("OBJECTID")
status = mbo.getString("STATUS")
wsname = mbo.getString("WSNAME")
delete = False
if wsname == 'OT' and status == 'PEND':
zwoesristatus(objectid,'SEND',None)

#envio da OT para o esri


if wsname == 'OT' and status == 'SENT':
wo = getMbo("WORKORDER",toSQL("WONUM='?'",objectid))
if wo != None:
log = Log()
log.setOutbound('ZWSObjectSend(OT)')
log.setKeyValue('codOrdemTrabalho',objectid)
wonum = wo.getString("WONUM")
try:
sendWOStatus(log,wo)
except:
type, value, traceback = sys.exc_info()
if 'BMXAA4214E' not in value.message:
zwoesristatus(wonum,'ERR_COM',value.message)
log.setError(sys)
else:
zwoesristatus(wonum,'WAIT',None)
log.setError(None)
log.save()
close(wo)
delete = True
#envio do reply do IF ZWS_EXP_SYNC
if wsname == 'ZWS_OT_SYNC' and status == 'SENT':
zp_eai_header = getMbo("ZP_EAI_LOG_HEADER",toSQL("ZP_EAI_LOG_HEADERID=?",obj
ectid))
if zp_eai_header != None:
log = Log()
log.setOutbound('ZWS_OT_SYNC_REPLY')
log.setKeyValue('ZP_EAI_LOG_HEADERID',objectid)
try:
sentOtReplay(log,zp_eai_header)
except:
type, value, traceback = sys.exc_info()
if 'BMXAA4214E' not in value.message:
log.setError(sys)
else:
log.setError(None)
log.save()
close(zp_eai_header)
delete = True
#envio do reply do IF ZWS_EXP_SYNC
if wsname == 'ZWS_EXP_SYNC' and status == 'SENT':
zp_eai_header = getMbo("ZP_EAI_LOG_HEADER",toSQL("ZP_EAI_LOG_HEADERID=?",obj
ectid))
if zp_eai_header != None:
log = Log()
log.setOutbound('ZWS_EXP_SYNC_REPLY')
log.setKeyValue('ZP_EAI_LOG_HEADERID',objectid)
try:
sentExpReplay(log,zp_eai_header)
except:
type, value, traceback = sys.exc_info()
if 'BMXAA4214E' not in value.message:
log.setError(sys)
else:
log.setError(None)

log.save()
close(zp_eai_header)
delete = True
#envio do status da Fatibilidade
if wsname == 'FAT' and status == 'SENT':
wo = getMbo("WORKORDER",toSQL("WONUM='?'",objectid))
if wo != None:
log = Log()
log.setOutbound('ZWSObjectSend(FAT)')
log.setKeyValue('codOrdemTrabalho',objectid)
try:
sendWOFat(log,wo)
except:
type, value, traceback = sys.exc_info()
if 'BMXAA4214E' not in value.message:
log.setError(sys)
else:
log.setError(None)
log.save()
close(wo)
delete = True
#envio do status do AVA
if wsname == 'AVA' and status == 'SENT':
wo = getMbo("WORKORDER",toSQL("WONUM='?'",objectid))
if wo != None:
log = Log()
log.setOutbound('ZWSObjectSend(AVA)')
log.setKeyValue('codOrdemTrabalho',objectid)
try:
sendWOAva(log,wo)
except:
type, value, traceback = sys.exc_info()
if 'BMXAA4214E' not in value.message:
log.setError(sys)
else:
log.setError(None)
log.save()
close(wo)
delete = True
if wsname == 'ZWS_CI_SYNC' and status == 'SENT':
zp_eai_header = getMbo("ZP_EAI_LOG_HEADER",toSQL("ZP_EAI_LOG_HEADERID=?",obj
ectid))
if zp_eai_header != None:
log = Log()
log.setOutbound('ZWSATIVOREPLAY')
log.setKeyValue('ZP_EAI_LOG_HEADERID',objectid)
try:
sendAtivoReply(log,zp_eai_header)
except:
type, value, traceback = sys.exc_info()
if 'BMXAA4214E' not in value.message:
log.setError(sys)
else:
log.setError(None)
log.save()
close(zp_eai_header)
delete = True

if delete:
mbo.delete(11)

You might also like