AnsweredAssumed Answered

User Creation Using Java API( With Specific Quota)

Question asked by sundar3686 on Jul 21, 2011
Latest reply on Jul 22, 2011 by sundar3686
Hi friends,
I successfully created user using web service client. But i cant specify the user quota. Is it possible in web service client?.Please help me.
This is my code.

import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.alfresco.webservice.administration.NewUserDetails;
import org.alfresco.webservice.administration.AdministrationServiceSoapBindingStub;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.WebServiceFactory;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.repository.QueryResult;

/**
*
* @author sundar
*/
public class CreateUserCommand {

    public CreateUserCommand() {
    }

    public static void main(String a[]) {
        try {
            CreateUserCommand c = new CreateUserCommand();
            AuthenticationUtils.startSession("admin", "admin");
          //  WebServiceFactory.getAdministrationService().changePassword("", "", "");
            Store s = new Store(Constants.WORKSPACE_STORE, "Spacesstore");
            AdministrationServiceSoapBindingStub ad = WebServiceFactory.getAdministrationService();
            String username="sundarpx";
            String password="sundarpx";
            String firstname="sundar";
            String midlename="p";
            String lastname="rajan";
            String email="sundar.p@demo.com";
            String regid="1";
           
            // check the user
            boolean existUser = false;
            try {
                // test before the user
                Query query = new Query("lucene", "+TYPE:\"cm:person\" AND +@cm\\:userName:\"" + username + "\"");
                QueryResult results = WebServiceFactory.getRepositoryService().query(s, query, true);
             
                if (results != null&&results.getResultSet()!=null) {
                    if (results.getResultSet().getRows().length > 0) {
                        existUser = true;
                    } else {
                        existUser = false;
                    }
                } else {
                    existUser = false;
                }
            } catch (Exception e) {
                    existUser = false;
            }
            if(existUser){
                System.out.println("This user already exists");
            }else{
            NamedValue[] properties = c.createUserProperties(s.getScheme() + "://" + s.getAddress() + "/", firstname, midlename, lastname, email, regid);
            NewUserDetails dc[] = new NewUserDetails[]{new NewUserDetails(username, password, properties)};
            ad.createUsers(dc);               
            }
            AuthenticationUtils.endSession();
        } catch (RemoteException ex) {
            Logger.getLogger(CreateUserCommand.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public NamedValue[] createUserProperties(String homefolder, String firstname, String midlename, String lastname, String email, String orgid) {
        return new NamedValue[]{
                    new NamedValue(Constants.PROP_USER_HOMEFOLDER, false, homefolder, null),
                    new NamedValue(Constants.PROP_USER_FIRSTNAME, false, firstname, null),
                    new NamedValue(Constants.PROP_USER_MIDDLENAME, false, midlename, null),
                    new NamedValue(Constants.PROP_USER_LASTNAME, false, lastname, null),
                    new NamedValue(Constants.PROP_USER_EMAIL, false, email, null),
                    new NamedValue(Constants.PROP_USER_ORGID, false, orgid, null)
           
                };
    }
}

Outcomes