cancel
Showing results for 
Search instead for 
Did you mean: 

User Creation Using Java API( With Specific Quota)

sundar3686
Champ in-the-making
Champ in-the-making
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)
           
                };
    }
}
10 REPLIES 10

sundar3686
Champ in-the-making
Champ in-the-making
###############################
## Common Alfresco Properties #
###############################

dir.root=C:/Alfresco/alf_data

web.application.context.url=http://127.0.0.1:8080/alfresco

### database connection properties ###
db.driver=org.gjt.mm.mysql.Driver
db.username=alfresco
db.password=password
db.name=alfresco
db.url=jdbc:mysql://localhost:3306/${db.name}?useUnicode=yes&characterEncoding=UTF-8

### FTP Server Configuration ###
ftp.enabled=true
ftp.port=21
ftp.ipv6.enabled=false

### RMI service ports ###
alfresco.rmi.services.port=50500
avm.rmi.service.port=0
avmsync.rmi.service.port=0
attribute.rmi.service.port=0
authentication.rmi.service.port=0
repo.rmi.service.port=0
action.rmi.service.port=0
deployment.rmi.service.port=0

### External executable locations ###
ooo.exe=C:/Alfresco/openoffice/App/openoffice/program/soffice.exe
ooo.enabled=false
img.root=C:/Alfresco/imagemagick
img.dyn=${img.root}/lib
img.exe=${img.root}/convert
swf.exe=C:/Alfresco/swftools/pdf2swf.exe
jodconverter.enabled=true
jodconverter.officeHome=C:/Alfresco/openoffice/App/openoffice
jodconverter.portNumbers=8101

### Initial admin password ###
alfresco_user_store.adminpassword=209c6174da490caeb422f3fa5a7ae634