Commit 3fe74e7a2d25c22e874ef146e37cd5baa5164127

Authored by Guilherme Andrade Del Cantoni
1 parent ff263bda

[Fixed #23] Correção de falha no envio de documentos externos autenticados

rn/ExpedirProcedimentoRN.php
... ... @@ -117,10 +117,12 @@ class ExpedirProcedimentoRN extends InfraRN {
117 117 return $this->objProcessoEletronicoRN->consultarMotivosUrgencia();
118 118 }
119 119  
120   - public function expedirProcedimentoControlado(ExpedirProcedimentoDTO $objExpedirProcedimentoDTO) {
  120 + public function expedirProcedimentoControlado(ExpedirProcedimentoDTO $objExpedirProcedimentoDTO)
  121 + {
121 122  
122 123 $numIdTramite = 0;
123 124  
  125 +
124 126 try {
125 127 //Valida Permissão
126 128 SessaoSEI::getInstance()->validarAuditarPermissao('pen_procedimento_expedir',__METHOD__, $objExpedirProcedimentoDTO);
... ... @@ -136,7 +138,6 @@ class ExpedirProcedimentoRN extends InfraRN {
136 138 $objProcedimentoDTO = $this->consultarProcedimento($dblIdProcedimento);
137 139 $objProcedimentoDTO->setArrObjDocumentoDTO($this->listarDocumentos($dblIdProcedimento));
138 140 $objProcedimentoDTO->setArrObjParticipanteDTO($this->listarInteressados($dblIdProcedimento));
139   -
140 141 $this->validarPreCondicoesExpedirProcedimento($objInfraException, $objProcedimentoDTO);
141 142 $this->validarParametrosExpedicao($objInfraException, $objExpedirProcedimentoDTO);
142 143 //Apresentao da mensagens de validao na janela da barra de progresso
... ... @@ -148,12 +149,15 @@ class ExpedirProcedimentoRN extends InfraRN {
148 149  
149 150 $this->barraProgresso->mover(ProcessoEletronicoINT::NEE_EXPEDICAO_ETAPA_PROCEDIMENTO);
150 151 $this->barraProgresso->setStrRotulo(sprintf(ProcessoEletronicoINT::TEE_EXPEDICAO_ETAPA_PROCEDIMENTO, $objProcedimentoDTO->getStrProtocoloProcedimentoFormatado()));
151   -
152 152 //Construo dos cabecalho para envio do processo
153 153 $objCabecalho = $this->construirCabecalho($objExpedirProcedimentoDTO);
  154 +
154 155 //Construo do processo para envio
155 156 $objProcesso = $this->construirProcesso($dblIdProcedimento, $objExpedirProcedimentoDTO->getArrIdProcessoApensado());
  157 +
156 158 try {
  159 +
  160 +
157 161 $param = new stdClass();
158 162 $param->novoTramiteDeProcesso = new stdClass();
159 163 $param->novoTramiteDeProcesso->cabecalho = $objCabecalho;
... ... @@ -164,6 +168,7 @@ class ExpedirProcedimentoRN extends InfraRN {
164 168 } catch (\Exception $e) {
165 169 throw new InfraException("Error Processing Request", $e);
166 170 }
  171 +
167 172 $this->atualizarPenProtocolo($dblIdProcedimento);
168 173 if (isset($novoTramite->dadosTramiteDeProcessoCriado)) {
169 174 $objTramite = $novoTramite->dadosTramiteDeProcessoCriado;
... ... @@ -199,6 +204,7 @@ class ExpedirProcedimentoRN extends InfraRN {
199 204 //saber quais precisam ser baixados. O processo poderia ser mais otimizado se o retorno nos metadados j informasse quais os
200 205 //componentes precisam ser baixados, semelhante ao que ocorre no enviarProcesso onde o barramento informa quais os componentes
201 206 //que precisam ser enviados
  207 +
202 208 $this->enviarComponentesDigitais($objTramite->NRE, $objTramite->IDT, $objProcesso->protocolo);
203 209 //error_log('after enviarComponentesDigitais');
204 210 //$strNumeroRegistro, $numIdTramite, $strProtocolo
... ... @@ -371,6 +377,7 @@ class ExpedirProcedimentoRN extends InfraRN {
371 377  
372 378 private function construirProcesso($dblIdProcedimento, $arrIdProcessoApensado = null)
373 379 {
  380 +
374 381 if(!isset($dblIdProcedimento)){
375 382 throw new InfraException('Parâmetro $dblIdProcedimento não informado.');
376 383 }
... ... @@ -378,29 +385,24 @@ class ExpedirProcedimentoRN extends InfraRN {
378 385 //TODO: Passar dados do ProcedimentoDTO via parâmetro j carregado anteriormente
379 386 $objProcedimentoDTO = $this->consultarProcedimento($dblIdProcedimento);
380 387 $objPenRelHipoteseLegalRN = new PenRelHipoteseLegalEnvioRN();
381   -
382 388 $objProcesso = new stdClass();
383 389 $objProcesso->protocolo = utf8_encode($objProcedimentoDTO->getStrProtocoloProcedimentoFormatado());
384 390 $objProcesso->nivelDeSigilo = $this->obterNivelSigiloPEN($objProcedimentoDTO->getStrStaNivelAcessoLocalProtocolo());
385 391 $objProcesso->processoDeNegocio = utf8_encode($objProcedimentoDTO->getStrNomeTipoProcedimento());
386 392 $objProcesso->descricao = utf8_encode($objProcedimentoDTO->getStrDescricaoProtocolo());
387 393 $objProcesso->dataHoraDeProducao = $this->objProcessoEletronicoRN->converterDataWebService($objProcedimentoDTO->getDtaGeracaoProtocolo());
388   -
389 394 if($objProcedimentoDTO->getStrStaNivelAcessoLocalProtocolo() == ProtocoloRN::$NA_RESTRITO){
390 395 $objProcesso->hipoteseLegal = new stdClass();
391 396 $objProcesso->hipoteseLegal->identificacao = $objPenRelHipoteseLegalRN->getIdHipoteseLegalPEN($objProcedimentoDTO->getNumIdHipoteseLegalProtocolo());
392 397 }
393   -
394 398 $this->atribuirProdutorProcesso($objProcesso,
395 399 $objProcedimentoDTO->getNumIdUsuarioGeradorProtocolo(),
396 400 $objProcedimentoDTO->getNumIdUnidadeGeradoraProtocolo());
397   -
398 401 $this->atribuirDataHoraDeRegistro($objProcesso, $objProcedimentoDTO->getDblIdProcedimento());
399 402  
400 403 $this->atribuirDocumentos($objProcesso, $dblIdProcedimento);
401 404 $this->atribuirDadosInteressados($objProcesso, $dblIdProcedimento);
402 405 $this->adicionarProcessosApensados($objProcesso, $arrIdProcessoApensado);
403   -
404 406 $objProcesso->idProcedimentoSEI = $dblIdProcedimento;
405 407 return $objProcesso;
406 408 }
... ... @@ -788,29 +790,23 @@ class ExpedirProcedimentoRN extends InfraRN {
788 790 if(!isset($arrDocumentosDTO)) {
789 791 throw new InfraException('Documentos não encontrados.');
790 792 }
791   -
792 793 $ordemDocumento = 1;
793 794 $objProcesso->documento = array();
794   -
795 795 foreach ($arrDocumentosDTO as $documentoDTO) {
796 796  
797 797 //$protocoloDocumentoDTO = $this->consultarProtocoloDocumento($documeto->getDblIdProcedimento());
798   -
799 798 $documento = new stdClass();
800 799 $objPenRelHipoteseLegalRN = new PenRelHipoteseLegalEnvioRN();
801 800 //TODO: Atribuir das informações abaixo ao documento
802 801 //<protocoloDoDocumentoAnexado>123</protocoloDoDocumentoAnexado>
803 802 //<protocoloDoProcessoAnexado>456</protocoloDoProcessoAnexado>
804 803 //Retirado
805   -
806 804 //Considera o nmero/nome do documento externo para descrio do documento
807 805 if($documentoDTO->getStrStaProtocoloProtocolo() == ProtocoloRN::$TP_DOCUMENTO_RECEBIDO && $documentoDTO->getStrNumero() != null) {
808 806 $strDescricaoDocumento = $documentoDTO->getStrNumero();
809   -
810 807 }else{
811 808 $strDescricaoDocumento = "***";
812 809 }
813   -
814 810 // Não é um documento externo
815 811 /*elseif($documentoDTO->isSetNumIdTipoConferencia()){
816 812  
... ... @@ -827,18 +823,14 @@ class ExpedirProcedimentoRN extends InfraRN {
827 823 }*/
828 824  
829 825 $documento->retirado = ($documentoDTO->getStrStaEstadoProtocolo() == ProtocoloRN::$TE_DOCUMENTO_CANCELADO) ? true : false;
830   -
831 826 $documento->ordem = $ordemDocumento++;
832 827 $documento->descricao = utf8_encode($strDescricaoDocumento);
833 828 $documento->nivelDeSigilo = $this->obterNivelSigiloPEN($documentoDTO->getStrStaNivelAcessoLocalProtocolo());
834   -
835 829 if($documentoDTO->getStrStaNivelAcessoLocalProtocolo() == ProtocoloRN::$NA_RESTRITO){
836 830 $documento->hipoteseLegal = new stdClass();
837 831 $documento->hipoteseLegal->identificacao = $objPenRelHipoteseLegalRN->getIdHipoteseLegalPEN($documentoDTO->getNumIdHipoteseLegalProtocolo());
838 832 }
839   -
840 833 $documento->dataHoraDeProducao = $this->objProcessoEletronicoRN->converterDataWebService($documentoDTO->getDtaGeracaoProtocolo());
841   -
842 834 $documento->produtor = new stdClass();
843 835 $usuarioDTO = $this->consultarUsuario($documentoDTO->getNumIdUsuarioGeradorProtocolo());
844 836 if(isset($usuarioDTO)) {
... ... @@ -848,7 +840,6 @@ class ExpedirProcedimentoRN extends InfraRN {
848 840 $documento->produtor->tipo = self::STA_TIPO_PESSOA_FISICA;;
849 841 }
850 842  
851   -
852 843 $unidadeDTO = $this->consultarUnidade($documentoDTO->getNumIdUnidadeResponsavel());
853 844 if(isset($unidadeDTO)) {
854 845 $documento->produtor->unidade = new stdClass();
... ... @@ -856,20 +847,16 @@ class ExpedirProcedimentoRN extends InfraRN {
856 847 $documento->produtor->unidade->tipo = self::STA_TIPO_PESSOA_ORGAOPUBLICO;
857 848 //TODO: Informar dados da estrutura organizacional (estruturaOrganizacional)
858 849 }
859   -
860 850 $documento->produtor->numeroDeIdentificacao = $documentoDTO->getStrProtocoloDocumentoFormatado();
861 851  
862 852 $this->atribuirDataHoraDeRegistro($documento, $documentoDTO->getDblIdProcedimento(), $documentoDTO->getDblIdDocumento());
863   -
864 853 //TODO: Implementar mapeamento de espécies documentais
865 854 $documento->especie = new stdClass();
866 855 $documento->especie->codigo = $this->obterEspecieMapeada($documentoDTO->getNumIdSerie());
867 856 $documento->especie->nomeNoProdutor = utf8_encode($documentoDTO->getStrNomeSerie());
868 857 //TODO: Tratar campos adicionais do documento
869   -
870 858 //Identificao do documento
871 859 $this->atribuirNumeracaoDocumento($documento, $documentoDTO);
872   -
873 860 if($documento->retirado === true){
874 861  
875 862 $penComponenteDigitalDTO = new ComponenteDigitalDTO();
... ... @@ -893,7 +880,6 @@ class ExpedirProcedimentoRN extends InfraRN {
893 880 $documento->componenteDigital->idAnexo = $componenteDigital->getNumIdAnexo();
894 881  
895 882  
896   -
897 883 // -------------------------- INICIO DA TAREFA US074 -------------------------------//
898 884 $documento = $this->atribuirDadosAssinaturaDigital($documentoDTO, $documento, $componenteDigital->getStrHashConteudo());
899 885 // -------------------------- FIM TAREFA US074 -------------------------------//
... ... @@ -908,7 +894,6 @@ class ExpedirProcedimentoRN extends InfraRN {
908 894  
909 895 }
910 896  
911   -
912 897 }else{
913 898 $this->atribuirComponentesDigitais($documento, $documentoDTO);
914 899 }
... ... @@ -922,7 +907,6 @@ class ExpedirProcedimentoRN extends InfraRN {
922 907 $documento->idDocumentoSEI = $documentoDTO->getDblIdDocumento();
923 908 $objProcesso->documento[] = $documento;
924 909 }
925   -
926 910 }
927 911  
928 912 public function atribuirComponentesDigitaisRetirados($documentoDTO){
... ... @@ -976,6 +960,7 @@ class ExpedirProcedimentoRN extends InfraRN {
976 960 private function atribuirComponentesDigitais($objDocumento, DocumentoDTO $objDocumentoDTO)
977 961 {
978 962  
  963 +
979 964 if(!isset($objDocumento)){
980 965 throw new InfraException('Parâmetro $objDocumento não informado.');
981 966 }
... ... @@ -989,30 +974,25 @@ class ExpedirProcedimentoRN extends InfraRN {
989 974 if(!isset($arrInformacaoArquivo) || count($arrInformacaoArquivo) == 0){
990 975 throw new InfraException('Erro durante obtenção de informações sobre o componente digital do documento {$objDocumentoDTO->getStrProtocoloDocumentoFormatado()}.');
991 976 }
992   -
993 977 //TODO: Revisar tal implementao para atender a gerao de hash de arquivos grandes
994 978 $strAlgoritmoHash = self::ALGORITMO_HASH_DOCUMENTO;
995 979 $strConteudoAssinatura = $arrInformacaoArquivo['CONTEUDO'];
996 980 $hashDoComponenteDigital = hash($strAlgoritmoHash, $strConteudoAssinatura, true);
997 981 $hashDoComponenteDigital = base64_encode($hashDoComponenteDigital);
998   -
999 982 $objDocumento->componenteDigital = new stdClass();
1000 983 $objDocumento->componenteDigital->ordem = 1;
1001 984 $objDocumento->componenteDigital->nome = utf8_encode($arrInformacaoArquivo["NOME"]);
1002 985 $objDocumento->componenteDigital->hash = new SoapVar("<hash algoritmo='{$strAlgoritmoHash}'>{$hashDoComponenteDigital}</hash>", XSD_ANYXML);
1003 986 $objDocumento->componenteDigital->tamanhoEmBytes = $arrInformacaoArquivo['TAMANHO'];
1004   -
1005 987 //TODO: Validar os tipos de mimetype de acordo com o WSDL do SEI
1006 988 //Caso no identifique o tipo correto, informar o valor [outro]
1007 989 $objDocumento->componenteDigital->mimeType = $arrInformacaoArquivo['MIME_TYPE'];
1008 990 $objDocumento->componenteDigital->tipoDeConteudo = $this->obterTipoDeConteudo($arrInformacaoArquivo['MIME_TYPE']);
1009 991  
1010   -
1011 992 // -------------------------- INICIO DA TAREFA US074 -------------------------------/
1012 993 $objDocumento = $this->atribuirDadosAssinaturaDigital($objDocumentoDTO, $objDocumento, $hashDoComponenteDigital);
1013 994 // -------------------------- FIM TAREFA US074 -------------------------------//
1014 995  
1015   -
1016 996 if($arrInformacaoArquivo['MIME_TYPE'] == 'outro'){
1017 997 $objDocumento->componenteDigital->dadosComplementaresDoTipoDeArquivo = $arrInformacaoArquivo['dadosComplementaresDoTipoDeArquivo'];
1018 998 }
... ... @@ -1020,7 +1000,6 @@ class ExpedirProcedimentoRN extends InfraRN {
1020 1000 //TODO: Preencher dados complementares do tipo de arquivo
1021 1001 //$objDocumento->componenteDigital->dadosComplementaresDoTipoDeArquivo = '';
1022 1002  
1023   -
1024 1003 //TODO: Carregar informações da assinatura digital
1025 1004 //$this->atribuirAssinaturaEletronica($objDocumento->componenteDigital, $objDocumentoDTO);
1026 1005  
... ... @@ -1047,12 +1026,13 @@ class ExpedirProcedimentoRN extends InfraRN {
1047 1026 $objDocumentoDTOTarjas->retNumIdUnidadeGeradoraProtocolo();
1048 1027 $objDocumentoDTOTarjas->retStrDescricaoTipoConferencia();
1049 1028 $objDocumentoDTOTarjas->setDblIdDocumento($objDocumentoDTO->getDblIdDocumento());
  1029 +
1050 1030 $objDocumentoRN = new DocumentoRN();
1051 1031 $objDocumentoDTOTarjas = $objDocumentoRN->consultarRN0005($objDocumentoDTOTarjas);
  1032 +
1052 1033 $objAssinaturaRN = new AssinaturaRN();
1053 1034 $tarjas = $objAssinaturaRN->montarTarjas($objDocumentoDTOTarjas);
1054 1035  
1055   -
1056 1036 //Remove todos os 12 espaos padres aps remover as tags.
1057 1037 $dataTarjas = explode(' ', strip_tags($tarjas));
1058 1038 foreach ($dataTarjas as $key => $content) {
... ... @@ -1063,42 +1043,46 @@ class ExpedirProcedimentoRN extends InfraRN {
1063 1043 $dataTarjas[$key] = html_entity_decode($contentTrim); //Decodifica por causa do strip_tags
1064 1044 }
1065 1045 }
1066   -
1067 1046 $dataTarjas = array_values($dataTarjas); //Reseta os valores da array
1068 1047  
1069 1048 $objAssinaturaDTO = new AssinaturaDTO();
1070 1049 $objAssinaturaDTO->setDblIdDocumento($objDocumentoDTO->getDblIdDocumento());
1071 1050 $objAssinaturaDTO->retNumIdAtividade();
  1051 + $objAssinaturaDTO->retStrStaFormaAutenticacao();
1072 1052 $objAssinaturaDTO->retStrP7sBase64();
  1053 +
1073 1054 $objAssinaturaRN = new AssinaturaRN();
1074 1055 $resAssinatura = $objAssinaturaRN->listarRN1323($objAssinaturaDTO);
1075 1056  
1076   -
1077 1057 $objDocumento->componenteDigital->assinaturaDigital = array();
1078 1058 //Para cada assinatura
1079 1059 foreach ($resAssinatura as $keyOrder => $assinatura) {
1080   -
1081 1060 //Busca data da assinatura
1082 1061 $objAtividadeDTO = new AtividadeDTO();
1083 1062 $objAtividadeDTO->setNumIdAtividade($assinatura->getNumIdAtividade());
1084   - $objAtividadeDTO->setNumIdTarefa(TarefaRN::$TI_ASSINATURA_DOCUMENTO);
  1063 + $objAtividadeDTO->setNumIdTarefa(array(TarefaRN::$TI_ASSINATURA_DOCUMENTO, TarefaRN::$TI_AUTENTICACAO_DOCUMENTO), InfraDTO::$OPER_IN);
1085 1064 $objAtividadeDTO->retDthAbertura();
1086 1065 $objAtividadeDTO->retNumIdAtividade();
1087 1066 $objAtividadeRN = new AtividadeRN();
1088 1067 $objAtividade = $objAtividadeRN->consultarRN0033($objAtividadeDTO);
1089 1068  
1090 1069 $objAssinaturaDigital = new stdClass();
1091   - $objAssinaturaDigital->dataHora = $this->objProcessoEletronicoRN->converterDataWebService($objAtividade->getDthAbertura());
1092   - $objAssinaturaDigital->hash = new SoapVar("<hash algoritmo='".self::ALGORITMO_HASH_ASSINATURA."'>{$strHashDocumento}</hash>", XSD_ANYXML);
1093   - $objAssinaturaDigital->cadeiaDoCertificado = new SoapVar('<cadeiaDoCertificado formato="PKCS7">'.($assinatura->getStrP7sBase64() ? $assinatura->getStrP7sBase64() : 'null').'</cadeiaDoCertificado>', XSD_ANYXML);
1094 1070 $objAssinaturaDigital->razao = utf8_encode($dataTarjas[$keyOrder]);
1095 1071 $objAssinaturaDigital->observacao = utf8_encode($dataTarjas[count($dataTarjas) - 1]);
  1072 + $objAssinaturaDigital->dataHora = $this->objProcessoEletronicoRN->converterDataWebService($objAtividade->getDthAbertura());
  1073 +
  1074 + if($assinatura->getStrStaFormaAutenticacao() == AssinaturaRN::$TA_CERTIFICADO_DIGITAL){
  1075 + $objAssinaturaDigital->hash = new SoapVar("<hash algoritmo='".self::ALGORITMO_HASH_ASSINATURA."'>{$strHashDocumento}</hash>", XSD_ANYXML);
  1076 + $objAssinaturaDigital->cadeiaDoCertificado = new SoapVar('<cadeiaDoCertificado formato="PKCS7">'.($assinatura->getStrP7sBase64() ? $assinatura->getStrP7sBase64() : 'null').'</cadeiaDoCertificado>', XSD_ANYXML);
  1077 + } else {
  1078 + $objAssinaturaDigital->hash = new SoapVar("<hash algoritmo='".self::ALGORITMO_HASH_ASSINATURA."'>null</hash>", XSD_ANYXML);
  1079 + $objAssinaturaDigital->cadeiaDoCertificado = new SoapVar('<cadeiaDoCertificado formato="PKCS7">null</cadeiaDoCertificado>', XSD_ANYXML);
  1080 + }
1096 1081  
1097 1082 $objDocumento->componenteDigital->assinaturaDigital[] = $objAssinaturaDigital;
1098 1083 }
1099 1084  
1100 1085  
1101   -
1102 1086 return $objDocumento;
1103 1087 }
1104 1088  
... ...
rn/PenAtualizarSeiRN.php
... ... @@ -604,7 +604,7 @@ class PenAtualizarSeiRN extends PenAtualizadorRN {
604 604 }
605 605 };
606 606  
607   -
  607 + //TODO: Corrigir mensagem com português errado
608 608 $fnCadastrar('Processo trâmitado externamente para a entidade @UNIDADE_DESTINO@ - @REPOSITORIO_DESTINO@ (@PROCESSO@, @UNIDADE@, @USUARIO@)', 'S', 'S', 'N', 'S', 'N', 'PEN_PROCESSO_EXPEDIDO');
609 609 $fnCadastrar('Processo recebido da entidade @ENTIDADE_ORIGEM@ - @REPOSITORIO_ORIGEM@ (@PROCESSO@, @ENTIDADE_ORIGEM@, @UNIDADE_DESTINO@, @USUARIO@)', 'S', 'S', 'N', 'S', 'N', 'PEN_PROCESSO_RECEBIDO');
610 610 $fnCadastrar('O processo foi recusado pelo orgão @UNIDADE_DESTINO@ pelo seguinte motivo: @MOTIVO@', 'S', 'S', 'N', 'N', 'S', 'PEN_PROCESSO_RECUSADO');
... ...
rn/ReceberProcedimentoRN.php
... ... @@ -1823,19 +1823,16 @@ protected function receberTramiteRecusadoInternoControlado(ReceberTramiteRecusad
1823 1823 * @param integer $parIdTramite
1824 1824 * @throws InfraException
1825 1825 */
1826   - public function verificarPermissoesDiretorios($parIdTramite){
1827   -
  1826 + public function verificarPermissoesDiretorios($parIdTramite)
  1827 + {
1828 1828 //Verifica se o usuário possui permissões de escrita no repositório de arquivos externos
1829   - if(!is_writable(ConfiguracaoSEI::getInstance()->getValor('SEI', 'RepositorioArquivos'))){
1830   -
  1829 + if(!is_writable(ConfiguracaoSEI::getInstance()->getValor('SEI', 'RepositorioArquivos'))) {
1831 1830 $this->objProcessoEletronicoRN->recusarTramite($parIdTramite, 'O sistema não possui permissão de escrita no diretório de armazenamento de documentos externos', ProcessoEletronicoRN::MTV_RCSR_TRAM_CD_OUTROU);
1832 1831 throw new InfraException('O sistema não possui permissão de escrita no diretório de armazenamento de documentos externos');
1833   -
1834 1832 }
1835 1833  
1836 1834 //Verifica se o usuário possui permissões de escrita no diretório temporário de arquivos
1837 1835 if(!is_writable(DIR_SEI_TEMP)){
1838   -
1839 1836 $this->objProcessoEletronicoRN->recusarTramite($parIdTramite, 'O sistema não possui permissão de escrita no diretório de armazenamento de arquivos temporários do sistema.', ProcessoEletronicoRN::MTV_RCSR_TRAM_CD_OUTROU);
1840 1837 throw new InfraException('O sistema não possui permissão de escrita no diretório de armazenamento de arquivos temporários do sistema.');
1841 1838  
... ...