Commit f278a5e4 authored by Aurelien Pupier's avatar Aurelien Pupier
Browse files

BS-14249: support generation of script for initial value of Business

Variable of types containing composition multiple (follow-up of the
previous commit...)
parent b368f0eb
...@@ -59,7 +59,7 @@ public class FieldToContractInputMappingExpressionBuilderTest { ...@@ -59,7 +59,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build()); mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build());
final BusinessObjectData businessObjectData = aBusinessData().withName("myEmployee").build(); final BusinessObjectData businessObjectData = aBusinessData().withName("myEmployee").build();
final Expression expression = expressionBuilder.toExpression(businessObjectData, final Expression expression = expressionBuilder.toExpression(businessObjectData,
mapping); mapping, false);
ExpressionAssert.assertThat(expression) ExpressionAssert.assertThat(expression)
.hasName("employee.address") .hasName("employee.address")
...@@ -77,7 +77,7 @@ public class FieldToContractInputMappingExpressionBuilderTest { ...@@ -77,7 +77,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build(); final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build();
final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build(); final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build();
final Expression expression = expressionBuilder.toExpression(aBusinessData().withName("myEmployee").build(), final Expression expression = expressionBuilder.toExpression(aBusinessData().withName("myEmployee").build(),
mapping); mapping, false);
ExpressionAssert.assertThat(expression) ExpressionAssert.assertThat(expression)
.hasName("lastName") .hasName("lastName")
...@@ -98,7 +98,7 @@ public class FieldToContractInputMappingExpressionBuilderTest { ...@@ -98,7 +98,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
final BusinessObjectData data = aBusinessData().withName("myEmployee").build(); final BusinessObjectData data = aBusinessData().withName("myEmployee").build();
final Expression expression = expressionBuilder.toExpression(data, final Expression expression = expressionBuilder.toExpression(data,
mapping); mapping, false);
ExpressionAssert.assertThat(expression) ExpressionAssert.assertThat(expression)
.hasName("employee.lastName") .hasName("employee.lastName")
......
...@@ -24,6 +24,7 @@ import static org.bonitasoft.studio.model.expression.builders.ExpressionBuilder. ...@@ -24,6 +24,7 @@ import static org.bonitasoft.studio.model.expression.builders.ExpressionBuilder.
import static org.bonitasoft.studio.model.process.builders.BusinessObjectDataBuilder.aBusinessData; import static org.bonitasoft.studio.model.process.builders.BusinessObjectDataBuilder.aBusinessData;
import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.aContractInput; import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.aContractInput;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -81,7 +82,7 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -81,7 +82,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build(); final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build();
final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build(); final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build();
final BusinessObjectData data = aBusinessData().withName("myEmployee").build(); final BusinessObjectData data = aBusinessData().withName("myEmployee").build();
when(expressionBuilder.toExpression(data, mapping)).thenReturn(anExpression().build()); when(expressionBuilder.toExpression(data, mapping, false)).thenReturn(anExpression().build());
final Operation operation = inputToOperation.toOperation(data, final Operation operation = inputToOperation.toOperation(data,
mapping); mapping);
...@@ -95,7 +96,7 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -95,7 +96,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.hasType(ExpressionConstants.VARIABLE_TYPE); .hasType(ExpressionConstants.VARIABLE_TYPE);
assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1); assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1);
verify(expressionBuilder).toExpression(data, mapping); verify(expressionBuilder).toExpression(data, mapping, false);
} }
@Test @Test
...@@ -108,7 +109,7 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -108,7 +109,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.withName("employee").build()); .withName("employee").build());
final BusinessObjectData data = aBusinessData().withName("myEmployee").build(); final BusinessObjectData data = aBusinessData().withName("myEmployee").build();
when(expressionBuilder.toExpression(data, mapping)).thenReturn(anExpression().build()); when(expressionBuilder.toExpression(data, mapping, false)).thenReturn(anExpression().build());
final Operation operation = inputToOperation.toOperation(data, final Operation operation = inputToOperation.toOperation(data,
mapping); mapping);
...@@ -121,7 +122,7 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -121,7 +122,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.hasName("myEmployee").hasContent("myEmployee") .hasName("myEmployee").hasContent("myEmployee")
.hasType(ExpressionConstants.VARIABLE_TYPE); .hasType(ExpressionConstants.VARIABLE_TYPE);
assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1); assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1);
verify(expressionBuilder).toExpression(data, mapping); verify(expressionBuilder).toExpression(data, mapping, false);
} }
@Test @Test
...@@ -132,7 +133,7 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -132,7 +133,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final FieldToContractInputMapping mapping = aRelationMapping(address).build(); final FieldToContractInputMapping mapping = aRelationMapping(address).build();
mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build()); mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build());
final BusinessObjectData businessObjectData = aBusinessData().withName("myEmployee").build(); final BusinessObjectData businessObjectData = aBusinessData().withName("myEmployee").build();
when(expressionBuilder.toExpression(businessObjectData, mapping)).thenReturn(anExpression().build()); when(expressionBuilder.toExpression(businessObjectData, mapping, false)).thenReturn(anExpression().build());
final Operation operation = inputToOperation.toOperation(businessObjectData, final Operation operation = inputToOperation.toOperation(businessObjectData,
mapping); mapping);
...@@ -145,7 +146,7 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -145,7 +146,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.hasType(ExpressionConstants.VARIABLE_TYPE); .hasType(ExpressionConstants.VARIABLE_TYPE);
assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1); assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1);
verify(expressionBuilder).toExpression(businessObjectData, mapping); verify(expressionBuilder).toExpression(businessObjectData, mapping, false);
} }
@Test @Test
...@@ -153,7 +154,8 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -153,7 +154,8 @@ public class FieldToContractInputMappingOperationBuilderTest {
final FieldToContractInputMappingOperationBuilder inputToOperation = createFixture(); final FieldToContractInputMappingOperationBuilder inputToOperation = createFixture();
when(expressionReturnTypeFilter.compatibleReturnTypes(anyString(), anyString())).thenReturn(false); when(expressionReturnTypeFilter.compatibleReturnTypes(anyString(), anyString())).thenReturn(false);
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build(); final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build();
when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class))).thenReturn(anExpression().build()); when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class), anyBoolean())).thenReturn(
anExpression().build());
thrown.expect(OperationCreationException.class); thrown.expect(OperationCreationException.class);
inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(), inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(),
aSimpleMapping(lastNameField).build()); aSimpleMapping(lastNameField).build());
...@@ -168,9 +170,10 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -168,9 +170,10 @@ public class FieldToContractInputMappingOperationBuilderTest {
final FieldToContractInputMapping mapping = spy(aRelationMapping(address).build()); final FieldToContractInputMapping mapping = spy(aRelationMapping(address).build());
mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build()); mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build());
final MappingOperationScriptBuilder fakeScriptBuilder = mock(MappingOperationScriptBuilder.class); final MappingOperationScriptBuilder fakeScriptBuilder = mock(MappingOperationScriptBuilder.class);
when(fakeScriptBuilder.toScript()).thenThrow(BusinessObjectInstantiationException.class); when(fakeScriptBuilder.toScript(false)).thenThrow(BusinessObjectInstantiationException.class);
doReturn(fakeScriptBuilder).when(mapping).getScriptBuilder(any(BusinessObjectData.class)); doReturn(fakeScriptBuilder).when(mapping).getScriptBuilder(any(BusinessObjectData.class));
when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class))).thenReturn(anExpression().build()); when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class), anyBoolean())).thenReturn(
anExpression().build());
thrown.expect(OperationCreationException.class); thrown.expect(OperationCreationException.class);
inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(), inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(),
mapping); mapping);
...@@ -182,7 +185,8 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -182,7 +185,8 @@ public class FieldToContractInputMappingOperationBuilderTest {
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build(); final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build();
final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build(); final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build();
when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class))).thenReturn(anExpression().build()); when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class), anyBoolean())).thenReturn(
anExpression().build());
final Operation operation = inputToOperation.toOperation(aBusinessData().multiple().withName("employees").build(), final Operation operation = inputToOperation.toOperation(aBusinessData().multiple().withName("employees").build(),
mapping); mapping);
......
...@@ -44,7 +44,7 @@ public class MappingOperationScriptBuilderTest { ...@@ -44,7 +44,7 @@ public class MappingOperationScriptBuilderTest {
final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(), final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(),
new SimpleFieldToContractInputMapping(firstNameField), firstNameField); new SimpleFieldToContractInputMapping(firstNameField), firstNameField);
final String script = scriptBuilder.toScript(); final String script = scriptBuilder.toScript(false);
assertThat(scriptBuilder.needsDataDependency()).isFalse(); assertThat(scriptBuilder.needsDataDependency()).isFalse();
assertThat(script).isEqualTo("firstName"); assertThat(script).isEqualTo("firstName");
...@@ -59,7 +59,7 @@ public class MappingOperationScriptBuilderTest { ...@@ -59,7 +59,7 @@ public class MappingOperationScriptBuilderTest {
final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(), final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(),
relationFieldToContractInputMapping, addressField); relationFieldToContractInputMapping, addressField);
final String script = scriptBuilder.toScript(); final String script = scriptBuilder.toScript(false);
assertThat(scriptBuilder.needsDataDependency()).isTrue(); assertThat(scriptBuilder.needsDataDependency()).isTrue();
assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator() assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator()
...@@ -78,7 +78,7 @@ public class MappingOperationScriptBuilderTest { ...@@ -78,7 +78,7 @@ public class MappingOperationScriptBuilderTest {
final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(), final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(),
relationFieldToContractInputMapping, addressField); relationFieldToContractInputMapping, addressField);
final String script = scriptBuilder.toScript(); final String script = scriptBuilder.toScript(false);
assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator() assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator()
+ "return addressVar"); + "return addressVar");
...@@ -95,7 +95,7 @@ public class MappingOperationScriptBuilderTest { ...@@ -95,7 +95,7 @@ public class MappingOperationScriptBuilderTest {
final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(), final MappingOperationScriptBuilder scriptBuilder = new MappingOperationScriptBuilder(aBusinessData().withName("employee").build(),
relationFieldToContractInputMapping, addressField); relationFieldToContractInputMapping, addressField);
final String script = scriptBuilder.toScript(); final String script = scriptBuilder.toScript(false);
assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator() assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator()
+ "addressVar.street = address.street" + System.lineSeparator() + "addressVar.street = address.street" + System.lineSeparator()
...@@ -126,6 +126,6 @@ public class MappingOperationScriptBuilderTest { ...@@ -126,6 +126,6 @@ public class MappingOperationScriptBuilderTest {
mapping, field); mapping, field);
thrown.expect(UnsupportedOperationException.class); thrown.expect(UnsupportedOperationException.class);
scriptBuilder.toScript(); scriptBuilder.toScript(false);
} }
} }
...@@ -44,7 +44,7 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -44,7 +44,7 @@ public class MultipleAggregationReferencePropertyInitializerTest {
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(null, employeeBo, final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(null, employeeBo,
employeesField, aContractInput().withName("persistenceId") employeesField, aContractInput().withName("persistenceId")
.in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build(), "emp"); .in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build(), "emp", false);
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
...@@ -63,6 +63,37 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -63,6 +63,37 @@ public class MultipleAggregationReferencePropertyInitializerTest {
+ "return employeeList}()"); + "return employeeList}()");
} }
@Test
public void should_embbed_aggregation_list_in_a_closure_WithoutExistingOnAPool() throws Exception {
final BusinessObject employeeBo = aBO("Employee").build();
final SimpleField pIdField = new SimpleField();
pIdField.setName(Field.PERSISTENCE_ID);
pIdField.setType(FieldType.LONG);
employeeBo.addField(pIdField);
final SimpleField nameField = aStringField("name").build();
employeeBo.addField(nameField);
final RelationField employeesField = anAggregationField("employees", employeeBo);
employeesField.setCollection(true);
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(null, employeeBo,
employeesField, aContractInput().withName("persistenceId")
.in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build(), "emp", true);
final String initialValue = initializer.getInitialValue();
assertThat(initialValue).isEqualTo("{" + System.lineSeparator()
+ "def employeeList = []" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator()
+ "employees.each{" + System.lineSeparator()
+ "//Add aggregated Employee instance" + System.lineSeparator()
+ "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator()
+ "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId.toLong())" + System.lineSeparator()
+ "return employeeVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator()
+ "}" + System.lineSeparator()
+ "return employeeList}()");
}
@Test @Test
public void should_use_parent_as_iterator() throws Exception { public void should_use_parent_as_iterator() throws Exception {
final BusinessObject directoryBo = aBO("Directory").build(); final BusinessObject directoryBo = aBO("Directory").build();
...@@ -81,7 +112,7 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -81,7 +112,7 @@ public class MultipleAggregationReferencePropertyInitializerTest {
employeesField, employeesField,
aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple() aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()
.havingInput(aContractInput().withName("persistenceId")) .havingInput(aContractInput().withName("persistenceId"))
.in(aContractInput().withName("direcotries").withType(ContractInputType.COMPLEX).multiple()).build(), "emp"); .in(aContractInput().withName("direcotries").withType(ContractInputType.COMPLEX).multiple()).build(), "emp", false);
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
......
...@@ -46,7 +46,7 @@ public class BusinessObjectInitializerFactoryTest { ...@@ -46,7 +46,7 @@ public class BusinessObjectInitializerFactoryTest {
final RelationField aCompositionField = aCompositionField("employee", aBO("Employee").build()); final RelationField aCompositionField = aCompositionField("employee", aBO("Employee").build());
final FieldToContractInputMapping mapping = aRelationMapping(aCompositionField) final FieldToContractInputMapping mapping = aRelationMapping(aCompositionField)
.addChild(aSimpleMapping(aStringField("name").build())).build(); .addChild(aSimpleMapping(aStringField("name").build())).build();
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping, aBusinessData().withName("employee").build()); final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping, aBusinessData().withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(NewBusinessObjectInitializer.class); assertThat(propertyInitializer).isInstanceOf(NewBusinessObjectInitializer.class);
} }
...@@ -60,7 +60,7 @@ public class BusinessObjectInitializerFactoryTest { ...@@ -60,7 +60,7 @@ public class BusinessObjectInitializerFactoryTest {
final FieldToContractInputMapping mapping = FieldToContractInputMappingBuilder final FieldToContractInputMapping mapping = FieldToContractInputMappingBuilder
.aRelationMapping(aCompositionField) .aRelationMapping(aCompositionField)
.addChild(aSimpleMapping(aStringField("name").build())).build(); .addChild(aSimpleMapping(aStringField("name").build())).build();
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping, aBusinessData().withName("employee").build()); final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping, aBusinessData().withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(NewBusinessObjectListInitializer.class); assertThat(propertyInitializer).isInstanceOf(NewBusinessObjectListInitializer.class);
} }
...@@ -71,7 +71,7 @@ public class BusinessObjectInitializerFactoryTest { ...@@ -71,7 +71,7 @@ public class BusinessObjectInitializerFactoryTest {
final BusinessObject businessObject = aBO("Employee").withField(anAggregationField("country", aBO("Country").build())).build(); final BusinessObject businessObject = aBO("Employee").withField(anAggregationField("country", aBO("Country").build())).build();
final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject); final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject);
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData().withName("employee").build()); final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData().withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(BusinessObjectQueryInitializer.class); assertThat(propertyInitializer).isInstanceOf(BusinessObjectQueryInitializer.class);
} }
...@@ -84,7 +84,7 @@ public class BusinessObjectInitializerFactoryTest { ...@@ -84,7 +84,7 @@ public class BusinessObjectInitializerFactoryTest {
final BusinessObject businessObject = aBO("Employee").withField(anAggregationField).build(); final BusinessObject businessObject = aBO("Employee").withField(anAggregationField).build();
final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject); final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject);
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData() final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData()
.withName("employee").build()); .withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(MultipleBusinessObjectQueryInitializer.class); assertThat(propertyInitializer).isInstanceOf(MultipleBusinessObjectQueryInitializer.class);
} }
......
...@@ -22,6 +22,7 @@ import static org.bonitasoft.studio.model.process.builders.ContractBuilder.aCont ...@@ -22,6 +22,7 @@ import static org.bonitasoft.studio.model.process.builders.ContractBuilder.aCont
import static org.bonitasoft.studio.model.process.builders.PoolBuilder.aPool; import static org.bonitasoft.studio.model.process.builders.PoolBuilder.aPool;
import static org.bonitasoft.studio.model.process.builders.TaskBuilder.aTask; import static org.bonitasoft.studio.model.process.builders.TaskBuilder.aTask;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
...@@ -158,7 +159,7 @@ public class ContractInputGenerationWizardTest { ...@@ -158,7 +159,7 @@ public class ContractInputGenerationWizardTest {
BusinessObjectBuilder.aBO("org.company.Employee").withField(SimpleFieldBuilder.aStringField("firstName").build()).build()); BusinessObjectBuilder.aBO("org.company.Employee").withField(SimpleFieldBuilder.aStringField("firstName").build()).build());
when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(store); when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(store);
when(preferenceStore.getString(ContractInputGenerationWizard.HIDE_GENERATION_SUCCESS_DIALOG)).thenReturn("always"); when(preferenceStore.getString(ContractInputGenerationWizard.HIDE_GENERATION_SUCCESS_DIALOG)).thenReturn("always");
when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class))).thenReturn( when(expressionBuilder.toExpression(any(BusinessObjectData.class), any(FieldToContractInputMapping.class), anyBoolean())).thenReturn(
aGroovyScriptExpression().build()); aGroovyScriptExpression().build());
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder, final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder, expressionBuilder,
......
...@@ -56,11 +56,11 @@ public class FieldToContractInputMappingExpressionBuilder { ...@@ -56,11 +56,11 @@ public class FieldToContractInputMappingExpressionBuilder {
this.expressionEditorService = expressionEditorService; this.expressionEditorService = expressionEditorService;
} }
public Expression toExpression(final BusinessObjectData data, final FieldToContractInputMapping mapping) public Expression toExpression(final BusinessObjectData data, final FieldToContractInputMapping mapping, final boolean isOnPool)
throws BusinessObjectInstantiationException, JavaModelException { throws BusinessObjectInstantiationException, JavaModelException {
final ContractInput contractInput = mapping.getContractInput(); final ContractInput contractInput = mapping.getContractInput();
final MappingOperationScriptBuilder mappingOperationScriptBuilder = mapping.getScriptBuilder(data); final MappingOperationScriptBuilder mappingOperationScriptBuilder = mapping.getScriptBuilder(data);
final Expression scriptExpression = ExpressionHelper.createGroovyScriptExpression(mappingOperationScriptBuilder.toScript(), final Expression scriptExpression = ExpressionHelper.createGroovyScriptExpression(mappingOperationScriptBuilder.toScript(isOnPool),
mapping.getFieldType()); mapping.getFieldType());
addScriptDependencies(mappingOperationScriptBuilder, mapping.getContractInput(), data, scriptExpression); addScriptDependencies(mappingOperationScriptBuilder, mapping.getContractInput(), data, scriptExpression);
scriptExpression.setName(Joiner.on(".").join(toAncestorNameList().apply(contractInput))); scriptExpression.setName(Joiner.on(".").join(toAncestorNameList().apply(contractInput)));
......
...@@ -43,12 +43,13 @@ public class FieldToContractInputMappingOperationBuilder { ...@@ -43,12 +43,13 @@ public class FieldToContractInputMappingOperationBuilder {
this.expressionBuilder = expressionBuilder; this.expressionBuilder = expressionBuilder;
} }
public Operation toOperation(final BusinessObjectData data, final FieldToContractInputMapping mapping) throws OperationCreationException { public Operation toOperation(final BusinessObjectData data, final FieldToContractInputMapping mapping)
throws OperationCreationException {
final Operation operation = ExpressionFactory.eINSTANCE.createOperation(); final Operation operation = ExpressionFactory.eINSTANCE.createOperation();
operation.setLeftOperand(ExpressionHelper.createVariableExpression(data)); operation.setLeftOperand(ExpressionHelper.createVariableExpression(data));
operation.setOperator(operator(mapping, data)); operation.setOperator(operator(mapping, data));
try { try {
operation.setRightOperand(expressionBuilder.toExpression(data, mapping)); operation.setRightOperand(expressionBuilder.toExpression(data, mapping, false));
} catch (final BusinessObjectInstantiationException | JavaModelException e) { } catch (final BusinessObjectInstantiationException | JavaModelException e) {
throw new OperationCreationException("Failed to create right operand expression", e); throw new OperationCreationException("Failed to create right operand expression", e);
} }
......
...@@ -54,9 +54,9 @@ public class MappingOperationScriptBuilder { ...@@ -54,9 +54,9 @@ public class MappingOperationScriptBuilder {
this.field = field; this.field = field;
} }
public String toScript() throws BusinessObjectInstantiationException { public String toScript(final boolean isOnPool) throws BusinessObjectInstantiationException {
mapping.getContractInput(); mapping.getContractInput();
return format(buildPropertyInitializerTree(mapping, field, data).getInitialValue()); return format(buildPropertyInitializerTree(mapping, field, data, isOnPool).getInitialValue());
} }
private String format(final String initialValue) { private String format(final String initialValue) {
...@@ -69,19 +69,20 @@ public class MappingOperationScriptBuilder { ...@@ -69,19 +69,20 @@ public class MappingOperationScriptBuilder {
return document.get(); return document.get();
} }
private IPropertyInitializer buildPropertyInitializerTree(final FieldToContractInputMapping mapping, final Field rootField, final BusinessObjectData data) { private IPropertyInitializer buildPropertyInitializerTree(final FieldToContractInputMapping mapping, final Field rootField, final BusinessObjectData data,
final boolean isOnPool) {
final Field field = mapping.getField(); final Field field = mapping.getField();
if (field instanceof SimpleField) { if (field instanceof SimpleField) {
return propertyInitializerFactory.newPropertyInitializer(mapping, data); return propertyInitializerFactory.newPropertyInitializer(mapping, data, isOnPool);
} }
if (field instanceof RelationField) { if (field instanceof RelationField) {
final AbstractBusinessObjectInitializer scriptInitializer = (AbstractBusinessObjectInitializer) findInitializerFactory(field, rootField) final AbstractBusinessObjectInitializer scriptInitializer = (AbstractBusinessObjectInitializer) findInitializerFactory(field, rootField)
.newPropertyInitializer( .newPropertyInitializer(
mapping, mapping,
data); data, isOnPool);
for (final FieldToContractInputMapping child : mapping.getChildren()) { for (final FieldToContractInputMapping child : mapping.getChildren()) {
if (child.isGenerated()) {