Histórico da Página
Objetivo
...
No Adapter é montada a mensagem de negócio (BusinessMessage) ou mensagem de retorno (ResponseMessage). O método prepareMessage() chamará a classe de InternalId vinculada ao Adapter.
...
Exemplo de utilização em Progress:
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
METHOD PUBLIC TOTVSMessage sendMessage(): DEFINE VARIABLE businessContent AS com.totvs.datasul.eai2.messages.CostCenter_2_000.BusinessContentType NO-UNDO. DEFINE VARIABLE response AS TOTVSMessage NO-UNDO. /* Criar o business content */ businessContent = CAST( helper:createBusinessContent(), "com.totvs.datasul.eai2.messages.CostCenter_2_000.BusinessContentType" ). /* Registrar a estrutura dos "internal IDs" da mensagem */ IF NOT mapper:existMapping("CompanyInternalId","empresa") THEN mapper:register( INPUT "CompanyInternalId", INPUT "empresa", INPUT "cod_empresa"). IF NOT mapper:existMapping("CostCenterInternalId", "centro_custo") THEN mapper:register( INPUT "CompanyInternalId", "centro_custo", "cod_empresa|cod_estabel|cod_ccusto"). /* Preencher o businessContent */ businessContent:CLASS = 111. businessContent:CODE = "111.000.000". businessContent:NAME = "Centro de custo 111". businessContent:SPED = TRUE. businessContent:ShortCode = "111". businessContent:CompanyId = "123". businessContent:BranchId = "XYZ". /* Preencher os dados dos "internal IDs" na mensagem */ businessContent:CompanyInternalId = "123@empresa". businessContent:InternalId = "123|XYZ|111.000.000@centro_custo". /* Criar a business message */ msg = BusinessMessage:createBusinessMessage( businessContent ). DO ON ERROR UNDO, LEAVE: /* Enviar a mensagem */ response = EAIEngine:instance:dispatchMessage( msg ). /* Tratar a resposta */ IF response:GetClass():IsA("com.totvs.datasul.eai.ResponseMessage") THEN THIS-OBJECT:processMessage( CAST(response,"com.totvs.datasul.eai.ResponseMessage")). CATCH e AS Progress.Lang.Error : EAILog:ERROR("Couldn’t send message!"). RETURN ?. END CATCH. END. RETURN response. END METHOD. METHOD PUBLIC LOGICAL processMessage( INPUT resp AS com.totvs.datasul.eai.ResponseMessage ): DEFINE VARIABLE businessContent AS BusinessContentType NO-UNDO. DEFINE VARIABLE returnContent AS ReturnContentType NO-UNDO. businessContent = CAST(MessageContentHelper:createBusinessContent( msg, helper ), "com.totvs.datasul.eai2.messages.CostCenter_2_000.BusinessContentType"). returnContent = CAST(MessageContentHelper:createReturnContent( resp, helper ), "com.totvs.datasul.eai2.messages.CostCenter_2_000.ReturnContentType"). IF returnContent = ? THEN RETURN FALSE. /* Extração dos internal ids enviados pelo destino */ DEFINE VARIABLE iCont AS INTEGER NO-UNDO. DEFINE VARIABLE internalId AS com.totvs.datasul.eai2.messages.CostCenter_2_000.InternalIdType NO-UNDO. DEFINE VARIABLE listOfinternalId AS com.totvs.datasul.eai2.messages.CostCenter_2_000.ListOfInternalIdType NO-UNDO. listOfinternalId = returnContent:ListOfInternalId. DO iCont = 1 TO listOfinternalId:NUM-InternalID: internalId = listOfInternalId:getInternalId(iCont). IF internalId:NAME = "CompanyInternalId" THEN DO: /* Completa o mapeamento dos internal ids, gravando o codigo do aplicativo de origem e o código do aplicativo de destino. */ mapper:setValue( internalId:NAME, businessContent:CompanyInternalId, resp:SourceApp, internalId:Destination ). END. END. RETURN TRUE. END METHOD. |
...
Exemplo de utilização em Java:
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public TOTVSMessage sendMessage(){ // Criar o businessContent CostCenter helper = new CostCenter(); BusinessContentType businessContent = (BusinessContentType) helper.createBusinessContent(); TOTVSMessage response = null; // Registrar a estrutura dos "internal IDs" da mensagem if(!mapper.exists("CompanyInternalId", "empresa")) { mapper.register("CompanyInternalId", "empresa", "cod_empresa"); } if(!mapper.exists("CostCenterInternalId", "centro_custo")){ mapper.register("CostCenterInternalId","centro_custo","cod_empresa|cod_estabel|cod_ccusto"); } // Preencher o businessContent businessContent.setClass(111); businessContent.setCode("111.000.000"); businessContent.setName("Centro de custo 111"); businessContent.setSPED(true); businessContent.setShortCode("111"); businessContent.setCompanyId("123"); businessContent.setBranchId("XYZ"); // Preencher os dados dos "internal IDs" na mensagem businessContent.setCompanyInternalId("123@empresa"); businessContent.setInternalId("123|XYZ|111.000.000@centro_custo"); // Criar a business message msg = BusinessMessage.createBusinessMessage( businessContent ); try { // Enviar a mensagem response = EAIEngine.getInstance().dispatchMessage( msg ); // Tratar a resposta if( response instanceof ResponseMessage ){ this.processMessage((ResponseMessage) response); } } catch (EAIException e) { EAILog.error(e, "Couldn’t send message!"); } return response; } @Override public boolean processMessage(ResponseMessage resp) { BusinessContentType businessContent = (BusinessContentType) MessageContentHelper.createBusinessContent(msg, new CostCenter()); ReturnContentType returnContent = (ReturnContentType) MessageContentHelper.createReturnContent(resp, new CostCenter()); if( returnContent == null ) return false; // Extração dos internal ids enviados pelo destino List<InternalIdType> internalIds = returnContent.getListOfInternalId().getInternalIdList(); } |
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas