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

fix(callActivity) fix data mapping type (#636)

Closes BS-16883
parent 5a11aee2
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.engine.export.builder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.expression.builders.ExpressionBuilder.aConstantExpression;
import static org.bonitasoft.studio.model.process.builders.StringDataTypeBuilder.aStringDataType;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
......@@ -41,6 +42,7 @@ import org.bonitasoft.engine.operation.Operation;
import org.bonitasoft.engine.operation.OperatorType;
import org.bonitasoft.studio.assertions.EngineExpressionAssert;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.engine.contribution.IEngineDefinitionBuilder;
import org.bonitasoft.studio.model.connectorconfiguration.builders.ConnectorConfigurationBuilder;
import org.bonitasoft.studio.model.connectorconfiguration.builders.ConnectorParameterBuilder;
......@@ -107,6 +109,8 @@ public class EngineFlowElementBuilderTest {
@Mock
private IEngineDefinitionBuilder engineContractBuilder;
@Mock
private DiagramRepositoryStore diagramStore;
/**
* @throws java.lang.Exception
......@@ -115,8 +119,10 @@ public class EngineFlowElementBuilderTest {
public void setUp() throws Exception {
instance = new ProcessDefinitionBuilder().createNewInstance("test", "1.0");
flowElementSwitch = spy(new EngineFlowElementBuilder(instance, Collections.<EObject> emptySet()));
doReturn(engineContractBuilder).when(flowElementSwitch).getEngineDefinitionBuilder(any(EObject.class), any(Contract.class));
doReturn(engineContractBuilder).when(flowElementSwitch).getEngineDefinitionBuilder(any(EObject.class),
any(Contract.class));
doReturn(userFilterBuilder).when(taskBuilder).addUserFilter(anyString(), anyString(), anyString());
doReturn(diagramStore).when(flowElementSwitch).getDiagramRepositoryStore();
}
/**
......@@ -135,7 +141,8 @@ public class EngineFlowElementBuilderTest {
subProcessEvent.getElements().add(startMessageEventinSubprocess);
flowElementSwitch.caseStartMessageEvent(startMessageEventinSubprocess);
verify(flowElementSwitch).addMessageCorrelation(eq(startMessageEventinSubprocess), any(CatchMessageEventTriggerDefinitionBuilder.class));
verify(flowElementSwitch).addMessageCorrelation(eq(startMessageEventinSubprocess),
any(CatchMessageEventTriggerDefinitionBuilder.class));
}
@Test
......@@ -148,7 +155,8 @@ public class EngineFlowElementBuilderTest {
final Activity activity = ProcessFactory.eINSTANCE.createActivity();
activity.getBoundaryIntermediateEvents().add(bmEvent);
when(activityDefinitionBuilder.addBoundaryEvent(bmEvent.getName(), true)).thenReturn(boundaryEventBuilder);
when(boundaryEventBuilder.addMessageEventTrigger(bmEvent.getEvent())).thenReturn(catchMessageEventTriggerDefinitionBuilder);
when(boundaryEventBuilder.addMessageEventTrigger(bmEvent.getEvent()))
.thenReturn(catchMessageEventTriggerDefinitionBuilder);
flowElementSwitch.addBoundaryEvents(activityDefinitionBuilder, activity);
verify(flowElementSwitch).addMessageCorrelation(eq(bmEvent), any(CatchMessageEventTriggerDefinitionBuilder.class));
}
......@@ -171,12 +179,16 @@ public class EngineFlowElementBuilderTest {
@Test
public void testAddContext() {
final Data collectionDataToMultiInstantiate = DataBuilder.aData().withName("pData").havingDataType(StringDataTypeBuilder.aStringDataType()).build();
final Data collectionDataToMultiInstantiate = DataBuilder.aData().withName("pData")
.havingDataType(StringDataTypeBuilder.aStringDataType()).build();
final TaskBuilder taskB = TaskBuilder.aTask().havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
final TaskBuilder taskB = TaskBuilder.aTask()
.havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
.havingIteratorExpression(ExpressionBuilder.anExpression()
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE).withReturnType(String.class.getName())
.withName("pData")).havingData(collectionDataToMultiInstantiate);
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE)
.withReturnType(String.class.getName())
.withName("pData"))
.havingData(collectionDataToMultiInstantiate);
final Pool pool = PoolBuilder.aPool()
.havingElements(taskB)
......@@ -195,17 +207,22 @@ public class EngineFlowElementBuilderTest {
@Test
public void testAddIteratorToContext() {
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData").withClassname("classname").build();
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData")
.withClassname("classname").build();
final TaskBuilder taskB = TaskBuilder.aTask().havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
final TaskBuilder taskB = TaskBuilder.aTask()
.havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
.havingIteratorExpression(ExpressionBuilder.anExpression()
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE).withReturnType(String.class.getName())
.withName("pData")).havingData(collectionDataToMultiInstantiate);
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE)
.withReturnType(String.class.getName())
.withName("pData"))
.havingData(collectionDataToMultiInstantiate);
final Pool pool = PoolBuilder.aPool().havingElements(taskB).build();
final MainProcess mainProcess = MainProcessBuilder.aMainProcess().build();
mainProcess.getElements().add(pool);
mainProcess.getDatatypes().add(BusinessObjectDataTypeBuilder.aBusinessObjectDataType().withName("classname").build());
mainProcess.getDatatypes()
.add(BusinessObjectDataTypeBuilder.aBusinessObjectDataType().withName("classname").build());
flowElementSwitch.addContext(taskBuilder, (Task) pool.getElements().get(0));
final ArgumentCaptor<Expression> argument = ArgumentCaptor.forClass(Expression.class);
......@@ -216,15 +233,18 @@ public class EngineFlowElementBuilderTest {
@Test
public void testAddIteratorToContext_robustnessWithNullValue() {
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData").withClassname("classname").build();
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData")
.withClassname("classname").build();
final TaskBuilder taskB = TaskBuilder.aTask().havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
final TaskBuilder taskB = TaskBuilder.aTask()
.havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
.havingData(collectionDataToMultiInstantiate);
final Pool pool = PoolBuilder.aPool().havingElements(taskB).build();
final MainProcess mainProcess = MainProcessBuilder.aMainProcess().build();
mainProcess.getElements().add(pool);
mainProcess.getDatatypes().add(BusinessObjectDataTypeBuilder.aBusinessObjectDataType().withName("classname").build());
mainProcess.getDatatypes()
.add(BusinessObjectDataTypeBuilder.aBusinessObjectDataType().withName("classname").build());
flowElementSwitch.addContext(taskBuilder, (Task) pool.getElements().get(0));
verify(taskBuilder, times(0)).addContextEntry(anyString(), any(Expression.class));
......@@ -237,11 +257,13 @@ public class EngineFlowElementBuilderTest {
CallActivityBuilder
.aCallActivity()
.withName("Call Activity")
.havingCalledActivityName(aConstantExpression().withContent("Pool1"))
.havingInputMappings(
InputMappingBuilder
.anInputMapping()
.setSubProcessTarget(InputMappingAssignationType.DATA, "subProcessData")
.setProcessSource(ExpressionBuilder.aVariableExpression().withContent("processData").build())
.setProcessSource(ExpressionBuilder.aVariableExpression()
.withContent("processData").build())
.build()))
.havingData(DataBuilder.aData().havingDataType(aStringDataType()).withName("processData"))
.build();
......@@ -266,8 +288,10 @@ public class EngineFlowElementBuilderTest {
.havingInputMappings(
InputMappingBuilder
.anInputMapping()
.setSubProcessTarget(InputMappingAssignationType.CONTRACT_INPUT, "contractInput")
.setProcessSource(ExpressionBuilder.aVariableExpression().withContent("processData").build())
.setSubProcessTarget(InputMappingAssignationType.CONTRACT_INPUT,
"contractInput")
.setProcessSource(ExpressionBuilder.aVariableExpression()
.withContent("processData").build())
.build()))
.havingData(DataBuilder.aData().havingDataType(aStringDataType()).withName("processData"))
.build();
......@@ -289,7 +313,8 @@ public class EngineFlowElementBuilderTest {
tableExpression.getExpressions().add(listExpression);
final ActorFilter actorFilter = ActorFilterBuilder.anActorFilter().havingConfiguration(
ConnectorConfigurationBuilder.aConnectorConfiguration().havingParameters(
ConnectorParameterBuilder.aConnectorParameter().withKey("plop").havingExpression(tableExpression))).build();
ConnectorParameterBuilder.aConnectorParameter().withKey("plop").havingExpression(tableExpression)))
.build();
flowElementSwitch.addUserFilterToTask(taskBuilder, "actor", actorFilter);
verify(userFilterBuilder).addInput(anyString(), any(Expression.class));
}
......@@ -298,25 +323,29 @@ public class EngineFlowElementBuilderTest {
public void testAddUserFilterToTask_withEmptyOptionalInputs() {
final ActorFilter actorFilter = ActorFilterBuilder.anActorFilter().havingConfiguration(
ConnectorConfigurationBuilder.aConnectorConfiguration().havingParameters(
ConnectorParameterBuilder.aConnectorParameter().withKey("plop"))).build();
ConnectorParameterBuilder.aConnectorParameter().withKey("plop")))
.build();
flowElementSwitch.addUserFilterToTask(taskBuilder, "actor", actorFilter);
verify(userFilterBuilder, never()).addInput(anyString(), any(Expression.class));
}
@Test
public void testAddDataForMultiInstanceIterator_WithBusinessData() {
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData").withClassname("classname").build();
final Data collectionDataToMultiInstantiate = BusinessObjectDataBuilder.aBusinessData().withName("bData")
.withClassname("classname").build();
final Pool pool = PoolBuilder.aPool()
.havingElements(
ActivityBuilder.anActivity()
.havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
.havingIteratorExpression(ExpressionBuilder.anExpression()
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE).withReturnType(String.class.getName())
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE)
.withReturnType(String.class.getName())
.withName("bData")))
.havingData(collectionDataToMultiInstantiate)
.build();
flowElementSwitch.addDataForMultiInstanceIterator(activityDefinitionBuilder, ((Activity) pool.getElements().get(0)).getIteratorExpression(),
flowElementSwitch.addDataForMultiInstanceIterator(activityDefinitionBuilder,
((Activity) pool.getElements().get(0)).getIteratorExpression(),
collectionDataToMultiInstantiate);
verify(activityDefinitionBuilder).addBusinessData(anyString(), anyString());
......@@ -324,18 +353,21 @@ public class EngineFlowElementBuilderTest {
@Test
public void testAddDataForMultiInstanceIterator_WithProcessData() {
final Data collectionDataToMultiInstantiate = DataBuilder.aData().withName("pData").havingDataType(StringDataTypeBuilder.aStringDataType()).build();
final Data collectionDataToMultiInstantiate = DataBuilder.aData().withName("pData")
.havingDataType(StringDataTypeBuilder.aStringDataType()).build();
final Pool pool = PoolBuilder.aPool()
.havingElements(
ActivityBuilder.anActivity()
.havingCollectionDataToMultiInstantiate(collectionDataToMultiInstantiate)
.havingIteratorExpression(ExpressionBuilder.anExpression()
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE).withReturnType(String.class.getName())
.withExpressionType(ExpressionConstants.MULTIINSTANCE_ITERATOR_TYPE)
.withReturnType(String.class.getName())
.withName("pData")))
.havingData(collectionDataToMultiInstantiate)
.build();
flowElementSwitch.addDataForMultiInstanceIterator(activityDefinitionBuilder, ((Activity) pool.getElements().get(0)).getIteratorExpression(),
flowElementSwitch.addDataForMultiInstanceIterator(activityDefinitionBuilder,
((Activity) pool.getElements().get(0)).getIteratorExpression(),
collectionDataToMultiInstantiate);
verify(activityDefinitionBuilder).addData(anyString(), anyString(), any(Expression.class));
......
......@@ -15,9 +15,12 @@
package org.bonitasoft.studio.engine.export.builder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import org.bonitasoft.engine.bpm.flownode.GatewayType;
import org.bonitasoft.engine.bpm.flownode.TaskPriority;
......@@ -50,12 +53,15 @@ import org.bonitasoft.studio.common.DateUtil;
import org.bonitasoft.studio.common.ExpressionConstants;
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.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.engine.export.EngineExpressionUtil;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorParameter;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ListExpression;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.process.AbstractCatchMessageEvent;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.AbstractTimerEvent;
import org.bonitasoft.studio.model.process.Activity;
import org.bonitasoft.studio.model.process.ActorFilter;
......@@ -105,7 +111,6 @@ import org.bonitasoft.studio.model.process.StartSignalEvent;
import org.bonitasoft.studio.model.process.StartTimerEvent;
import org.bonitasoft.studio.model.process.SubProcessEvent;
import org.bonitasoft.studio.model.process.Task;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
......@@ -431,10 +436,11 @@ public class EngineFlowElementBuilder extends AbstractProcessBuilder {
return object;
}
protected void exportInputMappingsForCallActivity(final CallActivity object, final CallActivityBuilder activityBuilder) {
for (final InputMapping mapping : object.getInputMappings()) {
protected void exportInputMappingsForCallActivity(final CallActivity callActivity,
final CallActivityBuilder activityBuilder) {
for (final InputMapping mapping : callActivity.getInputMappings()) {
if (InputMappingAssignationType.DATA == mapping.getAssignationType()) {
exportInputMappingAssignedToDataForCallActivity(activityBuilder, mapping);
exportInputMappingAssignedToDataForCallActivity(activityBuilder, callActivity, mapping);
} else {
exportInputMappingAssignedToContractInputForCallActivity(activityBuilder, mapping);
}
......@@ -448,24 +454,51 @@ public class EngineFlowElementBuilder extends AbstractProcessBuilder {
}
private void exportInputMappingAssignedToDataForCallActivity(final CallActivityBuilder activityBuilder,
final InputMapping mapping) {
CallActivity callActivity, final InputMapping mapping) {
final OperationBuilder opBuilder = new OperationBuilder();
opBuilder.createNewInstance();
opBuilder.setRightOperand(EngineExpressionUtil.createExpression(mapping.getProcessSource()));
final LeftOperandBuilder builder = new LeftOperandBuilder();
builder.createNewInstance();
builder.setName(mapping.getSubprocessTarget());
final EList<EObject> referencedElements = mapping.getProcessSource().getReferencedElements();
String type = LeftOperand.TYPE_DATA;
if (!referencedElements.isEmpty()) {
type = getLeftOperandTypeForData(referencedElements.get(0));
String subprocessTarget = mapping.getSubprocessTarget();
builder.setName(subprocessTarget);
Optional<Data> targetData = findProcess(
callActivity.getCalledActivityName() != null ? callActivity.getCalledActivityName().getContent() : null,
callActivity.getCalledActivityVersion() != null ? callActivity.getCalledActivityVersion().getContent()
: null)
.map(AbstractProcess::getData)
.map(Collection::stream)
.orElse(Stream.empty())
.filter(data -> subprocessTarget.equals(data.getName()))
.findFirst();
if (targetData.isPresent()) {
builder.setType(
targetData.get() instanceof BusinessObjectData ? LeftOperand.TYPE_BUSINESS_DATA : LeftOperand.TYPE_DATA);
} else {
final List<EObject> referencedElements = mapping.getProcessSource().getReferencedElements();
String type = LeftOperand.TYPE_DATA;
if (!referencedElements.isEmpty()) {
type = getLeftOperandTypeForData(referencedElements.get(0));
}
builder.setType(type);
}
builder.setType(type);
opBuilder.setLeftOperand(builder.done());
opBuilder.setType(OperatorType.ASSIGNMENT);
activityBuilder.addDataInputOperation(opBuilder.done());
}
protected Optional<AbstractProcess> findProcess(final String subprocessName, final String subprocessVersion) {
final DiagramRepositoryStore repositoryStore = getDiagramRepositoryStore();
return Optional
.ofNullable(ModelHelper.findProcess(subprocessName, subprocessVersion, repositoryStore.getAllProcesses()));
}
protected DiagramRepositoryStore getDiagramRepositoryStore() {
return RepositoryManager.getInstance().getCurrentRepository()
.getRepositoryStore(DiagramRepositoryStore.class);
}
protected void exportOutputMappingForCallActivities(final CallActivity object,
final CallActivityBuilder activityBuilder) {
for (final OutputMapping mapping : object.getOutputMappings()) {
......
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.properties.sections.callActivity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -41,15 +42,12 @@ public class CallActivityHelper {
this.selectionProvider = selectionProvider;
}
protected List<String> getCallActivityData() {
final List<String> res = new ArrayList<>();
protected List<Data> getCallActivityData() {
final AbstractProcess subProcess = getCalledProcess();
if (subProcess != null) {
for (final Data data : subProcess.getData()) {
res.add(data.getName());
}
return subProcess.getData();
}
return res;
return Collections.emptyList();
}
protected List<String> getCallActivityContractInput() {
......
......@@ -333,8 +333,8 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
protected void updateAvailableValuesInputMappingTargetCombo(final CCombo targetCombo,
final InputMappingAssignationType assignationType) {
if (InputMappingAssignationType.DATA == assignationType) {
for (final String subprocessData : callActivityHelper.getCallActivityData()) {
targetCombo.add(subprocessData);
for (final Data subprocessData : callActivityHelper.getCallActivityData()) {
targetCombo.add(subprocessData.getName());
}
} else {
for (final String contractInputOfCalledActivity : callActivityHelper.getCallActivityContractInput()) {
......
......@@ -248,8 +248,8 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
private CCombo createSubprocessSourceCombo(final Composite outputMappingControl, final OutputMapping mapping) {
final CCombo subprocessSourceCombo = getWidgetFactory().createCCombo(outputMappingControl, SWT.BORDER);
for (final String subprocessData : callActivityHelper.getCallActivityData()) {
subprocessSourceCombo.add(subprocessData);
for (final Data subprocessData : callActivityHelper.getCallActivityData()) {
subprocessSourceCombo.add(subprocessData.getName());
}
subprocessSourceCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(15, 0).create());
subprocessSourceCombo.addListener(SWT.Modify, new Listener() {
......
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