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

fix(bar builder): build bar without config (#2448)

When 'None' is selected for the configuration, an empty configuration is
created at build time and put into the bar.
Previously, we used a null argument for the conf Id when none was
selected. Now we use a dedicated none ID so it doesn't collude with the
logic that handle a real null id.

[STUDIO-3642](https://bonitasoft.atlassian.net/browse/STUDIO-3642)
Co-authored-by: default avataradrien <adrien.lachambre@bonitasoft.com>
parent 7698b1ef
......@@ -5,24 +5,22 @@
* 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.configuration.preferences;
/**
* @author Romain Bioteau
*
*/
public interface ConfigurationPreferenceConstants {
public static final String DEFAULT_CONFIGURATION = "defaultConfiguration" ;
public static final String LOCAL_CONFIGURAITON = "Local";
public static final String DEFAULT_CONFIGURATION = "defaultConfiguration";
public static final String LOCAL_CONFIGURAITON = "Local";
public static final String NONE_CONFIGURAITON = "None";
}
......@@ -23,12 +23,20 @@ import static org.bonitasoft.studio.model.configuration.builders.MembershipBuild
import static org.bonitasoft.studio.model.parameter.builders.ParameterBuilder.aBooleanParameter;
import static org.bonitasoft.studio.model.parameter.builders.ParameterBuilder.aStringParameter;
import static org.bonitasoft.studio.model.parameter.builders.ParameterBuilder.anIntegerParameter;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.Map;
import org.bonitasoft.engine.bpm.bar.actorMapping.Actor;
import org.bonitasoft.engine.bpm.bar.actorMapping.ActorMapping;
import org.bonitasoft.studio.configuration.preferences.ConfigurationPreferenceConstants;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.junit.Test;
public class BarExporterTest {
......@@ -43,23 +51,26 @@ public class BarExporterTest {
aBooleanParameter("useHTTPs", true),
aStringParameter("parameterNotSet", null))
.build());
assertThat(parameters).contains(entry("host", "localhost"), entry("port", "8080"), entry("useHTTPs", "true"), entry("parameterNotSet", null));
assertThat(parameters).contains(entry("host", "localhost"), entry("port", "8080"), entry("useHTTPs", "true"),
entry("parameterNotSet", null));
}
@Test
public void should_transform_actor_mappings_in_configuration_as_engine_actor_mappings() throws Exception {
final BarExporter barExporter = BarExporter.getInstance();
final ActorMapping actorMapping = barExporter.getActorMapping(aConfiguration()
.havingActorMapping(anActorMappingsType().havingMapping(anActorMapping().withActor("Employee").havingUsers("romain").havingGroups("/root").havingRoles("manager","dev").havingMemberships(aMembership("/root/rd","dev")))).build());
.havingActorMapping(anActorMappingsType()
.havingMapping(anActorMapping().withActor("Employee").havingUsers("romain").havingGroups("/root")
.havingRoles("manager", "dev").havingMemberships(aMembership("/root/rd", "dev"))))
.build());
final Actor employeeActor = new Actor("Employee");
employeeActor.addUser("romain");
employeeActor.addGroup("/root");
employeeActor.addRoles(Arrays.asList("manager","dev"));
employeeActor.addMembership("/root/rd","dev");
employeeActor.addRoles(Arrays.asList("manager", "dev"));
employeeActor.addMembership("/root/rd", "dev");
assertThat(actorMapping.getActors()).containsExactly(employeeActor);
}
......@@ -72,7 +83,14 @@ public class BarExporterTest {
assertThat(actorMapping).isEqualTo(new org.bonitasoft.engine.bpm.bar.actorMapping.ActorMapping());
}
@Test
public void should_create_empty_configuration_when_confId_is_none() throws Exception {
BarExporter exporter = spy(BarExporter.class);
AbstractProcess process = mock(AbstractProcess.class);
doReturn(null).when(exporter).getProcessConfigurationRepositoryStore();
doNothing().when(exporter).synchronizeConfiguration(any(), any());
exporter.getConfiguration(process, ConfigurationPreferenceConstants.NONE_CONFIGURAITON);
verify(exporter).createEmptyConfiguration(ConfigurationPreferenceConstants.NONE_CONFIGURAITON);
}
}
......@@ -21,6 +21,7 @@ import static com.google.common.collect.Maps.uniqueIndex;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.bonitasoft.engine.bpm.bar.BusinessArchive;
import org.bonitasoft.engine.bpm.bar.BusinessArchiveBuilder;
......@@ -70,7 +71,7 @@ public class BarExporter {
private static BarExporter INSTANCE;
private final ExtensionContextInjectionFactory extensionContextInjectionFactory;
private BarExporter() {
protected BarExporter() {
extensionContextInjectionFactory = new ExtensionContextInjectionFactory();
}
......@@ -107,13 +108,15 @@ public class BarExporter {
MultiStatus resourceConfigurationStatus = new MultiStatus(EnginePlugin.PLUGIN_ID, 0, null, null);
for (final BARResourcesProvider resourceProvider : getBARResourcesProvider()) {
try {
resourceConfigurationStatus.addAll(resourceProvider.addResourcesForConfiguration(builder, process, configuration));
resourceConfigurationStatus
.addAll(resourceProvider.addResourcesForConfiguration(builder, process, configuration));
} catch (final Exception e) {
throw new BarCreationException("Failed to add Process resources from configuration.", e);
}
}
if(!resourceConfigurationStatus.isOK()) {
throw new BarCreationException("Failed to add Process resources from configuration.", resourceConfigurationStatus);
if (!resourceConfigurationStatus.isOK()) {
throw new BarCreationException("Failed to add Process resources from configuration.",
resourceConfigurationStatus);
}
//Add forms resources
......@@ -185,8 +188,7 @@ public class BarExporter {
public Configuration getConfiguration(final AbstractProcess process, String configurationId) {
Configuration configuration = null;
final ProcessConfigurationRepositoryStore processConfStore = RepositoryManager.getInstance().getRepositoryStore(
ProcessConfigurationRepositoryStore.class);
final ProcessConfigurationRepositoryStore processConfStore = getProcessConfigurationRepositoryStore();
if (configurationId == null) {
configurationId = ConfigurationPlugin.getDefault().getPreferenceStore()
.getString(ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION);
......@@ -206,6 +208,8 @@ public class BarExporter {
} catch (final ReadFileStoreException e) {
BonitaStudioLog.error("Failed to read process configuration", e);
}
} else if (Objects.equals(configurationId, ConfigurationPreferenceConstants.NONE_CONFIGURAITON)) {
configuration = createEmptyConfiguration(configurationId);
} else {
for (final Configuration conf : process.getConfigurations()) {
if (configurationId.equals(conf.getName())) {
......@@ -214,14 +218,27 @@ public class BarExporter {
}
}
//TODO Remove configuration sync when all bar artifacts will be live update friendly (connectors, dependencies, parameters...) ?
if (configuration == null) {
configuration = ConfigurationFactory.eINSTANCE.createConfiguration();
configuration.setName(configurationId);
configuration.setVersion(ModelVersion.CURRENT_VERSION);
configuration = createEmptyConfiguration(configurationId);
}
synchronizeConfiguration(process, configuration);
return configuration;
}
protected void synchronizeConfiguration(final AbstractProcess process, Configuration configuration) {
//Synchronize configuration with definition
new ConfigurationSynchronizer(process, configuration).synchronize();
}
protected ProcessConfigurationRepositoryStore getProcessConfigurationRepositoryStore() {
return RepositoryManager.getInstance().getRepositoryStore(
ProcessConfigurationRepositoryStore.class);
}
protected Configuration createEmptyConfiguration(String id) {
Configuration configuration = ConfigurationFactory.eINSTANCE.createConfiguration();
configuration.setName(id);
configuration.setVersion(ModelVersion.CURRENT_VERSION);
return configuration;
}
......@@ -230,7 +247,6 @@ public class BarExporter {
transformValues(uniqueIndex(configuration.getParameters(), Parameter::getName), Parameter::getValue));
}
protected BARResourcesProvider getBARApplicationResourcesProvider() {
BARResourcesProvider result = null;
int maxPriority = -1;
......@@ -268,6 +284,4 @@ public class BarExporter {
return res;
}
}
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