Commit cbd28265 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

feat(explorer) import/export bdm + access control (#1342)

Closes BS-18868
parent 0dc7a43d
......@@ -109,6 +109,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
id="org.eclipse.babel.nls_webtools_ja"
version="0.0.0"/>
<includes
id="org.eclipse.emf.compare.ide.ui"
version="0.0.0"/>
<includes
id="org.eclipse.emf.compare.rcp.ui"
version="0.0.0"/>
<requires>
<import feature="org.eclipse.rcp" version="4.7.0.v20170612-1255" match="greaterOrEqual"/>
<import feature="platform-specific-feature" version="7.8.0" match="equivalent"/>
......
......@@ -1371,5 +1371,23 @@
name="Java Perspective">
</perspective>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="*">
<hiddenMenuItem
id="org.eclipse.jdt.ui.refactoring.menu">
</hiddenMenuItem>
<hiddenMenuItem
id="org.eclipse.search.menu">
</hiddenMenuItem>
<hiddenMenuItem
id="org.eclipse.jdt.ui/org.eclipse.jdt.ui.refactoring.menu">
</hiddenMenuItem>
<hiddenMenuItem
id="org.eclipse.jdt.ui.source.menu">
</hiddenMenuItem>
</perspectiveExtension>
</extension>
</plugin>
......@@ -66,7 +66,8 @@ Require-Bundle: org.bonitasoft.studio.engine;bundle-version="1.0.0",
org.eclipse.e4.core.contexts;bundle-version="1.6.0",
org.eclipse.e4.ui.workbench;bundle-version="1.5.0",
org.apache.commons.io;bundle-version="2.2.0",
org.eclipse.core.expressions
org.eclipse.core.expressions,
org.eclipse.e4.ui.services
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.api,
......
......@@ -123,12 +123,55 @@
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.bonitasoft.studio.businessobject.ui.BDMPropertyTester"
id="org.bonitasoft.studio.businessobject.CheckBDMExists"
id="org.bonitasoft.studio.businessobject.BDMPropertyTester"
namespace="org.bonitasoft.studio.businessobject"
properties="bdmExists"
type="org.eclipse.core.resources.IProject">
properties="bdmExists,isBDMFolder,isBDMFile"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.bonitasoft.studio.businessobject.ui.handler.ImportBusinessDataModelHandler"
commandId="org.bonitasoft.studio.application.import">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.businessobject.isBDMFolder">
</test>
</iterate>
<or>
<reference
definitionId="isABonitaProduct">
</reference>
<reference
definitionId="isTeamwork">
</reference>
</or>
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.businessobject.ui.handler.ExportBusinessDataModelHandler"
commandId="org.bonitasoft.studio.application.export">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.businessobject.isBDMFile">
</test>
</iterate>
</and>
</activeWhen>
</handler>
</extension>
......
......@@ -56,9 +56,6 @@ public class ExportBusinessDataModelHandlerTest {
@Mock
private RepositoryAccessor repositoryAccessor;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
Mockito.doReturn(businessStore).when(repositoryAccessor)
......@@ -66,16 +63,9 @@ public class ExportBusinessDataModelHandlerTest {
doReturn(wizardDialog).when(handlerUnderTest).createWizardDialog(shell, Messages.export);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void shouldExecute_OpenWizardDialogWithExportWizard() throws Exception {
handlerUnderTest.execute(repositoryAccessor, shell);
handlerUnderTest.execute(shell, repositoryAccessor);
verify(handlerUnderTest).createWizardDialog(shell, Messages.export);
verify(wizardDialog).open();
}
......
package org.bonitasoft.studio.businessobject.ui;
import java.util.Objects;
import org.bonitasoft.studio.businessobject.core.repository.AbstractBDMFileStore;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
public class BDMPropertyTester extends PropertyTester {
private static final String BDM_EXITS_PROPERTY = "bdmExists";
private static final String BDM_FOLDER_PROPERTY = "isBDMFolder";
private static final String BDM_FILE_PROPERTY = "isBDMFile";
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
BusinessObjectModelRepositoryStore store = RepositoryManager.getInstance()
.getRepositoryStore(BusinessObjectModelRepositoryStore.class);
return store.getChild(BusinessObjectModelFileStore.BOM_FILENAME) == null;
switch (property) {
case BDM_EXITS_PROPERTY:
return store.getChild(BusinessObjectModelFileStore.BOM_FILENAME) == null;
case BDM_FOLDER_PROPERTY:
return isBDMFolder(receiver, store);
case BDM_FILE_PROPERTY:
return isBDMFile(receiver, store);
default:
return false;
}
}
private boolean isBDMFolder(Object receiver, BusinessObjectModelRepositoryStore store) {
if (receiver instanceof IAdaptable) {
return Objects.equals(store.getResource(), ((IAdaptable) receiver).getAdapter(IResource.class));
}
return false;
}
private boolean isBDMFile(Object receiver, BusinessObjectModelRepositoryStore store) {
if (receiver instanceof IAdaptable) {
AbstractBDMFileStore child = store.getChild(BusinessObjectModelFileStore.BOM_FILENAME);
return child != null && Objects.equals(child.getResource(),
((IAdaptable) receiver).getAdapter(IResource.class));
}
return false;
}
}
......@@ -14,6 +14,8 @@
*/
package org.bonitasoft.studio.businessobject.ui.handler;
import javax.inject.Named;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.businessobject.i18n.Messages;
......@@ -21,21 +23,26 @@ import org.bonitasoft.studio.businessobject.ui.wizard.ExportBusinessDataModelWiz
import org.bonitasoft.studio.common.jface.CustomWizardDialog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* @author Romain Bioteau
*/
public class ExportBusinessDataModelHandler {
public class ExportBusinessDataModelHandler extends AbstractHandler {
private BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> store;
private RepositoryAccessor repositoryAccessor;
@Execute
public Object execute(RepositoryAccessor repositoryAccessor, Shell shell) throws ExecutionException {
public Object execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, RepositoryAccessor repositoryAccessor)
throws ExecutionException {
this.repositoryAccessor = repositoryAccessor;
store = repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class);
final CustomWizardDialog dialog = createWizardDialog(shell, Messages.export);
......@@ -47,14 +54,28 @@ public class ExportBusinessDataModelHandler {
return new CustomWizardDialog(shell, new ExportBusinessDataModelWizard(store), finishLabel);
}
@CanExecute
@Override
public boolean isEnabled() {
if (!PlatformUtil.isHeadless() && repositoryAccessor.getCurrentRepository().isLoaded()) {
final BusinessObjectModelFileStore fileStore = store.getChild(BusinessObjectModelFileStore.BOM_FILENAME);
if (!PlatformUtil.isHeadless() && RepositoryManager.getInstance().getCurrentRepository().isLoaded()) {
final BusinessObjectModelFileStore fileStore = (BusinessObjectModelFileStore) RepositoryManager.getInstance()
.getRepositoryStore(BusinessObjectModelRepositoryStore.class)
.getChild(BusinessObjectModelFileStore.BOM_FILENAME);
return fileStore != null && fileStore.getContent() != null
&& !fileStore.getContent().getBusinessObjects().isEmpty();
}
return false;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
return execute(Display.getDefault().getActiveShell(), repositoryAccessor);
}
}
......@@ -22,6 +22,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.util.Optional;
import javax.inject.Named;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.businessobject.i18n.Messages;
......@@ -29,19 +31,23 @@ import org.bonitasoft.studio.businessobject.ui.wizard.ImportBdmPage;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ImportBusinessDataModelHandler {
public class ImportBusinessDataModelHandler extends AbstractHandler {
@Execute
public void importBdmWizard(Shell activeShell, RepositoryAccessor repositoryAccessor) {
public void importBdmWizard(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell,
RepositoryAccessor repositoryAccessor) {
createWizard(newWizard(), repositoryAccessor)
.open(activeShell, Messages.importButtonLabel)
.ifPresent(o -> {
MessageDialog.openInformation(activeShell, Messages.bdmImportedTitle, Messages.bdmImported);
});
.ifPresent(o -> MessageDialog.openInformation(activeShell, Messages.bdmImportedTitle, Messages.bdmImported));
}
private WizardBuilder<BusinessObjectModelFileStore> createWizard(WizardBuilder<BusinessObjectModelFileStore> builder,
......@@ -78,4 +84,16 @@ public class ImportBusinessDataModelHandler {
}
}
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
importBdmWizard(Display.getDefault().getActiveShell(), repositoryAccessor);
return null;
}
}
......@@ -36,7 +36,8 @@ Require-Bundle: org.eclipse.swtbot.eclipse.gef.finder,
org.eclipse.egit.ui,
org.eclipse.jgit;bundle-version="4.10.0",
org.bonitasoft.studio.common;bundle-version="7.8.0",
org.bonitasoft.studio.diagram
org.bonitasoft.studio.diagram,
org.bonitasoft.studio.application
Import-Package: org.bonitasoft.studio.application.i18n,
org.bonitasoft.studio.configuration.i18n,
org.bonitasoft.studio.connector.model.i18n,
......
......@@ -16,12 +16,20 @@ package org.bonitasoft.studio.swtbot.framework.rule;
import static org.bonitasoft.studio.swtbot.framework.conditions.BonitaBPMConditions.activeWelcomePage;
import org.bonitasoft.studio.application.actions.coolbar.NormalCoolBarHandler;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.connector.model.definition.provider.ConnectorEditPlugin;
import org.bonitasoft.studio.connector.model.definition.wizard.AbstractDefinitionWizard;
import org.bonitasoft.studio.engine.EnginePlugin;
import org.bonitasoft.studio.engine.preferences.EnginePreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaCoolBarPreferenceConstant;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.bonitasoft.studio.swtbot.framework.conditions.BonitaBPMConditions;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
......@@ -33,8 +41,6 @@ import org.eclipse.ui.internal.browser.WebBrowserUIPlugin;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.bonitasoft.studio.engine.EnginePlugin;
import org.bonitasoft.studio.engine.preferences.EnginePreferenceConstants;
/**
* @author Romain Bioteau
......@@ -121,16 +127,26 @@ public class SWTGefBotRule implements TestRule {
}
protected void initPreferences() {
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
.setValue(BonitaPreferenceConstants.CONSOLE_BROWSER_CHOICE, BonitaPreferenceConstants.INTERNAL_BROWSER);
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
.setValue(BonitaPreferenceConstants.ASK_RENAME_ON_FIRST_SAVE, false);
ConnectorEditPlugin.getPlugin().getPreferenceStore()
.setValue(AbstractDefinitionWizard.HIDE_CONNECTOR_DEFINITION_CHANGE_WARNING, true);
IPreferenceStore preferenceStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
preferenceStore.setValue(BonitaCoolBarPreferenceConstant.COOLBAR_DEFAULT_SIZE,
BonitaCoolBarPreferenceConstant.NORMAL);
Display.getDefault().asyncExec(() -> {
try {
new NormalCoolBarHandler().execute(null);
} catch (ExecutionException e) {
BonitaStudioLog.error(e);
}
});
preferenceStore
.setValue(BonitaPreferenceConstants.ASK_RENAME_ON_FIRST_SAVE, false);
preferenceStore
.setValue(BonitaPreferenceConstants.CONSOLE_BROWSER_CHOICE, BonitaPreferenceConstants.INTERNAL_BROWSER);
WebBrowserUIPlugin.getInstance().getPreferenceStore()
.setValue(BonitaPreferenceConstants.CONSOLE_BROWSER_CHOICE, BonitaPreferenceConstants.INTERNAL_BROWSER);
EnginePlugin.getDefault().getPreferenceStore().setValue(EnginePreferenceConstants.LAZYLOAD_ENGINE, true);
disablePopup = FileActionDialog.getDisablePopup();
EnginePlugin.getDefault().getPreferenceStore().setValue(EnginePreferenceConstants.LAZYLOAD_ENGINE, true);
FileActionDialog.setDisablePopup(true);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment