[daisy] Running Example under daisy 2.0

Greg Sieranski greg.sieranski at quoininc.com
Fri Dec 8 12:39:20 CST 2006


importPackage(Packages.org.outerj.daisy.repository);
importClass(Packages.org.outerj.daisy.repository.clientimpl.RemoteRepositoryManager);

// A RepositoryManager represents one 'physical' repository (one database).
// All Repository instances retrieved from one RepositoryManager thus 
represent the same repository,
// the difference between the instances is they are authenticated for 
different users.
// A Repository object is obtained from the RepositoryManager and is 
contextualized for a certain user.
// Thus instead of having to supply credentials to each method, you 
authenticate once via the RepositoryManager\
// and can then do all further operations on this Repository object.
var repositoryManager = new 
RemoteRepositoryManager("http://localhost:9263", new 
Credentials("testuser","testuser"));

var repository = repositoryManager.getRepository(new 
Credentials("testuser","testuser"));

// With the UserManager we can manage users and roles
var userManager = repository.getUserManager();

// Get references to some roles
var guestRole = userManager.getRole("guest", false);
var adminRole = userManager.getRole("Administrator", false);

// Create the new user
var newUser = userManager.createUser("greg");

// The user needs to be added to at least one role
newUser.addToRole(guestRole);
newUser.addToRole(adminRole);

// Optionally, set a defaul role which will be active after
// logging in. If not set, all roles (with the exception of the 
Administrator role)
// will be active on login
// newUser.setDefaultRole(guestRole);
newUser.setDefaultRole(adminRole);

// Password is required when using Daisy's built-in authentication scheme
newUser.setPassword("hello");

// Alternatively, set another authentication scheme:
// newUser.setAuthenticationScheme("my-ldap");

// Optional things
newUser.setFirstName("new");
newUser.setLastName("user");

// Setting updateableByUser will allow the user to access the
// user settings page in the wiki, so that the user can
// update their e-mail
newUser.setUpdateableByUser(true);

newUser.save();

I am trying to run the following example under daisy 2.0 and I am 
receiving the following error message:

C:\opt\daisy-2.0\bin>daisy-js c:\opt\daisy\examples\new-user.js
org.mozilla.javascript.WrappedException: Wrapped 
org.outerj.daisy.repository.user.UserManagementException: Only 
Administrators can update user records. 
(c:\opt\daisy\examples\new-user.js#49)
        at 
org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1693)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
        at 
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:204)
        at 
org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:119)
        at 
org.mozilla.javascript.gen.c1._c0(c:\opt\daisy\examples\new-user.js:49)
        at 
org.mozilla.javascript.gen.c1.call(c:\opt\daisy\examples\new-user.js)
        at 
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
        at 
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
        at 
org.mozilla.javascript.gen.c1.call(c:\opt\daisy\examples\new-user.js)
        at 
org.mozilla.javascript.gen.c1.exec(c:\opt\daisy\examples\new-user.js)
        at 
org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:503)
        at 
org.mozilla.javascript.tools.shell.Main.processFileSecure(Main.java:425)
        at 
org.mozilla.javascript.tools.shell.Main.processFile(Main.java:391)
        at 
org.mozilla.javascript.tools.shell.Main.processSource(Main.java:382)
        at 
org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:179)
        at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:100)
        at org.mozilla.javascript.Context.call(Context.java:528)
        at 
org.mozilla.javascript.ContextFactory.call(ContextFactory.java:450)
        at org.mozilla.javascript.tools.shell.Main.exec(Main.java:162)
        at org.mozilla.javascript.tools.shell.Main.main(Main.java:140)
Caused by: org.outerj.daisy.repository.user.UserManagementException: 
Only Administrators can update user records.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method)
        at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
        at 
org.outerj.daisy.repository.clientimpl.infrastructure.DaisyHttpClient.tryRestoreOriginalException(DaisyHttpClient.java:227)
        at 
org.outerj.daisy.repository.clientimpl.infrastructure.DaisyHttpClient.handleNotOkResponse(DaisyHttpClient.java:153)
        at 
org.outerj.daisy.repository.clientimpl.infrastructure.DaisyHttpClient.executeMethod(DaisyHttpClient.java:86)
        at 
org.outerj.daisy.repository.clientimpl.user.RemoteUserManagementStrategy.store(RemoteUserManagementStrategy.java:174)
        at 
org.outerj.daisy.repository.commonimpl.user.UserImpl.save(UserImpl.java:163)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:145)
        ... 18 more

are there any variations of the above code that I need to make to get it 
to execute under 2.0?

-- 
Regards,

Greg Sieranski

-------------- next part --------------
A non-text attachment was scrubbed...
Name: greg.sieranski.vcf
Type: text/x-vcard
Size: 113 bytes
Desc: not available
Url : http://lists.cocoondev.org/pipermail/daisy/attachments/20061208/8e5010e7/greg.sieranski.vcf


More information about the daisy mailing list