roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r574745 - in /roller/trunk/sandbox/scripting/groovy/examples/adminprotocol: createuser.gy deleteuser.gy
Date Wed, 12 Sep 2007 01:21:52 GMT
Author: snoopdave
Date: Tue Sep 11 18:21:51 2007
New Revision: 574745

URL: http://svn.apache.org/viewvc?rev=574745&view=rev
Log:
Fix for http://opensource.atlassian.com/projects/roller/browse/ROL-1560
"RAP broken in 4.0" - fixing problems caused by move to JPA, RAP tests work 100% now. Also
fixed example Groovy scripts that call RAP.

Added:
    roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/deleteuser.gy
Modified:
    roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/createuser.gy

Modified: roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/createuser.gy
URL: http://svn.apache.org/viewvc/roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/createuser.gy?rev=574745&r1=574744&r2=574745&view=diff
==============================================================================
--- roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/createuser.gy (original)
+++ roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/createuser.gy Tue Sep 11
18:21:51 2007
@@ -3,7 +3,7 @@
 import java.net.*;
 import org.jdom.output.*;
 import org.apache.commons.codec.binary.Base64;
-import org.apache.roller.webservices.adminprotocol.sdk.*;
+import org.apache.roller.weblogger.webservices.adminprotocol.sdk.*;
 
 if (args.length < 6) {
     println "USAGE: groovy createuser.gy <admin-username> <admin-password> <new-username>
<new-password> <email> <rap-endpoint>"; 
@@ -13,9 +13,9 @@
 admin_username = args[0];
 admin_password = args[1];
 username = args[2];
-password = args[3]
+password = args[3];
 email    = args[4];
-rapuri   = args[5]
+rapuri   = args[5];
 
 fullName = username;
 locale   = "en_US";
@@ -50,6 +50,7 @@
 
 user = new UserEntry(username, baseURI);
 
+user.setScreenName(  username);
 user.setPassword(    password);
 user.setFullName(    fullName);
 user.setEmailAddress(email);

Added: roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/deleteuser.gy
URL: http://svn.apache.org/viewvc/roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/deleteuser.gy?rev=574745&view=auto
==============================================================================
--- roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/deleteuser.gy (added)
+++ roller/trunk/sandbox/scripting/groovy/examples/adminprotocol/deleteuser.gy Tue Sep 11
18:21:51 2007
@@ -0,0 +1,79 @@
+
+import java.io.*;
+import java.net.*;
+import org.jdom.output.*;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.roller.weblogger.webservices.adminprotocol.sdk.*;
+
+if (args.length < 4) {
+    println "USAGE: groovy deleteuser.gy <admin-username> <admin-password> <username>
<rap-endpoint>"; 
+    return;
+}
+
+admin_username = args[0];
+admin_password = args[1];
+username = args[2];
+rapuri   = args[3];
+
+fullName = username;
+locale   = "en_US";
+timeZone = "America/New_York";
+
+
+credentials = admin_username + ":" + admin_password; 
+authString = "Basic " + new String(Base64.encodeBase64(credentials.getBytes()));
+
+// get service doc
+
+url = new URL(rapuri);         
+conn = url.openConnection();
+conn.setRequestProperty("Authorization", authString);
+s = new Service(conn.getInputStream());
+
+// find user collection in service
+
+userCollectionURI = null;
+baseURI = null;
+for (w in s.entries) {
+    for (c in w.entries) {
+        if (c.memberType == "user") {
+            userCollectionURI = c.href;
+            baseURI = c.href.substring(0, c.href.length() - "users".length());
+            break;
+        }
+    }
+}
+
+
+// open connection
+url = new URL(userCollectionURI);         
+conn = url.openConnection();
+conn.setRequestProperty("Authorization", authString);
+UserEntrySet users = new UserEntrySet(conn.getInputStream(), rapuri);
+user = null;
+for (u in users) {
+    for (i in 0..(u.getEntries().length - 1)) {
+        if (username == u.getEntries()[i].name) {
+           user = u.getEntries()[i];
+           break;
+        }
+    }
+}
+
+if (user) {
+    url = new URL(user.getHref());         
+    conn = url.openConnection();
+    conn.setRequestProperty("Authorization", authString);
+    conn.setRequestMethod("DELETE");
+  
+    println "--- Response from server ---";
+    s = null; 
+    is = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
+    while ((s = is.readLine()) != null) {
+        println s
+    }
+
+} else {
+    println "User not found";
+}
+



Mime
View raw message