Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bonita
bonita-studio
Commits
6bed7796
Commit
6bed7796
authored
Sep 14, 2015
by
rbioteau
Browse files
BS-14058
Handle script generation whit same attribute name in business model hierarchy
parent
89d473d0
Changes
24
Hide whitespace changes
Inline
Side-by-side
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/VariableNameResolverTest.java
0 → 100644
View file @
6bed7796
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
org.bonitasoft.studio.contract.core.mapping.operation
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
bonitasoft
.
studio
.
model
.
businessObject
.
BusinessObjectBuilder
.
aBO
;
import
org.junit.Test
;
public
class
VariableNameResolverTest
{
@Test
public
void
should_create_a_variable_name_for_a_business_object
()
throws
Exception
{
final
VariableNameResolver
variableNameResolver
=
new
VariableNameResolver
();
final
String
varName
=
variableNameResolver
.
newVarName
(
aBO
(
"org.test.Employee"
).
build
());
assertThat
(
varName
).
isEqualTo
(
"employeeVar"
);
}
@Test
public
void
should_create_a_variable_name_for_a_business_object_with_suffix_if_variable_is_already_in_the_context
()
throws
Exception
{
final
VariableNameResolver
variableNameResolver
=
new
VariableNameResolver
();
final
String
varName
=
variableNameResolver
.
newVarName
(
aBO
(
"org.test.Employee"
).
build
());
final
String
varName2
=
variableNameResolver
.
newVarName
(
aBO
(
"org.test.Employee"
).
build
());
final
String
varName3
=
variableNameResolver
.
newVarName
(
aBO
(
"org.test.Employee"
).
build
());
assertThat
(
varName
).
isEqualTo
(
"employeeVar"
);
assertThat
(
varName2
).
isEqualTo
(
"employeeVar2"
);
assertThat
(
varName3
).
isEqualTo
(
"employeeVar3"
);
}
@Test
public
void
should_create_a_list_variable_name_for_a_business_object
()
throws
Exception
{
final
VariableNameResolver
variableNameResolver
=
new
VariableNameResolver
();
final
String
varName
=
variableNameResolver
.
newListVarName
(
aBO
(
"org.test.Employee"
).
build
());
assertThat
(
varName
).
isEqualTo
(
"employeeList"
);
}
@Test
public
void
should_create_a_list_variable_name_for_a_business_object_with_suffix_if_variable_is_already_in_the_context
()
throws
Exception
{
final
VariableNameResolver
variableNameResolver
=
new
VariableNameResolver
();
final
String
varName
=
variableNameResolver
.
newListVarName
(
aBO
(
"org.test.Employee"
).
build
());
final
String
varName2
=
variableNameResolver
.
newListVarName
(
aBO
(
"org.test.Employee"
).
build
());
final
String
varName3
=
variableNameResolver
.
newListVarName
(
aBO
(
"org.test.Employee"
).
build
());
assertThat
(
varName
).
isEqualTo
(
"employeeList"
);
assertThat
(
varName2
).
isEqualTo
(
"employeeList2"
);
assertThat
(
varName3
).
isEqualTo
(
"employeeList3"
);
}
}
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/AggregationReferencePropertyInitializerTest.java
View file @
6bed7796
...
...
@@ -19,6 +19,7 @@ import static org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder.a
import
static
org
.
bonitasoft
.
studio
.
model
.
businessObject
.
FieldBuilder
.
anAggregationField
;
import
static
org
.
bonitasoft
.
studio
.
model
.
process
.
builders
.
ContractInputBuilder
.
aContractInput
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.junit.Test
;
public
class
AggregationReferencePropertyInitializerTest
{
...
...
@@ -27,7 +28,7 @@ public class AggregationReferencePropertyInitializerTest {
public
void
should_call_query_in_a_closure
()
throws
Exception
{
final
AggregationReferencePropertyInitializer
propertyInitializer
=
new
AggregationReferencePropertyInitializer
(
null
,
anAggregationField
(
"country"
,
aBO
(
"country"
).
build
()),
aContractInput
().
withName
(
"persistenceId"
).
in
(
aContractInput
().
withName
(
"country"
)).
build
(),
""
);
""
,
new
VariableNameResolver
()
);
final
String
initialValue
=
propertyInitializer
.
getInitialValue
();
...
...
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/BusinessObjectQueryInitializerTest.java
View file @
6bed7796
...
...
@@ -20,6 +20,7 @@ import static org.bonitasoft.studio.model.businessObject.FieldBuilder.aStringFie
import
static
org
.
bonitasoft
.
studio
.
model
.
businessObject
.
FieldBuilder
.
anAggregationField
;
import
static
org
.
bonitasoft
.
studio
.
model
.
process
.
builders
.
ContractInputBuilder
.
aContractInput
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -35,7 +36,7 @@ public class BusinessObjectQueryInitializerTest {
final
BusinessObjectQueryInitializer
initializer
=
new
BusinessObjectQueryInitializer
(
null
,
anAggregationField
(
"country"
,
aBO
(
"org.test.Country"
)
.
build
()),
aContractInput
().
withName
(
"countryInput"
).
withType
(
ContractInputType
.
COMPLEX
).
havingInput
(
aContractInput
().
withName
(
"persistenceId"
)).
build
(),
"myCountry"
);
"myCountry"
,
new
VariableNameResolver
()
);
initializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
null
,
aStringField
(
"persistenceId"
).
build
(),
aContractInput
().
withName
(
"persistenceId"
).
in
(
aContractInput
().
withName
(
"countryInput"
).
withType
(
ContractInputType
.
COMPLEX
)).
build
()));
...
...
@@ -59,6 +60,6 @@ public class BusinessObjectQueryInitializerTest {
aContractInput
()
.
withName
(
"notPersistenceId"
)
.
in
(
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"myData.employees"
);
"myData.employees"
,
new
VariableNameResolver
()
);
}
}
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/CompositionReferencePropertyInitializerTest.java
View file @
6bed7796
...
...
@@ -23,6 +23,7 @@ import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.
import
org.bonitasoft.engine.bdm.model.field.FieldType
;
import
org.bonitasoft.engine.bdm.model.field.SimpleField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.BusinessObjectInstantiationException
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -37,7 +38,7 @@ public class CompositionReferencePropertyInitializerTest {
public
void
should_initialize_object_poperty_in_a_closure
()
throws
Exception
{
final
SimpleField
streetField
=
aSimpleField
().
withName
(
"street"
).
ofType
(
FieldType
.
TEXT
).
notNullable
().
build
();
final
CompositionReferencePropertyInitializer
propertyInitializer
=
new
CompositionReferencePropertyInitializer
(
aCompositionField
(
"address"
,
aBO
(
"org.test.Address"
).
withField
(
streetField
).
build
()),
aContractInput
().
build
(),
"employee.address"
);
aBO
(
"org.test.Address"
).
withField
(
streetField
).
build
()),
aContractInput
().
build
(),
new
VariableNameResolver
(),
"employee.address"
);
propertyInitializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
null
,
streetField
,
aContractInput
().
withName
(
"street"
)
.
in
(
aContractInput
().
withName
(
"address"
).
withType
(
ContractInputType
.
COMPLEX
)
...
...
@@ -58,7 +59,7 @@ public class CompositionReferencePropertyInitializerTest {
final
CompositionReferencePropertyInitializer
propertyInitializer
=
new
CompositionReferencePropertyInitializer
(
aCompositionField
(
"address"
,
aBO
(
"org.test.Address"
).
withField
(
aSimpleField
().
withName
(
"street"
).
notNullable
().
build
()).
build
()),
aContractInput
().
build
(),
"employee.address"
);
new
VariableNameResolver
(),
"employee.address"
);
thrown
.
expect
(
BusinessObjectInstantiationException
.
class
);
propertyInitializer
.
getInitialValue
();
...
...
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/MultipleAggregationReferencePropertyInitializerTest.java
View file @
6bed7796
...
...
@@ -25,6 +25,7 @@ import org.bonitasoft.engine.bdm.model.field.Field;
import
org.bonitasoft.engine.bdm.model.field.FieldType
;
import
org.bonitasoft.engine.bdm.model.field.RelationField
;
import
org.bonitasoft.engine.bdm.model.field.SimpleField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Test
;
...
...
@@ -44,7 +45,8 @@ public class MultipleAggregationReferencePropertyInitializerTest {
final
MultipleAggregationReferencePropertyInitializer
initializer
=
new
MultipleAggregationReferencePropertyInitializer
(
null
,
employeeBo
,
employeesField
,
aContractInput
().
withName
(
"persistenceId"
)
.
in
(
aContractInput
().
withName
(
"employees"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"emp"
,
false
);
.
in
(
aContractInput
().
withName
(
"employees"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"emp"
,
new
VariableNameResolver
(),
false
);
final
String
initialValue
=
initializer
.
getInitialValue
();
...
...
@@ -77,7 +79,8 @@ public class MultipleAggregationReferencePropertyInitializerTest {
final
MultipleAggregationReferencePropertyInitializer
initializer
=
new
MultipleAggregationReferencePropertyInitializer
(
null
,
employeeBo
,
employeesField
,
aContractInput
().
withName
(
"persistenceId"
)
.
in
(
aContractInput
().
withName
(
"employees"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"emp"
,
true
);
.
in
(
aContractInput
().
withName
(
"employees"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"emp"
,
new
VariableNameResolver
(),
true
);
final
String
initialValue
=
initializer
.
getInitialValue
();
...
...
@@ -112,7 +115,8 @@ 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"
,
false
);
.
in
(
aContractInput
().
withName
(
"direcotries"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"emp"
,
new
VariableNameResolver
(),
false
);
final
String
initialValue
=
initializer
.
getInitialValue
();
...
...
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/MultipleBusinessObjectQueryInitializerTest.java
View file @
6bed7796
...
...
@@ -25,6 +25,7 @@ import org.bonitasoft.engine.bdm.model.field.Field;
import
org.bonitasoft.engine.bdm.model.field.FieldType
;
import
org.bonitasoft.engine.bdm.model.field.RelationField
;
import
org.bonitasoft.engine.bdm.model.field.SimpleField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -50,7 +51,7 @@ public class MultipleBusinessObjectQueryInitializerTest {
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()
.
havingInput
(
aContractInput
()
.
withName
(
"persistenceId"
)).
build
(),
"myData.employees"
,
false
);
"myData.employees"
,
new
VariableNameResolver
(),
false
);
initializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
employeeBo
,
nameField
,
aContractInput
().
withName
(
"name"
)
.
in
(
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
()));
...
...
@@ -77,6 +78,6 @@ public class MultipleBusinessObjectQueryInitializerTest {
aContractInput
()
.
withName
(
"notPersistenceId"
)
.
in
(
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()).
build
(),
"myData.employees"
,
false
);
"myData.employees"
,
new
VariableNameResolver
(),
false
);
}
}
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/MultipleCompositionReferencePropertyInitializerTest.java
View file @
6bed7796
...
...
@@ -21,6 +21,7 @@ import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.
import
org.bonitasoft.engine.bdm.model.BusinessObject
;
import
org.bonitasoft.engine.bdm.model.field.RelationField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Test
;
...
...
@@ -34,7 +35,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
aContractInput
().
withName
(
"addresses"
).
multiple
()
.
in
(
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
))
.
build
(),
"employee"
,
false
);
"employee"
,
new
VariableNameResolver
(),
false
);
assertThat
(
initializer
.
getInitialValue
()).
isEqualTo
(
"{"
+
System
.
lineSeparator
()
+
"def addressList = []"
+
System
.
lineSeparator
()
...
...
@@ -59,7 +60,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
aContractInput
().
withName
(
"addresses"
).
multiple
()
.
in
(
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
))
.
build
(),
"employee"
,
true
);
"employee"
,
new
VariableNameResolver
(),
true
);
assertThat
(
initializer
.
getInitialValue
()).
isEqualTo
(
"{"
+
System
.
lineSeparator
()
+
"def addressList = []"
+
System
.
lineSeparator
()
...
...
@@ -83,7 +84,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
aContractInput
().
withName
(
"addresses"
).
multiple
()
.
in
(
aContractInput
().
withName
(
"employeeInput"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
())
.
build
(),
"employee"
,
false
);
"employee"
,
new
VariableNameResolver
(),
false
);
assertThat
(
initializer
.
getInitialValue
()).
isEqualTo
(
"{"
+
System
.
lineSeparator
()
+
"def addressList = []"
+
System
.
lineSeparator
()
...
...
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/NewBusinessObjectInitializerTest.java
View file @
6bed7796
...
...
@@ -23,6 +23,7 @@ import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.
import
org.bonitasoft.engine.bdm.model.field.FieldType
;
import
org.bonitasoft.engine.bdm.model.field.SimpleField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.BusinessObjectInstantiationException
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -36,7 +37,7 @@ public class NewBusinessObjectInitializerTest {
@Test
public
void
should_create_groovy_script_as_initial_value
()
throws
Exception
{
final
NewBusinessObjectInitializer
propertyInitializer
=
new
NewBusinessObjectInitializer
(
aCompositionField
(
"address"
,
aBO
(
"org.test.Address"
).
build
()),
"myAddress"
,
true
);
"address"
,
aBO
(
"org.test.Address"
).
build
()),
"myAddress"
,
new
VariableNameResolver
(),
true
);
assertThat
(
propertyInitializer
.
getInitialValue
()).
isEqualTo
(
"def addressVar = myAddress == null ? new org.test.Address() : myAddress"
+
System
.
lineSeparator
()
+
"return addressVar"
);
...
...
@@ -46,7 +47,7 @@ public class NewBusinessObjectInitializerTest {
public
void
should_initialize_new_object_property_for_simple_composed_reference
()
throws
Exception
{
final
SimpleField
streetField
=
aSimpleField
().
withName
(
"street"
).
ofType
(
FieldType
.
STRING
).
notNullable
().
build
();
final
NewBusinessObjectInitializer
propertyInitializer
=
new
NewBusinessObjectInitializer
(
aCompositionField
(
"address"
,
aBO
(
"org.test.Address"
).
withField
(
streetField
).
build
()),
"myAddress"
,
true
);
aBO
(
"org.test.Address"
).
withField
(
streetField
).
build
()),
"myAddress"
,
new
VariableNameResolver
(),
true
);
propertyInitializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
null
,
streetField
,
aContractInput
().
withName
(
"street"
)
.
in
(
aContractInput
().
withName
(
"address"
).
withType
(
ContractInputType
.
COMPLEX
)
...
...
@@ -61,7 +62,8 @@ public class NewBusinessObjectInitializerTest {
@Test
public
void
should_throw_an_BusinessObjectInstantiationException_when_creating_an_inconsistent_business_object
()
throws
Exception
{
final
NewBusinessObjectInitializer
propertyInitializer
=
new
NewBusinessObjectInitializer
(
aCompositionField
(
"address"
,
aBO
(
"org.test.Address"
).
withField
(
aSimpleField
().
withName
(
"street"
).
notNullable
().
build
()).
build
()),
"myAddress"
,
true
);
aCompositionField
(
"address"
,
aBO
(
"org.test.Address"
).
withField
(
aSimpleField
().
withName
(
"street"
).
notNullable
().
build
()).
build
()),
"myAddress"
,
new
VariableNameResolver
(),
true
);
thrown
.
expect
(
BusinessObjectInstantiationException
.
class
);
propertyInitializer
.
getInitialValue
();
...
...
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/NewBusinessObjectListInitializerTest.java
View file @
6bed7796
...
...
@@ -24,6 +24,7 @@ import org.bonitasoft.engine.bdm.model.BusinessObject;
import
org.bonitasoft.engine.bdm.model.field.FieldType
;
import
org.bonitasoft.engine.bdm.model.field.RelationField
;
import
org.bonitasoft.engine.bdm.model.field.SimpleField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.model.process.ContractInputType
;
import
org.junit.Test
;
...
...
@@ -37,7 +38,8 @@ 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"
,
false
);
.
multiple
().
in
(
aContractInput
().
withName
(
"employee"
).
withType
(
ContractInputType
.
COMPLEX
)).
build
(),
"myAddresses"
,
new
VariableNameResolver
(),
false
);
propertyInitializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
businessObject
,
streetField
,
aContractInput
().
withName
(
"street"
)
.
in
(
aContractInput
().
withName
(
"address"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()
...
...
@@ -65,7 +67,8 @@ 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"
,
true
);
.
multiple
().
in
(
aContractInput
().
withName
(
"employee"
).
withType
(
ContractInputType
.
COMPLEX
)).
build
(),
"myAddresses"
,
new
VariableNameResolver
(),
true
);
propertyInitializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
businessObject
,
streetField
,
aContractInput
().
withName
(
"street"
)
.
in
(
aContractInput
().
withName
(
"address"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()
...
...
@@ -91,7 +94,7 @@ public class NewBusinessObjectListInitializerTest {
businessObject
);
addressField
.
setCollection
(
true
);
final
AbstractBusinessObjectInitializer
propertyInitializer
=
new
NewBusinessObjectListInitializer
(
addressField
,
aContractInput
().
withName
(
"addresses"
)
.
multiple
().
build
(),
"myAddress"
,
false
);
.
multiple
().
build
(),
"myAddress"
,
new
VariableNameResolver
(),
false
);
propertyInitializer
.
addPropertyInitializer
(
new
SimpleFieldPropertyInitializer
(
businessObject
,
streetField
,
aContractInput
().
withName
(
"street"
)
.
in
(
aContractInput
().
withName
(
"address"
).
withType
(
ContractInputType
.
COMPLEX
).
multiple
()
...
...
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/factory/BusinessObjectInitializerFactoryTest.java
View file @
6bed7796
...
...
@@ -30,6 +30,7 @@ import org.bonitasoft.engine.bdm.model.field.RelationField;
import
org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping
;
import
org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMappingFactory
;
import
org.bonitasoft.studio.contract.core.mapping.operation.FieldToContractInputMappingBuilder
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.contract.core.mapping.operation.initializer.BusinessObjectQueryInitializer
;
import
org.bonitasoft.studio.contract.core.mapping.operation.initializer.IPropertyInitializer
;
import
org.bonitasoft.studio.contract.core.mapping.operation.initializer.MultipleBusinessObjectQueryInitializer
;
...
...
@@ -90,7 +91,7 @@ public class BusinessObjectInitializerFactoryTest {
}
private
BusinessObjectInitializerFactory
newFactory
()
{
return
new
BusinessObjectInitializerFactory
();
return
new
BusinessObjectInitializerFactory
(
new
VariableNameResolver
()
);
}
}
bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/core/mapping/operation/initializer/factory/RelationPropertyInitializerFactoryTest.java
View file @
6bed7796
...
...
@@ -29,6 +29,7 @@ import org.bonitasoft.engine.bdm.model.BusinessObject;
import
org.bonitasoft.engine.bdm.model.field.RelationField
;
import
org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping
;
import
org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMappingFactory
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
org.bonitasoft.studio.contract.core.mapping.operation.initializer.AggregationReferencePropertyInitializer
;
import
org.bonitasoft.studio.contract.core.mapping.operation.initializer.CompositionReferencePropertyInitializer
;
import
org.bonitasoft.studio.contract.core.mapping.operation.initializer.IPropertyInitializer
;
...
...
@@ -98,7 +99,7 @@ public class RelationPropertyInitializerFactoryTest {
}
private
RelationPropertyInitializerFactory
newFactory
()
{
return
new
RelationPropertyInitializerFactory
();
return
new
RelationPropertyInitializerFactory
(
new
VariableNameResolver
()
);
}
}
bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/core/mapping/operation/MappingOperationScriptBuilder.java
View file @
6bed7796
...
...
@@ -38,13 +38,13 @@ import org.eclipse.text.edits.MalformedTreeException;
public
class
MappingOperationScriptBuilder
{
private
static
final
IFormatterPreferences
DEFAULT_FORMATTER_PREFS
=
new
DefaultFormatterPreferences
();
private
final
BusinessObjectInitializerFactory
businessObjectInitializerFactory
=
new
BusinessObjectInitializerFactory
();
private
final
PropertyInitializerFactory
propertyInitializerFactory
=
new
PropertyInitializerFactory
(
new
RelationPropertyInitializerFactory
());
private
final
BusinessObjectInitializerFactory
businessObjectInitializerFactory
;
private
static
final
int
FORMAT_LEVEL
=
0
;
private
boolean
needsDataDependency
=
false
;
private
final
BusinessObjectData
data
;
private
final
FieldToContractInputMapping
mapping
;
private
final
Field
field
;
private
final
PropertyInitializerFactory
propertyInitializerFactory
;
public
MappingOperationScriptBuilder
(
final
BusinessObjectData
data
,
final
FieldToContractInputMapping
mapping
,
...
...
@@ -52,6 +52,9 @@ public class MappingOperationScriptBuilder {
this
.
data
=
data
;
this
.
mapping
=
mapping
;
this
.
field
=
field
;
final
VariableNameResolver
variableNameResolver
=
new
VariableNameResolver
();
businessObjectInitializerFactory
=
new
BusinessObjectInitializerFactory
(
variableNameResolver
);
propertyInitializerFactory
=
new
PropertyInitializerFactory
(
new
RelationPropertyInitializerFactory
(
variableNameResolver
));
}
public
String
toInstanciationScript
()
throws
BusinessObjectInstantiationException
{
...
...
bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/core/mapping/operation/VariableNameResolver.java
0 → 100644
View file @
6bed7796
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
org.bonitasoft.studio.contract.core.mapping.operation
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkArgument
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.bonitasoft.engine.bdm.BDMQueryUtil
;
import
org.bonitasoft.engine.bdm.model.BusinessObject
;
public
class
VariableNameResolver
{
private
static
final
String
VAR_SUFFIX
=
"Var"
;
private
static
final
String
LIST_VAR_SUFFIX
=
"List"
;
private
final
Map
<
String
,
Integer
>
context
=
new
HashMap
<>();
public
String
newVarName
(
BusinessObject
businessObject
)
{
checkArgument
(
businessObject
!=
null
);
return
varName
(
businessObject
,
VAR_SUFFIX
);
}
public
String
newListVarName
(
BusinessObject
businessObject
)
{
checkArgument
(
businessObject
!=
null
);
return
varName
(
businessObject
,
LIST_VAR_SUFFIX
);
}
private
String
varName
(
final
BusinessObject
businessObject
,
String
varSuffix
)
{
final
String
simpleBusinessObjectName
=
BDMQueryUtil
.
getSimpleBusinessObjectName
(
businessObject
.
getQualifiedName
());
String
result
=
uncapitalizeFirst
(
simpleBusinessObjectName
)
+
varSuffix
;
if
(
context
.
containsKey
(
varKey
(
varSuffix
,
simpleBusinessObjectName
)))
{
result
=
result
+
String
.
valueOf
(
context
.
get
(
varKey
(
varSuffix
,
simpleBusinessObjectName
)));
}
Integer
counter
=
context
.
get
(
varKey
(
varSuffix
,
simpleBusinessObjectName
));
counter
=
counter
==
null
?
1
:
counter
;
counter
++;
context
.
put
(
varKey
(
varSuffix
,
simpleBusinessObjectName
),
counter
);
return
result
;
}
private
String
varKey
(
String
varSuffix
,
final
String
simpleBusinessObjectName
)
{
return
simpleBusinessObjectName
+
varSuffix
;
}
private
String
uncapitalizeFirst
(
final
String
value
)
{
return
Character
.
toLowerCase
(
value
.
charAt
(
0
))
+
value
.
substring
(
1
,
value
.
length
());
}
}
bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/core/mapping/operation/initializer/AbstractBusinessObjectInitializer.java
View file @
6bed7796
...
...
@@ -23,11 +23,11 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.Set
;
import
org.bonitasoft.engine.bdm.BDMQueryUtil
;
import
org.bonitasoft.engine.bdm.model.BusinessObject
;
import
org.bonitasoft.engine.bdm.model.field.Field
;
import
org.bonitasoft.engine.bdm.model.field.RelationField
;
import
org.bonitasoft.studio.contract.core.mapping.operation.BusinessObjectInstantiationException
;
import
org.bonitasoft.studio.contract.core.mapping.operation.VariableNameResolver
;
import
com.google.common.base.Function
;
import
com.google.common.base.Predicate
;
...
...
@@ -37,10 +37,12 @@ public abstract class AbstractBusinessObjectInitializer implements IPropertyInit
protected
final
RelationField
field
;
protected
final
List
<
IPropertyInitializer
>
propertyInitializers
=
new
ArrayList
<
IPropertyInitializer
>();
protected
final
String
refName
;
protected
final
VariableNameResolver
variableNameResolver
;
public
AbstractBusinessObjectInitializer
(
final
RelationField
field
,
final
String
refName
)
{
public
AbstractBusinessObjectInitializer
(
final
RelationField
field
,
final
String
refName
,
VariableNameResolver
variableNameResolver
)
{
this
.
field
=
field
;
this
.
refName
=
refName
;
this
.
variableNameResolver
=
variableNameResolver
;
}
public
void
addPropertyInitializer
(
final
IPropertyInitializer
propertyInitializer
)
{
...
...
@@ -59,17 +61,18 @@ public abstract class AbstractBusinessObjectInitializer implements IPropertyInit
final
StringBuilder
scriptBuilder
=
new
StringBuilder
();
addCommentBeforeConstructor
(
scriptBuilder
,
businessObject
);
delcareVariable
(
scriptBuilder
,
varName
(
businessObject
));
final
String
varName
=
variableNameResolver
.
newVarName
(
businessObject
);
delcareVariable
(
scriptBuilder
,
varName
);
scriptBuilder
.
append
(
" = "
);
constructor
(
scriptBuilder
,
businessObject
,
checkExistence
());
scriptBuilder
.
append
(
System
.
lineSeparator
());
for
(
final
IPropertyInitializer
propertyInitializer
:
propertyInitializers
)
{
initializeProperty
(
scriptBuilder
,
propertyInitializer
,
businessObject
);
initializeProperty
(
scriptBuilder
,
propertyInitializer
,
varName
);
}
returnVar
(
scriptBuilder
,
businessObject
);
returnVar
(
scriptBuilder
,
varName
);
return
scriptBuilder
.
toString
();
}
...
...
@@ -86,9 +89,10 @@ public abstract class AbstractBusinessObjectInitializer implements IPropertyInit
}
}
protected
void
initializeProperty
(
final
StringBuilder
scriptBuilder
,
final
IPropertyInitializer
propertyInitializer
,
final
BusinessObject
businessObject
)
protected
void
initializeProperty
(
final
StringBuilder
scriptBuilder
,
final
IPropertyInitializer
propertyInitializer
,
final
String
varName
)
throws
BusinessObjectInstantiationException
{
scriptBuilder
.
append
(
varName
(
businessObject
)
);
scriptBuilder
.
append
(
varName
);
scriptBuilder
.
append
(
"."
);
scriptBuilder
.
append
(
propertyInitializer
.
getPropertyName
());
scriptBuilder
.
append
(
" = "
);
...
...
@@ -133,10 +137,10 @@ public abstract class AbstractBusinessObjectInitializer implements IPropertyInit
};
}
protected
void
returnVar
(
final
StringBuilder
scriptBuilder
,
final
BusinessObject
bo
)
{
protected
void
returnVar
(
final
StringBuilder
scriptBuilder
,
final
String
varName
)
{
scriptBuilder
.
append
(
"return"
);
scriptBuilder
.
append
(
" "
);
scriptBuilder
.
append
(
varName
(
bo
)
);
scriptBuilder
.
append
(
varName
);
}
protected
void
delcareVariable
(
final
StringBuilder
scriptBuilder
,
final
String
varName
)
{
...
...
@@ -145,9 +149,6 @@ public abstract class AbstractBusinessObjectInitializer implements IPropertyInit
scriptBuilder
.
append
(
varName
);
}
protected
String
varName
(
final
BusinessObject
bo
)
{