1
2
3
4
5
6
7
8
9
10
11
12 package net.sf.provisioner.requests;
13
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Enumeration;
17 import java.util.regex.*;
18
19 import net.sf.provisioner.adapters.SSHAdapter;
20 import net.sf.provisioner.commands.SERCommand;
21 import net.sf.provisioner.responses.Response;
22
23 import org.jdom.Document;
24 import org.jdom.Element;
25
26
27
28
29
30
31
32 public class SERRequest extends Request {
33
34
35 SERCommand command = new SERCommand();
36
37 public SERRequest (net.sf.provisioner.config.ConfigRequest request, Document parameters) {
38
39 _initRequest(parameters);
40 this.ne = request.service.ne;
41 this.command.bin = this.ne.bin;
42 this.command.operation = request.operationType;
43
44 }
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 void _initRequest(Document parameters) {
62
63 String paramName;
64
65 List children = parameters.getContent();
66 Iterator iterator = children.iterator();
67 while (iterator.hasNext()) {
68 Element child = (Element) iterator.next();
69 if (child.getName().equalsIgnoreCase("operation")) {
70 List children1 = child.getChildren();
71 Iterator iterator1 = children1.iterator();
72 while (iterator1.hasNext()) {
73 Element child1 = (Element) iterator1.next();
74 if (child1.getName().equalsIgnoreCase("parameter")) {
75 paramName = child1.getAttributeValue("name");
76 if (paramName.equalsIgnoreCase("numero_linea")) this.command.line1.number = child1.getAttributeValue("value");
77 if (paramName.equalsIgnoreCase("numero_linea_2")) this.command.line2.number = child1.getAttributeValue("value");
78 if (paramName.equalsIgnoreCase("contrasenia")) this.command.line1.password = child1.getAttributeValue("value");
79 if (paramName.equalsIgnoreCase("contrasenia_linea_2")) this.command.line2.password = child1.getAttributeValue("value");
80 if (paramName.equalsIgnoreCase("display")) this.command.line1.display = child1.getAttributeValue("value");
81 if (paramName.equalsIgnoreCase("display_linea_2")) this.command.line2.display = child1.getAttributeValue("value");
82 if (paramName.equalsIgnoreCase("puerto_sip")) this.command.line1.puertoSIP = child1.getAttributeValue("value");
83 if (paramName.equalsIgnoreCase("puerto_sip_linea_2")) this.command.line2.puertoSIP = child1.getAttributeValue("value");
84 if (paramName.equalsIgnoreCase("call_waiting")) this.command.line1.callWaiting = child1.getAttributeValue("value");
85 if (paramName.equalsIgnoreCase("call_waiting_linea_2")) this.command.line2.callWaiting = child1.getAttributeValue("value");
86 if (paramName.equalsIgnoreCase("caller_id")) this.command.line1.callerID = child1.getAttributeValue("value");
87 if (paramName.equalsIgnoreCase("caller_id_linea_2")) this.command.line2.callerID = child1.getAttributeValue("value");
88 if (paramName.equalsIgnoreCase("conference")) this.command.line1.conference = child1.getAttributeValue("value");
89 if (paramName.equalsIgnoreCase("conference_linea_2")) this.command.line2.conference = child1.getAttributeValue("value");
90 if (paramName.equalsIgnoreCase("voice_mail")) this.command.line1.voiceMail = child1.getAttributeValue("value");
91 if (paramName.equalsIgnoreCase("voice_mail_linea_2")) this.command.line2.voiceMail = child1.getAttributeValue("value");
92 if (paramName.equalsIgnoreCase("voice_mail_on_busy")) this.command.line1.voiceMailOnBusy = child1.getAttributeValue("value");
93 if (paramName.equalsIgnoreCase("voice_mail_on_busy_linea_2")) this.command.line2.voiceMailOnBusy = child1.getAttributeValue("value");
94 if (paramName.equalsIgnoreCase("call_forward")) this.command.line1.callForward = child1.getAttributeValue("value");
95 if (paramName.equalsIgnoreCase("call_forward_linea_2")) this.command.line2.callForward = child1.getAttributeValue("value");
96 if (paramName.equalsIgnoreCase("bloqueo_solo_sip")) this.command.line1.bloqueoSoloSip = child1.getAttributeValue("value");
97 if (paramName.equalsIgnoreCase("bloqueo_solo_sip_linea_2")) this.command.line2.bloqueoSoloSip = child1.getAttributeValue("value");
98 if (paramName.equalsIgnoreCase("mac_address")) this.command.macAddress = child1.getAttributeValue("value");
99 if (paramName.equalsIgnoreCase("puerto_rtp_minimo")) this.command.puertoRTPminimo = child1.getAttributeValue("value");
100 if (paramName.equalsIgnoreCase("puerto_rtp_maximo")) this.command.puertoRTPmaximo = child1.getAttributeValue("value");
101 if (paramName.equalsIgnoreCase("tipo_dispositivo")) this.command.tipoDispositivo = child1.getAttributeValue("value");
102 if (paramName.equalsIgnoreCase("tipo_bloqueo")) this.command.block = child1.getAttributeValue("value");
103 }
104 }
105 }
106 }
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 public Response sendRequest() throws Exception {
125
126 Response response = new Response();
127
128 String command = null;
129
130 SSHAdapter ser = new SSHAdapter(this.ne);
131
132
133 if (this.command.operation.equalsIgnoreCase("Create")) command = buildCreateCommand();
134
135 else if (this.command.operation.equalsIgnoreCase("Delete")) command = buildDeleteCommand();
136
137 else if (this.command.operation.equalsIgnoreCase("Disable")) command = buildSuspendCommand();
138
139 else if (this.command.operation.equalsIgnoreCase("Enable")) command = buildUnsuspendCommand();
140
141
142 try {
143
144
145 String respuesta = ser.ExecuteCommand(command);
146
147 logger.debug(respuesta);
148
149
150 response = interpretaRespuesta(respuesta);
151
152 } catch (Exception e) { throw e; }
153
154 return response;
155 }
156
157 Response interpretaRespuesta (String respuesta) {
158
159 Response posibleRespuesta = new Response();
160
161
162 Enumeration respuestas = this.ne.responses.elements();
163 while (respuestas.hasMoreElements()) {
164 posibleRespuesta = (Response)respuestas.nextElement();
165 Pattern pattern = Pattern.compile(posibleRespuesta.result, Pattern.CASE_INSENSITIVE);
166 Matcher matcher = pattern.matcher(respuesta);
167 if (matcher.find() && this.command.operation.equalsIgnoreCase(posibleRespuesta.tipoOperacion))
168 return posibleRespuesta;
169 }
170 posibleRespuesta.errorStr = "No match found in response configuration file";
171 posibleRespuesta.successfull = false;
172 posibleRespuesta.retry = false;
173 return posibleRespuesta;
174 }
175
176 String buildDeleteCommand() {
177
178
179 String command = this.command.bin + this.ne.delete;
180 command = command + " \"" + this.command.line1.number + "\"";
181
182 return command;
183 }
184
185 String buildSuspendCommand() {
186
187
188 String command = this.command.bin + this.ne.disable;
189 command = command + " \"" + this.command.line1.number + "\"";
190 command = command + " \"" + this.command.block + "\"";
191
192 return command;
193 }
194
195 String buildUnsuspendCommand() {
196
197
198 String command = this.command.bin + this.ne.enable;
199 command = command + " \"" + this.command.line1.number + "\"";
200 command = command + " \"" + this.command.block + "\"";
201
202 return command;
203 }
204
205 String buildCreateCommand() {
206
207
208
209 String command = this.command.bin + this.ne.create;
210 command = command + " \"" + this.command.line1.number + "\"";
211 if (this.command.line1.password != null)
212 command = command + " \"" + this.command.line1.password + "\"";
213 else
214 command = command + " \"\"";
215 if (this.command.line1.display != null)
216 command = command + " \"" + this.command.line1.display + "\"";
217 else
218 command = command + " \"\"";
219 command = command + " \"" + this.command.line2.number + "\"";
220 if (this.command.line2.password != null)
221 command = command + " \"" + this.command.line2.password + "\"";
222 else
223 command = command + " \"\"";
224 if (this.command.line2.display != null)
225 command = command + " \"" + this.command.line2.display + "\"";
226 else
227 command = command + " \"\"";
228 command = command + " \"" + this.command.macAddress + "\"";
229 if (this.command.line1.puertoSIP != null)
230 command = command + " \"" + this.command.line1.puertoSIP + "\"";
231 else
232 command = command + " \"\"";
233 if (this.command.line2.puertoSIP != null)
234 command = command + " \"" + this.command.line2.puertoSIP + "\"";
235 else
236 command = command + " \"\"";
237 if (this.command.puertoRTPminimo != null)
238 command = command + " \"" + this.command.puertoRTPminimo + "\"";
239 else
240 command = command + " \"\"";
241 if (this.command.puertoRTPmaximo != null)
242 command = command + " \"" + this.command.puertoRTPmaximo + "\"";
243 else
244 command = command + " \"\"";
245
246 command = command + " \"" + this.command.line1.callWaiting + "\"";
247 command = command + " \"" + this.command.line1.callerID + "\"";
248 command = command + " \"" + this.command.line1.conference + "\"";
249 command = command + " \"" + this.command.line2.callWaiting + "\"";
250 command = command + " \"" + this.command.line2.callerID + "\"";
251 command = command + " \"" + this.command.line2.conference + "\"";
252 command = command + " \"" + this.command.line1.voiceMail + "\"";
253 command = command + " \"" + this.command.line2.voiceMail + "\"";
254 command = command + " \"" + this.command.line1.voiceMailOnBusy + "\"";
255 command = command + " \"" + this.command.line2.voiceMailOnBusy + "\"";
256 command = command + " \"" + this.command.tipoDispositivo + "\"";
257 command = command + " \"" + this.command.line1.callForward + "\"";
258 command = command + " \"" + this.command.line2.callForward + "\"";
259 command = command + " \"" + this.command.line1.bloqueoSoloSip + "\"";
260 command = command + " \"" + this.command.line2.bloqueoSoloSip + "\"";
261
262 return command;
263 }
264 }