[jboss-svn-commits] JBL Code SVN: r35961 - in labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor: client/ruleeditor and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 12 12:11:02 EST 2010


Author: eaa
Date: 2010-11-12 12:11:00 -0500 (Fri, 12 Nov 2010)
New Revision: 35961

Modified:
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/GuidedEditorServlet.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java
Log:
GUVNOR-681: Create a new top component to display and run the Guided Editor (RuleModeller) and all the things it needs in a "standalone" way
	- Fixed concurrent problem when the same client accesses more than one editor at the same time.

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java	2010-11-12 16:56:18 UTC (rev 35960)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java	2010-11-12 17:11:00 UTC (rev 35961)
@@ -33,7 +33,7 @@
     RemoteService {
 
     
-     StandaloneGuidedEditorInvocationParameters getInvocationParameters() throws DetailedSerializationException;
+     StandaloneGuidedEditorInvocationParameters getInvocationParameters(String parametersUUID) throws DetailedSerializationException;
      String[] getAsstesDRL(RuleAsset[] assets) throws SerializationException;
      String[] getAsstesBRL(RuleAsset[] assets) throws SerializationException;
 

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java	2010-11-12 16:56:18 UTC (rev 35960)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java	2010-11-12 17:11:00 UTC (rev 35961)
@@ -26,7 +26,7 @@
  */
 public interface StandaloneGuidedEditorServiceAsync {
 
-    void getInvocationParameters(AsyncCallback<StandaloneGuidedEditorInvocationParameters> asyncCallback);
+    void getInvocationParameters(String parametersUUID, AsyncCallback<StandaloneGuidedEditorInvocationParameters> asyncCallback);
     void getAsstesDRL(RuleAsset[] assets, AsyncCallback<String[]> asyncCallback);
     void getAsstesBRL(RuleAsset[] assets, AsyncCallback<String[]> asyncCallback);
 

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java	2010-11-12 16:56:18 UTC (rev 35960)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java	2010-11-12 17:11:00 UTC (rev 35961)
@@ -36,7 +36,12 @@
     private RuleAsset[] assets;
 
     public Panel getBaseLayout() {
-
+        
+        String parametersUUID = Window.Location.getParameter("pUUID");
+        if (parametersUUID == null || parametersUUID.trim().equals("")){
+            return null;
+        }
+        
         //init JS hooks
         this.setHooks(this);
 
@@ -48,7 +53,7 @@
 
         //The package must exist (because we need at least a model to work with)
         //To make things easier (to me), the category must exist too.
-        standaloneGuidedEditorService.getInvocationParameters(new GenericCallback<StandaloneGuidedEditorInvocationParameters>() {
+        standaloneGuidedEditorService.getInvocationParameters(parametersUUID, new GenericCallback<StandaloneGuidedEditorInvocationParameters>() {
 
             public void onSuccess(final StandaloneGuidedEditorInvocationParameters parameters) {
 

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/GuidedEditorServlet.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/GuidedEditorServlet.java	2010-11-12 16:56:18 UTC (rev 35960)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/GuidedEditorServlet.java	2010-11-12 17:11:00 UTC (rev 35961)
@@ -17,6 +17,9 @@
 package org.drools.guvnor.server;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -68,18 +71,24 @@
                                                    IOException {
         HttpSession session = req.getSession( true );
 
+        //Each request uses its own parameters map (this allows concurrent requests
+        //from the same cilent)
+        Map<String,Object> parameters = new HashMap<String, Object>();
         //copy each registered parameter from request to session
         for ( GUIDED_EDITOR_SERVLET_PARAMETERS parameter : GUIDED_EDITOR_SERVLET_PARAMETERS.values() ) {
             if ( parameter.isMultipleValues() ) {
-                session.setAttribute( parameter.getParameterName(),
+            	parameters.put( parameter.getParameterName(),
                                       req.getParameterValues( parameter.getParameterName() ) );
             } else {
-                session.setAttribute( parameter.getParameterName(),
+                parameters.put( parameter.getParameterName(),
                                       req.getParameter( parameter.getParameterName() ) );
             }
         }
+        
+        String parametersUUID = UUID.randomUUID().toString();
+        session.setAttribute(parametersUUID, parameters);
 
-        resp.sendRedirect( "GuidedEditor.html?" + req.getQueryString() );
+        resp.sendRedirect( "GuidedEditor.html?pUUID="+parametersUUID+"&" + req.getQueryString() );
     }
 
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java	2010-11-12 16:56:18 UTC (rev 35960)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java	2010-11-12 17:11:00 UTC (rev 35961)
@@ -17,6 +17,7 @@
 
 import com.google.gwt.user.client.rpc.SerializationException;
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+import java.util.Map;
 import javax.servlet.http.HttpSession;
 import org.drools.guvnor.client.rpc.DetailedSerializationException;
 import org.drools.guvnor.client.rpc.RuleAsset;
@@ -54,38 +55,52 @@
         return RepositoryServiceServlet.getService();
     }
 
-    public StandaloneGuidedEditorInvocationParameters getInvocationParameters() throws DetailedSerializationException {
+    public StandaloneGuidedEditorInvocationParameters getInvocationParameters(String parametersUUID) throws DetailedSerializationException {
 
-        //Get the parameters from the session
         HttpSession session = this.getThreadLocalRequest().getSession();
+        
+        try{
+            //Get the parameters from the session
+            Map<String, Object> sessionParameters = (Map<String, Object>) session.getAttribute(parametersUUID);
 
-        boolean hideLHSInEditor = false;
-        Object attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_LHS_PARAMETER_NAME.getParameterName() );
-        if ( attribute != null ) {
-            hideLHSInEditor = Boolean.parseBoolean( attribute.toString() );
-        }
+            if (sessionParameters == null || sessionParameters.isEmpty()){
+                throw new DetailedSerializationException("Error initializing Guided Editor", "No initial parameters were supplied");
+            }
 
-        boolean hideRHSInEditor = false;
-        attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_RHS_PARAMETER_NAME.getParameterName() );
-        if ( attribute != null ) {
-            hideRHSInEditor = Boolean.parseBoolean( attribute.toString() );
-        }
+            boolean hideLHSInEditor = false;
+            Object attribute =  sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_LHS_PARAMETER_NAME.getParameterName() );
+            if ( attribute != null ) {
+                hideLHSInEditor = Boolean.parseBoolean( attribute.toString() );
+            }
 
-        boolean hideAttributesInEditor = false;
-        attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_ATTRIBUTES_PARAMETER_NAME.getParameterName() );
-        if ( attribute != null ) {
-            hideAttributesInEditor = Boolean.parseBoolean( attribute.toString() );
-        }
+            boolean hideRHSInEditor = false;
+            attribute = sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_RHS_PARAMETER_NAME.getParameterName() );
+            if ( attribute != null ) {
+                hideRHSInEditor = Boolean.parseBoolean( attribute.toString() );
+            }
 
-        StandaloneGuidedEditorInvocationParameters parameters = new StandaloneGuidedEditorInvocationParameters();
+            boolean hideAttributesInEditor = false;
+            attribute = sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_ATTRIBUTES_PARAMETER_NAME.getParameterName() );
+            if ( attribute != null ) {
+                hideAttributesInEditor = Boolean.parseBoolean( attribute.toString() );
+            }
 
-         this.loadRuleAssetsFromSession(parameters);
+            StandaloneGuidedEditorInvocationParameters invocationParameters = new StandaloneGuidedEditorInvocationParameters();
 
-        parameters.setHideLHS( hideLHSInEditor );
-        parameters.setHideRHS( hideRHSInEditor );
-        parameters.setHideAttributes( hideAttributesInEditor );
+            this.loadRuleAssetsFromSessionParameters(sessionParameters, invocationParameters);
 
-        return parameters;
+            invocationParameters.setHideLHS( hideLHSInEditor );
+            invocationParameters.setHideRHS( hideRHSInEditor );
+            invocationParameters.setHideAttributes( hideAttributesInEditor );
+
+
+
+            return invocationParameters;
+        } finally{
+            //clear session parameters
+            session.removeAttribute(parametersUUID);
+        }
+        
     }
 
     /**
@@ -97,41 +112,38 @@
      * @param parameters 
      * @throws DetailedSerializationException
      */
-    private void loadRuleAssetsFromSession(StandaloneGuidedEditorInvocationParameters parameters) throws DetailedSerializationException {
+    private void loadRuleAssetsFromSessionParameters(Map<String, Object> sessionParameters, StandaloneGuidedEditorInvocationParameters invocationParameters) throws DetailedSerializationException {
 
-        //Get the parameters from the session
-        HttpSession session = this.getThreadLocalRequest().getSession();
+        String packageName = (String)sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_PACKAGE_PARAMETER_NAME.getParameterName() );
+        String categoryName = (String)sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_CATEGORY_PARAMETER_NAME.getParameterName() );
+        String[] initialBRL = (String[])sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_BRL_PARAMETER_NAME.getParameterName() );
+        String[] assetsUUIDs = (String[])sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_ASSETS_UUIDS_PARAMETER_NAME.getParameterName() );
 
-        String packageName = (String) session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_PACKAGE_PARAMETER_NAME.getParameterName() );
-        String categoryName = (String) session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_CATEGORY_PARAMETER_NAME.getParameterName() );
-        String[] initialBRL = (String[]) session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_BRL_PARAMETER_NAME.getParameterName() );
-        String[] assetsUUIDs = (String[]) session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_ASSETS_UUIDS_PARAMETER_NAME.getParameterName() );
-
         boolean createNewAsset = false;
-        Object attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_CREATE_NEW_ASSET_PARAMETER_NAME.getParameterName() );
+        Object attribute = sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_CREATE_NEW_ASSET_PARAMETER_NAME.getParameterName() );
         if ( attribute != null ) {
             createNewAsset = Boolean.parseBoolean( attribute.toString() );
         }
-        String ruleName = (String) session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_PARAMETER_NAME.getParameterName() );
+        String ruleName = (String) sessionParameters.get( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_PARAMETER_NAME.getParameterName() );
 
         RuleAssetProvider provider;
         if ( createNewAsset ) {
             provider = new NewRuleAssetProvider( packageName,
                                                  categoryName,
                                                  ruleName );
-            parameters.setTemporalAssets(false);
+            invocationParameters.setTemporalAssets(false);
         } else if ( assetsUUIDs != null ) {
             provider = new UUIDRuleAssetProvider( assetsUUIDs );
-            parameters.setTemporalAssets(false);
+            invocationParameters.setTemporalAssets(false);
         } else if ( initialBRL != null ) {
             provider = new BRLRuleAssetProvider( packageName,
                                                  initialBRL );
-            parameters.setTemporalAssets(true);
+            invocationParameters.setTemporalAssets(true);
         } else {
             throw new IllegalStateException();
         }
 
-        parameters.setAssetsToBeEdited(provider.getRuleAssets());
+        invocationParameters.setAssetsToBeEdited(provider.getRuleAssets());
 
     }
 



More information about the jboss-svn-commits mailing list