View Javadoc

1   /**
2    * This class represents .
3    * <p>
4    * 
5    * .
6    * <p>
7    * 
8    *             
9    * @version $Revision: 1.1.2.1 $, 08/10/2007
10   * @author Gonzalo Espert 
11   */
12  package net.sf.provisioner.requests;
13  
14  
15  import net.sf.provisioner.commands.SPMLADDCommand;
16  import net.sf.provisioner.responses.Response;
17  
18  import org.jdom.Document;
19  import org.jdom.Element;
20  import org.openspml.client.SpmlClient;
21  import java.util.HashMap;
22  import java.util.Iterator;
23  import java.util.List;
24  
25  import org.openspml.message.AddRequest;
26  import org.openspml.message.AddResponse;
27  
28  
29  /**
30   * @author espertgo
31   *
32   */
33  public class SPMLRequest extends Request {
34  
35  	/* Add Request command */
36  	SPMLADDCommand command = new SPMLADDCommand();
37  	
38  	protected SpmlClient client = new SpmlClient();
39  	protected AddRequest request = new AddRequest();
40  	protected HashMap userAttr = new HashMap();
41  	protected AddResponse response;
42  	protected final String url = "http://localhost:8080/lighthouse/servlet/rpcrouter2";
43  
44  	/**
45  	 * 
46  	 */
47  	public SPMLRequest(net.sf.provisioner.config.ConfigRequest request, Document parameters) {
48  
49  		try {
50  			logger.info("Creating a SPML request to add a user");
51  			_initRequest(parameters);
52  			create();
53  			logger.info("SPML request generation is complete.");
54  		} catch (Throwable addUser) {
55  			// add exception handling
56  			logger.info(addUser.toString());
57  		}
58  	}
59  
60  	
61  	/**
62       * .
63       * <p>
64       * 
65       * .
66       * <p>
67       * 
68       * 
69       * 
70       * @param 
71       *            
72       * @throws 
73       *            
74       *           
75       */
76  	void _initRequest(Document parameters) {
77  		
78  		String paramName;
79  		
80  		List children = parameters.getContent();  
81  	    Iterator iterator = children.iterator();
82  	    while (iterator.hasNext()) {
83  	      Element child = (Element) iterator.next();
84  	      if (child.getName().equalsIgnoreCase("operation")) {
85  	    	  List children1 = child.getChildren();
86  	    	  Iterator iterator1 = children1.iterator();
87  	    	  while (iterator1.hasNext()) {
88  	    		  Element child1 = (Element) iterator1.next();
89  	    		  if (child1.getName().equalsIgnoreCase("parameter")) {
90  	    			  	paramName = child1.getAttributeValue("name");
91  	    		      	if (paramName.equalsIgnoreCase("firstName")) this.command.firstName = child1.getAttributeValue("value");
92  	    		      	if (paramName.equalsIgnoreCase("lastName")) this.command.lastName = child1.getAttributeValue("value");
93  	    		      	if (paramName.equalsIgnoreCase("fullName")) this.command.fullName = child1.getAttributeValue("value");
94  	    		      	if (paramName.equalsIgnoreCase("password")) this.command.password = child1.getAttributeValue("value");
95  	    		      	if (paramName.equalsIgnoreCase("email")) this.command.email = child1.getAttributeValue("value");
96  	    		      	if (paramName.equalsIgnoreCase("identifier")) this.command.identifier = child1.getAttributeValue("value");
97  	    		  }
98  	    	  }
99  	      }
100 	    }
101 	}
102 	
103 	/**
104 	 * Create SPML request for add user
105 	 * 
106 	 * @exception Exception ex
107 	 */
108 	private void create() throws Exception {
109 		
110 		this.client.setTrace(true);
111 		this.client.setUrl(this.url);
112 		
113 		this.request.setIdentifier(this.command.identifier);
114 		this.request.setObjectClass("user");
115 		// define user attributes
116 		this.userAttr.put("password", this.command.password);
117 		this.userAttr.put("email", this.command.email);
118 		this.userAttr.put("firstname", this.command.firstName);
119 		this.userAttr.put("lastname", this.command.lastName);
120 		this.userAttr.put("fullname", this.command.fullName);
121 		this.request.setAttributes(userAttr);
122 		
123 		// generate SPML request to add user
124 		response = (AddResponse)this.client.request(request);
125 		this.client.throwErrors(response);
126 		
127 	}
128 	
129 	/* (non-Javadoc)
130 	 * @see requests.Request#sendRequest()
131 	 */
132 	@Override
133 	public Response sendRequest() throws Exception {
134 		// TODO Auto-generated method stub
135 		return null;
136 	}
137 
138 }