Commit 123f5c55 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Merge pull request #267 from bonitasoft/defect/BS-14272-RedirectionWhenNoInstanciationForm

BS-14272: Better handling Run when "no form" for instanciation on pool
parents 1d54d7ff 2c8699ef
......@@ -75,6 +75,9 @@ Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.expression,
org.bonitasoft.engine.operation,
org.bonitasoft.engine.platform,
org.bonitasoft.engine.profile,
org.bonitasoft.engine.search,
org.bonitasoft.engine.search.impl,
org.bonitasoft.engine.session,
org.bonitasoft.engine.util
......@@ -53,8 +53,8 @@ undeploymentFailedMessage = Run has failed while undeploying the process
cannotStartTomcatTitle=Tomcat cannot be launched
cannotStartTomcatMessage=Tomcat cannot be launched:\nthe port might be already used by another application.\nPossible causes are that another Studio or another Tomcat is already running.
noInitiatorDefinedTitle=No initiator defined
noInitiatorDefinedMessage=No process initiator defined for {0}. You are going to be redirected to Bonita Portal.
dontaskagain=don't display next time.
noInitiatorDefinedMessage=No process initiator defined for {0}. You will be redirected to {1}.
dontaskagain=Do not display next time.
configure=Configure
processEnableFailedTitle=Enable process failed
processEnableFailedMessage=The process cannot be resolved. Please change the configuration to fix the following problems.
......@@ -63,4 +63,6 @@ deletingProcessInstances=Deleting {0} instances...
deletingProcessDefinition=Deleting {0} definition...
updatePortWarningMessage=Updating the port number will delete unsaved work in the {0}. Be sure you have saved any opened elements in the {0}.
updatePortWarningTitle=Update port number
buildingBar=Building {0} ({1})...
\ No newline at end of file
buildingBar=Building {0} ({1})...
contractButNoFormTitle=Process defined with contract but no form
contractButNoFormMessage=Process {0} defined with contract but no form. You will be redirected to {1}.
\ No newline at end of file
/**
* Copyright (C) 2015 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.engine.operation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import java.net.URL;
import java.net.URLEncoder;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.configuration.preferences.ConfigurationPreferenceConstants;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.ConfigurationFactory;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.eclipse.core.runtime.IProgressMonitor;
import org.junit.Before;
import org.junit.Test;
public class CaseDetailURLBuilderTest {
private CaseDetailURLBuilder caseDetailURLBuilder;
private String loginURL;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
final AbstractProcess process = ProcessFactory.eINSTANCE.createPool();
process.setName("testPool with space /and slash");
process.setVersion("1.0");
caseDetailURLBuilder = spy(new CaseDetailURLBuilder(process, ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION, 12L));
doReturn("fr").when(caseDetailURLBuilder).getWebLocale();
doReturn("william.jobs").when(caseDetailURLBuilder).getDefaultUsername();
doReturn("bpm").when(caseDetailURLBuilder).getDefaultPassword();
doReturn(45L).when(caseDetailURLBuilder).getUserProfileId(any(IProgressMonitor.class));
loginURL = "http://fakeLoginURL";
doReturn(loginURL).when(caseDetailURLBuilder).buildLoginUrl(anyString(), anyString());
}
/**
* Test method for {@link org.bonitasoft.studio.engine.operation.ApplicationURLBuilder#toURL(org.eclipse.core.runtime.IProgressMonitor)}.
*/
@Test
public void shouldToURL_RetursAValidURL() throws Exception {
final Configuration configuration = ConfigurationFactory.eINSTANCE.createConfiguration();
doReturn(configuration).when(caseDetailURLBuilder).getConfiguration();
final URL url = caseDetailURLBuilder.toURL(Repository.NULL_PROGRESS_MONITOR);
assertThat(url).isNotNull();
final String validLocale = URLEncoder.encode("_l=fr", "UTF-8");
final String appliPath = URLEncoder.encode("portal/homepage#?", "UTF-8");
final String pageCaseMoreDetails = URLEncoder.encode("_p=casemoredetails", "UTF-8");
final String profileID = URLEncoder.encode("_pf=45", "UTF-8");
assertThat(url.toString())
.contains(appliPath)
.contains(pageCaseMoreDetails)
.contains(validLocale)
.contains(profileID)
.startsWith(loginURL);
verify(caseDetailURLBuilder).buildLoginUrl("william.jobs", "bpm");
}
}
......@@ -19,7 +19,6 @@ package org.bonitasoft.studio.engine.operation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
......@@ -88,7 +87,6 @@ public class PortalURLBuilderTest {
@Test
public void shouldGetConfigurationReturnNull() {
doCallRealMethod().when(portalURLBuilder).getConfiguration();
doNothing().when(portalURLBuilder).initConfigurationId();
assertThat(portalURLBuilder.getConfiguration()).isNull();
}
......
......@@ -41,8 +41,11 @@ import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManag
import org.bonitasoft.studio.common.extension.IEngineAction;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.engine.export.BarExporter;
import org.bonitasoft.studio.engine.i18n.Messages;
import org.bonitasoft.studio.engine.preferences.EnginePreferenceConstants;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
......@@ -321,4 +324,18 @@ public class BOSEngineManager {
return TenantAPIAccessor.getTenantAdministrationAPI(session);
}
public APISession createSession(final AbstractProcess process, final String configurationId, final IProgressMonitor monitor) throws Exception {
final Configuration configuration = BarExporter.getInstance().getConfiguration(process, configurationId);
APISession session;
try {
session = BOSEngineManager.getInstance().loginTenant(configuration.getUsername(), configuration.getPassword(), monitor);
} catch (final Exception e1) {
throw new Exception(Messages.bind(Messages.loginFailed, new String[] { configuration.getUsername(), process.getName(), process.getVersion() }), e1);
}
if (session == null) {
throw new Exception(Messages.bind(Messages.loginFailed, new String[] { configuration.getUsername(), process.getName(), process.getVersion() }));
}
return session;
}
}
......@@ -150,6 +150,8 @@ public class Messages extends NLS {
public static String updatePortWarningTitle;
public static String buildingBar;
public static String contractButNoFormTitle;
public static String contractButNoFormMessage;
static {
NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
......
/**
* Copyright (C) 2015 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.engine.operation;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import org.bonitasoft.studio.engine.BOSWebServerManager;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
public abstract class AbstractBonitaURLBuilder {
protected static final String ENCODING_UTF8 = "UTF-8";
protected abstract String getRedirectURL(final String locale, final IProgressMonitor monitor) throws UnsupportedEncodingException;
protected abstract String getLocaleParameter(final String locale);
protected String encodeForPathURL(final String toEncode) throws UnsupportedEncodingException {
return URLEncoder.encode(toEncode, ENCODING_UTF8).replaceAll("\\+", "%20").replaceAll("%2F", "/");
}
protected String buildLoginUrl(final String userName, final String password) {
return BOSWebServerManager.getInstance().generateLoginURL(userName, password);
}
protected IPreferenceStore getPreferenceStore() {
return BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
}
protected String getWebLocale() {
return getPreferenceStore().getString(BonitaPreferenceConstants.CURRENT_UXP_LOCALE);
}
protected String getDefaultPassword() {
return getPreferenceStore().getString(BonitaPreferenceConstants.USER_PASSWORD);
}
protected String getDefaultUsername() {
return getPreferenceStore().getString(BonitaPreferenceConstants.USER_NAME);
}
public URL toURL(final IProgressMonitor monitor) throws MalformedURLException, UnsupportedEncodingException, URISyntaxException {
final String locale = getWebLocale();
String userName = getDefaultUsername();
String password = getDefaultPassword();
final Configuration conf = getConfiguration();
if (conf != null && conf.getUsername() != null) {
userName = conf.getUsername();
password = conf.getPassword();
}
final String loginURL = buildLoginUrl(userName, password);
return new URL(loginURL + "&redirectUrl="
+ URLEncoder.encode(getRedirectURL(locale, monitor), ENCODING_UTF8));
}
protected abstract Configuration getConfiguration();
}
/**
* Copyright (C) 2015 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.engine.operation;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.bonitasoft.studio.configuration.ConfigurationPlugin;
import org.bonitasoft.studio.configuration.preferences.ConfigurationPreferenceConstants;
import org.bonitasoft.studio.diagram.custom.repository.ProcessConfigurationRepositoryStore;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.process.AbstractProcess;
public abstract class AbstractProcessRelatedURLBuilder extends AbstractBonitaURLBuilder {
protected final AbstractProcess process;
protected String configurationId;
public AbstractProcessRelatedURLBuilder(final AbstractProcess process, final String configurationId) {
this.process = process;
this.configurationId = configurationId;
}
@Override
protected Configuration getConfiguration() {
if (process != null) {
initConfigurationId();
if (ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON.equals(configurationId)) {
return retrieveConfigurationForLocalConf();
} else {
return retrieveConfigurationInsideProcess();
}
}
return null;
}
protected void initConfigurationId() {
if (configurationId == null) {
configurationId = ConfigurationPlugin
.getDefault()
.getPreferenceStore()
.getString(
ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION);
}
}
private Configuration retrieveConfigurationInsideProcess() {
for (final Configuration conf : process.getConfigurations()) {
if (configurationId.equals(conf.getName())) {
return conf;
}
}
return null;
}
private Configuration retrieveConfigurationForLocalConf() {
final ProcessConfigurationRepositoryStore processConfStore = RepositoryManager.getInstance().getRepositoryStore(
ProcessConfigurationRepositoryStore.class);
final String id = ModelHelper.getEObjectID(process);
final IRepositoryFileStore file = processConfStore.getChild(id
+ ".conf");
if (file == null) {
return null;
}
try {
return (Configuration) file.getContent();
} catch (final ReadFileStoreException e) {
BonitaStudioLog.error("Failed to read process configuration", e);
}
return null;
}
}
......@@ -15,148 +15,38 @@
package org.bonitasoft.studio.engine.operation;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.bonitasoft.studio.configuration.ConfigurationPlugin;
import org.bonitasoft.studio.configuration.preferences.ConfigurationPreferenceConstants;
import org.bonitasoft.studio.diagram.custom.repository.ProcessConfigurationRepositoryStore;
import org.bonitasoft.studio.engine.BOSWebServerManager;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
/**
* @author Romain Bioteau
*/
public class ApplicationURLBuilder {
public class ApplicationURLBuilder extends AbstractProcessRelatedURLBuilder {
private static final String ENCODING_UTF8 = "UTF-8";
private static final String APPLI_PATH = "portal/resource"; //$NON-NLS-1$
private final AbstractProcess process;
private String configurationId;
private final long procDefId;
public ApplicationURLBuilder(final AbstractProcess process, final String configurationId, final long procDefId) {
this.process = process;
this.configurationId = configurationId;
super(process, configurationId);
this.procDefId = procDefId;
}
public URL toURL(final IProgressMonitor monitor)
throws MalformedURLException, UnsupportedEncodingException,
URISyntaxException {
final String locale = getWebLocale();
String userName = getDefaultUsername();
String password = getDefaultPassword();
final Configuration conf = getConfiguration();
if (conf != null && conf.getUsername() != null) {
userName = conf.getUsername();
password = conf.getPassword();
}
final String loginURL = buildLoginUrl(userName, password);
return new URL(loginURL + "&redirectUrl="
+ URLEncoder.encode(getRedirectURL(locale), ENCODING_UTF8));
}
protected String getRedirectURL(final String locale) throws UnsupportedEncodingException {
return APPLI_PATH
+ "/process"
+ "/" + encodeForPathURL(process.getName())
+ "/" + encodeForPathURL(process.getVersion())
+ "/content/?id=" + procDefId
+ "&" + getLocaleParameter(locale)
+ "&mode=app";
}
private String encodeForPathURL(final String toEncode) throws UnsupportedEncodingException {
return URLEncoder.encode(toEncode, ENCODING_UTF8).replaceAll("\\+", "%20").replaceAll("%2F", "/");
@Override
protected String getRedirectURL(final String locale, final IProgressMonitor monitor) throws UnsupportedEncodingException {
return APPLI_PATH
+ "/process"
+ "/" + encodeForPathURL(process.getName())
+ "/" + encodeForPathURL(process.getVersion())
+ "/content/?id=" + procDefId
+ "&" + getLocaleParameter(locale)
+ "&mode=app";
}
@Override
protected String getLocaleParameter(final String locale) {
return "locale=" + locale;
}
protected String buildLoginUrl(final String userName, final String password) {
return BOSWebServerManager.getInstance().generateLoginURL(userName, password);
}
protected IPreferenceStore getPreferenceStore() {
return BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
}
protected String getWebLocale() {
return getPreferenceStore().getString(BonitaPreferenceConstants.CURRENT_UXP_LOCALE);
}
protected String getDefaultPassword() {
return getPreferenceStore().getString(BonitaPreferenceConstants.USER_PASSWORD);
}
protected String getDefaultUsername() {
return getPreferenceStore().getString(BonitaPreferenceConstants.USER_NAME);
}
protected Configuration getConfiguration() {
if (process != null) {
initConfigurationId();
if (ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON.equals(configurationId)) {
return retrieveConfigurationForLocalConf();
} else {
return retrieveConfigurationInsideProcess();
}
}
return null;
}
protected void initConfigurationId() {
if (configurationId == null) {
configurationId = ConfigurationPlugin
.getDefault()
.getPreferenceStore()
.getString(
ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION);
}
}
private Configuration retrieveConfigurationInsideProcess() {
for (final Configuration conf : process.getConfigurations()) {
if (configurationId.equals(conf.getName())) {
return conf;
}
}
return null;
}
private Configuration retrieveConfigurationForLocalConf() {
final ProcessConfigurationRepositoryStore processConfStore = RepositoryManager
.getInstance().getRepositoryStore(
ProcessConfigurationRepositoryStore.class);
final String id = ModelHelper.getEObjectID(process);
final IRepositoryFileStore file = processConfStore.getChild(id
+ ".conf");
if (file == null) {
return null;
}
try {
return (Configuration) file.getContent();
} catch (final ReadFileStoreException e) {
BonitaStudioLog.error("Failed to read process configuration", e);
}
return null;
}
}
/**
* Copyright (C) 2015 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.engine.operation;
import java.io.UnsupportedEncodingException;
import org.bonitasoft.engine.api.ProfileAPI;
import org.bonitasoft.engine.profile.Profile;
import org.bonitasoft.engine.profile.ProfileSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.engine.BOSEngineManager;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.runtime.IProgressMonitor;
public class CaseDetailURLBuilder extends AbstractProcessRelatedURLBuilder {
private final Long caseId;
public CaseDetailURLBuilder(final AbstractProcess process, final String configurationId, final Long caseId) {
super(process, configurationId);
this.caseId = caseId;
}
@Override
protected String getRedirectURL(final String locale, final IProgressMonitor monitor) throws UnsupportedEncodingException {