Hi,

I have tried to add multiple ACL entries for a Google spread sheet. And I 
tried with Thread pool executor..

But after finished , while checking the Google spread sheet ACL entries 
in Google UI , only few of the entries are there. Some of the entries are 
missing..

Below the full code has been attached.. 

Don't know how to fix this ..

Any suggestion would be appreciated..  Kindly help me as soon as possible.. 
Since it is really blocking one for me..


Thanks & Regards

Senthilkumar

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.google.gdata.client.docs.DocsService;
import com.google.gdata.data.acl.AclEntry;
import com.google.gdata.data.acl.AclRole;
import com.google.gdata.data.acl.AclScope;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;


public class CreateAcl {

public static void main(String args[]) {
 CreateACLThreadPool threadPool = new CreateACLThreadPool();
threadPool.addUsers();
threadPool.waitUntilProcessingThreadCompletes();
System.out.println("Add acl execution finished...");
} 
}

class CreateACLThreadPool {
 ThreadPoolExecutor threadPool = null;
ArrayBlockingQueue<Runnable> workQueue = null;
 CreateACLThreadPool() { 
this.workQueue = new ArrayBlockingQueue<Runnable>(5);
this.threadPool = new ThreadPoolExecutor(0, 15, 30*30*1000, 
TimeUnit.MILLISECONDS, this.workQueue);
}
 public void addUsers() {

/* I have tried with the valid email Ids only  */

this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
this.threadPool.execute(new User("[email protected]"));
}
 public void waitUntilProcessingThreadCompletes() {
while(this.threadPool.getQueue().size() !=0 || 
this.threadPool.getActiveCount() != 0) {
try {
Thread.sleep(1000);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}


class User extends Thread {
 String userMailId;
DocsService service;
String documentURL;
 User(String str) {
this.userMailId = str;
this.service = new DocsService("createAclForUser"+this.userMailId); 
this.documentURL = 
"https://docs.google.com/spreadsheet/ccc?key=0AtfGXdPAzTJSdF84T2wzdFFGS285U2R3TjRlZE5qeGc#gid=0";;
}
 public void run() {    
try {
this.service.setUserCredentials("[email protected]", "password"); // tried 
with the valid user name and password
} catch (AuthenticationException e) { 
e.printStackTrace();
}    
    String spreadsheetKey = getKeyParameterValue();    
    createACL();
}
 private String getKeyParameterValue(){
String spreadSheetKey = this.documentURL.substring( 
this.documentURL.indexOf("key=") + 4 );
int index = spreadSheetKey.indexOf("&");
if( index != -1 )
{
spreadSheetKey = spreadSheetKey.substring(0, index);
}
return spreadSheetKey;
}
 private void createACL() {
String spreadsheetKey = getKeyParameterValue();
try {
DocumentListEntry docListEntry = this.service.getEntry( new 
URL("https://docs.google.com/feeds/default/private/full/"+spreadsheetKey), 
DocumentListEntry.class );
AclScope scope = new AclScope( AclScope.Type.valueOf( "USER" ), 
this.userMailId);
AclEntry aclEntry = new AclEntry();
aclEntry.setRole(new AclRole("reader"));
aclEntry.setScope(scope);
aclEntry = this.service.insert(new URL( 
docListEntry.getAclFeedLink().getHref() ) , aclEntry );
} catch (Exception e) { 
e.printStackTrace();
} 
}
}






Reply via email to