Results 1 to 9 of 9

Thread: How to get one callback from multiple soap request?

  1. #1
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default [SOLVED]How to get one callback from multiple soap request?

    The question facing is need to get a list of email addresses in the gal that the current user has special mount point permission to the inbox of the email address.

    The list of the email address can retrieve from SyncGalRequest.

    After getting the list, using GetShareInfoRequest to get the sharing right of each of the email address.

    but how to know whether the requests of GetShareInfoRequest complete?
    Last edited by hugo@dlshk; 04-23-2012 at 10:08 PM. Reason: problem solved

  2. #2
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default

    Code:
    com_project_utils_HandlerObject.prototype.GetShareInfoRequest = function(projectmail,callBackObj) {
    	var soapDoc = AjxSoapDoc.create("GetShareInfoRequest", "urn:zimbraAccount", "includeSelf=0");
    	
    	var granteeNode = soapDoc.set("grantee");
    	granteeNode.setAttribute("type", "usr");
    	
    	var ownerNode = soapDoc.set("owner",projectmail);
    	ownerNode.setAttribute("by", "name");
    	
    	var params = {
    			soapDoc: soapDoc,
    			asyncMode: true,
    			callback: (callBackObj),
    			errorCallback: (new AjxCallback(this, this._handleSOAPErrorResponseXML))
    			};
    	appCtxt.getAppController().sendRequest(params);	
    };
    The code is like that, if i want to use it in asyncMode:false, how do I get the response from GetShareInfoRequest? and the responses in asyncMode:true and asyncMode:false are the same or not?

  3. #3
    tdesorbaix is offline Zimlet Guru & Moderator
    Join Date
    Apr 2007
    Location
    Paris, France
    Posts
    365
    Rep Power
    8

    Default

    whether you use async or sync request, the content of the response will be the same.

    if you use should asyncMode:false, the code should be something like this :
    var response = appCtxt.getAppController().sendRequest(params);

  4. #4
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default

    But just use the same callback for asyncMode:true, an error appear: "t.getResponse is not a function"

    My code with using asyncMode:false is just like this:
    Code:
    com_projectapprovar_HandlerObject.prototype.checkShare = function(result) {	
    	try{
    		var response = result.getResponse().GetShareInfoResponse;
    		if (response.share != undefined){
    			var share = response.share;
    			for (var i = 0, count = share.length; i < count; i++) {			
    				alert(share[i].rights+" "+share[i].folderPath);
    			}
    		}
    	}catch(e){
    		alert("checkShare "+e.message);
    	}
    };
    below code use asyncMode:true
    Code:
    com_projectapprovar_HandlerObject.prototype.getEmailList = function(result) {
    	if (result.isException()) {
    		alert(result.getException());
    		return;
    	}
    	try{
    		var cns = result.getResponse().SyncGalResponse.cn;
    		var j = 0;
    		var email = new Array();
    		var current = "";
    		for (var i = 0, count = cns.length; i < count; i++) {
    			current = cns[i]._attrs.email;
    			if (current != this.getUsername()){
    				email[j++] = current;
    			this.checkShare(this.GetShareInfoRequest(current));
    				
    			}
    		}
    		this.emailListPopup(email.sort());
    	}catch(e){
    		alert("getEmailList "+e.message);
    	}
    };
    
    com_projectapprovar_HandlerObject.prototype.GetShareInfoRequest = function(projectmail) {
    	var soapDoc = AjxSoapDoc.create("GetShareInfoRequest", "urn:zimbraAccount", "includeSelf=0");
    	
    	var granteeNode = soapDoc.set("grantee");
    	granteeNode.setAttribute("type", "usr");
    	
    	var ownerNode = soapDoc.set("owner",projectmail);
    	ownerNode.setAttribute("by", "name");
    	
    	var params = {
    			soapDoc: soapDoc,
    			asyncMode: false
    			};
    
    	return appCtxt.getAppController().sendRequest(params);	
    };

  5. #5
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default

    Code:
    com_dlshk_projectapprovar_HandlerObject.prototype.checkShare = function(result) {
    	var d;
    	for (d in result){
    		alert(d);
    	}
    	
    	try{
    		var response = result.GetShareInfoResponse;
    		if (response.share != undefined){
    			var share = response.share;
    			for (var i = 0, count = share.length; i < count; i++) {			
    				alert(share[i].rights+" "+share[i].folderPath);
    			}
    		}
    	}catch(e){
    		alert("getEmailList "+e.message);
    	}
    };
    just using the code below, and find that there is only GetShareInfoResponse in the result object. So if using asyncMode:false, no need to use getResponse function.
    Code:
    for (d in result){
    	alert(d);
    }

  6. #6
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default

    The procedure above is really slow compare with using async mode, so I modify the code as follow: (the codes are from two js)

    Code:
    com_projectapprovar_HandlerObject.prototype.getEmailList = function(result) {
    	if (result.isException()) {
    		alert(result.getException());
    		return;
    	}
    	try{
    		var cns = result.getResponse().SyncGalResponse.cn;
    		var j = 0;
    		var currentName = "";
    		var currentId = "";
    		var response = "";
    		var userName = this.getUsername();
    		
    		for (var i = cns.length; i--;) {
    			currentName = cns[i]._attrs.email;
    			if (currentName != userName){
    				currentId = cns[i]._attrs.zimbraId;
    				this.soap.GetShareInfoRequest(currentId,true,new AjxCallback(this, this.checkShare));
    			}
    		}
    		
    	}catch(e){
    		alert("getEmailList "+e.message);
    	}
    };
    
    com_projectapprovar_HandlerObject.prototype.checkShare = function(result) {
    	if (result.isException()) {
    		alert(result.getException());
    		return;
    	}
    	try{
    		var response = result.getResponse().GetShareInfoResponse;
    		if (response.share != undefined){
    			var share = response.share;
    			var current;
    			for (var i = share.length; i--;) {	
    				current = share[i];
    				if ((current.folderPath=="/"+APPROVALFOLDERNAME)&&(current.rights.indexOf("r")==0)){					
    					this.emailFolderId.push({email:current.ownerEmail,ownerId:current.ownerId,ownerName:current.ownerName,folderId:current.folderId, rights:current.rights});
    				}
    			}
    		}
    	}catch(e){
    		alert("checkShare "+e.message);
    	}
    };
    
    com_projectapprovar_soap_HandlerObject.prototype.GetShareInfoRequest = function(val,asyncMode,callBackObj) {
    	var soapDoc = AjxSoapDoc.create("GetShareInfoRequest", "urn:zimbraAccount", "includeSelf=0");
    	
    	var granteeNode = soapDoc.set("grantee");
    	granteeNode.setAttribute("type", "usr");
    	
    	var ownerNode = soapDoc.set("owner",val);
    	ownerNode.setAttribute("by", "id");
    	
    	return this.soapRequestCore(soapDoc,asyncMode,callBackObj);
    };
    
    com_projectapprovar_soap_HandlerObject.prototype.soapRequestCore = function(soapDoc,asyncMode,callBackObj){	
    	var params = {
    			soapDoc: soapDoc,
    			asyncMode: asyncMode,
    			callback: (callBackObj),
    			errorCallback: (new AjxCallback(this, this._handleSOAPErrorResponseXML))
    			};
    	if (asyncMode){
    		appCtxt.getAppController().sendRequest(params);	
    	}else{
    		return appCtxt.getAppController().sendRequest(params);	
    	}
    }
    At the beginning, I really don't know how to handle the multiple callback from async mode, don't know how to store the result from the callback, since I really don't familiar with javascipt.

    Thanks you the guys in here point me to the right way!

  7. #7
    tdesorbaix is offline Zimlet Guru & Moderator
    Join Date
    Apr 2007
    Location
    Paris, France
    Posts
    365
    Rep Power
    8

    Default

    if you want to use async, but to get one callback for all the GetShareInfoRequest, you just need to make a batchrequest.

    And in your batchrequest, you put all the GetShareInfoRequest.

  8. #8
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default

    Thanks a lot!

  9. #9
    hugo@dlshk is offline Active Member
    Join Date
    Feb 2012
    Posts
    30
    Rep Power
    3

    Default

    The speed quite fast after change to use batch request, thanks tdesorbaix!

    Code:
    com_projectapprovar_soap_HandlerObject.prototype.BatchRequest_GetShareInfoRequest = function(ids,asyncMode,callBackObj) {
    	var soapDoc = AjxSoapDoc.create("BatchRequest", "urn:zimbra", "onerror=continue");
    	var mainNode,granteeNode,ownerNode;
    	for (var i = ids.length;i--;){
    		mainNode = soapDoc.set("GetShareInfoRequest",null,null,"urn:zimbraAccount");
    		mainNode.setAttribute("includeSelf", "0");
    		
    		granteeNode = soapDoc.set("grantee",null,mainNode);
    		granteeNode.setAttribute("type", "usr");
    	
    		ownerNode = soapDoc.set("owner",ids[i],mainNode);
    		ownerNode.setAttribute("by", "id");
    	
    	}
    	return this.soapRequestCore(soapDoc,asyncMode,callBackObj);
    };
    Code:
    com_projectapprovar_HandlerObject.prototype.getEmailList = function(result) {
    	if (result.isException()) {
    		//alert(result.getException());
    		return;
    	}
    	try{
    		var cns = result.getResponse().SyncGalResponse.cn;
    		var userName = this.getUsername();
    		var ids = [];
    		for (var i = cns.length; i--;) {
    			if (cns[i]._attrs.email != userName){
    				ids.push(cns[i]._attrs.zimbraId);
    			}
    		}
    		this.soap.BatchRequest_GetShareInfoRequest(ids,true,new AjxCallback(this, this.checkShare));
    		cns = null;
    		userName = null;
    	}catch(e){
    		alert("getEmailList "+e.message);
    	}
    };
    Code:
    com_projectapprovar_HandlerObject.prototype.checkShare = function(result) {
    	if (result.isException()) {
    		//alert(result.getException());
    		return;
    	}
    	try{
    		var response = result.getResponse().BatchResponse.GetShareInfoResponse;
    		var shares, current;
    		for (var i in response){
    			for (var j in response[i]){
    				if (response[i].share != undefined){
    					shares = response[i].share;
    					for (var k = shares.length; k--;) {	
    						current = shares[k];
    						if ((current.folderPath=="/"+APPROVALFOLDERNAME)&&(current.rights.indexOf("r")==0)){					
    							this.emailFolderId[current.ownerEmail]={email:current.ownerEmail,ownerId:current.ownerId,ownerName:current.ownerName,folderId:current.folderId, rights:current.rights,mid:current.mid};
    							ZmFolder.OUTBOUND.push(current.mid);
    						}else{
    							if ((current.folderId==6)||(current.folderId==5)){
    								ZmFolder.OUTBOUND.push(current.mid);
    							}
    						}
    					}
    				}
    			}
    		}
    		response = null;
    		shares = null;
    		current = null;
    		i = null;
    		j = null;
    		k = null;
    	}catch(e){
    		alert("checkShare "+e.message);
    	}
    };

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 06-13-2011, 11:58 AM
  2. zmzimletctl deploy zimbra_posixaccount.zip - ERROR -
    By todd_dsm in forum Administrators
    Replies: 0
    Last Post: 04-02-2009, 01:41 PM
  3. SOAP Request
    By urban@abak in forum Developers
    Replies: 15
    Last Post: 12-19-2006, 07:28 AM
  4. Problem to sync EXDATE in iCal with SOAP request
    By JackyQiu in forum Developers
    Replies: 1
    Last Post: 12-07-2006, 01:21 PM
  5. Replies: 6
    Last Post: 03-17-2006, 10:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •