/[openfoncier]/trunk/services/outgoing/messageenqueuer.php
ViewVC logotype

Annotation of /trunk/services/outgoing/messageenqueuer.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 851 - (hide annotations)
Wed Nov 28 12:54:56 2012 UTC (12 years, 2 months ago) by mlimic
File size: 7708 byte(s)
Envoi des messages: "ERP qualifie", "Demande d'ouverture ERP DAT", et "Depot de dossier DAT". Ajout des lignes dans table nature


1 mlimic 806 <?php
2    
3    
4 mlimic 834 require_once('vendor/autoload.php');
5 mlimic 806 use PhpAmqpLib\Connection\AMQPConnection;
6     use PhpAmqpLib\Message\AMQPMessage;
7    
8 mlimic 827 (defined("DEBUG") ? "" : define("DEBUG", EXTRA_VERBOSE_MODE));
9    
10     // pour des besoins de logging il faut setter $_SERVER["REQUEST_URI"]
11     if (!isset($_SERVER["REQUEST_URI"])) {
12     $_SERVER["REQUEST_URI"] = __FILE__;
13     }
14    
15     // Si le AMQP_DEBUG est defini a true, les messages DEBUG sont envoyes aux
16 mlimic 834 // stdout ce qui peut etre bien pour deboguer
17 mlimic 827 if (DEBUG > PRODUCTION_MODE) {
18     define('AMQP_DEBUG', true);
19     }
20    
21 mlimic 806
22 mlimic 829 class MessageEnqueuer {
23 mlimic 806
24     public static $ERP_DEMANDE_COMPLETUDE_PC = 'erpDemandeCompletudePc';
25     public static $ERP_QUALIFIE = 'erpQualifie';
26     public static $ERP_DEMANDE_QUALIFICATION_PC = 'erpDemandeQualificationPc';
27     public static $ERP_DEMANDE_INSTRUCTION_PC = 'erpDemandeInstructionPc';
28     public static $ERP_CONSULTATION_CONFORMITE = 'erpConsultationConformite';
29     public static $ERP_DEMANDE_OUVERTURE_PC = 'erpDemandeOuverturePc';
30     public static $ERP_DEPOT_DOSSIER_DAT = 'erpDepotDossierDat';
31     public static $ERP_ANNULATION_DEMANDE = 'erpAnnulationDemande';
32     public static $ERP_DEMANDE_OUVERTURE_DAT = 'erpDemandeOuvertureDat';
33     public static $ERP_DECISION_CONFORMITE_EFFECTUE = 'erpDecisionConformiteEffectue';
34 mlimic 810 public static $ERP_ARRETE_PC_EFFECTUE = 'erpArretePcEffectue';
35 mlimic 806
36     var $BAD_DATA = -2;
37     var $OK = 0;
38     var $KO = -1;
39    
40    
41     public function __construct() {
42 mlimic 834 include_once('../dyn/services.inc.php');
43 mlimic 806 $this->ret_array = array();
44     $this->ret_array['date'] = date('d/m/Y H:i');
45 mlimic 830 $this->ret_array['emetteur'] = $_SESSION['login'];
46 mlimic 806 $this->dossier_instruction = null;
47     $this->competence = null;
48     $this->contrainte_plu = null;
49 mlimic 810 $this->consultation = null;
50 mlimic 811 $this->decision = null;
51 mlimic 851 $this->reference_cadastrale = null;
52 mlimic 806
53     // les donnees de la connexion
54 mlimic 830 $this->queue = $ERP_QUEUE;
55     $this->host = $ERP_CONNECTION_HOST;
56     $this->port = $ERP_CONNECTIOn_PORT;
57     $this->user = $ERP_CONNECTION_USER;
58     $this->password = $ERP_CONNECTION_PASSWORD;
59     $this->vhost = $ERP_CONNECTION_VHOST;
60 mlimic 806 }
61    
62    
63     /**
64     * Precondition: $msg_type est egal a valeur d'une des $ERP_*
65     */
66 mlimic 829 public function enqueueMessage($method) {
67 mlimic 806 if (method_exists($this, $method)) {
68     return $this->$method();
69     }
70     return $this->KO;
71     }
72    
73    
74     private function enqueueRequest() {
75     $msg_str = json_encode($this->ret_array);
76    
77     if ($msg_str === false) {
78     return $this->KO;
79     }
80    
81     $exchange = 'router';
82     $queue = $this->queue;
83    
84     $conn = new AMQPConnection($this->host, $this->port, $this->user,
85     $this->password, $this->vhost);
86     $ch = $conn->channel();
87     if (is_null($ch)) {
88     return -1;
89     }
90    
91     $ch->queue_declare($queue, false, true, false, false);
92    
93     $ch->exchange_declare($exchange, 'direct', false, true, false);
94    
95     $ch->queue_bind($queue, $exchange);
96    
97 mlimic 811 $msg = new AMQPMessage($msg_str,
98 mlimic 806 array('content_type' => 'text/plain', 'delivery_mode' => 2));
99     $ch->basic_publish($msg, $exchange);
100    
101     $ch->close();
102     $conn->close();
103    
104 mlimic 827 // log le message qui etait mis sur la pile dans RabbitMQ
105     logger::instance()->log("Ajout du message sur pile: ".
106     json_encode($this->ret_array), EXTRA_VERBOSE_MODE);
107    
108 mlimic 806 return 0;
109     }
110    
111    
112     public function setDossierInstructionIdentifier($id) {
113     $this->dossier_instruction = $id;
114     }
115    
116    
117     public function setCompetence($competence) {
118     $this->competence = $competence;
119 mlimic 851 if (is_null($this->competence)) {
120     $this->competence = "";
121     }
122 mlimic 806 }
123    
124    
125     public function setContraintePlu($contrainte_plu) {
126     $this->contrainte_plu = $contrainte_plu;
127 mlimic 851 if (is_null($this->contrainte_plu)) {
128     $this->contrainte_plu = "";
129     }
130 mlimic 806 }
131    
132    
133 mlimic 810 public function setConsultationIdentifier($id) {
134     $this->consultation = $id;
135     }
136 mlimic 811
137    
138     public function setDecision($decision) {
139     $this->decision = $decision;
140 mlimic 851 if (is_null($this->decision)) {
141     $this->decision = "";
142     }
143 mlimic 811 }
144 mlimic 851
145    
146     public function setReferenceCadastrale($ref_cad) {
147     $this->reference_cadastrale = $ref_cad;
148     if (is_null($this->reference_cadastrale)) {
149     $this->reference_cadastrale = "";
150     }
151     }
152 mlimic 810
153 mlimic 811
154     private function generic($msg_type, $contenu_keys = null) {
155     $this->ret_array["type"] = $msg_type;
156     if (is_null($this->dossier_instruction)) {
157     // manque des donnees
158     return $this->BAD_DATA;
159     }
160     $this->ret_array['date'] = date('d/m/Y H:i');
161     $this->ret_array['emetteur'] = $_SESSION['login'];
162     $this->ret_array['dossier_instruction'] = $this->dossier_instruction;
163    
164     if (!is_null($contenu_keys)) {
165 mlimic 810 $contenu = array();
166 mlimic 811 foreach ($contenu_keys as $attrib) {
167 mlimic 810 if (is_null($this->$attrib)) {
168     return $this->BAD_DATA;
169     }
170     $contenu[$attrib] = $this->$attrib;
171     }
172     $this->ret_array['contenu'] = $contenu;
173     }
174     return $this->enqueueRequest();
175 mlimic 806 }
176    
177 mlimic 811
178 mlimic 810 private function erpQualifie() {
179 mlimic 811 $contenu_keys = array('competence',
180 mlimic 851 'contrainte_plu',
181     'reference_cadastrale');
182 mlimic 811 return $this->generic('ERP Qualifié',
183     $contenu_keys);
184 mlimic 810 }
185 mlimic 806
186 mlimic 810
187 mlimic 806 private function erpDemandeCompletudePc() {
188 mlimic 810 return $this->generic('Demande de complétude dossier ERP');
189 mlimic 806 }
190    
191 mlimic 810
192     private function erpDemandeQualificationPc() {
193     return $this->generic('Demande de qualification ERP');
194     }
195    
196    
197     private function erpDemandeInstructionPc() {
198     if (is_null($this->consultation)) {
199     return $this->BAD_DATA;
200     }
201 mlimic 811 //$this->ret_array['type'] = 'Demande d\'avis de dossier PC pour un ERP';
202 mlimic 810 $this->ret_array['consultation'] = $this->consultation;
203 mlimic 811 return $this->generic('Demande d\'avis de dossier PC pour un ERP');
204 mlimic 810 }
205    
206    
207     private function erpArretePcEffectue() {
208 mlimic 811 if (is_null($this->dossier_instruction)
209     || is_null($this->decision)) {
210     // manque des donnees
211     return $this->BAD_DATA;
212     }
213     return $this->generic('Arrêté PC effectué',
214     array('decision'));
215 mlimic 810 }
216    
217 mlimic 811
218     private function erpConsultationConformite() {
219     if (is_null($this->consultation)) {
220     return $this->BAD_DATA;
221     }
222     $this->ret_array['consultation'] = $this->consultation;
223     return $this->generic('Consultation ERP pour conformité');
224     }
225    
226    
227     private function erpDemandeOuverturePc() {
228     return $this->generic('Demande d\'ouverture ERP PC');
229     }
230    
231    
232     private function erpDepotDossierDat() {
233     return $this->generic('Dépôt de dossier DAT');
234     }
235    
236    
237     public function erpAnnulationDemande() {
238     return $this->generic('Annulation de la demande');
239     }
240    
241    
242     public function erpDemandeOuvertureDat() {
243     return $this->generic('Demande d\'ouverture ERP DAT');
244     }
245    
246    
247     public function erpDecisionConformiteEffectue() {
248     return $this->generic('Décision de conformité effectuée');
249     }
250 mlimic 806 }
251    
252     ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26