View Javadoc

1   /**
2    * 
3    */
4   package net.sf.provisioner.requests;
5   
6   
7   import java.util.Date;
8   import java.util.Enumeration;
9   import java.util.Iterator;
10  import java.util.List;
11  import java.util.regex.Matcher;
12  import java.util.regex.Pattern;
13  
14  import net.sf.provisioner.IntrawayWSDL.IntrawayWSDLPortTypeProxy;
15  import net.sf.provisioner.IntrawayWSDL_pkg.InterfaceObjInput;
16  import net.sf.provisioner.IntrawayWSDL_pkg.InterfaceObjOutput;
17  import net.sf.provisioner.responses.Response;
18  
19  import org.jdom.Element;
20  import org.jdom.Document;
21  
22  
23  /**
24   * Esta clase es .
25   * <p>
26   * 
27   * .
28   * <p>
29   * 
30   *             
31   * @version $Revision: 1.1.2.1 $, $Date: 2007/11/12 01:57:25 $
32   * @author Gonzalo Espert
33   */
34  public class IntrawayRequest extends Request {
35  
36  	private InterfaceObjInput request = new InterfaceObjInput();
37  		
38  	String operation = new String();
39  	/**
40       * .
41       * <p>
42       * 
43       * .
44       * <p>
45       * 
46       * 
47       * 
48       * @param 
49       *            
50       * @throws 
51       *            
52       *           
53       */
54  	public IntrawayRequest(net.sf.provisioner.config.ConfigRequest request, Document parameters) {
55      	
56  		this.operation = request.operationType;
57  		_initRequest(parameters);
58  		this.ne = request.service.ne;
59  		
60  	}
61  
62  	/**
63       * .
64       * <p>
65       * 
66       * .
67       * <p>
68       * 
69       * 
70       * 
71       * @param 
72       *            
73       * @throws 
74       *            
75       *           
76       */
77  	InterfaceObjInput _initRequestClient(Document parameters, String status) {
78  		
79  		String xmlEncoding = "<handleClient>";
80  		String paramName;
81  		
82  		// Static parameters
83      	String idVenta = "0", idVentaPadre = "0", idServicio = "0", empresa = "";
84      	String idProducto = "0", idCliente = "0", idServicioPadre = "0", idProductoPadre = "0", idPromotor = "0";
85      	
86      	List children = parameters.getContent();  
87  	    Iterator iterator = children.iterator();
88  	    while (iterator.hasNext()) {
89  	      Element child = (Element) iterator.next();
90  	      if (child.getName().equalsIgnoreCase("operation")) {
91  	    	  List children1 = child.getChildren();
92  	    	  Iterator iterator1 = children1.iterator();
93  	    	  while (iterator1.hasNext()) {
94  	    		  Element child1 = (Element) iterator1.next();
95  	    		  if (child1.getName().equalsIgnoreCase("parameter")) {
96  	    			  paramName = child1.getAttributeValue("name");
97  	    		      	if (paramName.equalsIgnoreCase("nombre_cliente")) xmlEncoding = xmlEncoding + "<Nombre>" + child1.getAttributeValue("value") + "</Nombre>";
98  	    		      	else if (paramName.equalsIgnoreCase("username")) xmlEncoding = xmlEncoding + "<Username>" + child1.getAttributeValue("value") + "</Username>";
99  	    		      	else if (paramName.equalsIgnoreCase("contrasena")) xmlEncoding = xmlEncoding + "<Contraseņa>" + child1.getAttributeValue("value") + "</Contraseņa>";
100 	    		      	else if (paramName.equalsIgnoreCase("tipo_cliente")) xmlEncoding = xmlEncoding + "<idTipoCliente>" + child1.getAttributeValue("value") + "</idTipoCliente>";
101 	    		      	else if (paramName.equalsIgnoreCase("numero_cliente")) idCliente = child1.getAttributeValue("value");
102 	    		      	else if (paramName.equalsIgnoreCase("email_noticias")) xmlEncoding = xmlEncoding + "<emailNoticias>" + child1.getAttributeValue("value") + "</emailNoticias>";
103 	    		      	else if (paramName.equalsIgnoreCase("empresa")) empresa = child1.getAttributeValue("value");
104 	    		      	else if (paramName.equalsIgnoreCase("idVenta")) idVenta = child1.getAttributeValue("value");
105 	    		      	else if (paramName.equalsIgnoreCase("idVentaPadre")) idVentaPadre = child1.getAttributeValue("value");
106 	    		      	else if (paramName.equalsIgnoreCase("idServicio")) idServicio = child1.getAttributeValue("value");
107 	    		      	else if (paramName.equalsIgnoreCase("idProducto")) idProducto = child1.getAttributeValue("value");
108 	    		      	else if (paramName.equalsIgnoreCase("idServicioPadre")) idServicioPadre = child1.getAttributeValue("value");
109 	    		      	else if (paramName.equalsIgnoreCase("idProductoPadre")) idProductoPadre = child1.getAttributeValue("value");
110 	    		      	else if (paramName.equalsIgnoreCase("idPromotor")) idPromotor = child1.getAttributeValue("value");
111 	    		  }
112 	    	  }
113 	      }
114 	    }
115     	 
116     	xmlEncoding = xmlEncoding + "</handleClient>";
117     				  
118     	Long timeStamp = new Date().getTime(); 
119     	
120     	return new InterfaceObjInput(timeStamp.toString(),
121     								 "500", // Customer management
122     								 status, // 1 Create, 2 Modification
123     								 "0",
124     								 "",
125     								 idCliente,
126     								 empresa,
127     								 idVenta,
128     								 idVentaPadre,
129     								 idServicio,
130     								 idProducto,
131     								 idServicioPadre,
132     								 idProductoPadre,
133     								 idPromotor,
134     								 xmlEncoding);
135 		
136 	}
137 	
138 	/**
139      * .
140      * <p>
141      * 
142      * .
143      * <p>
144      * 
145      * 
146      * 
147      * @param 
148      *            
149      * @throws 
150      *            
151      *           
152      */
153 	InterfaceObjInput _initRequestSpace(Document parameters, String status) {
154 	
155 		String xmlEncoding  = "<handleClient>";
156     	String paramName;
157     	
158     	// Static parameters
159     	String idVenta = "0", idVentaPadre = "0", idServicio = "0", empresa = "";
160     	String idProducto = "0", idCliente = "0", idServicioPadre = "0", idProductoPadre = "0", idPromotor = "0";
161     	
162     	List children = parameters.getContent();  
163 	    Iterator iterator = children.iterator();
164 	    while (iterator.hasNext()) {
165 	      Element child = (Element) iterator.next();
166 	      if (child.getName().equalsIgnoreCase("operation")) {
167 	    	  List children1 = child.getChildren();
168 	    	  Iterator iterator1 = children1.iterator();
169 	    	  while (iterator1.hasNext()) {
170 	    		  Element child1 = (Element) iterator1.next();
171 	    		  if (child1.getName().equalsIgnoreCase("parameter")) {
172 	    			  paramName = child1.getAttributeValue("name");
173 	    		      if (paramName.equalsIgnoreCase("ServicePackageCRMID")) xmlEncoding = xmlEncoding + "<ServicePackageCRMID>" + child1.getAttributeValue("value") + "</ServicePackageCRMID>";
174 	    		      else if (paramName.equalsIgnoreCase("Hub")) xmlEncoding = xmlEncoding + "<Hub>" + child1.getAttributeValue("value") + "</Hub>";
175 	    		      else if (paramName.equalsIgnoreCase("Nodo")) xmlEncoding = xmlEncoding + "<Nodo>" + child1.getAttributeValue("value") + "</Nodo>";
176 	    		      else if (paramName.equalsIgnoreCase("idIspCPECrmId")) xmlEncoding = xmlEncoding + "<idIspCPECrmId>" + child1.getAttributeValue("value") + "</idIspCPECrmId>";
177 	    		      else if (paramName.equalsIgnoreCase("idIspCmCrmId")) xmlEncoding = xmlEncoding + "<idIspCmCrmId>" + child1.getAttributeValue("value") + "</idIspCmCrmId>";
178 	    		      else if (paramName.equalsIgnoreCase("idIspMtaCrmId")) xmlEncoding = xmlEncoding + "<idIspMtaCrmId>" + child1.getAttributeValue("value") + "</idIspMtaCrmId>";
179 	    		      else if (paramName.equalsIgnoreCase("DocsisVersion")) xmlEncoding = xmlEncoding + "<DocsisVersion>" + child1.getAttributeValue("value") + "</DocsisVersion>";
180 	    		      else if (paramName.equalsIgnoreCase("EnableAccounting")) xmlEncoding = xmlEncoding + "<EnableAccounting>" + child1.getAttributeValue("value") + "</EnableAccounting>";
181 	    		      else if (paramName.equalsIgnoreCase("ProductName")) xmlEncoding = xmlEncoding + "<ProductName>" + child1.getAttributeValue("value") + "</ProductName>";
182 	    		      else if (paramName.equalsIgnoreCase("BandPackageCRMId")) xmlEncoding = xmlEncoding + "<BandPackageCRMId>" + child1.getAttributeValue("value") + "</BandPackageCRMId>";
183 	    		      else if (paramName.equalsIgnoreCase("PrepaidPolicyCrmId")) xmlEncoding = xmlEncoding + "<PrepaidPolicyCrmId>" + child1.getAttributeValue("value") + "</PrepaidPolicyCrmId>";
184 	    		      else if (paramName.equalsIgnoreCase("numero_cliente")) idCliente = child1.getAttributeValue("value");
185 	    		      else if (paramName.equalsIgnoreCase("idIspCRM")) xmlEncoding = xmlEncoding + "<idIspCRM>" + child1.getAttributeValue("value") + "</idIspCRM>";
186 	    		      else if (paramName.equalsIgnoreCase("BuscarTagCM")) xmlEncoding = xmlEncoding + "<BuscarTagCM>" + child1.getAttributeValue("value") + "</BuscarTagCM>";
187 	    		      else if (paramName.equalsIgnoreCase("CantidadPCs")) xmlEncoding = xmlEncoding + "<CantCPE>" + child1.getAttributeValue("value") + "</CantCPE>";
188 	    		      else if (paramName.equalsIgnoreCase("empresa")) empresa = child1.getAttributeValue("value");
189 	    		      else if (paramName.equalsIgnoreCase("idVenta")) idVenta = child1.getAttributeValue("value");
190 	    		      else if (paramName.equalsIgnoreCase("idVentaPadre")) idVentaPadre = child1.getAttributeValue("value");
191 	    		      else if (paramName.equalsIgnoreCase("idServicio")) idServicio = child1.getAttributeValue("value");
192 	    		      else if (paramName.equalsIgnoreCase("idProducto")) idProducto = child1.getAttributeValue("value");
193 	    		      else if (paramName.equalsIgnoreCase("idServicioPadre")) idServicioPadre = child1.getAttributeValue("value");
194 	    		      else if (paramName.equalsIgnoreCase("idProductoPadre")) idProductoPadre = child1.getAttributeValue("value");
195 	    		      else if (paramName.equalsIgnoreCase("idPromotor")) idPromotor = child1.getAttributeValue("value");
196 	    		  }
197 	    	  }
198 	      }
199 	    }
200     	 
201     	xmlEncoding = xmlEncoding + "</handleClient>";
202     				  
203     	Long timeStamp = new Date().getTime(); 
204     	
205     	return new InterfaceObjInput(timeStamp.toString(),
206     								 "620", // Internet spaces management
207     								 status, // 1 Create, 2 Modification with activation, 0 Delete, 4 Deactivate
208     								 "0",
209     								 "",
210     								 idCliente,
211     								 empresa,
212     								 idVenta,
213     								 idVentaPadre,
214     								 idServicio,
215     								 idProducto,
216     								 idServicioPadre,
217     								 idProductoPadre,
218     								 idPromotor,
219     								 xmlEncoding);
220 	}
221 	
222 	/**
223      * .
224      * <p>
225      * 
226      * .
227      * <p>
228      * 
229      * 
230      * 
231      * @param 
232      *            
233      * @throws 
234      *            
235      *           
236      */
237 	InterfaceObjInput _initRequestModem(Document parameters, String status) {
238 		
239 		String xmlEncoding = "<handleClient>";
240 		String paramName;
241 		
242 		// Static parameters
243     	String idVenta = "0", idVentaPadre = "0", idServicio = "0", empresa = "";
244     	String idProducto = "0", idCliente = "0", idServicioPadre = "0", idProductoPadre = "0", idPromotor = "0";
245     	
246     	List children = parameters.getContent();  
247 	    Iterator iterator = children.iterator();
248 	    while (iterator.hasNext()) {
249 	      Element child = (Element) iterator.next();
250 	      if (child.getName().equalsIgnoreCase("operation")) {
251 	    	  List children1 = child.getChildren();
252 	    	  Iterator iterator1 = children1.iterator();
253 	    	  while (iterator1.hasNext()) {
254 	    		  Element child1 = (Element) iterator1.next();
255 	    		  if (child1.getName().equalsIgnoreCase("parameter")) {
256 	    			  paramName = child1.getAttributeValue("name");
257 	    		      if (paramName.equalsIgnoreCase("mac_address")) xmlEncoding = xmlEncoding + "<MacAddress>" + child1.getAttributeValue("value") + "</MacAddress>";
258 	    		      else if (paramName.equalsIgnoreCase("numero_cliente")) idCliente = child1.getAttributeValue("value");
259 	    		      else if (paramName.equalsIgnoreCase("empresa")) empresa = child1.getAttributeValue("value");
260 	    		      else if (paramName.equalsIgnoreCase("idVenta")) idVenta = child1.getAttributeValue("value");
261 	    		      else if (paramName.equalsIgnoreCase("idVentaPadre")) idVentaPadre = child1.getAttributeValue("value");
262 	    		      else if (paramName.equalsIgnoreCase("idServicio")) idServicio = child1.getAttributeValue("value");
263 	    		      else if (paramName.equalsIgnoreCase("idProducto")) idProducto = child1.getAttributeValue("value");
264 	    		      else if (paramName.equalsIgnoreCase("idServicioPadre")) idServicioPadre = child1.getAttributeValue("value");
265 	    		      else if (paramName.equalsIgnoreCase("idProductoPadre")) idProductoPadre = child1.getAttributeValue("value");
266 	    		      else if (paramName.equalsIgnoreCase("idPromotor")) idPromotor = child1.getAttributeValue("value");
267 	    		  }
268 	    	  }
269 	      }
270 	    }
271     	
272     	xmlEncoding = xmlEncoding + "</handleClient>";
273     				  
274     	Long timeStamp = new Date().getTime(); 
275     	
276     	return new InterfaceObjInput(timeStamp.toString(),
277     								 "622", // Modems management
278     								 status, // 1 Create, 2 Modification
279     								 "0",
280     								 "",
281     								 idCliente,
282     								 empresa,
283     								 idVenta,
284     								 idVentaPadre,
285     								 idServicio,
286     								 idProducto,
287     								 idServicioPadre,
288     								 idProductoPadre,
289     								 idPromotor,
290     								 xmlEncoding);
291 	}
292 	
293 	/**
294      * .
295      * <p>
296      * 
297      * .
298      * <p>
299      * 
300      * 
301      * 
302      * @param 
303      *            
304      * @throws 
305      *            
306      *           
307      */
308 	InterfaceObjInput _initRequestPCs(Document parameters, String status) {
309 		
310 		String xmlEncoding = "<handleClient>";
311 		String paramName;
312 		
313 		// Static parameters
314     	String idVenta = "0", idVentaPadre = "0", idServicio = "0", empresa = "";
315     	String idProducto = "0", idCliente = "0", idServicioPadre = "0", idProductoPadre = "0", idPromotor = "0";
316     	
317     	List children = parameters.getContent();  
318 	    Iterator iterator = children.iterator();
319 	    while (iterator.hasNext()) {
320 	      Element child = (Element) iterator.next();
321 	      if (child.getName().equalsIgnoreCase("operation")) {
322 	    	  List children1 = child.getChildren();
323 	    	  Iterator iterator1 = children1.iterator();
324 	    	  while (iterator1.hasNext()) {
325 	    		  Element child1 = (Element) iterator1.next();
326 	    		  if (child1.getName().equalsIgnoreCase("parameter")) {
327 	    			  paramName = child1.getAttributeValue("name");
328 	    		      if (paramName.equalsIgnoreCase("CantidadPCs")) xmlEncoding = xmlEncoding + "<CantCPE>" + child1.getAttributeValue("value") + "</CantCPE>";
329 	    		      else if (paramName.equalsIgnoreCase("numero_cliente")) idCliente = child1.getAttributeValue("value");
330 	    		      else if (paramName.equalsIgnoreCase("empresa")) empresa = child1.getAttributeValue("value");
331 	    		      else if (paramName.equalsIgnoreCase("idVenta")) idVenta = child1.getAttributeValue("value");
332 	    		      else if (paramName.equalsIgnoreCase("idVentaPadre")) idVentaPadre = child1.getAttributeValue("value");
333 	    		      else if (paramName.equalsIgnoreCase("idServicio")) idServicio = child1.getAttributeValue("value");
334 	    		      else if (paramName.equalsIgnoreCase("idProducto")) idProducto = child1.getAttributeValue("value");
335 	    		      else if (paramName.equalsIgnoreCase("idServicioPadre")) idServicioPadre = child1.getAttributeValue("value");
336 	    		      else if (paramName.equalsIgnoreCase("idProductoPadre")) idProductoPadre = child1.getAttributeValue("value");
337 	    		      else if (paramName.equalsIgnoreCase("idPromotor")) idPromotor = child1.getAttributeValue("value");
338 	    		  }
339 	    	  }
340 	      }
341 	    }
342     	
343     	xmlEncoding = xmlEncoding + "</handleClient>";
344     				  
345     	Long timeStamp = new Date().getTime(); 
346     	
347     	return new InterfaceObjInput(timeStamp.toString(),
348     								 "630", // PC management
349     								 status, // 1 Create, 2 Modification
350     								 "0",
351     								 "",
352     								 idCliente,
353     								 empresa,
354     								 idVenta,
355     								 idVentaPadre,
356     								 idServicio,
357     								 idProducto,
358     								 idServicioPadre,
359     								 idProductoPadre,
360     								 idPromotor,
361     								 xmlEncoding);
362 	}
363 	
364 	/**
365      * .
366      * <p>
367      * 
368      * .
369      * <p>
370      * 
371      * 
372      * 
373      * @param 
374      *            
375      * @throws 
376      *            
377      *           
378      */
379 	void _initRequest(Document parameters) {
380 		
381 		/* Customer Operations */
382 		if (this.operation.equalsIgnoreCase("Create Customer")) 
383 			this.request = _initRequestClient(parameters, "1");
384     	else if (this.operation.equalsIgnoreCase("Change Customer")) 
385     		this.request = _initRequestClient(parameters, "2");
386     	else if (this.operation.equalsIgnoreCase("Delete Customer")) 
387     		this.request = _initRequestClient(parameters, "4");
388 
389 		/* Service Operations */
390     	else if (this.operation.equalsIgnoreCase("Assign Service")) 
391     		this.request = _initRequestSpace(parameters, "1");
392     	else if (this.operation.equalsIgnoreCase("Remove Service")) 
393     		this.request = _initRequestSpace(parameters, "0");
394     	else if (this.operation.equalsIgnoreCase("Suspend Service")) 
395     		this.request = _initRequestSpace(parameters, "4");
396     	else if (this.operation.equalsIgnoreCase("Unsuspend Service")) 
397     		this.request = _initRequestSpace(parameters, "2");
398 
399 		/* Modem Operations */
400     	else if (this.operation.equalsIgnoreCase("Assign Modem")) 
401     		this.request = _initRequestModem(parameters, "2");
402     	else if (this.operation.equalsIgnoreCase("Remove Modem")) 
403     		this.request = _initRequestModem(parameters, "2");
404 
405 		/* PCs Operations */
406     	else if (this.operation.equalsIgnoreCase("Change PCs")) 
407     		this.request = _initRequestPCs(parameters, "2");
408     	else if (this.operation.equalsIgnoreCase("Declare PCs")) 
409     		this.request = _initRequestPCs(parameters, "1");
410     	else if (this.operation.equalsIgnoreCase("Remove PCs")) 
411     		this.request = _initRequestPCs(parameters, "0");
412     	else
413     		/* Unrecognized operation */
414     		logger.error("IntrawayRequests._initRequest: operation " + this.operation + " unrecognized.");
415 	}
416 	
417 	/**
418      * .
419      * <p>
420      * 
421      * .
422      * <p>
423      * 
424      * 
425      * 
426      * @param 
427      *            
428      * @throws 
429      *            
430      *           
431      */
432 	public Response sendRequest() throws Exception {
433 		
434 		/* Input parameters */
435 		InterfaceObjInput[] arrayOfInterfaceObjInput = new InterfaceObjInput[1];
436 		arrayOfInterfaceObjInput[0] = this.request;
437 		
438 		logger.debug("Sending the following request to intraway: " );
439     	logger.debug("idEntradaCaller: " + this.request.getIdEntradaCaller());
440     	logger.debug("idInterface: " + this.request.getIdInterface());
441     	logger.debug("idEstado: " + this.request.getIdEstado());
442     	logger.debug("asyncronic: " + this.request.getAsyncronic());
443     	logger.debug("fechaDiferido: " + this.request.getFechaDiferido());
444     	logger.debug("idCliente: " + this.request.getIdCliente());
445     	logger.debug("idEmpresa: " + this.request.getIdEmpresa());
446     	logger.debug("idVenta: " + this.request.getIdVenta());
447     	logger.debug("idVentaPadre: " + this.request.getIdVentaPadre());
448     	logger.debug("idServicio: " + this.request.getIdServicio());
449     	logger.debug("idProducto: " + this.request.getIdProducto());
450     	logger.debug("idServicioPadre: " + this.request.getIdServicioPadre());
451     	logger.debug("idProductoPadre: " + this.request.getIdProductoPadre());
452     	logger.debug("idPromotor: " + this.request.getIdPromotor());
453     	logger.debug("xmlencoding: " + this.request.getXmlEncoding());
454 		
455 		/* Output parameters */
456 		InterfaceObjOutput[] interfaceObjOutput;
457 		Response response = new Response();
458 		
459 		/* Create a Proxy instance*/
460 		IntrawayWSDLPortTypeProxy IntrawayWSDLPortTypeProxyid = new IntrawayWSDLPortTypeProxy();
461 				
462 		/* Set the Web Service endpoint */
463 		IntrawayWSDLPortTypeProxyid.setEndpoint("http://" + this.ne.name + "/IntrawayWS/server.php");
464 		
465 		logger.info("Sending request to: " + "http://" + this.ne.name + "/IntrawayWS/server.php");
466 		
467 		/* Send to Intraway */
468 		try{
469 			
470 			//logger.debug("Authorisation key: " + this.ne.authKey);
471 			
472 			interfaceObjOutput = IntrawayWSDLPortTypeProxyid.put(this.ne.authKey,
473 																 arrayOfInterfaceObjInput);
474 			
475 			logger.info("Command executed at Intraway.........");
476 			
477 			if(interfaceObjOutput == null){
478 			    	
479 			    	logger.error("Call to put method returned null");
480 			    	response.successfull = false;
481 			    	response.retry = false;
482 			    	
483 			}else{
484 			    						
485 			    	String result = interfaceObjOutput[0].getIdError().toString();
486 		    		result = result + "-" + interfaceObjOutput[0].getErrorStr().toString();
487 		    		
488 		    		logger.debug("Intraway response: " + result);
489 					
490 					/* Interpret response */
491 					response = interpretResponse(result);
492 		    		
493 			}
494 
495 		} catch (Exception e) { throw e; }
496 		
497 		return response;
498 	}
499 	
500 	Response interpretResponse (String response) {
501 		
502 		Response possibleResponse = new Response();
503 		
504 		/* Match response with possible responses configured in xml file */
505 		Enumeration responses = this.ne.responses.elements();
506 		while (responses.hasMoreElements()) {
507 			possibleResponse = (Response)responses.nextElement();
508 			Pattern pattern = Pattern.compile(possibleResponse.result, Pattern.CASE_INSENSITIVE);
509 			Matcher matcher = pattern.matcher(response);
510 			if (matcher.find() && this.operation.equalsIgnoreCase(possibleResponse.tipoOperacion))
511 				return possibleResponse;
512 		}	
513 		possibleResponse.errorStr = "No match found on response file, unknown repsponse";
514 		possibleResponse.successfull = false;
515 		possibleResponse.retry = false;
516 		return possibleResponse;
517 	}
518 }