Commit 161bb5fa authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Merge pull request #258 from bonitasoft/defect/BS-14249-compositionMultipleForDefaultValue

BS-14249: support generation of script for initial value of Business
parents 37105620 7e1e5cde
......@@ -169,7 +169,7 @@ public class RootContractInputGeneratorTest {
rootContractInputGenerator.build(businessObjectData);
final ArgumentCaptor<FieldToContractInputMapping> argumentCaptor = ArgumentCaptor.forClass(FieldToContractInputMapping.class);
verify(expressionBuilder).toExpression(eq(businessObjectData), argumentCaptor.capture());
verify(expressionBuilder).toExpression(eq(businessObjectData), argumentCaptor.capture(), eq(false));
final FieldToContractInputMapping fieldToContractInputMapping = argumentCaptor.getValue();
assertThat(fieldToContractInputMapping.getField().getName()).isEqualTo("rootInputName");
assertThat(fieldToContractInputMapping.getField().isCollection()).isFalse();
......@@ -192,7 +192,7 @@ public class RootContractInputGeneratorTest {
rootContractInputGenerator.build(businessObjectData);
final ArgumentCaptor<FieldToContractInputMapping> argumentCaptor = ArgumentCaptor.forClass(FieldToContractInputMapping.class);
verify(expressionBuilder).toExpression(eq(businessObjectData), argumentCaptor.capture());
verify(expressionBuilder).toExpression(eq(businessObjectData), argumentCaptor.capture(), eq(false));
final FieldToContractInputMapping fieldToContractInputMapping = argumentCaptor.getValue();
assertThat(fieldToContractInputMapping.getField().getName()).isEqualTo("rootInputName");
assertThat(fieldToContractInputMapping.getField().isCollection()).isTrue();
......
......@@ -59,7 +59,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).build());
final BusinessObjectData businessObjectData = aBusinessData().withName("myEmployee").build();
final Expression expression = expressionBuilder.toExpression(businessObjectData,
mapping);
mapping, false);
ExpressionAssert.assertThat(expression)
.hasName("employee.address")
......@@ -77,7 +77,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build();
final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).build();
final Expression expression = expressionBuilder.toExpression(aBusinessData().withName("myEmployee").build(),
mapping);
mapping, false);
ExpressionAssert.assertThat(expression)
.hasName("lastName")
......@@ -98,7 +98,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
final BusinessObjectData data = aBusinessData().withName("myEmployee").build();
final Expression expression = expressionBuilder.toExpression(data,
mapping);
mapping, false);
ExpressionAssert.assertThat(expression)
.hasName("employee.lastName")
......
......@@ -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.ContractInputBuilder.aContractInput;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
......@@ -81,7 +82,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).build();
final FieldToContractInputMapping mapping = aSimpleMapping(lastNameField).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,
mapping);
......@@ -95,7 +96,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.hasType(ExpressionConstants.VARIABLE_TYPE);
assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1);
verify(expressionBuilder).toExpression(data, mapping);
verify(expressionBuilder).toExpression(data, mapping, false);
}
@Test
......@@ -108,7 +109,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.withName("employee").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,
mapping);
......@@ -121,7 +122,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.hasName("myEmployee").hasContent("myEmployee")
.hasType(ExpressionConstants.VARIABLE_TYPE);
assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1);
verify(expressionBuilder).toExpression(data, mapping);
verify(expressionBuilder).toExpression(data, mapping, false);
}
@Test
......@@ -132,7 +133,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final FieldToContractInputMapping mapping = aRelationMapping(address).build();
mapping.toContractInput(aContractInput().withName("employee").withType(ContractInputType.COMPLEX).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,
mapping);
......@@ -145,7 +146,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
.hasType(ExpressionConstants.VARIABLE_TYPE);
assertThat(operation.getLeftOperand().getReferencedElements()).hasSize(1);
verify(expressionBuilder).toExpression(businessObjectData, mapping);
verify(expressionBuilder).toExpression(businessObjectData, mapping, false);
}
@Test
......@@ -153,7 +154,8 @@ public class FieldToContractInputMappingOperationBuilderTest {
final FieldToContractInputMappingOperationBuilder inputToOperation = createFixture();
when(expressionReturnTypeFilter.compatibleReturnTypes(anyString(), anyString())).thenReturn(false);
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);
inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(),
aSimpleMapping(lastNameField).build());
......@@ -170,7 +172,8 @@ public class FieldToContractInputMappingOperationBuilderTest {
final MappingOperationScriptBuilder fakeScriptBuilder = mock(MappingOperationScriptBuilder.class);
when(fakeScriptBuilder.toScript()).thenThrow(BusinessObjectInstantiationException.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);
inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(),
mapping);
......@@ -182,7 +185,8 @@ public class FieldToContractInputMappingOperationBuilderTest {
final SimpleField lastNameField = aSimpleField().withName("lastName").ofType(FieldType.STRING).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(),
mapping);
......
......@@ -44,7 +44,7 @@ public class MultipleAggregationReferencePropertyInitializerTest {
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(null, employeeBo,
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();
......@@ -63,6 +63,37 @@ public class MultipleAggregationReferencePropertyInitializerTest {
+ "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
public void should_use_parent_as_iterator() throws Exception {
final BusinessObject directoryBo = aBO("Directory").build();
......@@ -81,7 +112,7 @@ public class MultipleAggregationReferencePropertyInitializerTest {
employeesField,
aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()
.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();
......
......@@ -50,7 +50,7 @@ public class MultipleBusinessObjectQueryInitializerTest {
aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple()
.havingInput(aContractInput()
.withName("persistenceId")).build(),
"myData.employees");
"myData.employees", false);
initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(employeeBo, nameField, aContractInput().withName("name")
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple()).build()));
......@@ -77,6 +77,6 @@ public class MultipleBusinessObjectQueryInitializerTest {
aContractInput()
.withName("notPersistenceId")
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple()).build(),
"myData.employees");
"myData.employees", false);
}
}
......@@ -34,7 +34,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
aContractInput().withName("addresses").multiple()
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX))
.build(),
"employee");
"employee", false);
assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator()
+ "def addressList = []" + System.lineSeparator()
......@@ -51,6 +51,29 @@ public class MultipleCompositionReferencePropertyInitializerTest {
+ "return addressList}()");
}
@Test
public void should_build_a_closure_for_multiple_field_in_a_single_businessObject_without_existingValueOnPool() throws Exception {
final RelationField field = aCompositionField("addresses", aBO("Address").build());
field.setCollection(true);
final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(null, field,
aContractInput().withName("addresses").multiple()
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX))
.build(),
"employee", true);
assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator()
+ "def addressList = []" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator()
+ "employeeInput.addresses.each{" + System.lineSeparator()
+ "//Add a new composed Address instance" + System.lineSeparator()
+ "addressList.add({ currentAddressInput ->" + System.lineSeparator()
+ "def addressVar = new Address()" + System.lineSeparator()
+ "return addressVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator()
+ "}" + System.lineSeparator()
+ "return addressList}()");
}
@Test
public void should_build_a_closure_using_parent_iterator_for_multiple_field_in_a_multiple_businessObject() throws Exception {
final RelationField field = aCompositionField("addresses", aBO("Address").build());
......@@ -60,7 +83,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
aContractInput().withName("addresses").multiple()
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple())
.build(),
"employee");
"employee", false);
assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator()
+ "def addressList = []" + System.lineSeparator()
......
......@@ -37,7 +37,7 @@ public class NewBusinessObjectListInitializerTest {
businessObject);
addressField.setCollection(true);
final AbstractBusinessObjectInitializer propertyInitializer = new NewBusinessObjectListInitializer(addressField, aContractInput().withName("address")
.multiple().in(aContractInput().withName("employee").withType(ContractInputType.COMPLEX)).build(), "myAddresses");
.multiple().in(aContractInput().withName("employee").withType(ContractInputType.COMPLEX)).build(), "myAddresses", false);
propertyInitializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(businessObject,
streetField, aContractInput().withName("street")
.in(aContractInput().withName("address").withType(ContractInputType.COMPLEX).multiple()
......@@ -57,6 +57,32 @@ public class NewBusinessObjectListInitializerTest {
+ "return addressList");
}
@Test
public void should_initialize_new_object_property_for_multiple_composed_reference_withoutExistingOnPool() throws Exception {
final SimpleField streetField = aSimpleField().withName("street").ofType(FieldType.STRING).notNullable().build();
final BusinessObject businessObject = aBO("org.test.Address").withField(streetField).build();
final RelationField addressField = aCompositionField("address",
businessObject);
addressField.setCollection(true);
final AbstractBusinessObjectInitializer propertyInitializer = new NewBusinessObjectListInitializer(addressField, aContractInput().withName("address")
.multiple().in(aContractInput().withName("employee").withType(ContractInputType.COMPLEX)).build(), "myAddresses", true);
propertyInitializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(businessObject,
streetField, aContractInput().withName("street")
.in(aContractInput().withName("address").withType(ContractInputType.COMPLEX).multiple()
.in(aContractInput().withName("employee").withType(ContractInputType.COMPLEX))).build()));
assertThat(propertyInitializer.getInitialValue()).isEqualTo("def addressList = []" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator()
+ "employee.address.each{" + System.lineSeparator()
+ "//Add a new composed Address instance" + System.lineSeparator()
+ "addressList.add({ currentAddressInput ->" + System.lineSeparator()
+ "def addressVar = new org.test.Address()" + System.lineSeparator()
+ "addressVar.street = currentAddressInput.street" + System.lineSeparator()
+ "return addressVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator()
+ "}" + System.lineSeparator()
+ "return addressList");
}
@Test
public void should_not_add_existing_object_to_list_input_is_a_root_input() throws Exception {
final SimpleField streetField = aSimpleField().withName("street").ofType(FieldType.STRING).notNullable().build();
......@@ -65,7 +91,7 @@ public class NewBusinessObjectListInitializerTest {
businessObject);
addressField.setCollection(true);
final AbstractBusinessObjectInitializer propertyInitializer = new NewBusinessObjectListInitializer(addressField, aContractInput().withName("addresses")
.multiple().build(), "myAddress");
.multiple().build(), "myAddress", false);
propertyInitializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(businessObject,
streetField, aContractInput().withName("street")
.in(aContractInput().withName("address").withType(ContractInputType.COMPLEX).multiple()
......
......@@ -46,7 +46,7 @@ public class BusinessObjectInitializerFactoryTest {
final RelationField aCompositionField = aCompositionField("employee", aBO("Employee").build());
final FieldToContractInputMapping mapping = aRelationMapping(aCompositionField)
.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);
}
......@@ -60,7 +60,7 @@ public class BusinessObjectInitializerFactoryTest {
final FieldToContractInputMapping mapping = FieldToContractInputMappingBuilder
.aRelationMapping(aCompositionField)
.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);
}
......@@ -71,7 +71,7 @@ public class BusinessObjectInitializerFactoryTest {
final BusinessObject businessObject = aBO("Employee").withField(anAggregationField("country", aBO("Country").build())).build();
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);
}
......@@ -84,7 +84,7 @@ public class BusinessObjectInitializerFactoryTest {
final BusinessObject businessObject = aBO("Employee").withField(anAggregationField).build();
final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject);
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(MultipleBusinessObjectQueryInitializer.class);
}
......
......@@ -51,7 +51,7 @@ public class PropertyInitializerFactoryTest {
final PropertyInitializerFactory factory = newFactory();
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(aSimpleMapping(aStringField("name").build()).build(), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(SimpleFieldPropertyInitializer.class);
}
......@@ -66,7 +66,7 @@ public class PropertyInitializerFactoryTest {
.aRelationMapping(employee)
.addChild(aSimpleMapping(aStringField("name").build())).build();
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping.getChildren().get(0), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(SimpleFieldPropertyInitializer.class);
assertThat(((SimpleFieldPropertyInitializer) propertyInitializer).getParentBusinessObject()).isNotNull();
......@@ -82,9 +82,9 @@ public class PropertyInitializerFactoryTest {
.addChild(aRelationMapping(employee)).build();
final BusinessObjectData businessObjectData = aBusinessData()
.withName("employee").build();
factory.newPropertyInitializer(mapping.getChildren().get(0), businessObjectData);
factory.newPropertyInitializer(mapping.getChildren().get(0), businessObjectData, false);
verify(relationFactory).newPropertyInitializer(mapping.getChildren().get(0), businessObjectData);
verify(relationFactory).newPropertyInitializer(mapping.getChildren().get(0), businessObjectData, false);
}
@Test
......@@ -93,7 +93,7 @@ public class PropertyInitializerFactoryTest {
thrown.expect(UnsupportedOperationException.class);
factory.newPropertyInitializer(new FakeMapping(new Field() {
}), aBusinessData().build());
}), aBusinessData().build(), false);
}
private PropertyInitializerFactory newFactory() {
......
......@@ -49,7 +49,7 @@ public class RelationPropertyInitializerFactoryTest {
.addChild(aRelationMapping(addressField))
.addChild(aSimpleMapping(aStringField("street").build())).build();
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping.getChildren().get(0), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(CompositionReferencePropertyInitializer.class);
}
......@@ -66,7 +66,7 @@ public class RelationPropertyInitializerFactoryTest {
.addChild(aRelationMapping(addressField))
.addChild(aSimpleMapping(aStringField("street").build())).build();
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mapping.getChildren().get(0), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(MultipleCompositionReferencePropertyInitializer.class);
}
......@@ -78,7 +78,7 @@ public class RelationPropertyInitializerFactoryTest {
final BusinessObject businessObject = aBO("Employee").withField(anAggregationField("country", aBO("Country").build())).build();
final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject);
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(AggregationReferencePropertyInitializer.class);
}
......@@ -92,7 +92,7 @@ public class RelationPropertyInitializerFactoryTest {
final BusinessObject businessObject = aBO("Employee").withField(anAggregationField).build();
final List<FieldToContractInputMapping> mappings = new FieldToContractInputMappingFactory().createMappingForBusinessObjectType(businessObject);
final IPropertyInitializer propertyInitializer = factory.newPropertyInitializer(mappings.get(0), aBusinessData()
.withName("employee").build());
.withName("employee").build(), false);
assertThat(propertyInitializer).isInstanceOf(MultipleAggregationReferencePropertyInitializer.class);
}
......
......@@ -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.TaskBuilder.aTask;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
......@@ -158,7 +159,7 @@ public class ContractInputGenerationWizardTest {
BusinessObjectBuilder.aBO("org.company.Employee").withField(SimpleFieldBuilder.aStringField("firstName").build()).build());
when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(store);
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());
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(process, editingDomain(), repositoryAccessor, operationBuilder,
expressionBuilder,
......
......@@ -55,7 +55,15 @@ public class RootContractInputGenerator {
this.expressionBuilder = expressionBuilder;
}
public void buildForInstanciation(final BusinessObjectData data) throws OperationCreationException {
build(data, true);
}
public void build(final BusinessObjectData data) throws OperationCreationException {
build(data, false);
}
private void build(final BusinessObjectData data, final boolean isOnPool) throws OperationCreationException {
contractInput = ProcessFactory.eINSTANCE.createContractInput();
contractInput.setName(rootContractInputName);
contractInput.setType(ContractInputType.COMPLEX);
......@@ -74,7 +82,7 @@ public class RootContractInputGenerator {
mappingOperations.add(operationBuilder.toOperation(data, createParentMapping(data, rootContractInputName)));
}
try {
initialValueExpression = expressionBuilder.toExpression(data, createParentMapping(data, rootContractInputName));
initialValueExpression = expressionBuilder.toExpression(data, createParentMapping(data, rootContractInputName), isOnPool);
} catch (JavaModelException | BusinessObjectInstantiationException e) {
throw new OperationCreationException("Failed to create initial value expression", e);
}
......
......@@ -56,17 +56,26 @@ public class FieldToContractInputMappingExpressionBuilder {
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 {
final ContractInput contractInput = mapping.getContractInput();
final MappingOperationScriptBuilder mappingOperationScriptBuilder = mapping.getScriptBuilder(data);
final Expression scriptExpression = ExpressionHelper.createGroovyScriptExpression(mappingOperationScriptBuilder.toScript(),
mapping.getFieldType());
final String script = getScriptText(isOnPool, mappingOperationScriptBuilder);
final Expression scriptExpression = ExpressionHelper.createGroovyScriptExpression(script, mapping.getFieldType());
addScriptDependencies(mappingOperationScriptBuilder, mapping.getContractInput(), data, scriptExpression);
scriptExpression.setName(Joiner.on(".").join(toAncestorNameList().apply(contractInput)));
return scriptExpression;
}
protected String getScriptText(final boolean isOnPool, final MappingOperationScriptBuilder mappingOperationScriptBuilder)
throws BusinessObjectInstantiationException {
if (isOnPool) {
return mappingOperationScriptBuilder.toInstanciationScript();
} else {
return mappingOperationScriptBuilder.toScript();
}
}
private void addScriptDependencies(final MappingOperationScriptBuilder scriptBuilder, final ContractInput contractInput, final BusinessObjectData data,
final Expression groovyScriptExpression) throws JavaModelException {
groovyScriptExpression.getReferencedElements().add(
......
......@@ -43,12 +43,13 @@ public class FieldToContractInputMappingOperationBuilder {
this.expressionBuilder = expressionBuilder;
}
public Operation toOperation(final BusinessObjectData data, final FieldToContractInputMapping mapping) throws OperationCreationException {
public Operation toOperation(final BusinessObjectData data, final FieldToContractInputMapping mapping)