[Building Sakai] How to enable a user MyWorkspace from code?

Manuel Pérez manuelpg07 at gmail.com
Fri Jan 15 11:41:58 PST 2010


Hello everyone,

will discuss with you the situation, first the code:

// authenticate with the admin user to obtain the necessary permissions
        // to create test data
        UsageSessionService.startSession("admin", "127.0.0.1",
"Voice-Agent");

        // set the user information into the current session
        Session sakaiSession = SessionManager.getCurrentSession();
        sakaiSession.setUserId("admin");
        sakaiSession.setUserEid("admin");

        // update the user's externally provided realm definitions
        AuthzGroupService.refreshUser("admin");

        // create an student user
        try {
            UserEdit ue = UserDirectoryService.addUser("teststudent1",
"teststudent1");
            ue.setEmail("test at student1.es");
            ue.setFirstName("test1");
            ue.setLastName("student1");
            ue.setPassword("sakai");
            ue.setType("user");
            UserDirectoryService.commitEdit(ue);
        } catch (UserIdInvalidException e) {
            throw new OSIDUnitTestException(e.getMessage());
        } catch (UserAlreadyDefinedException e) {
            // User already created
        } catch (UserPermissionException e) {
            throw new OSIDUnitTestException(e.getMessage());
        }

        // create one site and add the user.
        try {
            if (!SiteService.siteExists("testsite1")) {

                Site site1 = SiteService.addSite("testsite1", "course");

                // site information
                site1.setDescription("test description");
                site1.setPublished(true);
                site1.setPubView(false);
                site1.setShortDescription("test short description");
                site1.setTitle("Test Site 1");
                site1.setType("course");
                // add roles
                try {
                    site1.addRole("Instructor");
                } catch (RoleAlreadyDefinedException ralde) {
                }
                try {
                    site1.addRole("Student");
                } catch (RoleAlreadyDefinedException ralde) {
                }

                // add members to site
                site1.addMember("teststudent1", "Student", true, false);
                SiteService.saveSiteMembership(site1);

                SiteService.save(site1);
            }
        } catch (IdInvalidException e) {
            throw new OSIDUnitTestException(e.getMessage());
        } catch (IdUsedException e) {
            // Site already created
        } catch (PermissionException e) {
            throw new OSIDUnitTestException(e.getMessage());
        } catch (IdUnusedException e) {
            throw new OSIDUnitTestException(e.getMessage());
        }


and the problem is this, that somehow need, from high code also give that
user the MyWorkspace added, however with this code is not discharged until
this fall, but I'm not okay, is that be from code and have tried to make the
authentication from code or start a new session with UsageSessionService,
but nothing, so if anyone has any ideas would be very grateful. This code is
for some tests so having to do so.

Another thing, if anyone knows, how do you do to delete a gradebook from
code without modification of the database that you prevent this? FOREING
kinds of KEYS.

A greeting and thank you very much in advance for any response,
Manuel Pérez
Universidad de Oviedo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20100115/bb39f156/attachment.html 


More information about the sakai-dev mailing list