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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 834 - (show annotations)
Mon Nov 26 16:45:11 2012 UTC (12 years, 2 months ago) by mlimic
File size: 7117 byte(s)
Changement du dyn/include.inc.php et service/outgoing/messageenqueuer.php pour corriger le probleme d'includes.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26