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

feat(deploy) add deploy options (#1826)

* choose Clean BDM when deploying a BDM
* select default username when deploying an orga

Closes BST-456
parent 5f8d00e3
......@@ -8,7 +8,11 @@ Bundle-Activator: org.bonitasoft.studio.actors.ActorsPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.bonitasoft.studio.actors,
org.bonitasoft.studio.actors.i18n;x-friends:="org.bonitasoft.studio.actors.tests,org.bonitasoft.studio.test.swtbot.util,org.bonitasoft.studio.tests",
org.bonitasoft.studio.actors.i18n;
x-friends:="org.bonitasoft.studio.actors.tests,
org.bonitasoft.studio.test.swtbot.util,
org.bonitasoft.studio.tests,
org.bonitasoft.studio.application",
org.bonitasoft.studio.actors.model.organization,
org.bonitasoft.studio.actors.model.organization.impl,
org.bonitasoft.studio.actors.model.organization.util,
......
......@@ -92,14 +92,15 @@ public class ActorMappingConfigurationWizardPage extends WizardPage
setDescription(Messages.actorMappingDesc);
adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
adapterFactory.addAdapterFactory(new ActorMappingAdapterFactory());
deployedOrganization = Optional.ofNullable(RepositoryManager.getInstance()
.getRepositoryStore(OrganizationRepositoryStore.class)
.getChild(String.format("%s.organization", new ActiveOrganizationProvider().getActiveOrganization()), true))
.map(OrganizationFileStore::getContent);
}
@Override
public void createControl(final Composite parent) {
deployedOrganization = Optional.ofNullable(RepositoryManager.getInstance()
.getRepositoryStore(OrganizationRepositoryStore.class)
.getChild(String.format("%s.organization", new ActiveOrganizationProvider().getActiveOrganization()), true))
.map(OrganizationFileStore::getContent);
final Composite mainComposite = new Composite(parent, SWT.NONE);
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).spacing(5, 2).create());
......
......@@ -27,11 +27,14 @@ import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.model.organization.DocumentRoot;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.OrganizationFactory;
import org.bonitasoft.studio.actors.model.organization.PasswordType;
import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.model.organization.util.OrganizationXMLProcessor;
import org.bonitasoft.studio.actors.operation.CleanPublishOrganizationOperation;
import org.bonitasoft.studio.actors.operation.PublishOrganizationOperation;
import org.bonitasoft.studio.actors.operation.UpdateOrganizationOperation;
import org.bonitasoft.studio.actors.styler.ActiveOrganizationStyler;
import org.bonitasoft.studio.actors.ui.control.DeployOrganizationControlSupplier;
import org.bonitasoft.studio.actors.ui.handler.DeployOrganizationHandler;
import org.bonitasoft.studio.actors.ui.wizard.ManageOrganizationWizard;
import org.bonitasoft.studio.common.jface.FileActionDialog;
......@@ -40,6 +43,7 @@ import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.common.repository.filestore.EMFFileStore;
import org.bonitasoft.studio.common.repository.model.DeployOptions;
import org.bonitasoft.studio.common.repository.model.IDeployable;
import org.bonitasoft.studio.common.repository.model.IRenamable;
import org.bonitasoft.studio.common.repository.model.ITenantResource;
......@@ -245,7 +249,7 @@ public class OrganizationFileStore extends EMFFileStore implements IDeployable,
}
@Override
public IStatus deploy(APISession session, IProgressMonitor monitor) {
public IStatus deploy(APISession session, Map<String, Object> options, IProgressMonitor monitor) {
final String activeOrganization = activeOrganizationProvider.getActiveOrganization();
Organization organization = getContent();
PublishOrganizationOperation operation = Objects.equals(organization.getName(), activeOrganization)
......@@ -257,6 +261,8 @@ public class OrganizationFileStore extends EMFFileStore implements IDeployable,
operation.setSession(session);
try {
operation.run(monitor);
String defaultUsername = String.valueOf(options.get(DeployOptions.DEFAULT_USERNAME));
updateDefaultUserPreference(organization, defaultUsername);
return ValidationStatus.info(String.format(org.bonitasoft.studio.actors.i18n.Messages.organizationDeployed,
organization.getName()));
} catch (InvocationTargetException | InterruptedException e) {
......@@ -264,5 +270,25 @@ public class OrganizationFileStore extends EMFFileStore implements IDeployable,
return new Status(IStatus.ERROR, ActorsPlugin.PLUGIN_ID, "An error occured while depoying the Organization", e);
}
}
protected void updateDefaultUserPreference(Organization organization,
String userName) {
if(userName == null || userName.isEmpty()) {
if(!organization.getUsers().getUser().isEmpty()) {
User user = organization.getUsers().getUser().get(0);
userName = user.getUserName();
}
}
String defaultUserName = userName;
activeOrganizationProvider.saveDefaultUser(userName);
if (organization != null) {
activeOrganizationProvider.saveDefaultPassword(organization.getUsers().getUser().stream()
.filter(user -> Objects.equals(user.getUserName(), defaultUserName))
.findFirst()
.map(User::getPassword)
.map(PasswordType::getValue)
.orElse(""));
}
}
}
......@@ -64,7 +64,9 @@ Require-Bundle: org.bonitasoft.studio.diagram,
org.eclipse.wst.xml.core,
org.eclipse.wst.html.core,
org.bonitasoft.studio.ui;bundle-version="7.9.0",
org.bonitasoft.studio.validation.common
org.bonitasoft.studio.validation.common,
org.bonitasoft.studio.actors;bundle-version="7.10.0",
org.eclipse.core.databinding.property;bundle-version="1.6.300"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.2.0",
......
......@@ -77,4 +77,5 @@ collapseAll=Collapse all
buildErrorTitle=Build error
build=Build
deployStatus=Deploy status
deployStatusMessage=Deploy status below:
\ No newline at end of file
deployStatusMessage=Deploy status below:
cleanBDMDatabase=Clean BDM database
\ No newline at end of file
......@@ -19,6 +19,8 @@ import static org.bonitasoft.studio.ui.wizard.WizardPageBuilder.newPage;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import javax.inject.Named;
......@@ -33,6 +35,7 @@ import org.bonitasoft.studio.application.operation.ValidateProjectOperation;
import org.bonitasoft.studio.application.ui.control.SelectArtifactToDeployPage;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.DeployOptions;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.engine.operation.GetApiSessionOperation;
import org.bonitasoft.studio.ui.dialog.MultiStatusDialog;
......@@ -68,7 +71,7 @@ public class DeployArtifactsHandler {
}
protected IStatus deployArtifacts(RepositoryAccessor repositoryAccessor,
Collection<IRepositoryFileStore> artifactsToDeploy, IWizardContainer container) {
Collection<IRepositoryFileStore> artifactsToDeploy, Map<String, Object> deployOptions, IWizardContainer container) {
MultiStatus status = new MultiStatus(ApplicationPlugin.PLUGIN_ID, 0, null, null);
try {
......@@ -78,7 +81,7 @@ public class DeployArtifactsHandler {
try {
APISession session = apiSessionOperation.getSession();
DeployTenantResourcesOperation deployTenantResourcesOperation = new DeployTenantResourcesOperation(
artifactsToDeploy, session);
artifactsToDeploy, session, deployOptions);
deployTenantResourcesOperation.run(monitor);
status.addAll(deployTenantResourcesOperation.getStatus());
if (shouldValidate()) {
......@@ -102,7 +105,7 @@ public class DeployArtifactsHandler {
});
} catch (InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
return new Status(IStatus.ERROR, ApplicationPlugin.PLUGIN_ID, "Failed to deploy some tenant resources.", e);
return new Status(IStatus.ERROR, ApplicationPlugin.PLUGIN_ID, "Deploy failed", e.getCause() != null ? e.getCause() : e);
}
return status;
}
......@@ -126,18 +129,23 @@ public class DeployArtifactsHandler {
.withDescription(description)
.withControl(page))
.onFinish(container -> Optional
.ofNullable(deployArtifacts(repositoryAccessor, page.getElements(), container)));
.ofNullable(deployArtifacts(repositoryAccessor, page.getElements(), buildOptions(page), container)));
}
private Map<String, Object> buildOptions(SelectArtifactToDeployPage page) {
HashMap<String, Object> options = new HashMap<String, Object>();
options.put(DeployOptions.CLEAN_BDM, page.isCleanBDM());
options.put(DeployOptions.DEFAULT_USERNAME, page.getDefaultUsername());
return options;
}
private void openStatusDialog(Shell activeShell, IStatus status) {
if (status instanceof MultiStatus) {
new MultiStatusDialog(activeShell, Messages.deployStatus, Messages.deployStatusMessage,
new String[] { IDialogConstants.OK_LABEL }, (MultiStatus) status).open();
} else {
StatusManager.getManager().handle(status);
// MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.deployErrorTitle,
// String.format("%s\n\n%s", message.orElse(""), status.getMessage()));
StatusManager.getManager().handle(status, StatusManager.SHOW);
}
}
......
......@@ -115,6 +115,7 @@ public class Messages extends NLS {
public static String build;
public static String deployStatus;
public static String deployStatusMessage;
public static String cleanBDMDatabase;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
......
......@@ -16,6 +16,8 @@ package org.bonitasoft.studio.application.operation;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.common.core.IRunnableWithStatus;
......@@ -31,10 +33,12 @@ public class DeployTenantResourcesOperation implements IRunnableWithStatus {
private Collection<IRepositoryFileStore> artifactsToDeploy;
private MultiStatus status;
private APISession apiSession;
private Map<String, Object> deployOptions = new HashMap<String, Object>();
public DeployTenantResourcesOperation(Collection<IRepositoryFileStore> artifactsToDeploy, APISession apiSession) {
public DeployTenantResourcesOperation(Collection<IRepositoryFileStore> artifactsToDeploy, APISession apiSession, Map<String, Object> deployOptions) {
this.artifactsToDeploy = artifactsToDeploy;
this.apiSession = apiSession;
this.deployOptions = deployOptions;
}
@Override
......@@ -42,7 +46,7 @@ public class DeployTenantResourcesOperation implements IRunnableWithStatus {
status = artifactsToDeploy.stream()
.filter(ITenantResource.class::isInstance)
.map(ITenantResource.class::cast)
.map(artifact -> artifact.deploy(apiSession, monitor))
.map(artifact -> artifact.deploy(apiSession, deployOptions, monitor))
.collect(StatusCollectors.toMultiStatus());
}
......
......@@ -37,6 +37,7 @@ import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.DeployOptions;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.dependencies.repository.DependencyFileStore;
import org.bonitasoft.studio.dependencies.repository.DependencyRepositoryStore;
......@@ -241,9 +242,15 @@ public class BusinessObjectModelFileStore extends AbstractBDMFileStore {
}
@Override
public IStatus deploy(APISession session, IProgressMonitor monitor) {
public IStatus deploy(APISession session, Map<String, Object> options, IProgressMonitor monitor) {
GenerateBDMOperation generateBDMOperation = new GenerateBDMOperation(this);
DeployBDMOperation deployBDMOperation = new DeployBDMOperation(this).reuseSession(session);
Object cleanBDM = options.containsKey(DeployOptions.CLEAN_BDM) ? false : options.get(DeployOptions.CLEAN_BDM);
if(!(cleanBDM instanceof Boolean)) {
return new Status(IStatus.ERROR,
BusinessObjectPlugin.PLUGIN_ID,
String.format("Invalid option type for %s. Expected a Boolean value but found a %s",DeployOptions.CLEAN_BDM, cleanBDM.getClass()));
}
DeployBDMOperation deployBDMOperation = new DeployBDMOperation(this, (boolean) cleanBDM).reuseSession(session);
try {
generateBDMOperation.run(monitor);
deployBDMOperation.run(monitor);
......
/**
* Copyright (C) 2019 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.repository.model;
public interface DeployOptions {
public static final String DEFAULT_USERNAME = "DEFAULT_USERNAME";
public static final String CLEAN_BDM = "CLEAN_BDM";
}
......@@ -14,12 +14,14 @@
*/
package org.bonitasoft.studio.common.repository.model;
import java.util.Map;
import org.bonitasoft.engine.session.APISession;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
public interface ITenantResource {
public IStatus deploy(APISession session, IProgressMonitor monitor);
public IStatus deploy(APISession session, Map<String, Object> options, IProgressMonitor monitor);
}
......@@ -86,9 +86,6 @@ public class ConnectorConfigurationWizardPage extends WizardPage implements IPro
private static final ConnectorsConfigurationSynchronizer CONNECTORS_CONFIGURATION_SYNCHRONIZER = new ConnectorsConfigurationSynchronizer();
protected TableViewer viewer;
protected IDefinitionRepositoryStore defStore;
protected IImplementationRepositoryStore implStore;
protected DefinitionResourceProvider resourceProvider;
private Button selectImplementationButton;
private Button clearImplementationButton;
protected Configuration configuration;
......@@ -97,9 +94,18 @@ public class ConnectorConfigurationWizardPage extends WizardPage implements IPro
super(ConnectorConfigurationWizardPage.class.getName());
setTitle(Messages.connectors) ;
setDescription(Messages.connectorsConfigurationDescription) ;
defStore = RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class) ;
implStore = RepositoryManager.getInstance().getRepositoryStore(ConnectorImplRepositoryStore.class) ;
resourceProvider= DefinitionResourceProvider.getInstance((IRepositoryStore<? extends IRepositoryFileStore>) defStore, ConnectorPlugin.getDefault().getBundle()) ;
}
protected DefinitionResourceProvider getResourceProvider() {
return DefinitionResourceProvider.getInstance((IRepositoryStore<? extends IRepositoryFileStore>) getDefinitionStore(), ConnectorPlugin.getDefault().getBundle());
}
protected IImplementationRepositoryStore getImplStore() {
return (IImplementationRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(ConnectorImplRepositoryStore.class);
}
protected IDefinitionRepositoryStore getDefinitionStore() {
return (IDefinitionRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class);
}
/* (non-Javadoc)
......@@ -151,12 +157,12 @@ public class ConnectorConfigurationWizardPage extends WizardPage implements IPro
viewer.getTable().setLayout(tableLayout);
final TableViewerColumn columnDefViewer = new TableViewerColumn(viewer, SWT.NONE);
columnDefViewer.setLabelProvider(new DefinitionLabelProvider(resourceProvider, defStore));
columnDefViewer.setLabelProvider(new DefinitionLabelProvider(getResourceProvider(), getDefinitionStore()));
TableColumn column = columnDefViewer.getColumn();
column.setText(Messages.definition);
final TableViewerColumn columnImplIdViewer = new TableViewerColumn(viewer, SWT.NONE);
columnImplIdViewer.setLabelProvider(new ImplementationLabelProvider(implStore));
columnImplIdViewer.setLabelProvider(new ImplementationLabelProvider(getImplStore()));
column = columnImplIdViewer.getColumn();
column.setText(Messages.implementation);
......@@ -270,7 +276,7 @@ public class ConnectorConfigurationWizardPage extends WizardPage implements IPro
if(implementationId == null || implementationVersion == null){
return Messages.bind(Messages.invalidImplementationFor, association.getDefinitionId()) ;
}
final ConnectorImplementation impl = implStore.getImplementation(implementationId,implementationVersion) ;
final ConnectorImplementation impl = getImplStore().getImplementation(implementationId,implementationVersion) ;
if(impl == null){
return Messages.bind(Messages.implementationNotFound, implementationId +" ("+implementationVersion+")") ;
}
......@@ -312,7 +318,7 @@ public class ConnectorConfigurationWizardPage extends WizardPage implements IPro
final DependencyRepositoryStore depStore = RepositoryManager.getInstance().getRepositoryStore(DependencyRepositoryStore.class) ;
for(final String jarName : implementation.getJarDependencies().getJarDependency()){
if( depStore.getChild(jarName, true) == null){
final InputStream is = resourceProvider.getDependencyInputStream(jarName) ;
final InputStream is = getResourceProvider().getDependencyInputStream(jarName) ;
if(is != null){
depStore.importInputStream(jarName, is) ;
}
......
......@@ -35,7 +35,9 @@ public class MenuLevelValidatorTest {
@Test
public void should_add_warning_message() throws Exception {
final IFile resource = anIFile().build();
final MenuLevelValidator menuLevelValidator = spy(new MenuLevelValidator(new ApplicationNodeContainerConverter()));
final MenuLevelValidator menuLevelValidator = spy(MenuLevelValidator.class);
doReturn(new ApplicationNodeContainerConverter()).when(menuLevelValidator).getConverter();
doReturn(true).when(menuLevelValidator).shouldValidate();
doReturn(appWithDeepMenus()).when(menuLevelValidator)
.toApplicationContainer(resource);
doReturn(null).when(menuLevelValidator).createMessage(resource);
......@@ -48,7 +50,9 @@ public class MenuLevelValidatorTest {
@Test
public void should_not_add_warning_message() throws Exception {
final IFile resource = anIFile().build();
final MenuLevelValidator menuLevelValidator = spy(new MenuLevelValidator(new ApplicationNodeContainerConverter()));
final MenuLevelValidator menuLevelValidator = spy(MenuLevelValidator.class);
doReturn(new ApplicationNodeContainerConverter()).when(menuLevelValidator).getConverter();
doReturn(true).when(menuLevelValidator).shouldValidate();
doReturn(appWithSingleMenus()).when(menuLevelValidator)
.toApplicationContainer(resource);
doReturn(null).when(menuLevelValidator).createMessage(resource);
......
......@@ -46,17 +46,12 @@ public class MenuLevelValidator extends AbstractValidator {
private ApplicationNodeContainerConverter converter;
MenuLevelValidator(ApplicationNodeContainerConverter converter) {
this.converter = converter;
}
public MenuLevelValidator() {
this.converter = RepositoryManager.getInstance()
.getRepositoryStore(ApplicationRepositoryStore.class).getConverter();
}
@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
if (!shouldValidate()) {
return new ValidationResult();
}
this.converter = getConverter();
if (resource.getType() != IResource.FILE) {
return null;
}
......@@ -80,6 +75,15 @@ public class MenuLevelValidator extends AbstractValidator {
return validationResult;
}
protected ApplicationNodeContainerConverter getConverter() {
return RepositoryManager.getInstance()
.getRepositoryStore(ApplicationRepositoryStore.class).getConverter();
}
protected boolean shouldValidate() {
return RepositoryManager.getInstance().hasActiveRepository();
}
protected ValidatorMessage createMessage(IResource resource) {
final ValidatorMessage warningMessage = ValidatorMessage
.create(Messages.menuLevelWarning, resource);
......
......@@ -28,11 +28,12 @@ public class BonitaStatusHandler extends WorkbenchErrorHandler {
String message = statusAdapter.getStatus().getMessage();
if (message != null && message.contains("Server Tomcat")) {
return;
}else {
super.handle(statusAdapter, style);
}
} else {
super.handle(statusAdapter, style);
}
}
@Override
......
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