Commit 4d55814c authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

fix(bar_export) fix parameter empty value export (#226)

parent 69b194a5
......@@ -64,6 +64,7 @@ Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.bpm,
org.bonitasoft.engine.bpm.bar,
org.bonitasoft.engine.bpm.bar.actorMapping,
org.bonitasoft.engine.bpm.businessdata,
org.bonitasoft.engine.bpm.connector,
org.bonitasoft.engine.bpm.contract,
......
/**
* Copyright (C) 2016 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.export;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.bonitasoft.studio.model.configuration.builders.ActorMappingBuilder.anActorMapping;
import static org.bonitasoft.studio.model.configuration.builders.ActorMappingsTypeBuilder.anActorMappingsType;
import static org.bonitasoft.studio.model.configuration.builders.ConfigurationBuilder.aConfiguration;
import static org.bonitasoft.studio.model.configuration.builders.MembershipBuilder.aMembership;
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 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.junit.Test;
public class BarExporterTest {
@Test
public void should_transform_parameters_in_configuration_as_a_Map() throws Exception {
final BarExporter barExporter = BarExporter.getInstance();
final Map<String, String> parameters = barExporter.getParameters(aConfiguration().havingParameters(
aStringParameter("host", "localhost"),
anIntegerParameter("port", 8080),
aBooleanParameter("useHTTPs", true),
aStringParameter("parameterNotSet", null))
.build());
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());
final Actor employeeActor = new Actor("Employee");
employeeActor.addUser("romain");
employeeActor.addGroup("/root");
employeeActor.addRoles(Arrays.asList("manager","dev"));
employeeActor.addMembership("/root/rd","dev");
assertThat(actorMapping.getActors()).containsExactly(employeeActor);
}
@Test
public void should_export_empty_configuration_actor_mapping_as_empty_engine_actor_mappings() throws Exception {
final BarExporter barExporter = BarExporter.getInstance();
final ActorMapping actorMapping = barExporter.getActorMapping(aConfiguration().build());
assertThat(actorMapping).isEqualTo(new org.bonitasoft.engine.bpm.bar.actorMapping.ActorMapping());
}
}
......@@ -15,10 +15,11 @@
package org.bonitasoft.studio.engine.export;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -47,6 +48,9 @@ import org.bonitasoft.studio.configuration.preferences.ConfigurationPreferenceCo
import org.bonitasoft.studio.diagram.custom.repository.ProcessConfigurationRepositoryStore;
import org.bonitasoft.studio.engine.EnginePlugin;
import org.bonitasoft.studio.engine.i18n.Messages;
import org.bonitasoft.studio.model.actormapping.ActorMapping;
import org.bonitasoft.studio.model.actormapping.ActorMappingsType;
import org.bonitasoft.studio.model.actormapping.MembershipType;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.ConfigurationFactory;
import org.bonitasoft.studio.model.parameter.Parameter;
......@@ -65,6 +69,9 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
/**
* @author Romain Bioteau
*/
......@@ -103,7 +110,7 @@ public class BarExporter {
DesignProcessDefinition def;
try {
def = procBuilder.createDefinition(process);
} catch (InvalidProcessDefinitionException e1) {
} catch (final InvalidProcessDefinitionException e1) {
throw new BarCreationException(String.format("Failed to create process definition for %s (%s)", process.getName(), process.getVersion()), e1);
}
......@@ -112,23 +119,12 @@ public class BarExporter {
}
final BusinessArchiveBuilder builder = new BusinessArchiveBuilder().createNewBusinessArchive();
builder.setProcessDefinition(def);
builder.setParameters(getParameterMapFromConfiguration(configuration));
byte[] content;
try {
content = new ActorMappingExporter().toByteArray(configuration);
if (content != null) {
builder.setActorMapping(content);
}
} catch (ActorMappingExportException | IOException e1) {
throw new BarCreationException("Failed to add Actor mapping.", e1);
}
builder.setProcessDefinition(def).setParameters(getParameters(configuration)).setActorMapping(getActorMapping(configuration));
for (final BARResourcesProvider resourceProvider : getBARResourcesProvider()) {
try {
resourceProvider.addResourcesForConfiguration(builder, process, configuration, excludedObject);
} catch (Exception e) {
} catch (final Exception e) {
throw new BarCreationException("Failed to add Process resources from configuration.", e);
}
}
......@@ -138,7 +134,7 @@ public class BarExporter {
if (provider != null) {
try {
provider.addResourcesForConfiguration(builder, process, configuration, excludedObject);
} catch (Exception e) {
} catch (final Exception e) {
throw new BarCreationException("Failed to add Application resources from configuration.", e);
}
}
......@@ -163,11 +159,33 @@ public class BarExporter {
final BusinessArchive archive = builder.done();
BonitaStudioLog.info("Build complete for process " + process.getName() + " (" + process.getVersion() + " ).", EnginePlugin.PLUGIN_ID);
return archive;
}catch (InvalidBusinessArchiveFormatException e) {
} catch (final InvalidBusinessArchiveFormatException e) {
throw new BarCreationException("Failed to create Business Archive.", e);
}
}
protected org.bonitasoft.engine.bpm.bar.actorMapping.ActorMapping getActorMapping(Configuration configuration) {
final ActorMappingsType mappings = configuration.getActorMappings();
final org.bonitasoft.engine.bpm.bar.actorMapping.ActorMapping actorMapping = new org.bonitasoft.engine.bpm.bar.actorMapping.ActorMapping();
if (mappings != null) {
for (final ActorMapping mapping : mappings.getActorMapping()) {
actorMapping.addActor(toEngineActor(mapping));
}
}
return actorMapping;
}
private org.bonitasoft.engine.bpm.bar.actorMapping.Actor toEngineActor(ActorMapping mapping) {
final org.bonitasoft.engine.bpm.bar.actorMapping.Actor actor = new org.bonitasoft.engine.bpm.bar.actorMapping.Actor(mapping.getName());
actor.addUsers(mapping.getUsers().getUser());
actor.addGroups(mapping.getGroups().getGroup());
actor.addRoles(mapping.getRoles().getRole());
for (final MembershipType membership : mapping.getMemberships().getMembership()) {
actor.addMembership(membership.getGroup(), membership.getRole());
}
return actor;
}
public DesignProcessDefinitionBuilder getProcessDefinitionBuilder() {
for (final IConfigurationElement element : BonitaStudioExtensionRegistryManager.getInstance()
.getConfigurationElements(PROCESS_DEFINITION_EXPORTER_ID)) {
......@@ -219,6 +237,8 @@ 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);
......@@ -229,14 +249,28 @@ public class BarExporter {
return configuration;
}
public Map<String, String> getParameterMapFromConfiguration(final Configuration configuration) {
final Map<String, String> result = new HashMap<String, String>();
for (final Parameter p : configuration.getParameters()) {
if (p.getValue() != null) {
result.put(p.getName(), p.getValue());
protected Map<String, String> getParameters(final Configuration configuration) {
return Maps.newHashMap(transformValues(uniqueIndex(configuration.getParameters(), toParameterKeys()), toParameterValues()));
}
private Function<Parameter, String> toParameterValues() {
return new Function<Parameter, String>() {
@Override
public String apply(Parameter parameter) {
return parameter.getValue();
}
};
}
private Function<Parameter, String> toParameterKeys() {
return new Function<Parameter, String>() {
@Override
public String apply(Parameter parameter) {
return parameter.getName();
}
}
return result;
};
}
protected BARResourcesProvider getBARApplicationResourcesProvider() {
......@@ -261,7 +295,7 @@ public class BarExporter {
}
public List<BARResourcesProvider> getBARResourcesProvider() {
final List<BARResourcesProvider> res = new ArrayList<BARResourcesProvider>();
final List<BARResourcesProvider> res = new ArrayList<>();
final IConfigurationElement[] extensions = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements(
BAR_RESOURCE_PROVIDERS_EXTENSION_POINT);
for (final IConfigurationElement extension : extensions) {
......
/**
* Copyright (C) 2014 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.model.configuration.builders;
import java.util.Arrays;
import org.bonitasoft.studio.model.Buildable;
import org.bonitasoft.studio.model.actormapping.ActorMapping;
import org.bonitasoft.studio.model.actormapping.ActorMappingFactory;
import org.bonitasoft.studio.model.actormapping.MembershipType;
/**
* @author Romain Bioteau
*/
public class ActorMappingBuilder implements Buildable<ActorMapping> {
private final ActorMapping actorMapping;
private ActorMappingBuilder(final ActorMapping actorMapping) {
this.actorMapping = actorMapping;
}
public static ActorMappingBuilder anActorMapping() {
ActorMapping mapping = ActorMappingFactory.eINSTANCE.createActorMapping();
mapping.setUsers(ActorMappingFactory.eINSTANCE.createUsers());
mapping.setMemberships(ActorMappingFactory.eINSTANCE.createMembership());
mapping.setGroups(ActorMappingFactory.eINSTANCE.createGroups());
mapping.setRoles(ActorMappingFactory.eINSTANCE.createRoles());
return new ActorMappingBuilder(mapping);
}
public ActorMappingBuilder withActor(final String actorName) {
actorMapping.setName(actorName);
return this;
}
public ActorMappingBuilder havingUsers(final String... users) {
actorMapping.getUsers().getUser().addAll(Arrays.asList(users));
return this;
}
public ActorMappingBuilder havingRoles(final String... roles) {
actorMapping.getRoles().getRole().addAll(Arrays.asList(roles));
return this;
}
public ActorMappingBuilder havingGroups(final String... groups) {
actorMapping.getGroups().getGroup().addAll(Arrays.asList(groups));
return this;
}
public ActorMappingBuilder havingMemberships(final Buildable<MembershipType>... memberships) {
for (final Buildable<? extends MembershipType> membership : memberships) {
actorMapping.getMemberships().getMembership().add(membership.build());
}
return this;
}
public ActorMapping build() {
return actorMapping;
}
}
/**
* Copyright (C) 2014 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.model.configuration.builders;
import org.bonitasoft.studio.model.Buildable;
import org.bonitasoft.studio.model.actormapping.ActorMapping;
import org.bonitasoft.studio.model.actormapping.ActorMappingFactory;
import org.bonitasoft.studio.model.actormapping.ActorMappingsType;
/**
* @author Romain Bioteau
*/
public class ActorMappingsTypeBuilder implements Buildable<ActorMappingsType> {
private final ActorMappingsType actorMappingsType;
private ActorMappingsTypeBuilder(final ActorMappingsType actorMapping) {
this.actorMappingsType = actorMapping;
}
public static ActorMappingsTypeBuilder anActorMappingsType() {
return new ActorMappingsTypeBuilder(ActorMappingFactory.eINSTANCE.createActorMappingsType());
}
public ActorMappingsTypeBuilder havingMapping(final Buildable<? extends ActorMapping>... mappings) {
for (final Buildable<? extends ActorMapping> mapping : mappings) {
actorMappingsType.getActorMapping().add(mapping.build());
}
return this;
}
public ActorMappingsType build() {
return actorMappingsType;
}
}
......@@ -15,10 +15,14 @@
package org.bonitasoft.studio.model.configuration.builders;
import org.bonitasoft.studio.model.Buildable;
import org.bonitasoft.studio.model.actormapping.ActorMapping;
import org.bonitasoft.studio.model.actormapping.ActorMappingsType;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.ConfigurationFactory;
import org.bonitasoft.studio.model.configuration.DefinitionMapping;
import org.bonitasoft.studio.model.configuration.FragmentContainer;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.parameter.builders.ParameterBuilder;
/**
* @author Romain Bioteau
......@@ -91,6 +95,18 @@ public class ConfigurationBuilder {
return this;
}
public ConfigurationBuilder havingParameters(final Buildable<? extends Parameter>... parameters) {
for (final Buildable<? extends Parameter> parameter : parameters) {
configuration.getParameters().add(parameter.build());
}
return this;
}
public ConfigurationBuilder havingActorMapping(final Buildable<? extends ActorMappingsType> actorMapping) {
configuration.setActorMappings(actorMapping.build());
return this;
}
public Configuration build() {
return configuration;
}
......
/**
* Copyright (C) 2014 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.model.configuration.builders;
import org.bonitasoft.studio.model.Buildable;
import org.bonitasoft.studio.model.actormapping.ActorMappingFactory;
import org.bonitasoft.studio.model.actormapping.MembershipType;
/**
* @author Romain Bioteau
*/
public class MembershipBuilder implements Buildable<MembershipType> {
private final MembershipType membership;
private MembershipBuilder(final MembershipType actorMapping) {
this.membership = actorMapping;
}
public static MembershipBuilder aMembership() {
return new MembershipBuilder(ActorMappingFactory.eINSTANCE.createMembershipType());
}
public static MembershipBuilder aMembership(String group, String role) {
return aMembership().withGroup(group).withRole(role);
}
public MembershipBuilder withGroup(String group) {
membership.setGroup(group);
return this;
}
public MembershipBuilder withRole(String role) {
membership.setRole(role);
return this;
}
public MembershipType build() {
return membership;
}
}
......@@ -16,6 +16,7 @@
*/
package org.bonitasoft.studio.model.parameter.builders;
import org.bonitasoft.studio.model.Buildable;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.parameter.ParameterFactory;
......@@ -23,12 +24,24 @@ import org.bonitasoft.studio.model.parameter.ParameterFactory;
* @author Romain Bioteau
*
*/
public class ParameterBuilder {
public class ParameterBuilder implements Buildable<Parameter>{
public static ParameterBuilder aParameter() {
return new ParameterBuilder();
}
public static ParameterBuilder aStringParameter(String name,String value) {
return new ParameterBuilder().withName(name).withValue(value).withType(String.class.getName());
}
public static ParameterBuilder aBooleanParameter(String name,boolean value) {
return new ParameterBuilder().withName(name).withValue(String.valueOf(value)).withType(Boolean.class.getName());
}
public static ParameterBuilder anIntegerParameter(String name,int value) {
return new ParameterBuilder().withName(name).withValue(String.valueOf(value)).withType(Integer.class.getName());
}
private final Parameter parameter;
......
Supports Markdown
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