Commit 5216eb0a authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(data management) add persistence_id contract input by default (#1589)

* multiple business data have a persistenceId_string contract input (on
task) in order to provide an edition behavior by default. Associated
operation script has been updated. Operator is now "takes value of"
* Idem for multiple reference in aggregation/composition
* For aggregation, the contract input is now persistenceId_string
instead of persistenceId, in order to avoid potential issues related to
js behavior (Long max range isn't the same ...)

closes [BST-101](https://bonitasoft.atlassian.net/browse/BST-101)
parent 436097e0
...@@ -29,7 +29,6 @@ import java.util.List; ...@@ -29,7 +29,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import org.bonitasoft.engine.bdm.BusinessObjectModelConverter; import org.bonitasoft.engine.bdm.BusinessObjectModelConverter;
...@@ -61,9 +60,6 @@ import org.eclipse.jdt.core.ITypeHierarchy; ...@@ -61,9 +60,6 @@ import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.wiring.BundleWiring;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
...@@ -90,13 +86,11 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore> ...@@ -90,13 +86,11 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
static { static {
extensions.add(BDM_TYPE_EXTENSION); extensions.add(BDM_TYPE_EXTENSION);
} }
public BusinessObjectModelConverter getConverter() { public BusinessObjectModelConverter getConverter() {
return converter; return converter;
} }
@Override @Override
public AbstractBDMFileStore createRepositoryFileStore(final String fileName) { public AbstractBDMFileStore createRepositoryFileStore(final String fileName) {
return new BusinessObjectModelFileStore(fileName, this); return new BusinessObjectModelFileStore(fileName, this);
...@@ -107,13 +101,11 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore> ...@@ -107,13 +101,11 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
return STORE_NAME; return STORE_NAME;
} }
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return Messages.businessObjectRepositoryStoreName; return Messages.businessObjectRepositoryStoreName;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return Pics.getImage("bdm.png", BusinessObjectPlugin.getDefault()); return Pics.getImage("bdm.png", BusinessObjectPlugin.getDefault());
...@@ -131,7 +123,7 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore> ...@@ -131,7 +123,7 @@ public class BusinessObjectModelRepositoryStore<F extends AbstractBDMFileStore>
.map(fileStore -> fileStore.getBusinessObject(qualifiedName) != null ? fileStore : null); .map(fileStore -> fileStore.getBusinessObject(qualifiedName) != null ? fileStore : null);
} }
public Optional<BusinessObject> getBusinessObjectByQualifiedName(final String qualifiedName) { public Optional<BusinessObject> getBusinessObjectByQualifiedName(String qualifiedName) {
final Optional<BusinessObjectModelFileStore> businessObjectFileStore = Optional final Optional<BusinessObjectModelFileStore> businessObjectFileStore = Optional
.ofNullable((BusinessObjectModelFileStore) getChild(BusinessObjectModelFileStore.BOM_FILENAME)); .ofNullable((BusinessObjectModelFileStore) getChild(BusinessObjectModelFileStore.BOM_FILENAME));
return businessObjectFileStore.map(fileStore -> fileStore.getBusinessObject(qualifiedName)); return businessObjectFileStore.map(fileStore -> fileStore.getBusinessObject(qualifiedName));
......
...@@ -198,9 +198,8 @@ public class FieldToContractInputMappingOperationBuilderTest { ...@@ -198,9 +198,8 @@ public class FieldToContractInputMappingOperationBuilderTest {
mapping, new NullProgressMonitor()); mapping, new NullProgressMonitor());
OperatorAssert.assertThat(operation.getOperator()) OperatorAssert.assertThat(operation.getOperator())
.hasType(ExpressionConstants.JAVA_METHOD_OPERATOR) .hasType(ExpressionConstants.ASSIGNMENT_OPERATOR)
.hasInputTypes(Collection.class.getName()) .hasInputTypes(Collection.class.getName());
.hasExpression("addAll");
} }
private FieldToContractInputMappingOperationBuilder createFixture() { private FieldToContractInputMappingOperationBuilder createFixture() {
......
...@@ -27,17 +27,26 @@ public class AggregationReferencePropertyInitializerTest { ...@@ -27,17 +27,26 @@ public class AggregationReferencePropertyInitializerTest {
@Test @Test
public void should_call_query_in_a_closure() throws Exception { public void should_call_query_in_a_closure() throws Exception {
final InitializerContext context = new InitializerContext(); final InitializerContext context = new InitializerContext();
final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(anAggregationField("country", final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(
aBO("country").build())); anAggregationField("country",
aBO("country").build()));
context.setMapping(mapping); context.setMapping(mapping);
context.setContractInput(aContractInput().withName("persistenceId").in(aContractInput().withName("country")).build()); context.setContractInput(
aContractInput().withName("persistenceId_string").in(aContractInput().withName("country")).build());
context.setLocalVariableName("countryVar"); context.setLocalVariableName("countryVar");
final String initialValue = new AggregationReferencePropertyInitializer(null, context).getInitialValue(); final String initialValue = new AggregationReferencePropertyInitializer(null, context).getInitialValue();
assertThat(initialValue).isEqualTo("{" + System.lineSeparator() assertThat(initialValue).isEqualTo("{" + System.lineSeparator()
+ "//Retrieve aggregated country using its DAO and persistenceId" + System.lineSeparator() + "//Retrieve aggregated country using its DAO and persistenceId" + System.lineSeparator()
+ "def countryVar = countryDAO.findByPersistenceId(country.persistenceId.toLong())" + System.lineSeparator() + "def countryVar = countryDAO.findByPersistenceId(country.persistenceId_string.toLong())"
+ System.lineSeparator()
+ "if(!countryVar) {"
+ System.lineSeparator()
+ "throw new IllegalArgumentException(\"The aggregated reference of type `country` with the persistence id \" + country.persistenceId_string.toLong() + \" has not been found.\")"
+ System.lineSeparator()
+ "}"
+ System.lineSeparator()
+ "return countryVar}()"); + "return countryVar}()");
} }
} }
...@@ -35,35 +35,47 @@ public class BusinessObjectQueryInitializerTest { ...@@ -35,35 +35,47 @@ public class BusinessObjectQueryInitializerTest {
@Test @Test
public void should_generate_a_script_using_query_to_retrieve_a_business_object_in_initial_value() throws Exception { public void should_generate_a_script_using_query_to_retrieve_a_business_object_in_initial_value() throws Exception {
final InitializerContext context = new InitializerContext(); final InitializerContext context = new InitializerContext();
final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(anAggregationField("country", final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(
aBO("org.test.Country").build())); anAggregationField("country",
aBO("org.test.Country").build()));
context.setMapping(mapping); context.setMapping(mapping);
context.setData(aBusinessData().withName("myCountry").build()); context.setData(aBusinessData().withName("myCountry").build());
context.setContractInput(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX) context.setContractInput(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX)
.havingInput(aContractInput().withName("persistenceId")).build()); .havingInput(aContractInput().withName("persistenceId_string")).build());
context.setLocalVariableName("countryVar"); context.setLocalVariableName("countryVar");
final BusinessObjectQueryInitializer initializer = new BusinessObjectQueryInitializer(null, context); final BusinessObjectQueryInitializer initializer = new BusinessObjectQueryInitializer(null, context);
initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(null, aStringField("persistenceId").build(), initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(null, aStringField("persistenceId").build(),
aContractInput().withName("persistenceId").in(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX)).build())); aContractInput().withName("persistenceId_string")
.in(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX)).build()));
initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(null, aStringField("name").build(), initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(null, aStringField("name").build(),
aContractInput().withName("name").in(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX)).build())); aContractInput().withName("name")
.in(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX)).build()));
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
assertThat(initialValue).isEqualTo( assertThat(initialValue).isEqualTo(
"//Retrieve aggregated Country using its DAO and persistenceId" + System.lineSeparator() "//Retrieve aggregated Country using its DAO and persistenceId" + System.lineSeparator()
+ "def countryVar = countryDAO.findByPersistenceId(countryInput.persistenceId.toLong())" + System.lineSeparator() + "def countryVar = countryDAO.findByPersistenceId(countryInput.persistenceId_string.toLong())"
+ "countryVar.name = countryInput.name" + System.lineSeparator() + System.lineSeparator()
+ "if(!countryVar) {"
+ System.lineSeparator()
+ "throw new IllegalArgumentException(\"The aggregated reference of type `Country` with the persistence id \" + countryInput.persistenceId_string.toLong() + \" has not been found.\")"
+ System.lineSeparator()
+ "}"
+ System.lineSeparator()
+ "countryVar.name = countryInput.name"
+ System.lineSeparator()
+ "return countryVar"); + "return countryVar");
} }
@Test @Test
public void should_throw_an_IllegalStateException_if_persistenceId_is_not_found() throws Exception { public void should_throw_an_IllegalStateException_if_persistenceId_is_not_found() throws Exception {
final InitializerContext context = new InitializerContext(); final InitializerContext context = new InitializerContext();
final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(anAggregationField("country", final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(
aBO("org.test.Country").build())); anAggregationField("country",
aBO("org.test.Country").build()));
context.setMapping(mapping); context.setMapping(mapping);
context.setData(aBusinessData().withName("myCountry").build()); context.setData(aBusinessData().withName("myCountry").build());
context.setContractInput(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX) context.setContractInput(aContractInput().withName("countryInput").withType(ContractInputType.COMPLEX)
......
...@@ -32,7 +32,7 @@ import org.junit.Rule; ...@@ -32,7 +32,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
public class MultipleBusinessObjectQueryInitializerTest { public class MultipleAggregationBusinessObjectQueryInitializerTest {
@Rule @Rule
public ExpectedException expectedException = ExpectedException.none(); public ExpectedException expectedException = ExpectedException.none();
...@@ -55,22 +55,34 @@ public class MultipleBusinessObjectQueryInitializerTest { ...@@ -55,22 +55,34 @@ public class MultipleBusinessObjectQueryInitializerTest {
context.setData(aBusinessData().withName("myData").build()); context.setData(aBusinessData().withName("myData").build());
context.setContractInput(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple() context.setContractInput(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple()
.havingInput(aContractInput() .havingInput(aContractInput()
.withName("persistenceId")).build()); .withName("persistenceId_string"))
.build());
context.setLocalVariableName("employeeVar"); context.setLocalVariableName("employeeVar");
context.setLocalListVariableName("employeeList"); context.setLocalListVariableName("employeeList");
final MultipleBusinessObjectQueryInitializer initializer = new MultipleBusinessObjectQueryInitializer(employeeBo, context); final MultipleAggregationBusinessObjectQueryInitializer initializer = new MultipleAggregationBusinessObjectQueryInitializer(
initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(employeeBo, nameField, aContractInput().withName("name") employeeBo,
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple()).build())); context);
initializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(employeeBo, nameField,
aContractInput().withName("name")
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple())
.build()));
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
assertThat(initialValue).isEqualTo("def employeeList = []" + System.lineSeparator() assertThat(initialValue).isEqualTo("def employeeList = []" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator() + "//For each item collected in multiple input" + System.lineSeparator()
+ "employeeInput.each{" + System.lineSeparator() + "employeeInput.each{" + System.lineSeparator()
+ "//Add aggregated Employee instance" + System.lineSeparator() + "//Add Employee instance" + System.lineSeparator()
+ "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator() + "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator()
+ "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId.toLong())" + System.lineSeparator() + "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId_string.toLong())"
+ System.lineSeparator()
+ "if(!employeeVar) {"
+ System.lineSeparator()
+ "throw new IllegalArgumentException(\"The aggregated reference of type `Employee` with the persistence id \" + currentEmployeeInput.persistenceId_string.toLong() + \" has not been found.\")"
+ System.lineSeparator()
+ "}"
+ System.lineSeparator()
+ "employeeVar.name = currentEmployeeInput.name" + System.lineSeparator() + "employeeVar.name = currentEmployeeInput.name" + System.lineSeparator()
+ "return employeeVar" + System.lineSeparator() + "return employeeVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator() + "}(it))" + System.lineSeparator()
...@@ -90,6 +102,6 @@ public class MultipleBusinessObjectQueryInitializerTest { ...@@ -90,6 +102,6 @@ public class MultipleBusinessObjectQueryInitializerTest {
context.setLocalVariableName("employeeVar"); context.setLocalVariableName("employeeVar");
context.setLocalListVariableName("employeeList"); context.setLocalListVariableName("employeeList");
new MultipleBusinessObjectQueryInitializer(null, context); new MultipleAggregationBusinessObjectQueryInitializer(null, context);
} }
} }
...@@ -48,24 +48,30 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -48,24 +48,30 @@ public class MultipleAggregationReferencePropertyInitializerTest {
final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(employeesField); final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(employeesField);
context.setMapping(mapping); context.setMapping(mapping);
context.setData(aBusinessData().withName("emp").build()); context.setData(aBusinessData().withName("emp").build());
context.setContractInput(aContractInput().withName("persistenceId") context.setContractInput(aContractInput().withName("persistenceId_string")
.in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build()); .in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build());
context.setLocalVariableName("employeeVar"); context.setLocalVariableName("employeeVar");
context.setLocalListVariableName("employeeList"); context.setLocalListVariableName("employeeList");
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(null, employeeBo, context); final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(
null, employeeBo, context);
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
assertThat(initialValue).isEqualTo("{" + System.lineSeparator() assertThat(initialValue).isEqualTo("{" + System.lineSeparator()
+ "def employeeList = []" + System.lineSeparator() + "def employeeList = []" + System.lineSeparator()
+ "//Uncomment line below to append existing employees" + System.lineSeparator()
+ "//employeeList.addAll(emp.employees)" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator() + "//For each item collected in multiple input" + System.lineSeparator()
+ "employees.each{" + System.lineSeparator() + "employees.each{" + System.lineSeparator()
+ "//Add aggregated Employee instance" + System.lineSeparator() + "//Add Employee instance" + System.lineSeparator()
+ "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator() + "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator()
+ "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId.toLong())" + System.lineSeparator() + "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId_string.toLong())"
+ System.lineSeparator()
+ "if(!employeeVar) {"
+ System.lineSeparator()
+ "throw new IllegalArgumentException(\"The aggregated reference of type `Employee` with the persistence id \" + currentEmployeeInput.persistenceId_string.toLong() + \" has not been found.\")"
+ System.lineSeparator()
+ "}"
+ System.lineSeparator()
+ "return employeeVar" + System.lineSeparator() + "return employeeVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator() + "}(it))" + System.lineSeparator()
+ "}" + System.lineSeparator() + "}" + System.lineSeparator()
...@@ -88,22 +94,30 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -88,22 +94,30 @@ public class MultipleAggregationReferencePropertyInitializerTest {
final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(employeesField); final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping(employeesField);
context.setMapping(mapping); context.setMapping(mapping);
context.setData(aBusinessData().withName("emp").build()); context.setData(aBusinessData().withName("emp").build());
context.setContractInput(aContractInput().withName("persistenceId") context.setContractInput(aContractInput().withName("persistenceId_string")
.in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build()); .in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build());
context.setLocalVariableName("employeeVar"); context.setLocalVariableName("employeeVar");
context.setLocalListVariableName("employeeList"); context.setLocalListVariableName("employeeList");
context.setOnPool(true); context.setOnPool(true);
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(null, employeeBo, context); final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(
null, employeeBo, context);
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
assertThat(initialValue).isEqualTo("{" + System.lineSeparator() assertThat(initialValue).isEqualTo("{" + System.lineSeparator()
+ "def employeeList = []" + System.lineSeparator() + "def employeeList = []" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator() + "//For each item collected in multiple input" + System.lineSeparator()
+ "employees.each{" + System.lineSeparator() + "employees.each{" + System.lineSeparator()
+ "//Add aggregated Employee instance" + System.lineSeparator() + "//Add Employee instance" + System.lineSeparator()
+ "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator() + "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator()
+ "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId.toLong())" + System.lineSeparator() + "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId_string.toLong())"
+ System.lineSeparator()
+ "if(!employeeVar) {"
+ System.lineSeparator()
+ "throw new IllegalArgumentException(\"The aggregated reference of type `Employee` with the persistence id \" + currentEmployeeInput.persistenceId_string.toLong() + \" has not been found.\")"
+ System.lineSeparator()
+ "}"
+ System.lineSeparator()
+ "return employeeVar" + System.lineSeparator() + "return employeeVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator() + "}(it))" + System.lineSeparator()
+ "}" + System.lineSeparator() + "}" + System.lineSeparator()
...@@ -129,12 +143,13 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -129,12 +143,13 @@ public class MultipleAggregationReferencePropertyInitializerTest {
context.setMapping(mapping); context.setMapping(mapping);
context.setData(aBusinessData().withName("emp").build()); context.setData(aBusinessData().withName("emp").build());
context.setContractInput(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple() context.setContractInput(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()
.havingInput(aContractInput().withName("persistenceId")) .havingInput(aContractInput().withName("persistenceId_string"))
.in(aContractInput().withName("direcotries").withType(ContractInputType.COMPLEX).multiple()).build()); .in(aContractInput().withName("direcotries").withType(ContractInputType.COMPLEX).multiple()).build());
context.setLocalVariableName("employeeVar"); context.setLocalVariableName("employeeVar");
context.setLocalListVariableName("employeeList"); context.setLocalListVariableName("employeeList");
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(directoryBo, employeeBo, final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(
directoryBo, employeeBo,
context); context);
final String initialValue = initializer.getInitialValue(); final String initialValue = initializer.getInitialValue();
...@@ -142,9 +157,16 @@ public class MultipleAggregationReferencePropertyInitializerTest { ...@@ -142,9 +157,16 @@ public class MultipleAggregationReferencePropertyInitializerTest {
+ "def employeeList = []" + System.lineSeparator() + "def employeeList = []" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator() + "//For each item collected in multiple input" + System.lineSeparator()
+ "currentDirectoryInput.employees.each{" + System.lineSeparator() + "currentDirectoryInput.employees.each{" + System.lineSeparator()
+ "//Add aggregated Employee instance" + System.lineSeparator() + "//Add Employee instance" + System.lineSeparator()
+ "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator() + "employeeList.add({ currentEmployeeInput ->" + System.lineSeparator()
+ "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId.toLong())" + System.lineSeparator() + "def employeeVar = employeeDAO.findByPersistenceId(currentEmployeeInput.persistenceId_string.toLong())"
+ System.lineSeparator()
+ "if(!employeeVar) {"
+ System.lineSeparator()
+ "throw new IllegalArgumentException(\"The aggregated reference of type `Employee` with the persistence id \" + currentEmployeeInput.persistenceId_string.toLong() + \" has not been found.\")"
+ System.lineSeparator()
+ "}"
+ System.lineSeparator()
+ "return employeeVar" + System.lineSeparator() + "return employeeVar" + System.lineSeparator()
+ "}(it))" + System.lineSeparator() + "}(it))" + System.lineSeparator()
+ "}" + System.lineSeparator() + "}" + System.lineSeparator()
......
...@@ -43,12 +43,11 @@ public class MultipleCompositionReferencePropertyInitializerTest { ...@@ -43,12 +43,11 @@ public class MultipleCompositionReferencePropertyInitializerTest {
context.setLocalVariableName("addressVar"); context.setLocalVariableName("addressVar");
context.setLocalListVariableName("addressList"); context.setLocalListVariableName("addressList");
final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(null, context); final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(
null, context);
assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator() assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator()
+ "def addressList = []" + System.lineSeparator() + "def addressList = []" + System.lineSeparator()
+ "//Uncomment line below to append existing addresses" + System.lineSeparator()
+ "//addressList.addAll(employee.addresses)" + System.lineSeparator()
+ "//For each item collected in multiple input" + System.lineSeparator() + "//For each item collected in multiple input" + System.lineSeparator()
+ "employeeInput.addresses.each{" + System.lineSeparator() + "employeeInput.addresses.each{" + System.lineSeparator()
+ "//Add a new composed Address instance" + System.lineSeparator() + "//Add a new composed Address instance" + System.lineSeparator()
...@@ -61,7 +60,8 @@ public class MultipleCompositionReferencePropertyInitializerTest { ...@@ -61,7 +60,8 @@ public class MultipleCompositionReferencePropertyInitializerTest {
} }
@Test @Test
public void should_build_a_closure_for_multiple_field_in_a_single_businessObject_without_existingValueOnPool() throws Exception { 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()); final RelationField field = aCompositionField("addresses", aBO("Address").build());
field.setCollection(true); field.setCollection(true);
...@@ -76,7 +76,8 @@ public class MultipleCompositionReferencePropertyInitializerTest { ...@@ -76,7 +76,8 @@ public class MultipleCompositionReferencePropertyInitializerTest {
context.setLocalListVariableName("addressList"); context.setLocalListVariableName("addressList");
context.setOnPool(true); context.setOnPool(true);
final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(null, context); final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(
null, context);
assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator() assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator()
+ "def addressList = []" + System.lineSeparator() + "def addressList = []" + System.lineSeparator()
...@@ -92,7 +93,8 @@ public class MultipleCompositionReferencePropertyInitializerTest { ...@@ -92,7 +93,8 @@ public class MultipleCompositionReferencePropertyInitializerTest {
} }
@Test @Test
public void should_build_a_closure_using_parent_iterator_for_multiple_field_in_a_multiple_businessObject() throws Exception { 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()); final RelationField field = aCompositionField("addresses", aBO("Address").build());
field.setCollection(true); field.setCollection(true);
...@@ -108,7 +110,8 @@ public class MultipleCompositionReferencePropertyInitializerTest { ...@@ -108,7 +110,8 @@ public class MultipleCompositionReferencePropertyInitializerTest {
context.setOnPool(true); context.setOnPool(true);
final BusinessObject employee = aBO("Employee").withField(field).build(); final BusinessObject employee = aBO("Employee").withField(field).build();
final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(employee, context); final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(
employee, context);
assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator() assertThat(initializer.getInitialValue()).isEqualTo("{" + System.lineSeparator()
+ "def addressList = []" + System.lineSeparator() + "def addressList = []" + System.lineSeparator()
......
...@@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder.aBO; import static org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder.aBO;
import static org.bonitasoft.studio.model.businessObject.FieldBuilder.aCompositionField; import static org.bonitasoft.studio.model.businessObject.FieldBuilder.aCompositionField;
import static org.bonitasoft.studio.model.businessObject.FieldBuilder.aSimpleField; import static org.bonitasoft.studio.model.businessObject.FieldBuilder.aSimpleField;
import static org.bonitasoft.studio.model.businessObject.FieldBuilder.aStringField;
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;
...@@ -26,41 +27,48 @@ import org.bonitasoft.engine.bdm.model.field.FieldType; ...@@ -26,41 +27,48 @@ import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.engine.bdm.model.field.RelationField; import org.bonitasoft.engine.bdm.model.field.RelationField;
import org.bonitasoft.engine.bdm.model.field.SimpleField; import org.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.studio.contract.core.mapping.RelationFieldToContractInputMapping; import org.bonitasoft.studio.contract.core.mapping.RelationFieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.SimpleFieldToContractInputMapping;
import org.bonitasoft.studio.model.process.ContractInputType; import org.bonitasoft.studio.model.process.ContractInputType;
import org.junit.Test; import org.junit.Test;
public class NewBusinessObjectListInitializerTest { public class NewBusinessObjectListInitializerTest {
@SuppressWarnings("unchecked")
@Test @Test
public void should_initialize_new_object_property_for_multiple_composed_reference() throws Exception { public void should_initialize_new_object_property_for_multiple_composed_reference() throws Exception {