[jboss-svn-commits] JBL Code SVN: r35855 - in labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor: client/ruleeditor and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 3 15:30:28 EDT 2010
Author: eaa
Date: 2010-11-03 15:30:27 -0400 (Wed, 03 Nov 2010)
New Revision: 35855
Added:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/BRLRuleAssetProvider.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/NewRuleAssetProvider.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/RuleAssetProvider.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/UUIDRuleAssetProvider.java
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
- Now it is possible to edit existing assets (instead of create new ones from brl) using their UUIDs
- Now it is also possible to start a new asset from the scratch.
- Implemented "Remove On Close" and programatically remove of edited assets
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-03 19:12:09 UTC (rev 35854)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -36,5 +36,6 @@
String[] getAsstesDRL(String[] assetsUids) throws SerializationException;
String[] getAsstesBRL(String[] assetsUids) throws SerializationException;
+ void removeAssets(String[] assetsUUIDs);
}
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-03 19:12:09 UTC (rev 35854)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -28,4 +28,5 @@
void loadRuleAssetsFromSession(AsyncCallback<RuleAsset[]> asyncCallback);
void getAsstesDRL(String[] assetsUids, AsyncCallback<String[]> asyncCallback);
void getAsstesBRL(String[] assetsUids, AsyncCallback<String[]> asyncCallback);
+ void removeAssets(String[] assetsUUIDs, AsyncCallback<Void> 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-03 19:12:09 UTC (rev 35854)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -1,6 +1,7 @@
package org.drools.guvnor.client.ruleeditor;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window.ClosingEvent;
import org.drools.guvnor.client.common.GenericCallback;
import org.drools.guvnor.client.common.LoadingPopup;
import org.drools.guvnor.client.packages.SuggestionCompletionCache;
@@ -10,6 +11,7 @@
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.ScrollPanel;
@@ -39,11 +41,23 @@
private String[] assetsUids;
+ private Window.ClosingHandler windowCloseingHandler = new Window.ClosingHandler() {
+
+ public void onWindowClosing(ClosingEvent event) {
+ removeAssets();
+ }
+ };
+
public Panel getBaseLayout() {
//init JS hoocks
this.setHooks(this);
+ //remove assets on close
+ if (Boolean.parseBoolean(Window.Location.getParameter("removeAssetsOnClose"))){
+ Window.addWindowClosingHandler(windowCloseingHandler);
+ }
+
mainLayout = new DockLayoutPanel(Unit.EM);
final ScrollPanel mainPanel = new ScrollPanel();
@@ -99,6 +113,13 @@
}
}, new StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider());
+ editor.setCloseCommand(new Command() {
+
+ public void execute() {
+ afterSaveAndClose();
+ }
+ });
+
//Add the editor to main panel
mainPanel.add(editor);
}
@@ -111,6 +132,22 @@
return mainLayout;
}
+ /**
+ * Remove the assets used by this Guided Editor instance
+ */
+ public void removeAssets(){
+ standaloneGuidedEditorService.removeAssets(assetsUids, new AsyncCallback<Void>() {
+
+ public void onFailure(Throwable caught) {
+ removeAssetsCallback(false,caught.getMessage());
+ }
+
+ public void onSuccess(Void result) {
+ LoadingPopup.showMessage("Assets removed");
+ removeAssetsCallback(true,"Assets removed");
+ }
+ });
+ }
/**
* This method should be invoked from JS using window.getEditorDRL().
@@ -181,8 +218,18 @@
$wnd.guvnorGuidedEditorBRLCallbackFunction = callbackFunction;
app. at org.drools.guvnor.client.ruleeditor.GuidedEditorManager::getBRLs()();
};
-
-
+
+
+ $wnd.removeAssets = function (callbackFunction) {
+ $wnd.guvnorGuidedEditorRemoveAssetsCallbackFunction = callbackFunction;
+ app. at org.drools.guvnor.client.ruleeditor.GuidedEditorManager::removeAssets()();
+ };
+
+ //close function listener. The function you register here will be called
+ //after the "Save and Close" button is pressed
+ $wnd.guvnorGuidedEditorOnSaveAndCloseFunction=null;
+
+
}-*/;
/**
@@ -204,4 +251,24 @@
$wnd.guvnorGuidedEditorBRLCallbackFunction(brl);
}
}-*/;
+
+ /**
+ * Callback method invoked from removeAssets().
+ * @param success
+ * @param message
+ */
+ public native void removeAssetsCallback(boolean success, String message)/*-{
+ if ($wnd.guvnorGuidedEditorRemoveAssetsCallbackFunction){
+ $wnd.guvnorGuidedEditorRemoveAssetsCallbackFunction(success, message);
+ }
+ }-*/;
+
+ /**
+ * Method invoked after the "Save an Close" button is pressed.
+ */
+ public native void afterSaveAndClose()/*-{
+ if ($wnd.guvnorGuidedEditorOnSaveAndCloseFunction){
+ $wnd.guvnorGuidedEditorOnSaveAndCloseFunction();
+ }
+ }-*/;
}
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-03 19:12:09 UTC (rev 35854)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/GuidedEditorServlet.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -19,7 +19,6 @@
import java.io.IOException;
-import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -32,7 +31,14 @@
GE_PACKAGE_PARAMETER_NAME("packageName",false),
GE_CATEGORY_PARAMETER_NAME("categoryName",false),
GE_BRL_PARAMETER_NAME("brlSource",true),
+ GE_ASSETS_UUIDS_PARAMETER_NAME("assetsUUIDs",true),
+ GE_CREATE_NEW_ASSET_PARAMETER_NAME("createNewAsset",false),
+ //Only used when creating a new Rule
+ GE_RULE_PARAMETER_NAME("ruleName",false),
+
+ GE_RULE_REMOVE_ASSETS_ON_CLOSE_PARAMETER_NAME("removeAssetsOnClose",false),
+
GE_HIDE_RULE_LHS_PARAMETER_NAME("hideRuleLHS",false),
GE_HIDE_RULE_RHS_PARAMETER_NAME("hideRuleRHS",false),
GE_HIDE_RULE_ATTRIBUTES_PARAMETER_NAME("hideRuleAttributes",false);
@@ -68,7 +74,9 @@
}
}
- resp.sendRedirect("GuidedEditor.html?"+req.getQueryString());
+ boolean removeAssetsOnClose = req.getParameter(GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_REMOVE_ASSETS_ON_CLOSE_PARAMETER_NAME.getParameterName())==null?false:Boolean.parseBoolean(req.getParameter(GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_REMOVE_ASSETS_ON_CLOSE_PARAMETER_NAME.getParameterName()));
+
+ resp.sendRedirect("GuidedEditor.html?"+GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_REMOVE_ASSETS_ON_CLOSE_PARAMETER_NAME.getParameterName()+"="+removeAssetsOnClose+"&"+req.getQueryString());
}
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-03 19:12:09 UTC (rev 35854)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -24,6 +24,10 @@
import org.drools.guvnor.client.rpc.DetailedSerializationException;
import org.drools.guvnor.client.rpc.RuleAsset;
import org.drools.guvnor.client.rpc.StandaloneGuidedEditorService;
+import org.drools.guvnor.server.guidededitor.BRLRuleAssetProvider;
+import org.drools.guvnor.server.guidededitor.NewRuleAssetProvider;
+import org.drools.guvnor.server.guidededitor.RuleAssetProvider;
+import org.drools.guvnor.server.guidededitor.UUIDRuleAssetProvider;
import org.drools.guvnor.server.util.LoggingHelper;
import org.drools.ide.common.client.modeldriven.brl.RuleMetadata;
import org.drools.ide.common.client.modeldriven.brl.RuleModel;
@@ -74,9 +78,19 @@
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());
+ if (attribute != null){
+ createNewAsset = Boolean.parseBoolean(attribute.toString());
+ }
+ String ruleName = (String)session.getAttribute(GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_PARAMETER_NAME.getParameterName());
+
+
+
boolean hideLHSInEditor = false;
- Object attribute = session.getAttribute(GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_LHS_PARAMETER_NAME.getParameterName());
+ attribute = session.getAttribute(GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_LHS_PARAMETER_NAME.getParameterName());
if (attribute != null){
hideLHSInEditor = Boolean.parseBoolean(attribute.toString());
}
@@ -93,90 +107,38 @@
hideAttributesInEditor = Boolean.parseBoolean(attribute.toString());
}
- List<RuleModel> models = new ArrayList<RuleModel>(initialBRL.length);
- List<RuleAsset> assets = new ArrayList<RuleAsset>(initialBRL.length);
- //We wan't to avoid inconsistent states, that is why we first unmarshal
- //each brl and then (if nothing fails) create each rule
- for (String brl : initialBRL) {
- //convert the BRL to RuleModel and update the rule
- models.add(BRXMLPersistence.getInstance().unmarshal(brl));
+ RuleAssetProvider provider;
+ Object data;
+ if (createNewAsset){
+ provider = new NewRuleAssetProvider();
+ data = ruleName;
+ }else if (assetsUUIDs != null){
+ provider = new UUIDRuleAssetProvider();
+ data = assetsUUIDs;
+ }else if (initialBRL != null){
+ provider = new BRLRuleAssetProvider();
+ data = initialBRL;
+ }else{
+ throw new IllegalStateException();
}
- //no unmarshal errors, it's time to create the rules
- try{
- for (RuleModel ruleModel : models) {
- assets.add(this.createRuleAssetFromRuleModel(packageName, categoryName, ruleModel, hideLHSInEditor, hideRHSInEditor, hideAttributesInEditor));
- }
- } catch (Exception e){
- //if something failed, delete the generated assets
- for (RuleAsset ruleAsset : assets) {
- this.getService().removeAsset(ruleAsset.uuid);
- }
-
- if (e instanceof DetailedSerializationException){
- throw (DetailedSerializationException)e;
- }
-
- throw new DetailedSerializationException("Error creating assets", e.getMessage());
- }
+ return provider.getRuleAssets(packageName, categoryName, data, hideLHSInEditor, hideRHSInEditor, hideAttributesInEditor);
- return assets.toArray(new RuleAsset[assets.size()]);
-
}
/**
- * Creates a new RuleAsset from a RuleModel. The name of the RuleAsset will
- * be the original name plus a unique number.
- * @param packageName
- * @param categoryName
- * @param model
- * @param hideLHSInEditor
- * @param hideRHSInEditor
- * @param hideAttributesInEditor
- * @return
- * @throws DetailedSerializationException
- */
- private RuleAsset createRuleAssetFromRuleModel(String packageName, String categoryName, RuleModel model, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException {
-
- try {
- //creates a new empty rule with a unique name (this is because
- //multiple clients could be opening the same rule at the same time)
- String ruleUUID = this.getService().createNewRule(model.name+System.nanoTime(), "imported from BRL", categoryName, packageName, AssetFormats.BUSINESS_RULE);
- RuleAsset newRule = this.getService().loadRuleAsset(ruleUUID);
-
- //update its content and persist
- model.addMetadata(new RuleMetadata(RuleMetadata.HIDE_LHS_IN_EDITOR, hideLHSInEditor.toString()));
- model.addMetadata(new RuleMetadata(RuleMetadata.HIDE_RHS_IN_EDITOR, hideRHSInEditor.toString()));
- model.addMetadata(new RuleMetadata(RuleMetadata.HIDE_ATTRIBUTES_IN_EDITOR, hideAttributesInEditor.toString()));
- newRule.content = model;
- ruleUUID = this.getService().checkinVersion(newRule);
-
- if (ruleUUID == null) {
- throw new IllegalStateException("Failed checking int the new version");
- }
-
- return this.getService().loadRuleAsset(ruleUUID);
- } catch (Exception ex) {
- log.error("Unable to create Rule: " + ex.getMessage());
- throw new DetailedSerializationException("Unable to create Rule",
- ex.getMessage());
- }
-
- }
-
- /**
* Returns the DRL source code of the given assets.
- * @param assetsUids
+ * @param assetsUUIDs
* @return
* @throws SerializationException
*/
- public String[] getAsstesDRL(String[] assetsUids) throws SerializationException{
+ public String[] getAsstesDRL(String[] assetsUUIDs) throws SerializationException{
- String[] sources = new String[assetsUids.length];
+ String[] sources = new String[assetsUUIDs.length];
- for (int i = 0; i < assetsUids.length; i++) {
- RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUids[i]);
+ for (int i = 0; i < assetsUUIDs.length; i++) {
+ RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUUIDs[i]);
sources[i] = this.getService().buildAssetSource(ruleAsset);
}
@@ -185,20 +147,28 @@
/**
* Returns the DRL source code of the given assets.
- * @param assetsUids
+ * @param assetsUUIDs
* @return
* @throws SerializationException
*/
- public String[] getAsstesBRL(String[] assetsUids) throws SerializationException{
+ public String[] getAsstesBRL(String[] assetsUUIDs) throws SerializationException{
- String[] sources = new String[assetsUids.length];
+ String[] sources = new String[assetsUUIDs.length];
BRLPersistence converter = BRXMLPersistence.getInstance();
- for (int i = 0; i < assetsUids.length; i++) {
- RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUids[i]);
+ for (int i = 0; i < assetsUUIDs.length; i++) {
+ RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUUIDs[i]);
sources[i] = converter.marshal((RuleModel) ruleAsset.content);
}
return sources;
}
+
+ /**
+ * Remove all the given assets
+ * @param assetsUUIDs the assets UUIDs
+ */
+ public void removeAssets(String[] assetsUUIDs){
+ this.getService().removeAssets(assetsUUIDs);
+ }
}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/BRLRuleAssetProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/BRLRuleAssetProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/BRLRuleAssetProvider.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.guvnor.server.guidededitor;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.drools.guvnor.client.common.AssetFormats;
+import org.drools.guvnor.client.rpc.DetailedSerializationException;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.server.RepositoryServiceServlet;
+import org.drools.guvnor.server.ServiceImplementation;
+import org.drools.guvnor.server.util.LoggingHelper;
+import org.drools.ide.common.client.modeldriven.brl.RuleMetadata;
+import org.drools.ide.common.client.modeldriven.brl.RuleModel;
+import org.drools.ide.common.server.util.BRXMLPersistence;
+
+/**
+ * BRL -> RuleAsset converter used by standalone guided editor.
+ * For each brl provided, a new RuleAsset is created. The name of the RuleAsset
+ * will be the name present in the brl concatenated with a unique number.
+ * @author esteban.aliverti
+ */
+public class BRLRuleAssetProvider implements RuleAssetProvider {
+
+ private static final LoggingHelper log = LoggingHelper.getLogger(BRLRuleAssetProvider.class);
+
+ public RuleAsset[] getRuleAssets(String packageName, String categoryName, Object initialBRLs, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException {
+
+ //initialBRLs must be a String[] containing the brl code
+ if (!(initialBRLs instanceof String[])){
+ throw new IllegalArgumentException("Expected String[] and not "+initialBRLs.getClass().getName());
+ }
+
+ String[] brls = (String[])initialBRLs;
+
+ List<RuleModel> models = new ArrayList<RuleModel>(brls.length);
+ List<RuleAsset> assets = new ArrayList<RuleAsset>(brls.length);
+
+ //We wan't to avoid inconsistent states, that is why we first unmarshal
+ //each brl and then (if nothing fails) create each rule
+ for (String brl : brls) {
+ //convert the BRL to RuleModel
+ models.add(BRXMLPersistence.getInstance().unmarshal(brl));
+ }
+
+ //no unmarshal errors, it's time to create the rules
+ try{
+ for (RuleModel ruleModel : models) {
+ assets.add(this.createRuleAssetFromRuleModel(packageName, categoryName, ruleModel, hideLHSInEditor, hideRHSInEditor, hideAttributesInEditor));
+ }
+ } catch (Exception e){
+ //if something failed, delete the generated assets
+ for (RuleAsset ruleAsset : assets) {
+ this.getService().removeAsset(ruleAsset.uuid);
+ }
+
+ if (e instanceof DetailedSerializationException){
+ throw (DetailedSerializationException)e;
+ }
+
+ throw new DetailedSerializationException("Error creating assets", e.getMessage());
+ }
+
+ return assets.toArray(new RuleAsset[assets.size()]);
+ }
+
+ /**
+ * Creates a new RuleAsset from a RuleModel. The name of the RuleAsset will
+ * be the original name plus a unique number.
+ * @param packageName
+ * @param categoryName
+ * @param model
+ * @param hideLHSInEditor
+ * @param hideRHSInEditor
+ * @param hideAttributesInEditor
+ * @return
+ * @throws DetailedSerializationException
+ */
+ private RuleAsset createRuleAssetFromRuleModel(String packageName, String categoryName, RuleModel model, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException {
+
+ try {
+ //creates a new empty rule with a unique name (this is because
+ //multiple clients could be opening the same rule at the same time)
+ String ruleUUID = this.getService().createNewRule(model.name+System.nanoTime(), "imported from BRL", categoryName, packageName, AssetFormats.BUSINESS_RULE);
+ RuleAsset newRule = this.getService().loadRuleAsset(ruleUUID);
+
+ //update its content and persist
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_LHS_IN_EDITOR, hideLHSInEditor.toString()));
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_RHS_IN_EDITOR, hideRHSInEditor.toString()));
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_ATTRIBUTES_IN_EDITOR, hideAttributesInEditor.toString()));
+ newRule.content = model;
+ ruleUUID = this.getService().checkinVersion(newRule);
+
+ if (ruleUUID == null) {
+ throw new IllegalStateException("Failed checking int the new version");
+ }
+
+ return this.getService().loadRuleAsset(ruleUUID);
+ } catch (Exception ex) {
+ log.error("Unable to create Rule: " + ex.getMessage());
+ throw new DetailedSerializationException("Unable to create Rule",
+ ex.getMessage());
+ }
+
+ }
+
+ private ServiceImplementation getService() {
+ return RepositoryServiceServlet.getService();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/NewRuleAssetProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/NewRuleAssetProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/NewRuleAssetProvider.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.guvnor.server.guidededitor;
+
+import com.google.gwt.user.client.rpc.SerializationException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.drools.guvnor.client.common.AssetFormats;
+import org.drools.guvnor.client.rpc.DetailedSerializationException;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.server.RepositoryServiceServlet;
+import org.drools.guvnor.server.ServiceImplementation;
+import org.drools.guvnor.server.util.LoggingHelper;
+import org.drools.ide.common.client.modeldriven.brl.RuleMetadata;
+import org.drools.ide.common.client.modeldriven.brl.RuleModel;
+import org.drools.ide.common.server.util.BRXMLPersistence;
+
+/**
+ * Creates a new RuleAsset.
+ * @author esteban.aliverti
+ */
+public class NewRuleAssetProvider implements RuleAssetProvider {
+
+ private static final LoggingHelper log = LoggingHelper.getLogger(NewRuleAssetProvider.class);
+
+ public RuleAsset[] getRuleAssets(String packageName, String categoryName, Object ruleName, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException {
+ try {
+ //ruleName must be a String
+ if (!(ruleName instanceof String)) {
+ throw new IllegalArgumentException("Expected String and not " + ruleName.getClass().getName());
+ }
+
+ String name = (String) ruleName;
+
+ //creates a new empty rule with a unique name (this is because
+ //multiple clients could be opening the same rule at the same time)
+ String ruleUUID = this.getService().createNewRule(name, "created by standalone guided editor", categoryName, packageName, AssetFormats.BUSINESS_RULE);
+ RuleAsset newRule = this.getService().loadRuleAsset(ruleUUID);
+
+ //update its content and persist
+ RuleModel model = (RuleModel) newRule.content;
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_LHS_IN_EDITOR, hideLHSInEditor.toString()));
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_RHS_IN_EDITOR, hideRHSInEditor.toString()));
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_ATTRIBUTES_IN_EDITOR, hideAttributesInEditor.toString()));
+ ruleUUID = this.getService().checkinVersion(newRule);
+
+ if (ruleUUID == null) {
+ throw new IllegalStateException("Failed checking int the new version");
+ }
+
+ newRule = this.getService().loadRuleAsset(ruleUUID);
+
+ return new RuleAsset[]{newRule};
+ } catch (SerializationException ex) {
+ throw new DetailedSerializationException("Error creating rule asset", ex.getMessage());
+ }
+
+
+ }
+
+ private ServiceImplementation getService() {
+ return RepositoryServiceServlet.getService();
+ }
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/RuleAssetProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/RuleAssetProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/RuleAssetProvider.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.guvnor.server.guidededitor;
+
+import org.drools.guvnor.client.rpc.DetailedSerializationException;
+import org.drools.guvnor.client.rpc.RuleAsset;
+
+/**
+ * Interface used by the standalone guided editor to convert request parameters
+ * to RuleAssets.
+ * @author esteban.aliverti
+ */
+public interface RuleAssetProvider {
+
+ RuleAsset[] getRuleAssets(String packageName, String categoryName, Object data, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException ;
+
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/UUIDRuleAssetProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/UUIDRuleAssetProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/UUIDRuleAssetProvider.java 2010-11-03 19:30:27 UTC (rev 35855)
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.guvnor.server.guidededitor;
+
+import com.google.gwt.user.client.rpc.SerializationException;
+import org.drools.guvnor.client.rpc.DetailedSerializationException;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.server.RepositoryServiceServlet;
+import org.drools.guvnor.server.ServiceImplementation;
+import org.drools.guvnor.server.util.LoggingHelper;
+import org.drools.ide.common.client.modeldriven.brl.RuleMetadata;
+import org.drools.ide.common.client.modeldriven.brl.RuleModel;
+
+/**
+ * Creates a new RuleAsset.
+ * @author esteban.aliverti
+ */
+public class UUIDRuleAssetProvider implements RuleAssetProvider {
+
+ private static final LoggingHelper log = LoggingHelper.getLogger(UUIDRuleAssetProvider.class);
+
+ public RuleAsset[] getRuleAssets(String packageName, String categoryName, Object assetsUUIDs, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException {
+ try {
+ //assetsUUIDs must be a String[]
+ if (!(assetsUUIDs instanceof String[])) {
+ throw new IllegalArgumentException("Expected String[] and not " + assetsUUIDs.getClass().getName());
+ }
+
+ String[] uuids = (String[]) assetsUUIDs;
+ RuleAsset[] assets = new RuleAsset[uuids.length];
+
+ for (int i = 0; i < uuids.length; i++) {
+ String uuid = uuids[i];
+ assets[i] = this.getService().loadRuleAsset(uuid);
+ }
+
+ //update its content and reload
+ for (int i = 0; i < assets.length; i++) {
+ RuleAsset ruleAsset = assets[i];
+ RuleModel model = (RuleModel) ruleAsset.content;
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_LHS_IN_EDITOR, hideLHSInEditor.toString()));
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_RHS_IN_EDITOR, hideRHSInEditor.toString()));
+ model.updateMetadata(new RuleMetadata(RuleMetadata.HIDE_ATTRIBUTES_IN_EDITOR, hideAttributesInEditor.toString()));
+ String ruleUUID = this.getService().checkinVersion(ruleAsset);
+ assets[i] = this.getService().loadRuleAsset(ruleUUID);
+ }
+
+ return assets;
+ } catch (SerializationException ex) {
+ throw new DetailedSerializationException("Error creating rule asset", ex.getMessage());
+ }
+
+
+ }
+
+ private ServiceImplementation getService() {
+ return RepositoryServiceServlet.getService();
+ }
+}
More information about the jboss-svn-commits
mailing list