View Javadoc

1   /***
2    * This is the access point to MySpace
3    * @usage: create an instance of MySpaceManagerDelegate by passing targetEndPoint then call the method you desire.
4    * @author: CLQ
5    */
6   
7   package org.astrogrid.mySpace.delegate.mySpaceManager;
8   
9   import java.io.*;
10  import java.net.*;
11  import java.util.Vector;
12  import org.astrogrid.mySpace.delegate.helper.*;
13  
14  //
15  // Note: Throughout this class the acronym `MSS' denotes a MySpace System.
16  
17  public class MySpaceManagerDelegate {
18  
19      private String mssUrl = " ";       // MSS the delegate is operating on.
20      private Vector queryMssUrl = new Vector(); // Vector of MSSs to query.
21      private boolean DEBUG = true;
22     
23      private String value ="";
24  
25  //
26  // Constructors.
27  
28  /***
29   * Constructor with no arguments.  Both the MSS to operate on and the
30   * vector of MSSs to query are set to null.  These items need to be
31   * specified using the appropriate set methods before the delegate can
32   * invoke a MySpace system.
33   */
34  
35      public MySpaceManagerDelegate() {
36      }
37  
38  /***
39   * Constructor with a single argument.  This argument is the URL of the
40   * MSS which the delegate is to invoke.  The vector of MSSs to query is
41   * set to a single element vector contining this same MSS.
42   */
43  
44      public MySpaceManagerDelegate(String mssUrl) {
45          this.mssUrl = mssUrl;
46          System.out.println("initializor: mssUrl: "+mssUrl);
47          (this.queryMssUrl).add(mssUrl);
48      }    
49      
50  /***
51   * Constructor with two arguments.  The first argument is the URL of the
52   * MSS which the delegate is to invoke.  The second is a Vector
53   * containing the URLs of all the MSSs which are to be queried.
54   */
55  
56      public MySpaceManagerDelegate(String mssUrl, Vector queryMssUrl) {
57          this.mssUrl = mssUrl;
58          this.queryMssUrl = queryMssUrl;
59      }
60  
61  //
62  // Get and set methods.
63  //
64  // These method are provided to get and set the URL of the MSS to invoke
65  // and the Vector of MSSs to query.
66  
67  /***
68   * Get the URL of the current MSS.
69   */
70  
71      public String getMssUrl() {
72          return this.mssUrl;
73      }
74  
75  /***
76   * Set the URL of the MSS to invoke.
77   */
78  
79      public void   setMssUrl(String mssUrl) {
80          this.mssUrl = mssUrl;
81      }
82  
83  /***
84   * Get a Vector containing the URLs of the MSSs which are currently
85   * queried.
86   */
87  
88      public Vector getQueryMssUrl() {
89         return queryMssUrl;
90      }
91  
92  /***
93   * Specify the list of MSSs to be queried.  A Vector containing the
94   * URLs of the required MSSs is supplied.
95   *
96   * <p>
97   * There is a special syntax to indicate that all the MSS known to
98   * the AstroGrid system are to be queried.  This option is invoked
99   * by supplying a single element Vector in which the first element is
100  * a single asterisk.
101  */
102 
103     public void setQueryMssUrl(Vector queryMssUrl) throws Exception{
104         if (queryMssUrl.size() == 1) {
105             if ( ((String)queryMssUrl.elementAt(0)).equals("*") ) {
106                 this.queryMssUrl = this.getAllMssUrl();
107             }
108             else {
109                 this.queryMssUrl = queryMssUrl;
110             } 
111         }
112         else {
113             this.queryMssUrl = queryMssUrl;
114         } 
115     }
116 
117 /***
118  * Get a Vector containing the URLs of all the MSSs known to AstroGrid.
119  */
120 
121     public Vector getAllMssUrl() throws Exception {
122         Vector allMssUrls = null;
123 
124         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
125 
126         try {
127             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
128               new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator()
129                 .getMySpaceManager(new java.net.URL(mssUrl));
130         }
131         catch (javax.xml.rpc.ServiceException jre) {
132             if(jre.getLinkedCause()!=null)
133                 jre.getLinkedCause().printStackTrace();
134         }
135         
136         try{
137         	System.out.println("before call getServerURLs");
138            allMssUrls  = binding.getServerURLs();
139            
140 		   System.out.println("after call getServerURLs  "+allMssUrls.size());
141 		   for (int i=0;i<allMssUrls.size(); i++)
142 		   {
143 		   	System.out.println("after... "+allMssUrls.elementAt(i));
144 		   }
145         }catch(java.rmi.RemoteException re) {
146            re.printStackTrace();
147         }
148 
149         return allMssUrls;
150     }    
151 
152 //
153 // --------------------------------------------------------------------------
154 
155 //
156 // Action methods.
157 //
158 // The following methods invoke an MSS to perform some action.  All
159 // the methods invoke a single MSS apart from
160 // <code>listDataHoldings</code> and <code>listDataHoldingsGen</code>
161 // which query a group of them.
162 
163 /***
164  * Search a list of MSSs and return the MySpace names of entries which
165  * match the query.
166  *
167  * @param userId User identifier.
168  * @param communityId Community identifier.
169  * @param query Query which MySpace names should match, eg:
170  *    /userid@communityid/server/workflows/A*
171  *
172  * @return A list of MySpace names which match the query.  Note that
173  * short (and incomplete) MySpace names are returned, with the details
174  * of their enclosing containers removed.  A Vector is returned, each
175  * element of which corresponds to one of the MSS searched.  Each of
176  * these elements is itself a Vector, whose elements are Strings
177  * containing the MySpace names which matched the query.
178  */
179  
180     public Vector listDataHoldings(String userId, String communityId, String credential,
181       String query)throws Exception {
182         Vector returnList = new Vector();
183         if (DEBUG) System.out.println("listDataholdings..."+userId +":   :"+communityId+": query:"+query);
184         try {
185             for (int loop = 0; loop<queryMssUrl.size(); loop++) {
186                 String currentResponse = this.internalDataHoldings(
187                   userId, communityId, credential, query,
188                   (String)queryMssUrl.elementAt(loop) );
189                 MySpaceHelper helper = new MySpaceHelper();
190 				if (DEBUG) System.out.println("currentResponse from internalDataHoldings: "+currentResponse);
191                 Vector currentList  = helper.getList(currentResponse, "dataItemName");
192 				if (DEBUG){ 
193 					System.out.println("size: "+currentList.size()); 
194 					for (int j=0;j<currentList.size();j++){
195 						System.out.println(" currentlist: "+currentList.elementAt(j));
196 					}
197 				}
198                 returnList.add(currentList);
199                 if (DEBUG){
200                 	for (int i=0;i<returnList.size();i++){
201                 		System.out.println("returnList from delegate: "+returnList.elementAt(i));
202                 	}
203                 }
204             }
205            
206         }catch(java.rmi.RemoteException re) {
207             re.printStackTrace();
208         }
209 
210         return returnList;
211     }        
212 
213 //
214 // --------------------------------------------------------------------------
215 
216 /***
217  * Search a list of MSSs and return the details of all the MySpace
218  * entries which match the query.  The details for each entry are
219  * a string containing XML.
220  *
221  * @param userId User identifier.
222  * @param communityId Community identifier.
223  * @param query Query which MySpace names should match, eg:
224  *    /userid@communityid/server/workflows/A*
225  *
226  * @return A list of MySpace entries which match the query.  For each
227  * matching entry an XML string containing the details is returned.
228  * A Vector is returned, each element of which corresponds to one of
229  * the MSS searched.  Each of these elements is itself a Vector,
230  * whose elements are Strings containing the details of the entry
231  *which matched the query.
232  */
233 
234     public Vector listDataHoldingsGen(String userId, String communityId, String credential,
235       String query)throws Exception {
236       	System.out.println("xxxxxxxxxxxxxxxxx");
237         Vector returnList = new Vector();
238         this.setQueryMssUrl(this.getAllMssUrl());
239         //query = "/" +userId+"@"+communityId+"/"+"*";
240         try {
241             for (int loop = 0; loop<queryMssUrl.size(); loop++) {
242             	
243 				System.out.println("before call internalDataHoldings "+ userId +"  :"+communityId +"  query: "+query);
244                 String currentResponse = this.internalDataHoldings(
245                   userId, communityId, credential, query,
246                   (String)queryMssUrl.elementAt(loop) );
247                   System.out.println("yyyyyyyy"+(String)queryMssUrl.elementAt(loop) );
248 
249                 returnList.add(currentResponse);
250             }
251            
252         }catch(java.rmi.RemoteException re) {
253             re.printStackTrace();
254         }
255 
256         return returnList;
257     }    
258     
259     public String lookupDataHoldersDetails(String jobDetails){
260     	
261     	return "";    
262     }
263 
264 //
265 // --------------------------------------------------------------------------
266 
267     /***
268      * 
269      * @param userId
270      * @param communityId
271      * @param serverFileName: full file name eg: /clq/serv1/File1.xml
272      * @return
273      * @throws Exception
274      */
275     public String listDataHolding(String userId, String communityId, String credential, String serverFileName) throws Exception {
276         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
277         try {
278             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
279                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
280         }
281         catch (javax.xml.rpc.ServiceException jre) {
282             if(jre.getLinkedCause()!=null)
283                 jre.getLinkedCause().printStackTrace();
284         }
285         
286         try{
287             MySpaceHelper helper = new MySpaceHelper();
288             String jobDetails = helper.buildListDataHolding(userId, communityId, credential, serverFileName);
289             value = binding.lookupDataHolderDetails(jobDetails);
290         }catch(java.rmi.RemoteException re) {
291                     re.printStackTrace();
292         }
293         return (String)value;
294     }    
295    
296 //
297 // --------------------------------------------------------------------------
298  
299     /***
300      * @param userId
301      * @param communityId
302      * @param serverFileName: full file name copy from
303      * @param newDataItemName: full file name copy to
304      * @return
305      * @throws Exception
306      */
307     public String copyDataHolding(String userId, String communityId, String credential, String serverFileName, String newDataItemName) throws Exception {
308         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
309         try {
310             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
311                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
312         }
313         catch (javax.xml.rpc.ServiceException jre) {
314             if(jre.getLinkedCause()!=null)
315                 jre.getLinkedCause().printStackTrace();
316         }
317         try{
318             MySpaceHelper helper = new MySpaceHelper();
319             String jobDetails = helper.buildCopy(userId, communityId, credential, serverFileName, newDataItemName);
320             value = binding.copyDataHolder(jobDetails);
321         }catch(java.rmi.RemoteException re) {
322         re.printStackTrace();
323     }
324         return (String)value;
325     }    
326     
327 //
328 // --------------------------------------------------------------------------
329 
330 /***
331  * Retrieve a copy of a dataHolder on a remote MSS and save it with a
332  * specified MySpace name on the current MSS.
333  * 
334  * @param userId User identifier.
335  * @param communityId Community identifier.
336  * @param remoteMssUrl URL of the remote MSS.
337  * @param remoteMySpaceName MySpace name of the dataHolder to be
338  *   retrieved from the remote MSS.
339  * @param newMySpaceName MySpace name for the copy of the dataHolder on
340  *   the current MSS.
341  *
342  * @return boolean; true if the copy succeeded.
343  * @throws Exception
344  */
345 
346     public boolean copyRemoteDataHolding(String userId, String communityId, String credential,
347       String remoteMssUrl, String remoteMySpaceName,
348       String newMySpaceName) throws Exception {
349         boolean isSaved = false;
350         org.astrogrid.mySpace.delegate.mySpaceManager.
351           MySpaceManagerSoapBindingStub binding = null;
352 
353 //
354 //     Set up for accessing the remote MSS.
355 
356         try {
357             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.
358               MySpaceManagerSoapBindingStub)
359               new org.astrogrid.mySpace.delegate.mySpaceManager.
360                 MySpaceManagerServiceLocator(). getMySpaceManager(
361                   new java.net.URL(remoteMssUrl));
362         }
363         catch (javax.xml.rpc.ServiceException jre) {
364             if(jre.getLinkedCause()!=null)
365                 jre.getLinkedCause().printStackTrace();
366         }
367 
368 //
369 //     Obtain the URL to access the remote dataHolder.
370 
371         String remoteURL = null;
372         try{
373             MySpaceHelper helper = new MySpaceHelper();
374             String jobDetails =
375               helper.buildDownload(userId, communityId, credential, remoteMySpaceName);
376             remoteURL = binding.exportDataHolder(jobDetails);
377         }catch(java.rmi.RemoteException re) {
378             re.printStackTrace();
379             isSaved = false;
380         }
381 
382 //
383 //     Proceed if ok.
384 
385         if (isSaved) {
386 
387 //
388 //         Set up for accessing the current MSS.
389     
390             try {
391                 binding = (org.astrogrid.mySpace.delegate.mySpaceManager.
392                   MySpaceManagerSoapBindingStub)
393                   new org.astrogrid.mySpace.delegate.mySpaceManager.
394                      MySpaceManagerServiceLocator().getMySpaceManager(
395                        new java.net.URL(mssUrl));
396             }
397             catch (javax.xml.rpc.ServiceException jre) {
398                 isSaved = false;
399                 if(jre.getLinkedCause()!=null){
400                     jre.getLinkedCause().printStackTrace();
401                 }
402             }
403 
404 //
405 //         Import the dataHolder into the current MSS.
406 
407             try{
408                 MySpaceHelper helper = new MySpaceHelper();
409                 String jobDetails = helper.buildSaveURL(userId,
410                   communityId, credential, newMySpaceName, remoteURL, " ", " ");
411                 binding.upLoadURL(jobDetails);
412                 isSaved = true;
413             }catch(java.rmi.RemoteException re) {
414                 isSaved = false;
415                 re.printStackTrace();
416             }
417         }
418         return isSaved;
419     }
420 
421 //
422 // --------------------------------------------------------------------------
423 
424     /***
425      * 
426      * @param userId
427      * @param communityId
428      * @param serverFileName: ole file full name
429      * @param newDataItemName: new file full name
430      * @return
431      * @throws Exception
432      */    
433  
434     public String renameDataHolding(String userId, String communityId, String credential, String serverFileName, String newDataItemName) throws Exception {
435         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
436         try {
437             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
438                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
439         }
440         catch (javax.xml.rpc.ServiceException jre) {
441             if(jre.getLinkedCause()!=null)
442                 jre.getLinkedCause().printStackTrace();
443         }
444 
445         try{
446             MySpaceHelper helper = new MySpaceHelper();
447             String jobDetails = helper.buildRename(userId, communityId, credential, serverFileName, newDataItemName);
448             value = binding.moveDataHolder(jobDetails);
449         }catch(java.rmi.RemoteException re) {
450                     re.printStackTrace();
451         }
452         return (String)value;
453     }    
454     
455 //
456 // --------------------------------------------------------------------------
457 
458     /***
459      * 
460      * @param userId
461      * @param communityId
462      * @param serverFileName: Full file name which you want to delete
463      * @return
464      * @throws Exception
465      */
466     public String deleteDataHolding(String userId, String communityId, String credential, String serverFileName) throws Exception {
467         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
468         try {
469             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
470                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
471         }
472         catch (javax.xml.rpc.ServiceException jre) {
473             if(jre.getLinkedCause()!=null)
474                 jre.getLinkedCause().printStackTrace();
475         }
476         
477         try{
478             MySpaceHelper helper = new MySpaceHelper();
479             String jobDetails = helper.buildDelete(userId, communityId, credential, serverFileName);
480             value = binding.deleteDataHolder(jobDetails);
481         }catch(java.rmi.RemoteException re) {
482                 re.printStackTrace();
483             }
484         return (String)value;
485     }    
486     
487 //
488 // --------------------------------------------------------------------------
489 
490     /*** saveDataHolding(upLoad),this function will save workflow/query into MySpace system.
491     * @param: userId: userid
492     * @param: communityId
493     * @param: fileName: unique file name for Workflow or Query you want to store.
494     * @param: fileContent: content of workflow or data query
495     * @param: category "WF" or "QUERY", if not set, default is "VOTable"
496     * @param: action "Overwrite" or "Append", if not set, default is "Overwrite"
497     * @return: boolean true if file successfully stored in MySapce false otherwise.
498     */
499     
500     public boolean saveDataHolding(String userId, String communityId, String credential, String fileName, String fileContent, 
501                                    String category, String action) throws Exception {
502         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
503         boolean isSaved = false;
504         try {
505             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
506                       new org.astrogrid.mySpace.delegate.mySpaceManager.
507                              MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
508         }
509         catch (javax.xml.rpc.ServiceException jre) {
510             isSaved = false;
511             if(jre.getLinkedCause()!=null){
512                 jre.getLinkedCause().printStackTrace();
513             }
514         }
515         try{
516             MySpaceHelper helper = new MySpaceHelper();
517             String jobDetails = helper.buildSave(userId, communityId, credential, fileName, fileContent, category, action);
518             binding.upLoad(jobDetails);
519             isSaved = true;
520         }catch(java.rmi.RemoteException re) {
521             isSaved = false;
522             re.printStackTrace();
523         }
524         return isSaved;
525     }
526     
527 //
528 // --------------------------------------------------------------------------
529 
530     /***
531      * saveDataHoldingURL is different from saveDataHolding since it is taking a URL where MySpace will pull the file from. 
532      * @param userId
533      * @param communityId
534      * @param fileName
535      * @param importURI - url that save the dataholding from
536      * @param category
537      * @param action
538      * @return
539      * @throws Exception
540      */
541     
542     public boolean saveDataHoldingURL(String userId, String communityId, String credential, String fileName, String importURL, 
543                                    String category, String action) throws Exception {
544         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
545         boolean isSaved = false;
546         try {
547             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
548                       new org.astrogrid.mySpace.delegate.mySpaceManager.
549                              MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
550         }
551         catch (javax.xml.rpc.ServiceException jre) {
552             isSaved = false;
553             if(jre.getLinkedCause()!=null){
554                 jre.getLinkedCause().printStackTrace();
555             }
556         }
557         try{
558             MySpaceHelper helper = new MySpaceHelper();
559             String jobDetails = helper.buildSaveURL(userId, communityId, credential, fileName, importURL, category, action);
560             System.out.println("filename: "+fileName+ "importURL: "+importURL);
561             binding.upLoadURL(jobDetails);
562             isSaved = true;
563         }catch(java.rmi.RemoteException re) {
564             isSaved = false;
565             re.printStackTrace();
566         }
567         return isSaved;
568     }
569  
570 //
571 // --------------------------------------------------------------------------
572 
573 /***
574  * Retrieve the contents of a dataHolder and supply them as the String
575  * returned by the method.
576  *
577  * @param userId User identifier.
578  * @param communityId community identifier.
579  * @param  mySpaceName MySpace name of the dataHolder whose contents are
580  *   to be retrieved.
581  *
582  * @return: A String containing the contents of the specified dataHolder.
583  */
584     public String getDataHolding(String userId, String communityId, String credential,
585       String mySpaceName) throws Exception {
586         String contents = null;
587         org.astrogrid.mySpace.delegate.mySpaceManager.
588           MySpaceManagerSoapBindingStub binding = null;
589 
590 //
591 //     Set up for accessing the current MSS.
592 
593         try {
594             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.
595               MySpaceManagerSoapBindingStub)
596               new org.astrogrid.mySpace.delegate.mySpaceManager.
597                 MySpaceManagerServiceLocator().
598                   getMySpaceManager(new java.net.URL(mssUrl));
599         }
600         catch (javax.xml.rpc.ServiceException jre) {
601             if(jre.getLinkedCause()!=null)
602                 jre.getLinkedCause().printStackTrace();
603         }
604 
605 //
606 //     Obtain the URL of the required dataHolder.
607 
608         boolean isOk = false;
609         String responsXML = " ";
610         String dataHolderUrl = " ";
611 
612         try{
613             MySpaceHelper helper = new MySpaceHelper();
614             String jobDetails = helper.buildDownload(userId,
615               communityId, credential, mySpaceName);
616 			responsXML = binding.exportDataHolder(jobDetails);
617 			System.out.println("2222jobDetails : "+responsXML);
618 			Vector dataHolderUrlReturn  = helper.getList(responsXML, "dataHolderURI");
619 			for (int i=0;i<dataHolderUrlReturn.size();i++){
620 				//System.out.println("$*********size: "+dataHolderUrlReturn.size());
621 				dataHolderUrl = (String)dataHolderUrlReturn.elementAt(i);
622 				//System.out.println("$*********elementat i:: "+dataHolderUrl);
623 			}
624 			//System.out.println("$*********** dataHolderUrl:0000000"+dataHolderUrl);
625             if (dataHolderUrl != null) {
626                isOk = true;
627             }
628         }
629         catch(java.rmi.RemoteException re) {
630             re.printStackTrace();
631         }
632 
633 //
634 //     If the URL was obtained ok then attempt to retrieve the contents.
635 
636         if (isOk) {
637             try {
638                 URL url = new URL(dataHolderUrl);
639                 //System.out.println("$*********** url: "+url);
640                 InputStream iStream = url.openStream();
641 
642                 int b;
643                 StringBuffer buffer = new StringBuffer("");
644 
645                 while( (b = iStream.read())  !=  -1) {
646                     buffer.append(b);
647                 }
648 
649                 contents = buffer.toString();
650 
651             }
652             catch (Exception re) {
653                 re.printStackTrace();
654             }
655 
656         }
657          // System.out.println("  YYYYYYYYYYYY content: "+contents);
658         return contents;
659     }        
660     
661 //
662 // --------------------------------------------------------------------------
663 
664     /***
665      * 
666      * @param userId
667      * @param communityId
668      * @param serverFileName: full file name 
669      * @param extentionPeriod: number of days you would like to extend this item
670      * @return
671      * @throws Exception
672      */
673     public String extendLease(String userId, String communityId, String credential, String serverFileName, int extentionPeriod) throws Exception {
674         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
675         try {
676             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
677                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
678         }
679         catch (javax.xml.rpc.ServiceException jre) {
680             if(jre.getLinkedCause()!=null)
681                 jre.getLinkedCause().printStackTrace();
682         }
683 
684         try{
685             MySpaceHelper helper = new MySpaceHelper();
686             String jobDetails = helper.buildExtendlease(userId, communityId, credential, serverFileName, extentionPeriod);
687             value = binding.extendLease(jobDetails);
688         }catch(java.rmi.RemoteException re) {
689                 re.printStackTrace();
690         }        
691         return (String)value;
692     }        
693 
694     
695     
696     /***
697      * 
698      * @param jobDetails: use mySpace/configFiles/MSManagerRequestTemplate.xml to create an xml String by filling in userId/communityId/jobID/serverFileName
699      * @return
700      * @throws Exception
701      */
702     
703     public String publish(String jobDetails) throws Exception {
704         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
705         try {
706             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
707                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
708         }
709         catch (javax.xml.rpc.ServiceException jre) {
710             if(jre.getLinkedCause()!=null)
711                 jre.getLinkedCause().printStackTrace();
712         }
713 
714         try{
715             value = binding.publish(jobDetails);
716         }catch(java.rmi.RemoteException re) {
717                     re.printStackTrace();
718         }
719         return (String)value;
720     }        
721     
722 //
723 // --------------------------------------------------------------------------
724 
725     /***
726      * 
727      * @param userId
728      * @param communityId
729      * @param newContainerName
730      * @return
731      */
732     public String createContainer(String userId, String communityId, String credential, String newContainerName)throws Exception {
733     //public String createFolder(String jobDetails) throws Exception {
734         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
735         try {
736             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
737                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
738         }
739         catch (javax.xml.rpc.ServiceException jre) {
740             if(jre.getLinkedCause()!=null)
741                 jre.getLinkedCause().printStackTrace();
742         }
743         try{
744             MySpaceHelper helper = new MySpaceHelper();
745             String jobDetails = helper.buildContainer(userId, communityId, credential, newContainerName);
746             value = binding.createContainer(jobDetails);
747         }catch(java.rmi.RemoteException re) {
748                 re.printStackTrace();
749             }
750         return (String)value;
751     }            
752     
753 //
754 // --------------------------------------------------------------------------
755 
756 /***
757  * Create a new user on the current MSS.
758  * 
759  * @param userId User identifier.
760  * @param servers Vector of server names on which containers will be
761  *   created for the user.
762  *
763  * @return boolean; true the user was created successfully.
764  * @throws Exception
765  */
766 
767     public boolean createUser(String userId, String communityId, String credential, Vector servers) throws Exception {
768         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
769         boolean isUserCreated = false;
770         try {
771             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
772               new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().
773                 getMySpaceManager(new java.net.URL(mssUrl));
774         }
775         catch (javax.xml.rpc.ServiceException jre) {
776             if(jre.getLinkedCause()!=null)
777                 jre.getLinkedCause().printStackTrace();
778         }
779         try{
780             isUserCreated = binding.createUser(userId, communityId, servers);
781         }catch(java.rmi.RemoteException re) {
782                 re.printStackTrace();
783             }
784         return isUserCreated;
785     }    
786     
787 //
788 // --------------------------------------------------------------------------
789 
790 /***
791  * Delete a user from the current MSS.
792  *
793  * @param userId User identifier.
794  *
795  * @return boolean; true is the user was deleted successfully.
796  * @throws Exception
797  */
798     
799     public boolean deleteUser(String userId, String communityId, String credential) throws Exception {
800         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
801         boolean isUserDeleted = false;
802         try {
803             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
804               new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().
805                 getMySpaceManager(new java.net.URL(mssUrl));
806         }
807         catch (javax.xml.rpc.ServiceException jre) {
808             if(jre.getLinkedCause()!=null)
809                 jre.getLinkedCause().printStackTrace();
810         }
811         
812         try{
813             isUserDeleted = binding.deleteUser(userId, communityId);
814         }catch(java.rmi.RemoteException re) {
815                 re.printStackTrace();
816             }
817         return isUserDeleted;
818     }        
819     
820 //
821 // --------------------------------------------------------------------------
822 
823     /***
824      * 
825      * @param dataHolderName: file working on
826      * @param newOwnerID: userId changing to
827      * @return
828      * @throws Exception
829      */
830     public String changeOwner(String userId, String communityId, String credential, String dataHolderName,String newOwnerID) throws Exception {
831         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
832         try {
833             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
834                           new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator().getMySpaceManager(new java.net.URL(mssUrl));
835         }
836         catch (javax.xml.rpc.ServiceException jre) {
837             if(jre.getLinkedCause()!=null)
838                 jre.getLinkedCause().printStackTrace();
839         }
840         try{
841             //FixME to MSManager to match these set of argument!        
842             value = binding.changeOwner(userId, communityId, dataHolderName, newOwnerID);
843             //value = binding.changeOwner(userId,communityId, dataHolderName, newOwnerID);
844         }catch(java.rmi.RemoteException re) {
845         re.printStackTrace();
846     }
847         return (String)value;
848     }        
849 
850 //
851 // ==========================================================================
852 
853     private String internalDataHoldings(String userId,
854       String communityId, String credential, String criteria, String currentURL)
855       throws Exception {
856 
857         String response = null;
858 
859         org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub binding = null;
860         try {
861             binding = (org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerSoapBindingStub)
862               new org.astrogrid.mySpace.delegate.mySpaceManager.MySpaceManagerServiceLocator()
863                 .getMySpaceManager(new java.net.URL(currentURL));
864         }
865         catch (javax.xml.rpc.ServiceException jre) {
866             if(jre.getLinkedCause()!=null)
867                 jre.getLinkedCause().printStackTrace();
868         }
869         try{
870             MySpaceHelper helper = new MySpaceHelper();
871             String jobDetails = helper.buildListDataHoldings(userId, communityId, credential, criteria);
872             response = binding.lookupDataHoldersDetails(jobDetails);
873             
874         }   
875         catch(java.rmi.RemoteException re) {
876             re.printStackTrace();
877         }
878         return response;
879     }        
880 }