[jboss-svn-commits] JBL Code SVN: r35922 - in labs/jbossrules/trunk: drools-guvnor/src/main/java/org/drools/guvnor/client/rpc and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 9 05:58:29 EST 2010
Author: Rikkola
Date: 2010-11-09 05:58:28 -0500 (Tue, 09 Nov 2010)
New Revision: 35922
Added:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewerSettings.java
Modified:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/Guvnor.gwt.xml
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/MetaData.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/DiscussionWidget.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/client/ruleeditor/MultiViewEditor.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleDocumentWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.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/ServiceImplementation.java
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/contenthandler/BRLContentHandler.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/ContentHandler.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DRLFileContentHandler.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DSLRuleContentHandler.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DecisionTableXLSHandler.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/GuidedDTContentHandler.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/IRuleAsset.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/BRLRuleAssetProvider.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/PortableObject.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
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/Guvnor.gwt.xml
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/Guvnor.gwt.xml 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/Guvnor.gwt.xml 2010-11-09 10:58:28 UTC (rev 35922)
@@ -48,6 +48,8 @@
<servlet path="/workflowmanager" class="org.gridcc.mce.mceworkflow.servlets.WorkflowManagerServlet"/>
<servlet path="/wsdlparser" class="org.gridcc.mce.mceworkflow.servlets.WSDLParserServlet"/>
<servlet path="/verificationService" class="org.drools.guvnor.server.VerificationServiceImplementation"/>
+ <servlet path="/guidedEditorServlet" class="org.drools.guvnor.server.GuidedEditorServlet"/>
+ <servlet path="/standaloneGuidedEditorService" class="org.drools.guvnor.server.StandaloneGuidedEditorServiceImplementation"/>
<set-property name="gwt.suppressNonStaticFinalFieldWarnings" value="true" />
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/MetaData.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/MetaData.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/MetaData.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2010 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,34 +28,36 @@
implements
IsSerializable {
- public String name = "";
- public String description = "";
+ public String name = "";
+ public String description = "";
- public String title = "";
- public String status = "";
+ public String title = "";
+ public String status = "";
public Date lastModifiedDate;
- public String lastContributor = "";
+ public String lastContributor = "";
public long versionNumber;
public Date createdDate;
- public String packageName = "";
- public String packageUUID = "";
- public String[] categories = new String[0];
+ public String packageName = "";
+ public String packageUUID = "";
+ public String[] categories = new String[0];
- public String format = "";
- public String type = "";
- public String creator = "";
- public String externalSource = "";
- public String subject = "";
- public String externalRelation = "";
- public String rights = "";
- public String coverage = "";
- public String publisher = "";
- public String checkinComment = "";
+ public String format = "";
+ public String type = "";
+ public String creator = "";
+ public String externalSource = "";
+ public String subject = "";
+ public String externalRelation = "";
+ public String rights = "";
+ public String coverage = "";
+ public String publisher = "";
+ public String checkinComment = "";
- public boolean disabled = false;
+ private boolean binary = false;
+
+ public boolean disabled = false;
public boolean hasPreceedingVersion = false;
public boolean hasSucceedingVersion = false;
@@ -98,4 +100,12 @@
this.categories = newList;
}
+ public void setBinary(boolean binary) {
+ this.binary = binary;
+ }
+
+ public boolean isBinary() {
+ return binary;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/DiscussionWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/DiscussionWidget.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/DiscussionWidget.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -127,30 +127,32 @@
}
private Widget appendComment(DiscussionRecord r) {
- SmallLabel hrd = new SmallLabel(Format.format(constants.smallCommentBy0On1Small(), r.author, new Date(r.timestamp).toString()));
- hrd.addStyleName("discussion-header");
- commentList.add(hrd);
-
- String[] parts = r.note.split("\n");
-
- if(parts.length > 0) {
- String txt = "";
- for(int i=0;i<parts.length;i++) {
- txt += parts[i];
- if(i != parts.length-1) {
- txt += "<br/>";
- }
- }
- HTML hth = new HTML(txt);
- hth.setStyleName("x-form-field");
- commentList.add(hth);
+ SmallLabel hrd = new SmallLabel( Format.format( constants.smallCommentBy0On1Small(),
+ r.author,
+ new Date( r.timestamp ).toString() ) );
+ hrd.addStyleName( "discussion-header" );
+ commentList.add( hrd );
+
+ String[] parts = r.note.split( "\n" );
+
+ if ( parts.length > 0 ) {
+ String txt = "";
+ for ( int i = 0; i < parts.length; i++ ) {
+ txt += parts[i];
+ if ( i != parts.length - 1 ) {
+ txt += "<br/>";
+ }
+ }
+ HTML hth = new HTML( txt );
+ hth.setStyleName( "x-form-field" );
+ commentList.add( hth );
} else {
- Label lbl = new Label(r.note);
- lbl.setStyleName("x-form-field");
- commentList.add(lbl);
+ Label lbl = new Label( r.note );
+ lbl.setStyleName( "x-form-field" );
+ commentList.add( lbl );
}
-
- commentList.add(new HTML("<br/>"));
+
+ commentList.add( new HTML( "<br/>" ) );
return hrd;
}
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-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -104,16 +104,6 @@
LoadingPopup.close();
- //For each asset we need to create a MultiViewRow
- List<MultiViewRow> rows = new ArrayList<MultiViewRow>();
- for (RuleAsset ruleAsset : parameters.getAssetsToBeEdited()) {
- MultiViewRow row = new MultiViewRow();
- row.uuid = ruleAsset.uuid;
- row.name = ruleAsset.metaData.name;
- //row.name = ((RuleModel)ruleAsset.content).name;
- row.format = AssetFormats.BUSINESS_RULE;
- rows.add(row);
- }
//Configure RuleModeller
RuleModellerConfiguration ruleModellerConfiguration = RuleModellerConfiguration.getInstance();
ruleModellerConfiguration.setHideLHS(parameters.isHideLHS());
@@ -121,7 +111,7 @@
ruleModellerConfiguration.setHideAttributes(parameters.isHideAttributes());
//Create the editor
- editor = new MultiViewEditor(rows.toArray(new MultiViewRow[rows.size()]), new EditItemEvent() {
+ editor = new MultiViewEditor(parameters.getAssetsToBeEdited(), new EditItemEvent() {
public void open(MultiViewRow[] rows) {
// TODO Auto-generated method stub
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -15,30 +15,31 @@
*/
package org.drools.guvnor.client.ruleeditor;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.drools.guvnor.client.common.AssetFormats;
import org.drools.guvnor.client.common.GenericCallback;
import org.drools.guvnor.client.messages.Constants;
import org.drools.guvnor.client.packages.SuggestionCompletionCache;
import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.client.ruleeditor.toolbar.ActionToolbarButtonsConfigurationProvider;
import org.drools.guvnor.client.rulelist.EditItemEvent;
+import org.drools.guvnor.client.util.LazyStackPanel;
import org.drools.guvnor.client.util.LoadContentCommand;
-import org.drools.guvnor.client.util.LazyStackPanel;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.logical.shared.OpenEvent;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-import org.drools.guvnor.client.rpc.StandaloneGuidedEditorService;
-import org.drools.guvnor.client.ruleeditor.toolbar.ActionToolbarButtonsConfigurationProvider;
/**
*
@@ -47,40 +48,87 @@
*/
public class MultiViewEditor extends GuvnorEditor {
- private Constants constants = GWT.create(Constants.class);
- private VerticalPanel viewsPanel = new VerticalPanel();
- private boolean showMetadata = false;
- private boolean showDescription = false;
- private Command closeCommand;
- private final Set<MultiViewRow> rows;
- private Map<String, RuleViewer> ruleViews = new HashMap<String, RuleViewer>();
- private final EditItemEvent editItemEvent;
+ private Constants constants = GWT.create( Constants.class );
+
+ private VerticalPanel viewsPanel = new VerticalPanel();
+ private boolean showMetadata = false;
+ private boolean showDescription = false;
+ private Command closeCommand;
+ private final Set<MultiViewRow> rows = new HashSet<MultiViewRow>();
+ private Map<String, RuleViewer> ruleViews = new HashMap<String, RuleViewer>();
+ private final EditItemEvent editItemEvent;
private ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider;
+ private Map<String, RuleAsset> assets = new HashMap<String, RuleAsset>();
+
public MultiViewEditor(MultiViewRow[] rows,
- EditItemEvent editItemEvent) {
- this(rows, editItemEvent, null);
+ EditItemEvent editItemEvent) {
+ this( rows,
+ editItemEvent,
+ null );
}
-
+
+ public MultiViewEditor(RuleAsset[] assets,
+ EditItemEvent editItemEvent,
+ ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider) {
+ this.rows.addAll( createRows( assets ) );
+ this.editItemEvent = editItemEvent;
+ this.individualActionToolbarButtonsConfigurationProvider = individualActionToolbarButtonsConfigurationProvider;
+
+ addAssets( assets );
+ init();
+ }
+
+ private void addAssets(RuleAsset[] assets) {
+ for ( RuleAsset ruleAsset : assets ) {
+ this.assets.put( ruleAsset.uuid,
+ ruleAsset );
+ }
+ }
+
+ private static List<MultiViewRow> createRows(RuleAsset[] assets) {
+ List<MultiViewRow> rows = new ArrayList<MultiViewRow>();
+ for ( RuleAsset ruleAsset : assets ) {
+ MultiViewRow row = new MultiViewRow();
+ row.uuid = ruleAsset.uuid;
+ row.name = ruleAsset.metaData.name;
+ row.format = AssetFormats.BUSINESS_RULE;
+ rows.add( row );
+ }
+ return rows;
+ }
+
public MultiViewEditor(MultiViewRow[] rows,
- EditItemEvent editItemEvent, ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider) {
+ EditItemEvent editItemEvent,
+ ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider) {
+ this( Arrays.asList( rows ),
+ editItemEvent,
+ individualActionToolbarButtonsConfigurationProvider );
+ }
+
+ public MultiViewEditor(List<MultiViewRow> rows,
+ EditItemEvent editItemEvent,
+ ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider) {
+ this.rows.addAll( rows );
this.editItemEvent = editItemEvent;
- this.rows = new HashSet<MultiViewRow>();
- this.rows.addAll(Arrays.asList(rows));
this.individualActionToolbarButtonsConfigurationProvider = individualActionToolbarButtonsConfigurationProvider;
+ init();
+ }
+
+ private void init() {
VerticalPanel rootPanel = new VerticalPanel();
- rootPanel.setWidth("100%");
+ rootPanel.setWidth( "100%" );
- rootPanel.add(createToolbar());
+ rootPanel.add( createToolbar() );
- viewsPanel.setWidth("100%");
- rootPanel.add(viewsPanel);
+ viewsPanel.setWidth( "100%" );
+ rootPanel.add( viewsPanel );
doViews();
- initWidget(rootPanel);
+ initWidget( rootPanel );
}
// MenuBar layoutMenu = new MenuBar( true );
@@ -102,20 +150,20 @@
private MenuBar createToolbar() {
MenuBar toolbar = new MenuBar();
- toolbar.addItem(constants.SaveAllChanges(),
- new Command() {
+ toolbar.addItem( constants.SaveAllChanges(),
+ new Command() {
- public void execute() {
- checkin(false);
- }
- });
- toolbar.addItem(constants.SaveAndCloseAll(),
- new Command() {
+ public void execute() {
+ checkin( false );
+ }
+ } );
+ toolbar.addItem( constants.SaveAndCloseAll(),
+ new Command() {
- public void execute() {
- checkin(true);
- }
- });
+ public void execute() {
+ checkin( true );
+ }
+ } );
return toolbar;
}
@@ -125,10 +173,10 @@
viewsPanel.clear();
ruleViews.clear();
final LazyStackPanel panel = new LazyStackPanel();
-
+
//the first row will be expanded
int rowNumber = 1;
- for (final MultiViewRow row : rows) {
+ for ( final MultiViewRow row : rows ) {
// panel.add( row.name );
// panel.setIconCls( EditorLauncher.getAssetFormatBGStyle( row.format ) ); //NON-NLS
// panel.setCollapsible( true );
@@ -139,49 +187,37 @@
// panel.addListener( new PanelListenerAdapter() {
// public void onExpand(final Panel panel) {
- panel.add(row.name,
- new LoadContentCommand() {
+ panel.add( row.name,
+ new LoadContentCommand() {
- public Widget load() {
- final SimplePanel content = new SimplePanel();
- RepositoryServiceFactory.getService().loadRuleAsset(row.uuid,
- new GenericCallback<RuleAsset>() {
+ public Widget load() {
+ final SimplePanel content = new SimplePanel();
- public void onSuccess(final RuleAsset asset) {
- SuggestionCompletionCache.getInstance().doAction(asset.metaData.packageName,
- new Command() {
+ if ( assets.containsKey( row.uuid ) ) {
+ addRuleViewInToSimplePanel( row,
+ content,
+ assets.get( row.uuid ) );
+ } else {
+ RepositoryServiceFactory.getService().loadRuleAsset( row.uuid,
+ new GenericCallback<RuleAsset>() {
- public void execute() {
+ public void onSuccess(final RuleAsset asset) {
+ assets.put( asset.uuid,
+ asset );
- final RuleViewer ruleViewer = new RuleViewer(asset,
- editItemEvent,false, individualActionToolbarButtonsConfigurationProvider);
- ruleViewer.setDocoVisible(showDescription);
- ruleViewer.setMetaVisible(showMetadata);
+ addRuleViewInToSimplePanel( row,
+ content,
+ asset );
+ }
- content.add(ruleViewer);
- ruleViewer.setWidth("100%");
+ } );
- ruleViewer.setCloseCommand(new Command() {
+ }
+ return content;
+ }
+ },
+ rowNumber == 1 );
- public void execute() {
- ruleViews.remove(row.uuid);
- rows.remove(row);
- doViews();
- }
- });
-
- ruleViews.put(row.uuid,
- ruleViewer);
-
- }
- });
- }
- });
-
- return content;
- }
- },rowNumber == 1);
-
// Only load if it doesn't exist yet.
// if ( ruleViews.get( row.uuid ) == null ) {
//
@@ -196,28 +232,67 @@
rowNumber++;
}
- viewsPanel.add(panel);
+ viewsPanel.add( panel );
}
+ private void addRuleViewInToSimplePanel(final MultiViewRow row,
+ final SimplePanel content,
+ final RuleAsset asset) {
+ SuggestionCompletionCache.getInstance().doAction( asset.metaData.packageName,
+ new Command() {
+
+ public void execute() {
+
+ RuleViewerSettings ruleViewerSettings = new RuleViewerSettings();
+ ruleViewerSettings.setDocoVisible( false );
+ ruleViewerSettings.setMetaVisible( false );
+
+ final RuleViewer ruleViewer = new RuleViewer( asset,
+ editItemEvent,
+ false,
+ individualActionToolbarButtonsConfigurationProvider,
+ ruleViewerSettings );
+ ruleViewer.setDocoVisible( showDescription );
+ ruleViewer.setMetaVisible( showMetadata );
+
+ content.add( ruleViewer );
+ ruleViewer.setWidth( "100%" );
+
+ ruleViewer.setCloseCommand( new Command() {
+
+ public void execute() {
+ ruleViews.remove( row.uuid );
+ rows.remove( row );
+ doViews();
+ }
+ } );
+
+ ruleViews.put( row.uuid,
+ ruleViewer );
+
+ }
+ } );
+ }
+
private void checkin(final boolean closeAfter) {
- final CheckinPopup pop = new CheckinPopup(constants.CheckInChanges());
- pop.setCommand(new Command() {
+ final CheckinPopup pop = new CheckinPopup( constants.CheckInChanges() );
+ pop.setCommand( new Command() {
public void execute() {
String comment = pop.getCheckinComment();
- for (RuleViewer ruleViewer : ruleViews.values()) {
- ruleViewer.checkInCommand.doCheckin(comment);
+ for ( RuleViewer ruleViewer : ruleViews.values() ) {
+ ruleViewer.checkInCommand.doCheckin( comment );
}
- if (closeAfter) {
+ if ( closeAfter ) {
close();
}
}
- });
+ } );
pop.show();
}
-
+
public void close() {
closeCommand.execute();
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleDocumentWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleDocumentWidget.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleDocumentWidget.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -31,10 +31,22 @@
*/
public class RuleDocumentWidget extends DirtyableComposite {
- final VerticalPanel layout = new VerticalPanel();
+ final VerticalPanel layout = new VerticalPanel();
- public RuleDocumentWidget(final RuleAsset asset) {
+ private final RuleAsset asset;
+ public RuleDocumentWidget(final RuleAsset asset,
+ boolean visible) {
+ this.asset = asset;
+
+ initWidget( layout );
+
+ setVisible( visible );
+ }
+
+ private void initLayout() {
+ layout.clear();
+
layout.add( new CommentWidget( asset.metaData ) );
DeferredCommand.addCommand( new Command() {
@@ -45,7 +57,13 @@
layout.setWidth( "100%" );
- initWidget( layout );
}
+ public void setVisible(boolean visible) {
+ if ( visible && layout.getWidgetCount() == 0 ) {
+ initLayout();
+ }
+
+ super.setVisible( visible );
+ };
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -52,29 +52,28 @@
*/
public class RuleViewer extends GuvnorEditor {
- private Command closeCommand;
- private Command archiveCommand;
- public Command checkedInCommand;
- public ActionToolbar.CheckinAction checkInCommand;
- protected RuleAsset asset;
+ private Command closeCommand;
+ private Command archiveCommand;
+ public Command checkedInCommand;
+ public ActionToolbar.CheckinAction checkInCommand;
+ protected RuleAsset asset;
- private boolean readOnly;
+ private boolean readOnly;
- private boolean metaVisible = true;
- private boolean docoVisible = true;
- private MetaDataWidget metaWidget;
- private RuleDocumentWidget doco;
- private Widget editor;
+ private final RuleViewerSettings ruleViewerSettings;
+ private MetaDataWidget metaWidget;
+ private RuleDocumentWidget ruleDocumentWidget;
+ private Widget editor;
- private ActionToolbar toolbar;
- private VerticalPanel layout;
- private HorizontalPanel hsp;
+ private ActionToolbar toolbar;
+ private VerticalPanel layout;
+ private HorizontalPanel hsp;
- private long lastSaved = System.currentTimeMillis();
- private Constants constants = ((Constants) GWT.create( Constants.class ));
+ private long lastSaved = System.currentTimeMillis();
+ private Constants constants = ((Constants) GWT.create( Constants.class ));
- private final EditItemEvent editEvent;
-
+ private final EditItemEvent editEvent;
+
private ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider;
/**
@@ -84,16 +83,22 @@
final EditItemEvent event) {
this( asset,
event,
- false, null );
+ false,
+ null,
+ null );
}
-
+
/**
* @param historicalReadOnly true if this is a read only view for historical purposes.
*/
public RuleViewer(RuleAsset asset,
final EditItemEvent event,
boolean historicalReadOnly) {
- this (asset, event, historicalReadOnly, null);
+ this( asset,
+ event,
+ historicalReadOnly,
+ null,
+ null );
}
/**
@@ -103,13 +108,21 @@
*/
public RuleViewer(RuleAsset asset,
final EditItemEvent event,
- boolean historicalReadOnly, ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider) {
+ boolean historicalReadOnly,
+ ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider,
+ RuleViewerSettings ruleViewerSettings) {
this.editEvent = event;
this.asset = asset;
this.readOnly = historicalReadOnly && asset.isreadonly;
+ if ( ruleViewerSettings == null ) {
+ this.ruleViewerSettings = new RuleViewerSettings();
+ } else {
+ this.ruleViewerSettings = ruleViewerSettings;
+ }
+
this.layout = new VerticalPanel();
-
+
this.actionToolbarButtonsConfigurationProvider = actionToolbarButtonsConfigurationProvider;
layout.setWidth( "100%" );
@@ -138,14 +151,14 @@
LoadingPopup.close();
}
-
+
public void setDocoVisible(boolean docoVisible) {
- this.docoVisible = docoVisible;
- this.doco.setVisible( docoVisible );
+ this.ruleViewerSettings.setDocoVisible( docoVisible );
+ this.ruleDocumentWidget.setVisible( docoVisible );
}
public void setMetaVisible(boolean metaVisible) {
- this.metaVisible = metaVisible;
+ this.ruleViewerSettings.setMetaVisible( metaVisible );
this.metaWidget.setVisible( metaVisible );
}
@@ -196,7 +209,7 @@
doPromptToGlobal();
}
} );
-
+
//layout.add(toolbar, DockPanel.NORTH);
layout.add( toolbar );
layout.setCellHeight( toolbar,
@@ -213,21 +226,23 @@
doMetaWidget();
hsp = new HorizontalPanel();
- hsp.setHeight("100%");
- hsp.setWidth("100%");
+ hsp.setHeight( "100%" );
+ hsp.setWidth( "100%" );
layout.add( hsp );
- layout.setCellHeight(hsp, "100%");
+ layout.setCellHeight( hsp,
+ "100%" );
//the document widget
- doco = new RuleDocumentWidget( asset );
- doco.setVisible( docoVisible );
+ ruleDocumentWidget = new RuleDocumentWidget( asset,
+ ruleViewerSettings.isDocoVisible() );
VerticalPanel vert = new VerticalPanel();
vert.setWidth( "100%" );
vert.setHeight( "100%" );
-
+
vert.add( editor );
- vert.setCellHeight( editor, "100%" );
+ vert.setCellHeight( editor,
+ "100%" );
hsp.add( vert );
//hsp.addStyleName("HorizontalSplitPanel");
@@ -237,8 +252,7 @@
hsp.setCellWidth( metaWidget,
"25%" );
-
- layout.add( doco );
+ layout.add( ruleDocumentWidget );
}
private void doMetaWidget() {
@@ -255,7 +269,7 @@
refreshDataAndView();
}
} );
- metaWidget.setVisible( metaVisible );
+ metaWidget.setVisible( ruleViewerSettings.isMetaVisible() );
}
protected boolean hasDirty() {
@@ -295,16 +309,16 @@
//layout.clear();
this.asset.metaData.checkinComment = comment;
final boolean[] saved = {false};
-
+
if ( !saved[0] ) LoadingPopup.showMessage( constants.SavingPleaseWait() );
- //Not sure why we need a delay here.
-/* Timer t = new Timer() {
- public void run() {
- if ( !saved[0] ) LoadingPopup.showMessage( constants.SavingPleaseWait() );
- }
- };
- t.schedule( 500 );*/
+ //Not sure why we need a delay here.
+ /* Timer t = new Timer() {
+ public void run() {
+ if ( !saved[0] ) LoadingPopup.showMessage( constants.SavingPleaseWait() );
+ }
+ };
+ t.schedule( 500 );*/
RepositoryServiceFactory.getService().checkinVersion( this.asset,
new GenericCallback<String>() {
@@ -326,7 +340,7 @@
((DirtyableComposite) editor).resetDirty();
}
- doco.resetDirty();
+ ruleDocumentWidget.resetDirty();
refreshMetaWidgetOnly( false );
@@ -381,8 +395,7 @@
}
private void refreshMetaWidgetOnly(final boolean showBusy) {
-
-
+
if ( showBusy ) LoadingPopup.showMessage( constants.RefreshingItem() );
RepositoryServiceFactory.getService().loadRuleAsset( asset.uuid,
new GenericCallback<RuleAsset>() {
@@ -434,19 +447,19 @@
pop.addRow( new HTML( constants.AreYouSureYouWantToDiscardChanges() ) );
pop.addRow( hor );
- dis.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent arg0) {
+ dis.addClickHandler( new ClickHandler() {
+ public void onClick(ClickEvent arg0) {
closeCommand.execute();
- pop.hide();
- }
- });
-
- can.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent arg0) {
- pop.hide();
- }
- });
+ pop.hide();
+ }
+ } );
+ can.addClickHandler( new ClickHandler() {
+ public void onClick(ClickEvent arg0) {
+ pop.hide();
+ }
+ } );
+
pop.show();
}
@@ -461,9 +474,9 @@
sel );
Button ok = new Button( constants.CreateCopy() );
-
- ok.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent arg0) {
+
+ ok.addClickHandler( new ClickHandler() {
+ public void onClick(ClickEvent arg0) {
if ( newName.getText() == null || newName.getText().equals( "" ) ) {
Window.alert( constants.AssetNameMustNotBeEmpty() );
return;
@@ -493,13 +506,12 @@
}
} );
}
-
-
- });
-
- form.addAttribute( "", ok );
+ } );
+ form.addAttribute( "",
+ ok );
+
//form.setPopupPosition((DirtyableComposite.getWidth() - form.getOffsetWidth()) / 2, 100);
form.show();
}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewerSettings.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewerSettings.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewerSettings.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 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.client.ruleeditor;
+
+/**
+ *
+ * @author rikkola
+ *
+ */
+public class RuleViewerSettings {
+
+ private boolean metaVisible = true;
+ private boolean docoVisible = true;
+
+ public void setMetaVisible(boolean metaVisible) {
+ this.metaVisible = metaVisible;
+ }
+
+ public void setDocoVisible(boolean docoVisible) {
+ this.docoVisible = docoVisible;
+ }
+
+ public boolean isDocoVisible() {
+ return docoVisible;
+ }
+
+ public boolean isMetaVisible() {
+ return metaVisible;
+ }
+}
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-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/GuidedEditorServlet.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -16,7 +16,6 @@
package org.drools.guvnor.server;
-
import java.io.IOException;
import javax.servlet.ServletException;
@@ -27,30 +26,35 @@
public class GuidedEditorServlet extends HttpServlet {
- public static enum GUIDED_EDITOR_SERVLET_PARAMETERS{
- 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),
-
+ public static enum GUIDED_EDITOR_SERVLET_PARAMETERS {
+ 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);
-
- private String parameterName;
+ 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);
+
+ private String parameterName;
private boolean multipleValues;
- private GUIDED_EDITOR_SERVLET_PARAMETERS(String parameterName, boolean multipleValues){
+ private GUIDED_EDITOR_SERVLET_PARAMETERS(String parameterName,
+ boolean multipleValues) {
this.parameterName = parameterName;
this.multipleValues = multipleValues;
}
-
+
public String getParameterName() {
return parameterName;
}
@@ -58,27 +62,29 @@
public boolean isMultipleValues() {
return multipleValues;
}
-
+
}
-
+
@Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- HttpSession session = req.getSession(true);
-
+ protected void doPost(HttpServletRequest req,
+ HttpServletResponse resp) throws ServletException,
+ IOException {
+ HttpSession session = req.getSession( true );
+
//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(), req.getParameterValues(parameter.getParameterName()));
- }else{
- session.setAttribute(parameter.getParameterName(), req.getParameter(parameter.getParameterName()));
+ for ( GUIDED_EDITOR_SERVLET_PARAMETERS parameter : GUIDED_EDITOR_SERVLET_PARAMETERS.values() ) {
+ if ( parameter.isMultipleValues() ) {
+ session.setAttribute( parameter.getParameterName(),
+ req.getParameterValues( parameter.getParameterName() ) );
+ } else {
+ session.setAttribute( parameter.getParameterName(),
+ req.getParameter( parameter.getParameterName() ) );
}
}
-
- 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());
+
+ 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() );
}
-
-
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -16,7 +16,6 @@
package org.drools.guvnor.server;
-
import static org.drools.guvnor.server.util.ClassicDRLImporter.getRuleName;
import java.io.ByteArrayInputStream;
@@ -114,6 +113,7 @@
import org.drools.guvnor.server.util.TableDisplayHandler;
import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngine;
import org.drools.ide.common.client.modeldriven.testing.Scenario;
+import org.drools.ide.common.server.util.GuidedDTDRLPersistence;
import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.TypeDeclarationDescr;
import org.drools.repository.AssetHistoryIterator;
@@ -152,7 +152,6 @@
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
-
/**
* This is the implementation of the repository service to drive the GWT based
* front end.
@@ -178,7 +177,7 @@
private static final DateFormat dateFormatter = DateFormat.getInstance();
- private static final LoggingHelper log = LoggingHelper.getLogger( ServiceImplementation.class );
+ private static final LoggingHelper log = LoggingHelper.getLogger( ServiceImplementation.class );
private MetaDataMapper metaDataMapper = new MetaDataMapper();
@@ -510,12 +509,12 @@
}
AssetItemPageResult result = repository.findAssetsByCategory( categoryPath,
- false,
- skip,
- numRows);
+ false,
+ skip,
+ numRows );
TableDisplayHandler handler = new TableDisplayHandler( tableConfig );
// log.debug("time for load: " + (System.currentTimeMillis() - time) );
- return handler.loadRuleListTable(result);
+ return handler.loadRuleListTable( result );
}
@@ -528,16 +527,16 @@
// love you
// long time = System.currentTimeMillis();
- //TODO: May need to use a filter that acts on both package based and category based.
+ //TODO: May need to use a filter that acts on both package based and category based.
RepositoryFilter filter = new AssetItemFilter();
AssetItemPageResult result = repository.findAssetsByState( stateName,
- false,
- skip,
- numRows,
- filter );
+ false,
+ skip,
+ numRows,
+ filter );
TableDisplayHandler handler = new TableDisplayHandler( tableConfig );
// log.debug("time for load: " + (System.currentTimeMillis() - time) );
- return handler.loadRuleListTable(result);
+ return handler.loadRuleListTable( result );
}
@WebRemote
@@ -576,36 +575,34 @@
//Verify if the user has permission to access the asset through package based permission.
//If failed, then verify if the user has permission to access the asset through category
//based permission
- if (Contexts.isSessionContextActive()) {
- boolean passed = false;
+ if ( Contexts.isSessionContextActive() ) {
+ boolean passed = false;
- try {
- Identity.instance().checkPermission(
- new PackageNameType(asset.metaData.packageName),
- RoleTypes.PACKAGE_READONLY);
- } catch (RuntimeException e) {
- if (asset.metaData.categories.length == 0) {
- Identity.instance().checkPermission(
- new CategoryPathType(null), RoleTypes.ANALYST_READ);
- } else {
- RuntimeException exception = null;
+ try {
+ Identity.instance().checkPermission( new PackageNameType( asset.metaData.packageName ),
+ RoleTypes.PACKAGE_READONLY );
+ } catch ( RuntimeException e ) {
+ if ( asset.metaData.categories.length == 0 ) {
+ Identity.instance().checkPermission( new CategoryPathType( null ),
+ RoleTypes.ANALYST_READ );
+ } else {
+ RuntimeException exception = null;
- for (String cat : asset.metaData.categories) {
- try {
- Identity.instance().checkPermission(
- new CategoryPathType(cat),
- RoleTypes.ANALYST_READ);
- passed = true;
- } catch (RuntimeException re) {
- exception = re;
- }
- }
- if (!passed) {
- throw exception;
- }
- }
- }
- }
+ for ( String cat : asset.metaData.categories ) {
+ try {
+ Identity.instance().checkPermission( new CategoryPathType( cat ),
+ RoleTypes.ANALYST_READ );
+ passed = true;
+ } catch ( RuntimeException re ) {
+ exception = re;
+ }
+ }
+ if ( !passed ) {
+ throw exception;
+ }
+ }
+ }
+ }
// get package header
@@ -618,7 +615,7 @@
handler.retrieveAssetContent( asset,
pkgItem,
item );
-
+
asset.isreadonly = asset.metaData.hasSucceedingVersion;
if ( pkgItem.isSnapshot() ) {
@@ -694,6 +691,7 @@
meta.packageName = item.getPackageName();
meta.packageUUID = item.getPackage().getUUID();
+ meta.setBinary( item.isBinary() );
List cats = item.getCategories();
meta.categories = new String[cats.size()];
@@ -732,42 +730,39 @@
* and this role has permission to access the package which the asset belongs to.
*/
public String checkinVersion(RuleAsset asset) throws SerializationException {
-
+
//Verify if the user has permission to access the asset through package based permission.
//If failed, then verify if the user has permission to access the asset through category
//based permission
- if (Contexts.isSessionContextActive()) {
- boolean passed = false;
+ if ( Contexts.isSessionContextActive() ) {
+ boolean passed = false;
- try {
- Identity.instance().checkPermission(
- new PackageNameType(asset.metaData.packageName),
- RoleTypes.PACKAGE_DEVELOPER);
- } catch (RuntimeException e) {
- if (asset.metaData.categories.length == 0) {
- Identity.instance().checkPermission(
- new CategoryPathType(null), RoleTypes.ANALYST);
- } else {
- RuntimeException exception = null;
+ try {
+ Identity.instance().checkPermission( new PackageNameType( asset.metaData.packageName ),
+ RoleTypes.PACKAGE_DEVELOPER );
+ } catch ( RuntimeException e ) {
+ if ( asset.metaData.categories.length == 0 ) {
+ Identity.instance().checkPermission( new CategoryPathType( null ),
+ RoleTypes.ANALYST );
+ } else {
+ RuntimeException exception = null;
- for (String cat : asset.metaData.categories) {
- try {
- Identity.instance().checkPermission(
- new CategoryPathType(cat),
- RoleTypes.ANALYST);
- passed = true;
- } catch (RuntimeException re) {
- exception = re;
- }
- }
- if (!passed) {
- throw exception;
- }
- }
- }
- }
-
-
+ for ( String cat : asset.metaData.categories ) {
+ try {
+ Identity.instance().checkPermission( new CategoryPathType( cat ),
+ RoleTypes.ANALYST );
+ passed = true;
+ } catch ( RuntimeException re ) {
+ exception = re;
+ }
+ }
+ if ( !passed ) {
+ throw exception;
+ }
+ }
+ }
+ }
+
log.info( "USER:" + getCurrentUserName() + " CHECKING IN asset: [" + asset.metaData.name + "] UUID: [" + asset.uuid + "] " );
AssetItem repoAsset = repository.loadAssetByUUID( asset.uuid );
@@ -889,10 +884,10 @@
TableDataResult table = new TableDataResult();
table.data = result.toArray( new TableDataRow[result.size()] );
- table.currentPosition = it.getPosition();
- table.total = it.getSize();
+ table.currentPosition = it.getPosition();
+ table.total = it.getSize();
table.hasNext = it.hasNext();
-
+
return table;
}
@@ -1090,7 +1085,7 @@
log.debug( "Loading asset list for [" + uuid + "]" );
if ( numRows == 0 ) {
throw new DetailedSerializationException( "Unable to return zero results (bug)",
- "probably have the parameters around the wrong way, sigh..." );
+ "probably have the parameters around the wrong way, sigh..." );
}
long start = System.currentTimeMillis();
PackageItem pkg = repository.loadPackageByUUID( uuid );
@@ -1115,7 +1110,7 @@
int numRows) throws SerializationException {
if ( numRows == 0 ) {
throw new DetailedSerializationException( "Unable to return zero results (bug)",
- "probably have the parameters around the wrong way, sigh..." );
+ "probably have the parameters around the wrong way, sigh..." );
}
AssetItemIterator it = repository.queryFullText( text,
seekArchived );
@@ -1151,7 +1146,7 @@
int numRows) throws SerializationException {
if ( numRows == 0 ) {
throw new DetailedSerializationException( "Unable to return zero results (bug)",
- "probably have the parameters around the wrong way, sigh..." );
+ "probably have the parameters around the wrong way, sigh..." );
}
Map<String, String[]> q = new HashMap<String, String[]>() {
{
@@ -1263,7 +1258,7 @@
} catch ( RulesRepositoryException e ) {
throw new DetailedSerializationException( "Unable to remove status. It is probably still used (even by archived items).",
- e.getMessage() );
+ e.getMessage() );
}
}
@@ -1306,54 +1301,50 @@
if ( !wholePackage ) {
AssetItem asset = repository.loadAssetByUUID( uuid );
-
+
//Verify if the user has permission to access the asset through package based permission.
//If failed, then verify if the user has permission to access the asset through category
//based permission
- if (Contexts.isSessionContextActive()) {
- boolean passed = false;
+ if ( Contexts.isSessionContextActive() ) {
+ boolean passed = false;
- try {
- Identity.instance().checkPermission(
- new PackageUUIDType(asset.getPackage().getUUID()),
- RoleTypes.PACKAGE_DEVELOPER);
- } catch (RuntimeException e) {
- if (asset.getCategories().size() == 0) {
- Identity.instance().checkPermission(
- new CategoryPathType(null), RoleTypes.ANALYST);
- } else {
- RuntimeException exception = null;
+ try {
+ Identity.instance().checkPermission( new PackageUUIDType( asset.getPackage().getUUID() ),
+ RoleTypes.PACKAGE_DEVELOPER );
+ } catch ( RuntimeException e ) {
+ if ( asset.getCategories().size() == 0 ) {
+ Identity.instance().checkPermission( new CategoryPathType( null ),
+ RoleTypes.ANALYST );
+ } else {
+ RuntimeException exception = null;
- for (CategoryItem cat : asset.getCategories()) {
- try {
- Identity.instance().checkPermission(
- new CategoryPathType(cat.getName()),
- RoleTypes.ANALYST);
- passed = true;
- } catch (RuntimeException re) {
- exception = re;
- }
- }
- if (!passed) {
- throw exception;
- }
- }
- }
- }
-
-
- log.info("USER:" + getCurrentUserName()
- + " CHANGING ASSET STATUS. Asset name, uuid: " + "["
- + asset.getName() + ", " + asset.getUUID() + "]" + " to ["
- + newState + "]");
- String oldState = asset.getStateDescription();
- asset.updateState(newState);
+ for ( CategoryItem cat : asset.getCategories() ) {
+ try {
+ Identity.instance().checkPermission( new CategoryPathType( cat.getName() ),
+ RoleTypes.ANALYST );
+ passed = true;
+ } catch ( RuntimeException re ) {
+ exception = re;
+ }
+ }
+ if ( !passed ) {
+ throw exception;
+ }
+ }
+ }
+ }
- push("statusChange", oldState);
- push("statusChange", newState);
+ log.info( "USER:" + getCurrentUserName() + " CHANGING ASSET STATUS. Asset name, uuid: " + "[" + asset.getName() + ", " + asset.getUUID() + "]" + " to [" + newState + "]" );
+ String oldState = asset.getStateDescription();
+ asset.updateState( newState );
- addToDiscussionForAsset(asset.getUUID(), oldState + " -> "
- + newState);
+ push( "statusChange",
+ oldState );
+ push( "statusChange",
+ newState );
+
+ addToDiscussionForAsset( asset.getUUID(),
+ oldState + " -> " + newState );
} else {
if ( Contexts.isSessionContextActive() ) {
Identity.instance().checkPermission( new PackageUUIDType( uuid ),
@@ -1541,7 +1532,7 @@
log.info( "Unable to remove category [" + categoryPath + "]. It is probably still used: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to remove category. It is probably still used.",
- e.getMessage() );
+ e.getMessage() );
}
}
@@ -1637,10 +1628,10 @@
customSelectorName );
} catch ( NoClassDefFoundError e ) {
throw new DetailedSerializationException( "Unable to find a class that was needed when building the package [" + e.getMessage() + "]",
- "Perhaps you are missing them from the model jars, or from the BRMS itself (lib directory)." );
+ "Perhaps you are missing them from the model jars, or from the BRMS itself (lib directory)." );
} catch ( UnsupportedClassVersionError e ) {
throw new DetailedSerializationException( "Can not build the package. One or more of the classes that are needed were compiled with an unsupported Java version.",
- "For example the pojo classes were compiled with Java 1.6 and Guvnor is running on Java 1.5. [" + e.getMessage() + "]" );
+ "For example the pojo classes were compiled with Java 1.6 and Guvnor is running on Java 1.5. [" + e.getMessage() + "]" );
}
}
@@ -1709,7 +1700,7 @@
e.printStackTrace();
log.error( "An error occurred building the package [" + item.getName() + "]: " + e.getMessage() );
throw new DetailedSerializationException( "An error occurred building the package.",
- e.getMessage() );
+ e.getMessage() );
}
return null;
@@ -1765,29 +1756,37 @@
RoleTypes.PACKAGE_DEVELOPER );
}
- AssetItem item = repository.loadAssetByUUID( asset.uuid );
+ ContentHandler handler = ContentManager.getHandler( asset.metaData.format );
- ContentHandler handler = ContentManager.getHandler( item.getFormat() );// new
- // AssetContentFormatHandler();
- handler.storeAssetContent( asset,
- item );
StringBuffer buf = new StringBuffer();
if ( handler.isRuleAsset() ) {
BRMSPackageBuilder builder = new BRMSPackageBuilder();
// now we load up the DSL files
- builder.setDSLFiles( BRMSPackageBuilder.getDSLMappingFiles( item.getPackage(),
+ PackageItem packageItem = repository.loadPackage( asset.metaData.packageName );
+ builder.setDSLFiles( BRMSPackageBuilder.getDSLMappingFiles( packageItem,
new BRMSPackageBuilder.DSLErrorEvent() {
public void recordError(AssetItem asset,
String message) {
// ignore at this point...
}
} ) );
- ((IRuleAsset) handler).assembleDRL( builder,
- item,
- buf );
- } else {
- return item.getContent();
+
+ if ( asset.metaData.isBinary() ) {
+ AssetItem item = repository.loadAssetByUUID( asset.uuid );
+
+ // AssetContentFormatHandler();
+ handler.storeAssetContent( asset,
+ item );
+ ((IRuleAsset) handler).assembleDRL( builder,
+ item,
+ buf );
+ } else {
+ ((IRuleAsset) handler).assembleDRL( builder,
+ asset,
+ buf );
+ }
+
}
return buf.toString();
@@ -1823,7 +1822,8 @@
}
}
} catch ( Exception e ) {
- log.error("Unable to build asset.", e );
+ log.error( "Unable to build asset.",
+ e );
result = new BuilderResult();
BuilderResultLine res = new BuilderResultLine();
@@ -1854,7 +1854,8 @@
repository.copyPackage( sourcePackageName,
destPackageName );
} catch ( RulesRepositoryException e ) {
- log.error("Unable to copy package.", e );
+ log.error( "Unable to copy package.",
+ e );
throw e;
}
@@ -1921,7 +1922,8 @@
((ICanHasAttachment) handler).onAttachmentRemoved( item );
}
} catch ( IOException e ) {
- log.error("Unable to remove asset attachment", e );
+ log.error( "Unable to remove asset attachment",
+ e );
}
item.archiveItem( archive );
@@ -1938,7 +1940,8 @@
pkg.getName() );
} catch ( RulesRepositoryException e ) {
- log.error("Unable to get item format.", e );
+ log.error( "Unable to get item format.",
+ e );
throw e;
}
}
@@ -1966,7 +1969,8 @@
item.remove();
repository.save();
} catch ( RulesRepositoryException e ) {
- log.error("Unable to remove asset.", e );
+ log.error( "Unable to remove asset.",
+ e );
throw e;
}
}
@@ -1993,7 +1997,8 @@
item.remove();
repository.save();
} catch ( RulesRepositoryException e ) {
- log.error("Unable to remove package.", e );
+ log.error( "Unable to remove package.",
+ e );
throw e;
}
}
@@ -2019,29 +2024,31 @@
Identity.instance().checkPermission( new PackageNameType( packageName ),
RoleTypes.PACKAGE_ADMIN );
}
- log.info( "USER:" + getCurrentUserName() + " export package [name: " + packageName + "] ");
-
+ log.info( "USER:" + getCurrentUserName() + " export package [name: " + packageName + "] " );
+
byte[] result = null;
-
+
try {
- result = repository.dumpPackageFromRepositoryXml( packageName);
- } catch (PathNotFoundException e) {
- throw new RulesRepositoryException(e);
- } catch (IOException e) {
- throw new RulesRepositoryException(e);
- } catch (RepositoryException e) {
- throw new RulesRepositoryException(e);
- }
+ result = repository.dumpPackageFromRepositoryXml( packageName );
+ } catch ( PathNotFoundException e ) {
+ throw new RulesRepositoryException( e );
+ } catch ( IOException e ) {
+ throw new RulesRepositoryException( e );
+ } catch ( RepositoryException e ) {
+ throw new RulesRepositoryException( e );
+ }
return result;
}
-
+
@WebRemote
@Restrict("#{identity.loggedIn}")
//TODO: Not working. GUVNOR-475
- public void importPackages(byte[] byteArray, boolean importAsNew) {
- repository.importPackageToRepository( byteArray, importAsNew);
+ public void importPackages(byte[] byteArray,
+ boolean importAsNew) {
+ repository.importPackageToRepository( byteArray,
+ importAsNew );
}
-
+
@WebRemote
public void rebuildSnapshots() throws SerializationException {
if ( Contexts.isSessionContextActive() ) {
@@ -2065,7 +2072,7 @@
buf.append( '\n' );
}
throw new DetailedSerializationException( "Unable to rebuild snapshot [" + snapName,
- buf.toString() + "]" );
+ buf.toString() + "]" );
}
}
}
@@ -2114,7 +2121,8 @@
return result.toArray( new String[result.size()] );
} catch ( DroolsParserException e ) {
- log.error("Unable to list rules in package", e );
+ log.error( "Unable to list rules in package",
+ e );
return new String[0];
}
}
@@ -2232,7 +2240,7 @@
this.ruleBaseCache.put( item.getUUID(),
rb );
} else throw new DetailedSerializationException( "Build error",
- result.lines );
+ result.lines );
}
}
@@ -2245,11 +2253,13 @@
return deserKnowledgebase( item,
cl );
} catch ( ClassNotFoundException e ) {
- log.error("Unable to load rule base.", e );
+ log.error( "Unable to load rule base.",
+ e );
throw new DetailedSerializationException( "A required class was not found.",
- e.getMessage() );
+ e.getMessage() );
} catch ( Exception e ) {
- log.error("Unable to load rule base.", e );
+ log.error( "Unable to load rule base.",
+ e );
log.info( "...but trying to rebuild binaries..." );
try {
BuilderResult res = this.buildPackage( item,
@@ -2257,7 +2267,7 @@
if ( res != null && res.lines.length > 0 ) {
log.error( "There were errors when rebuilding the knowledgebase." );
throw new DetailedSerializationException( "There were errors when rebuilding the knowledgebase.",
- "" );
+ "" );
}
try {
return deserKnowledgebase( item,
@@ -2265,12 +2275,12 @@
} catch ( Exception e2 ) {
log.error( "Unable to reload knowledgebase: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to reload knowledgebase.",
- e.getMessage() );
+ e.getMessage() );
}
} catch ( Exception e1 ) {
log.error( "Unable to rebuild the rulebase: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to rebuild the rulebase.",
- "" );
+ "" );
}
}
@@ -2325,21 +2335,21 @@
} catch ( ClassNotFoundException e ) {
log.error( "Unable to load a required class: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to load a required class.",
- e.getMessage() );
+ e.getMessage() );
} catch ( ConsequenceException e ) {
String messageShort = "There was an error executing the consequence of rule [" + e.getRule().getName() + "]";
String messageLong = e.getMessage();
- if (e.getCause() != null){
- messageLong += "\nCAUSED BY "+e.getCause().getMessage();
+ if ( e.getCause() != null ) {
+ messageLong += "\nCAUSED BY " + e.getCause().getMessage();
}
- log.error( messageShort+": "+messageLong );
+ log.error( messageShort + ": " + messageLong );
throw new DetailedSerializationException( messageShort,
- messageLong );
+ messageLong );
} catch ( Exception e ) {
log.error( "Unable to run the scenario: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to run the scenario.",
- e.getMessage() );
+ e.getMessage() );
}
}
@@ -2438,7 +2448,7 @@
}
return h;
}
-
+
@WebRemote
@Restrict("#{identity.loggedIn}")
public String[] listTypesInPackage(String packageUUID) throws SerializationException {
@@ -2489,7 +2499,7 @@
} catch ( IOException e ) {
log.error( "Unable to read the jar files in the package: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to read the jar files in the package.",
- e.getMessage() );
+ e.getMessage() );
} finally {
IOUtils.closeQuietly( jis );
}
@@ -2614,7 +2624,7 @@
if ( errs.toString().length() > 0 ) {
throw new DetailedSerializationException( "Unable to rebuild all packages.",
- errs.toString() );
+ errs.toString() );
}
}
@@ -2747,7 +2757,7 @@
Discussion dp = new Discussion();
List<DiscussionRecord> discussion = dp.fromString( asset.getStringProperty( Discussion.DISCUSSION_PROPERTY_KEY ) );
discussion.add( new DiscussionRecord( repo.getSession().getUserID(),
- StringEscapeUtils.escapeXml(comment) ) );
+ StringEscapeUtils.escapeXml( comment ) ) );
asset.updateStringProperty( dp.toString( discussion ),
Discussion.DISCUSSION_PROPERTY_KEY,
false );
@@ -2792,7 +2802,7 @@
} catch ( Exception e ) {
log.error( "Unable to load Inbox: " + e.getMessage() );
throw new DetailedSerializationException( "Unable to load Inbox",
- e.getMessage() );
+ e.getMessage() );
}
}
@@ -2806,15 +2816,15 @@
}
public List<PushResponse> subscribe() {
- if (Contexts.isApplicationContextActive() && !Session.instance().isInvalid()) {
- try {
- return backchannel.await(getCurrentUserName());
- } catch (InterruptedException e) {
- return new ArrayList<PushResponse>();
- }
- } else {
- return new ArrayList<PushResponse>();
- }
+ if ( Contexts.isApplicationContextActive() && !Session.instance().isInvalid() ) {
+ try {
+ return backchannel.await( getCurrentUserName() );
+ } catch ( InterruptedException e ) {
+ return new ArrayList<PushResponse>();
+ }
+ } else {
+ return new ArrayList<PushResponse>();
+ }
}
private String getCurrentUserName() {
@@ -2924,30 +2934,34 @@
diffs.diffs = list.toArray( new SnapshotDiff[list.size()] );
return diffs;
}
-
+
/**
* Load and process the repository configuration templates.
*/
- public String processTemplate(String name, Map<String, Object> data) {
- try {
- Configuration cfg = new Configuration();
- cfg.setObjectWrapper(new DefaultObjectWrapper());
- cfg.setTemplateUpdateDelay(0);
+ public String processTemplate(String name,
+ Map<String, Object> data) {
+ try {
+ Configuration cfg = new Configuration();
+ cfg.setObjectWrapper( new DefaultObjectWrapper() );
+ cfg.setTemplateUpdateDelay( 0 );
- Template temp = new Template(name, new InputStreamReader(ServiceImplementation.class.getResourceAsStream("/repoconfig/" + name + ".xml")), cfg);
- StringWriter strw = new StringWriter();
- temp.process(data, strw);
- return StringEscapeUtils.escapeXml(strw.toString());
- } catch (Exception e) {
- return "";
- }
- }
-
- /**
- * Check to see if app context is active (not in hosted)
- */
- public Boolean isHostedMode() {
- Boolean hm = Contexts.isApplicationContextActive() ? Boolean.FALSE : Boolean.TRUE;
- return hm;
- }
+ Template temp = new Template( name,
+ new InputStreamReader( ServiceImplementation.class.getResourceAsStream( "/repoconfig/" + name + ".xml" ) ),
+ cfg );
+ StringWriter strw = new StringWriter();
+ temp.process( data,
+ strw );
+ return StringEscapeUtils.escapeXml( strw.toString() );
+ } catch ( Exception e ) {
+ return "";
+ }
+ }
+
+ /**
+ * Check to see if app context is active (not in hosted)
+ */
+ public Boolean isHostedMode() {
+ Boolean hm = Contexts.isApplicationContextActive() ? Boolean.FALSE : Boolean.TRUE;
+ return hm;
+ }
}
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-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -32,7 +32,6 @@
import org.drools.repository.RulesRepository;
import org.jboss.seam.annotations.In;
-
import org.drools.ide.common.server.util.BRXMLPersistence;
/**
@@ -41,11 +40,11 @@
* @author esteban.aliverti
*/
public class StandaloneGuidedEditorServiceImplementation extends RemoteServiceServlet
- implements
- StandaloneGuidedEditorService {
+ implements
+ StandaloneGuidedEditorService {
@In
- public RulesRepository repository;
+ public RulesRepository repository;
private static final long serialVersionUID = 520l;
public RulesRepository getRulesRepository() {
@@ -56,43 +55,40 @@
return RepositoryServiceServlet.getService();
}
-
- public StandaloneGuidedEditorInvocationParameters getInvocationParameters() throws DetailedSerializationException{
-
+ public StandaloneGuidedEditorInvocationParameters getInvocationParameters() throws DetailedSerializationException {
+
//Get the parameters from the session
HttpSession session = this.getThreadLocalRequest().getSession();
-
+
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());
+ Object attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_LHS_PARAMETER_NAME.getParameterName() );
+ if ( attribute != null ) {
+ hideLHSInEditor = Boolean.parseBoolean( attribute.toString() );
}
-
+
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());
+ attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_RHS_PARAMETER_NAME.getParameterName() );
+ if ( attribute != null ) {
+ hideRHSInEditor = 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());
+ attribute = session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_HIDE_RULE_ATTRIBUTES_PARAMETER_NAME.getParameterName() );
+ if ( attribute != null ) {
+ hideAttributesInEditor = Boolean.parseBoolean( attribute.toString() );
}
-
-
+
StandaloneGuidedEditorInvocationParameters parameters = new StandaloneGuidedEditorInvocationParameters();
-
- parameters.setAssetsToBeEdited(this.loadRuleAssetsFromSession());
-
- parameters.setHideLHS(hideLHSInEditor);
- parameters.setHideRHS(hideRHSInEditor);
- parameters.setHideAttributes(hideAttributesInEditor);
-
-
+
+ parameters.setAssetsToBeEdited( this.loadRuleAssetsFromSession() );
+
+ parameters.setHideLHS( hideLHSInEditor );
+ parameters.setHideRHS( hideRHSInEditor );
+ parameters.setHideAttributes( hideAttributesInEditor );
+
return parameters;
}
-
+
/**
* To open the Guided Editor as standalone, you should be gone through
* GuidedEditorServlet first. This servlet put all the POST parameters into
@@ -102,81 +98,84 @@
* one asset per BRL with a unique name.
* @return
* @throws DetailedSerializationException
- */
- private RuleAsset[] loadRuleAssetsFromSession() throws DetailedSerializationException{
-
+ */
+ private RuleAsset[] loadRuleAssetsFromSession() throws DetailedSerializationException {
+
//Get the parameters from the session
HttpSession session = this.getThreadLocalRequest().getSession();
-
- 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());
-
+
+ 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());
+ 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());
-
- RuleAssetProvider provider;
- if (createNewAsset){
- provider = new NewRuleAssetProvider(packageName,categoryName,ruleName);
- }else if (assetsUUIDs != null){
- provider = new UUIDRuleAssetProvider(assetsUUIDs);
- }else if (initialBRL != null){
- provider = new BRLRuleAssetProvider(packageName,categoryName,initialBRL);
- }else{
+ String ruleName = (String) session.getAttribute( GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_RULE_PARAMETER_NAME.getParameterName() );
+
+ RuleAssetProvider provider;
+ if ( createNewAsset ) {
+ provider = new NewRuleAssetProvider( packageName,
+ categoryName,
+ ruleName );
+ } else if ( assetsUUIDs != null ) {
+ provider = new UUIDRuleAssetProvider( assetsUUIDs );
+ } else if ( initialBRL != null ) {
+ provider = new BRLRuleAssetProvider( packageName,
+ initialBRL );
+ } else {
throw new IllegalStateException();
}
-
+
return provider.getRuleAssets();
-
+
}
-
+
/**
* Returns the DRL source code of the given assets.
* @param assetsUUIDs
* @return
* @throws SerializationException
*/
- public String[] getAsstesDRL(String[] assetsUUIDs) throws SerializationException{
-
+ public String[] getAsstesDRL(String[] assetsUUIDs) throws SerializationException {
+
String[] sources = new String[assetsUUIDs.length];
-
- for (int i = 0; i < assetsUUIDs.length; i++) {
- RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUUIDs[i]);
- sources[i] = this.getService().buildAssetSource(ruleAsset);
+
+ for ( int i = 0; i < assetsUUIDs.length; i++ ) {
+ RuleAsset ruleAsset = this.getService().loadRuleAsset( assetsUUIDs[i] );
+ sources[i] = this.getService().buildAssetSource( ruleAsset );
}
-
+
return sources;
}
-
+
/**
* Returns the BRL source code of the given assets.
* @param assetsUUIDs
* @return
* @throws SerializationException
*/
- public String[] getAsstesBRL(String[] assetsUUIDs) throws SerializationException{
-
+ public String[] getAsstesBRL(String[] assetsUUIDs) throws SerializationException {
+
String[] sources = new String[assetsUUIDs.length];
-
+
BRLPersistence converter = BRXMLPersistence.getInstance();
- for (int i = 0; i < assetsUUIDs.length; i++) {
- RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUUIDs[i]);
- sources[i] = converter.marshal((RuleModel) ruleAsset.content);
+ 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);
+ public void removeAssets(String[] assetsUUIDs) {
+ this.getService().removeAssets( assetsUUIDs );
}
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/BRLContentHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/BRLContentHandler.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/BRLContentHandler.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -47,16 +47,20 @@
import org.drools.repository.PackageItem;
import com.google.gwt.user.client.rpc.SerializationException;
+import com.sun.tools.javac.resources.compiler;
-
public class BRLContentHandler extends ContentHandler
- implements IRuleAsset {
+ implements
+ IRuleAsset {
-
- public void retrieveAssetContent(RuleAsset asset,
+ public void retrieveAssetContent(RuleAsset asset,
PackageItem pkg,
AssetItem item) throws SerializationException {
- asset.content = getBrlXmlPersistence().unmarshal( item.getContent() );
+ RuleModel ruleModel = getBrlXmlPersistence().unmarshal( item.getContent() );
+
+ ruleModel.name = asset.metaData.name;
+
+ asset.content = ruleModel;
}
public void storeAssetContent(RuleAsset asset,
@@ -72,21 +76,28 @@
AssetItem asset,
ContentPackageAssembler.ErrorLogger logger) throws DroolsParserException,
IOException {
- builder.addPackageFromDrl( new StringReader( getSourceDRL( asset,
+ builder.addPackageFromDrl( new StringReader( getSourceDRL( buildModelFromAsset( asset ),
builder ) ) );
}
public void assembleDRL(BRMSPackageBuilder builder,
+ RuleAsset asset,
+ StringBuffer buf) {
+ String drl = getSourceDRL( (RuleModel) asset.content,
+ builder );
+ buf.append( drl );
+ }
+
+ public void assembleDRL(BRMSPackageBuilder builder,
AssetItem asset,
StringBuffer buf) {
- String drl = getSourceDRL( asset,
+ String drl = getSourceDRL( buildModelFromAsset( asset ),
builder );
buf.append( drl );
}
- private String getSourceDRL(AssetItem asset,
+ private String getSourceDRL(RuleModel model,
BRMSPackageBuilder builder) {
- RuleModel model = buildModelFromAsset(asset);
String drl = getBrlDrlPersistence().marshal( model );
if ( builder.hasDSL() && model.hasDSLSentences() ) {
@@ -95,24 +106,25 @@
return drl;
}
- protected RuleModel buildModelFromAsset(AssetItem asset) {
- RuleModel model = getBrlXmlPersistence().unmarshal(asset.getContent());
- model.name = asset.getName();
- model.parentName = this.parentNameFromCategory(asset, model.parentName);
- return model;
- }
+ protected RuleModel buildModelFromAsset(AssetItem asset) {
+ RuleModel model = getBrlXmlPersistence().unmarshal( asset.getContent() );
+ model.name = asset.getName();
+ model.parentName = this.parentNameFromCategory( asset,
+ model.parentName );
+ return model;
+ }
public String getRawDRL(AssetItem asset) {
RuleModel model = getBrlXmlPersistence().unmarshal( asset.getContent() );
return getBrlDrlPersistence().marshal( model );
}
-
+
protected BRLPersistence getBrlDrlPersistence() {
- return BRDRLPersistence.getInstance();
- }
+ return BRDRLPersistence.getInstance();
+ }
protected BRLPersistence getBrlXmlPersistence() {
- return BRXMLPersistence.getInstance();
- }
+ return BRXMLPersistence.getInstance();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/ContentHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/ContentHandler.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/ContentHandler.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -44,7 +44,6 @@
import com.google.gwt.user.client.rpc.SerializationException;
-
/**
* All content handlers must implement this, and be registered in content_types.properties
* @author Michael Neale
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DRLFileContentHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DRLFileContentHandler.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DRLFileContentHandler.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -37,6 +37,8 @@
import java.util.StringTokenizer;
import org.drools.compiler.DroolsParserException;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.client.rpc.RuleContentText;
import org.drools.guvnor.server.builder.BRMSPackageBuilder;
import org.drools.guvnor.server.builder.ContentPackageAssembler;
import org.drools.repository.AssetItem;
@@ -114,6 +116,22 @@
}
public void assembleDRL(BRMSPackageBuilder builder,
+ RuleAsset asset,
+ StringBuffer buf) {
+
+ String content = ((RuleContentText) asset.content).content;
+
+ if ( isStandAloneRule( content ) ) {
+
+ content = wrapRuleDeclaration( asset.metaData.name,
+ "",
+ content );
+ }
+
+ buf.append( content );
+ }
+
+ public void assembleDRL(BRMSPackageBuilder builder,
AssetItem asset,
StringBuffer buf) {
String content = getRawDRL( asset );
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DSLRuleContentHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DSLRuleContentHandler.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DSLRuleContentHandler.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -50,7 +50,6 @@
import com.google.gwt.user.client.rpc.SerializationException;
-
public class DSLRuleContentHandler extends ContentHandler
implements
IRuleAsset {
@@ -86,7 +85,7 @@
if ( DRLFileContentHandler.isStandAloneRule( source ) ) {
String parentName = this.parentNameFromCategory( asset,
"" );
- source = wrapRule( asset,
+ source = wrapRule( asset.getName(),
parentName,
source );
}
@@ -119,6 +118,20 @@
}
public void assembleDRL(BRMSPackageBuilder builder,
+ RuleAsset asset,
+ StringBuffer buf) {
+ RuleContentText text = (RuleContentText) asset.content;
+ String source = text.content;
+
+ source = getDRL( source,
+ asset.metaData.name,
+ null );
+
+ DefaultExpander expander = builder.getDSLExpander();
+ buf.append( expander.expand( source ) );
+ }
+
+ public void assembleDRL(BRMSPackageBuilder builder,
AssetItem asset,
StringBuffer buf) {
//add the rule keyword if its 'stand alone'
@@ -129,23 +142,33 @@
}
- private String wrapRule(AssetItem asset,
+ private String wrapRule(String assetName,
String parentName,
String source) {
if ( parentName == null || "".equals( parentName ) ) {
- return "rule '" + asset.getName() + "' \n" + source + "\nend";
+ return "rule '" + assetName + "' \n" + source + "\nend";
} else {
- return "rule '" + asset.getName() + "' extends " + parentName + " \n" + source + "\nend";
+ return "rule '" + assetName + "' extends " + parentName + " \n" + source + "\nend";
}
}
public String getRawDRL(AssetItem asset) {
String source = asset.getContent();
+ String parentName = this.parentNameFromCategory( asset,
+ "" );
+ source = getDRL( source,
+ asset.getName(),
+ parentName );
+
+ return source;
+ }
+
+ public String getDRL(String source,
+ String assetName,
+ String parentName) {
if ( DRLFileContentHandler.isStandAloneRule( source ) ) {
- String parentName = this.parentNameFromCategory( asset,
- "" );
- source = wrapRule( asset,
+ source = wrapRule( assetName,
parentName,
source );
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DecisionTableXLSHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DecisionTableXLSHandler.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/DecisionTableXLSHandler.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -33,6 +33,7 @@
*/
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringReader;
import org.drools.compiler.DroolsParserException;
@@ -46,7 +47,6 @@
import com.google.gwt.user.client.rpc.SerializationException;
-
/**
* This is for handling XLS content (classic decision tables).
*
@@ -68,6 +68,13 @@
}
public void assembleDRL(BRMSPackageBuilder builder,
+ RuleAsset asset,
+ StringBuffer buf) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void assembleDRL(BRMSPackageBuilder builder,
AssetItem asset,
StringBuffer buf) {
buf.append( getRawDRL( asset ) );
@@ -87,9 +94,13 @@
}
public String getRawDRL(AssetItem asset) {
+ return getDRL( asset.getBinaryContentAttachment() );
+ }
+
+ private String getDRL(InputStream stream) {
SpreadsheetCompiler comp = new SpreadsheetCompiler();
String drl = comp.compile( false,
- asset.getBinaryContentAttachment(),
+ stream,
InputType.XLS );
return drl;
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/GuidedDTContentHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/GuidedDTContentHandler.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/GuidedDTContentHandler.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -47,7 +47,6 @@
import com.google.gwt.user.client.rpc.SerializationException;
-
/**
* For guided decision tables.
*
@@ -91,6 +90,14 @@
}
public void assembleDRL(BRMSPackageBuilder builder,
+ RuleAsset asset,
+ StringBuffer buf) {
+ GuidedDecisionTable model = (GuidedDecisionTable) asset.content;
+
+ buf.append( GuidedDTDRLPersistence.getInstance().marshal( model ) );
+ }
+
+ public void assembleDRL(BRMSPackageBuilder builder,
AssetItem asset,
StringBuffer buf) {
String drl = getRawDRL( asset );
@@ -101,7 +108,7 @@
GuidedDecisionTable model = GuidedDTXMLPersistence.getInstance().unmarshal( asset.getContent() );
model.setTableName( asset.getName() );
model.setParentName( this.parentNameFromCategory( asset,
- model.getParentName() ) );
+ model.getParentName() ) );
return GuidedDTDRLPersistence.getInstance().marshal( model );
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/IRuleAsset.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/IRuleAsset.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/contenthandler/IRuleAsset.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2010 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,7 @@
package org.drools.guvnor.server.contenthandler;
+import org.drools.guvnor.client.rpc.RuleAsset;
import org.drools.guvnor.server.builder.BRMSPackageBuilder;
import org.drools.repository.AssetItem;
@@ -34,8 +35,13 @@
AssetItem asset,
StringBuffer buf);
+ public void assembleDRL(BRMSPackageBuilder builder,
+ RuleAsset asset,
+ StringBuffer buf);
+
/**
* If the rule has DSL in it, it is presented unexpanded.
*/
public String getRawDRL(AssetItem asset);
+
}
Modified: 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 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/guidededitor/BRLRuleAssetProvider.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -18,8 +18,10 @@
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.MetaData;
import org.drools.guvnor.client.rpc.RuleAsset;
import org.drools.guvnor.server.RepositoryServiceServlet;
import org.drools.guvnor.server.ServiceImplementation;
@@ -32,82 +34,75 @@
* will be the name present in the brl concatenated with a unique number.
* @author esteban.aliverti
*/
-public class BRLRuleAssetProvider implements RuleAssetProvider {
-
- private String packageName;
- private String categoryName;
+public class BRLRuleAssetProvider
+ implements
+ RuleAssetProvider {
+
+ private String packageName;
private String[] initialBRLs;
- public BRLRuleAssetProvider(String packageName, String categoryName, String[] initialBRLs) {
+ public BRLRuleAssetProvider(String packageName,
+ String[] initialBRLs) {
this.packageName = packageName;
- this.categoryName = categoryName;
this.initialBRLs = initialBRLs;
}
-
+
public RuleAsset[] getRuleAssets() throws DetailedSerializationException {
-
- List<RuleModel> models = new ArrayList<RuleModel>(initialBRLs.length);
- List<RuleAsset> assets = new ArrayList<RuleAsset>(initialBRLs.length);
-
+
+ List<RuleModel> models = new ArrayList<RuleModel>( initialBRLs.length );
+ List<RuleAsset> assets = new ArrayList<RuleAsset>( initialBRLs.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 : initialBRLs) {
+ for ( String brl : initialBRLs ) {
//convert the BRL to RuleModel
- models.add(BRXMLPersistence.getInstance().unmarshal(brl));
+ 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(ruleModel));
+ try {
+ for ( RuleModel ruleModel : models ) {
+ assets.add( this.createAsset( ruleModel ) );
}
- } catch (Exception e){
+ } catch ( Exception e ) {
//if something failed, delete the generated assets
- for (RuleAsset ruleAsset : assets) {
- this.getService().removeAsset(ruleAsset.uuid);
+ for ( RuleAsset ruleAsset : assets ) {
+ this.getService().removeAsset( ruleAsset.uuid );
}
-
- if (e instanceof DetailedSerializationException){
- throw (DetailedSerializationException)e;
+
+ if ( e instanceof DetailedSerializationException ) {
+ throw (DetailedSerializationException) e;
}
-
- throw new DetailedSerializationException("Error creating assets", e.getMessage());
+
+ throw new DetailedSerializationException( "Error creating assets",
+ e.getMessage() );
}
-
- return assets.toArray(new RuleAsset[assets.size()]);
+
+ 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.
- * @return
- * @throws DetailedSerializationException
- */
- private RuleAsset createRuleAssetFromRuleModel(RuleModel model) 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
- newRule.content = model;
- ruleUUID = this.getService().checkinVersion(newRule);
+ private RuleAsset createAsset(RuleModel ruleModel) {
+ RuleAsset asset = new RuleAsset();
- if (ruleUUID == null) {
- throw new IllegalStateException("Failed checking int the new version");
- }
+ asset.uuid = "mock";
+ asset.content = ruleModel;
+ asset.metaData = createMetaData( ruleModel );
- return this.getService().loadRuleAsset(ruleUUID);
-
- } catch (Exception ex) {
- throw new DetailedSerializationException("Unable to create Rule",
- ex.getMessage());
- }
+ return asset;
+ }
+ private MetaData createMetaData(RuleModel ruleModel) {
+ MetaData metaData = new MetaData();
+
+ metaData.name = ruleModel.name;
+ metaData.packageName = packageName;
+ metaData.format = AssetFormats.BUSINESS_RULE;
+
+ metaData.packageUUID = "mock";
+
+ return metaData;
}
-
+
private ServiceImplementation getService() {
return RepositoryServiceServlet.getService();
}
Modified: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/PortableObject.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/PortableObject.java 2010-11-09 08:14:37 UTC (rev 35921)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/PortableObject.java 2010-11-09 10:58:28 UTC (rev 35922)
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2010 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
More information about the jboss-svn-commits
mailing list