...
 
Commits (4)
......@@ -161,6 +161,8 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="inputs" upperBound="-1"
eType="#//ContractInput" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="dataReference" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="createMode" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
defaultValueLiteral="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ContractConstraint">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="expression" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
......
......@@ -349,6 +349,7 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference process.ecore#//ContractInput/mapping"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference process.ecore#//ContractInput/inputs"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute process.ecore#//ContractInput/dataReference"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute process.ecore#//ContractInput/createMode"/>
<genOperations ecoreOperation="process.ecore#//ContractInput/getJavaType" body="switch(getType()){&#xD;&#xA;case BOOLEAN:return java.lang.Boolean.class.getName();&#xD;&#xA;case DATE: return java.util.Date.class.getName();&#xD;&#xA;case LOCALDATE: return java.time.LocalDate.class.getName();&#xD;&#xA;case LOCALDATETIME: return java.time.LocalDateTime.class.getName();&#xD;&#xA;case OFFSETDATETIME: return java.time.OffsetDateTime.class.getName();&#xD;&#xA;case INTEGER: return java.lang.Integer.class.getName();&#xA;case LONG: return java.lang.Long.class.getName();&#xD;&#xA;case DECIMAL: return java.lang.Double.class.getName();&#xD;&#xA;case FILE:return &quot;org.bonitasoft.engine.bpm.contract.FileInputValue&quot;;&#xD;&#xA;case COMPLEX:return java.util.Map.class.getName();&#xD;&#xA;case TEXT:&#xD;&#xA;default: return java.lang.String.class.getName();&#xD;&#xA;}"/>
</genClasses>
<genClasses ecoreClass="process.ecore#//ContractConstraint">
......
......@@ -14737,5 +14737,53 @@
</operation>
</changes>
</releases>
<releases xmi:id="_lzQvMESbEemR1awCVq5q5Q" date="2019-03-12T10:43:27.494+0100" label="7.9.0-002">
<changes xsi:type="history:OperationChange" xmi:id="_oXg0oESbEemR1awCVq5q5Q">
<changes xsi:type="history:Create" xmi:id="_oXg0oUSbEemR1awCVq5q5Q" referenceName="eStructuralFeatures">
<target href="process.ecore#//ContractInput"/>
<element href="process.ecore#//ContractInput/createMode"/>
<changes xsi:type="history:Set" xmi:id="_oXg0okSbEemR1awCVq5q5Q" featureName="name" dataValue="createMode">
<element href="process.ecore#//ContractInput/createMode"/>
</changes>
<changes xsi:type="history:Set" xmi:id="_oXg0o0SbEemR1awCVq5q5Q" featureName="defaultValueLiteral" dataValue="true">
<element href="process.ecore#//ContractInput/createMode"/>
</changes>
<changes xsi:type="history:Set" xmi:id="_oXg0pESbEemR1awCVq5q5Q" featureName="eType">
<element href="process.ecore#//ContractInput/createMode"/>
<referenceValue href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</changes>
</changes>
<operation xmi:id="_oXg0pUSbEemR1awCVq5q5Q" name="newAttribute">
<parameters xmi:id="_oXg0pkSbEemR1awCVq5q5Q" name="eClass">
<referenceValue xmi:id="_oXg0p0SbEemR1awCVq5q5Q">
<element href="process.ecore#//ContractInput"/>
</referenceValue>
<referenceValue xmi:id="_oXg0qESbEemR1awCVq5q5Q">
<element href="process.ecore#//ContractInput"/>
</referenceValue>
</parameters>
<parameters xmi:id="_oXg0qUSbEemR1awCVq5q5Q" name="name">
<dataValue>createMode</dataValue>
</parameters>
<parameters xmi:id="_oXg0qkSbEemR1awCVq5q5Q" name="type">
<referenceValue xmi:id="_oXg0q0SbEemR1awCVq5q5Q">
<element href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</referenceValue>
<referenceValue xmi:id="_oXg0rESbEemR1awCVq5q5Q">
<element href="http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</referenceValue>
</parameters>
<parameters xmi:id="_oXg0rUSbEemR1awCVq5q5Q" name="lowerBound">
<dataValue>0</dataValue>
</parameters>
<parameters xmi:id="_oXg0rkSbEemR1awCVq5q5Q" name="upperBound">
<dataValue>1</dataValue>
</parameters>
<parameters xmi:id="_oXg0r0SbEemR1awCVq5q5Q" name="defaultValue">
<dataValue>true</dataValue>
</parameters>
</operation>
</changes>
</releases>
<releases xmi:id="_15TmyGnREeaTLbmqFFisdA"/>
</history:History>
......@@ -29,6 +29,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.assertj.core.api.Condition;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.field.Field;
import org.bonitasoft.engine.bdm.model.field.RelationField;
......@@ -39,8 +40,10 @@ import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInputMappingExpressionBuilder;
import org.bonitasoft.studio.contract.core.mapping.operation.FieldToContractInputMappingOperationBuilder;
import org.bonitasoft.studio.contract.core.mapping.operation.OperationCreationException;
import org.bonitasoft.studio.contract.ui.wizard.GenerationOptions.EditMode;
import org.bonitasoft.studio.model.businessObject.FieldBuilder.SimpleFieldBuilder;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.ContractInputType;
import org.bonitasoft.studio.model.process.assertions.ContractInputAssert;
import org.eclipse.core.runtime.IProgressMonitor;
......@@ -60,7 +63,7 @@ public class RootContractInputGeneratorTest {
mock(FieldToContractInputMappingOperationBuilder.class),
mock(FieldToContractInputMappingExpressionBuilder.class));
rootContractInputGenerator.build(aBusinessData().build(), new NullProgressMonitor());
rootContractInputGenerator.build(aBusinessData().build(), EditMode.EDIT, new NullProgressMonitor());
ContractInputAssert.assertThat(rootContractInputGenerator.getRootContractInput()).hasName("rootInputName")
.hasType(ContractInputType.COMPLEX);
......@@ -82,7 +85,7 @@ public class RootContractInputGeneratorTest {
repositoryAccessor, mock(FieldToContractInputMappingOperationBuilder.class),
mock(FieldToContractInputMappingExpressionBuilder.class));
rootContractInputGenerator.build(aBusinessData().build(), new NullProgressMonitor());
rootContractInputGenerator.build(aBusinessData().build(), EditMode.EDIT, new NullProgressMonitor());
assertThat(rootContractInputGenerator.getRootContractInput().getInputs()).hasSize(1);
}
......@@ -103,9 +106,9 @@ public class RootContractInputGeneratorTest {
repositoryAccessor, operationBuilder, mock(FieldToContractInputMappingExpressionBuilder.class));
BusinessObjectData businessObjectData = aBusinessData().withName("employee").build();
IProgressMonitor monitor = new NullProgressMonitor();
rootContractInputGenerator.build(businessObjectData, monitor);
rootContractInputGenerator.build(businessObjectData, EditMode.EDIT, monitor);
verify(operationBuilder).toOperation(businessObjectData, mapping, monitor);
verify(operationBuilder).toOperation(businessObjectData, mapping, EditMode.EDIT, monitor);
}
@Test
......@@ -123,7 +126,7 @@ public class RootContractInputGeneratorTest {
newArrayList(notGeneratedMapping),
repositoryAccessor, operationBuilder, mock(FieldToContractInputMappingExpressionBuilder.class));
BusinessObjectData businessObjectData = aBusinessData().withName("employee").build();
rootContractInputGenerator.build(businessObjectData, new NullProgressMonitor());
rootContractInputGenerator.build(businessObjectData, EditMode.EDIT, new NullProgressMonitor());
assertThat(rootContractInputGenerator.isAllAttributesGenerated()).isFalse();
}
......@@ -144,7 +147,7 @@ public class RootContractInputGeneratorTest {
.aStringField("input1").build())),
repositoryAccessor, operationBuilder, mock(FieldToContractInputMappingExpressionBuilder.class));
BusinessObjectData businessObjectData = aBusinessData().withName("employee").build();
rootContractInputGenerator.build(businessObjectData, new NullProgressMonitor());
rootContractInputGenerator.build(businessObjectData, EditMode.EDIT, new NullProgressMonitor());
assertThat(rootContractInputGenerator.isAllAttributesGenerated()).isTrue();
}
......@@ -167,11 +170,12 @@ public class RootContractInputGeneratorTest {
BusinessObjectData businessObjectData = aBusinessData().withName("employees")
.withClassname("org.test.Employee").multiple().build();
NullProgressMonitor monitor = new NullProgressMonitor();
rootContractInputGenerator.build(businessObjectData, monitor);
rootContractInputGenerator.build(businessObjectData, EditMode.EDIT, monitor);
ArgumentCaptor<FieldToContractInputMapping> argumentCaptor = ArgumentCaptor
.forClass(FieldToContractInputMapping.class);
verify(operationBuilder).toOperation(eq(businessObjectData), argumentCaptor.capture(), eq(monitor));
verify(operationBuilder).toOperation(eq(businessObjectData), argumentCaptor.capture(), eq(EditMode.EDIT),
eq(monitor));
Field field = argumentCaptor.getValue().getField();
assertThat(field).isInstanceOf(RelationField.class);
assertThat(field.getName()).isEqualTo("employeesInput");
......@@ -235,7 +239,63 @@ public class RootContractInputGeneratorTest {
assertThat(fieldToContractInputMapping.getField().isCollection()).isTrue();
assertThat(fieldToContractInputMapping.getChildren()).hasSize(1);
}
@Test
public void should_set_edit_mode_on_contract_input()
throws Exception {
SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping(
SimpleFieldBuilder.aStringField("firstName").build());
FieldToContractInputMappingOperationBuilder operationBuilder = mock(
FieldToContractInputMappingOperationBuilder.class);
RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> businessStore = getBusinessObjectModelRepositoryStore();
when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(businessStore);
FieldToContractInputMappingExpressionBuilder expressionBuilder = mock(
FieldToContractInputMappingExpressionBuilder.class);
RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator("rootInputName",
newArrayList(mapping),
repositoryAccessor, operationBuilder, expressionBuilder);
BusinessObjectData businessObjectData = aBusinessData().withName("employee").multiple().build();
rootContractInputGenerator.build(businessObjectData, EditMode.EDIT,new NullProgressMonitor());
ContractInput rootContractInput = rootContractInputGenerator.getRootContractInput();
assertThat(rootContractInput.isCreateMode()).isFalse();
assertEditMode(rootContractInput.getInputs(), EditMode.EDIT);
}
@Test
public void should_set_create_mode_on_contract_input()
throws Exception {
SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping(
SimpleFieldBuilder.aStringField("firstName").build());
FieldToContractInputMappingOperationBuilder operationBuilder = mock(
FieldToContractInputMappingOperationBuilder.class);
RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> businessStore = getBusinessObjectModelRepositoryStore();
when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)).thenReturn(businessStore);
FieldToContractInputMappingExpressionBuilder expressionBuilder = mock(
FieldToContractInputMappingExpressionBuilder.class);
RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator("rootInputName",
newArrayList(mapping),
repositoryAccessor, operationBuilder, expressionBuilder);
BusinessObjectData businessObjectData = aBusinessData().withName("employee").multiple().build();
rootContractInputGenerator.buildForInstanciation(businessObjectData, new NullProgressMonitor());
ContractInput rootContractInput = rootContractInputGenerator.getRootContractInput();
assertThat(rootContractInput.isCreateMode()).isTrue();
assertEditMode(rootContractInput.getInputs(), EditMode.CREATE);
}
private void assertEditMode(List<ContractInput> inputs,EditMode mode) {
for(ContractInput child : inputs) {
assertThat(child.isCreateMode()).is(new Condition<Boolean>(value -> mode == EditMode.CREATE ? value : !value,
"Invalid create mode"));
assertEditMode(child.getInputs(), mode);
}
}
private BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> getBusinessObjectModelRepositoryStore() {
BusinessObjectModelRepositoryStore<BusinessObjectModelFileStore> businessStore = mock(
BusinessObjectModelRepositoryStore.class);
......
......@@ -148,7 +148,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
ExpressionAssert.assertThat(expression)
.hasName("initMyEmployee()")
.hasContent("def addressVar = myEmployee.address ?: new Address()" + System.lineSeparator()
.hasContent("def addressVar = new Address()" + System.lineSeparator()
+ "return addressVar")
.hasReturnType("Address")
.hasType(ExpressionConstants.SCRIPT_TYPE);
......@@ -174,7 +174,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myBooks").multiple().build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a task
// Edit mode
Expression expression = expressionBuilder.toExpression(businessData, bookMapping, false);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -202,7 +202,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
+ "}\n"
+ "return bookList");
//On a pool
// Create mode
expression = expressionBuilder.toExpression(businessData, bookMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -238,7 +238,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myBooks").multiple().build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a task
// Edit mode
Expression expression = expressionBuilder.toExpression(businessData, bookMapping, false);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -259,7 +259,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
+ "}\n"
+ "return bookList");
//On a pool
// Create mode
expression = expressionBuilder.toExpression(businessData, bookMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -288,7 +288,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myBooks").multiple().build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a task
// Edit mode
Expression expression = expressionBuilder.toExpression(businessData, bookMapping, false);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -305,7 +305,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
+ "}\n"
+ "return bookList");
//On a pool
// Create mode
expression = expressionBuilder.toExpression(businessData, bookMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -330,7 +330,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myBooks").multiple().build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a task
// Edit mode
Expression expression = expressionBuilder.toExpression(businessData, bookMapping, false);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -355,7 +355,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
+ "}\n"
+ "return bookList");
//On a pool
// Create mode
expression = expressionBuilder.toExpression(businessData, bookMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def bookList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -454,7 +454,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myRoot").build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a pool
// Create mode
Expression expression = expressionBuilder.toExpression(businessData, rootMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def rootVar = new com.company.Root()\n"
+ "rootVar.rootName = rootInput.rootName\n"
......@@ -468,7 +468,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
+ " return nodeVar}()\n"
+ "return rootVar");
// On a task -> on the node mapping (operation setNode)
// Edite mode -> on the node mapping (operation setNode)
expression = expressionBuilder.toExpression(businessData, nodeMapping, false);
assertThat(expression.getContent())
.isEqualToIgnoringWhitespace("def nodeVar = myRoot.node ?: new com.company.Node()\n"
......@@ -527,7 +527,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myRoot").build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a pool
// Create mode
Expression expression = expressionBuilder.toExpression(businessData, rootMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def rootVar = new com.company.Root()\n"
+ "rootVar.rootName = rootInput.rootName\n"
......@@ -557,7 +557,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
+ " return nodeList}()\n"
+ "return rootVar");
// On a task -> on the node mapping (operation setNode)
// Edit mode -> on the node mapping (operation setNode)
expression = expressionBuilder.toExpression(businessData, nodeMapping, false);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def nodeList = []\n"
+ "//For each item collected in multiple input\n"
......@@ -631,7 +631,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
BusinessObjectData businessData = aBusinessData().withName("myRoot").build();
FieldToContractInputMappingExpressionBuilder expressionBuilder = newExpressionBuilder();
// On a pool
// Create mode
Expression expression = expressionBuilder.toExpression(businessData, rootMapping, true);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def rootList = []\n" +
"//For each item collected in multiple input\n" +
......@@ -661,7 +661,7 @@ public class FieldToContractInputMappingExpressionBuilderTest {
"}\n" +
"return rootList");
// On a task
// Edit mode
expression = expressionBuilder.toExpression(businessData, rootMapping, false);
assertThat(expression.getContent()).isEqualToIgnoringWhitespace("def rootList = []\n" +
"//For each item collected in multiple input\n" +
......
......@@ -41,6 +41,7 @@ import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInputMappingExpressionBuilder;
import org.bonitasoft.studio.contract.ui.wizard.GenerationOptions.EditMode;
import org.bonitasoft.studio.expression.editor.ExpressionProviderService;
import org.bonitasoft.studio.expression.editor.filter.ExpressionReturnTypeFilter;
import org.bonitasoft.studio.model.expression.Operation;
......@@ -86,7 +87,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final BusinessObjectData data = aBusinessData().withName("myEmployee").build();
when(expressionBuilder.toExpression(data, mapping, false)).thenReturn(anExpression().build());
final Operation operation = inputToOperation.toOperation(data,
mapping, new NullProgressMonitor());
mapping, EditMode.EDIT, new NullProgressMonitor());
OperatorAssert.assertThat(operation.getOperator())
.hasType(ExpressionConstants.JAVA_METHOD_OPERATOR)
......@@ -114,7 +115,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final BusinessObjectData data = aBusinessData().withName("myEmployee").build();
when(expressionBuilder.toExpression(data, mapping, false)).thenReturn(anExpression().build());
final Operation operation = inputToOperation.toOperation(data,
mapping, new NullProgressMonitor());
mapping, EditMode.EDIT, new NullProgressMonitor());
OperatorAssert.assertThat(operation.getOperator())
.hasType(ExpressionConstants.JAVA_METHOD_OPERATOR)
......@@ -139,7 +140,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
final BusinessObjectData businessObjectData = aBusinessData().withName("myEmployee").build();
when(expressionBuilder.toExpression(businessObjectData, mapping, false)).thenReturn(anExpression().build());
final Operation operation = inputToOperation.toOperation(businessObjectData,
mapping, new NullProgressMonitor());
mapping, EditMode.EDIT, new NullProgressMonitor());
OperatorAssert.assertThat(operation.getOperator())
.hasType(ExpressionConstants.JAVA_METHOD_OPERATOR)
......@@ -163,7 +164,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
anExpression().build());
thrown.expect(OperationCreationException.class);
inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(),
aSimpleMapping(lastNameField).build(), new NullProgressMonitor());
aSimpleMapping(lastNameField).build(), EditMode.EDIT, new NullProgressMonitor());
}
@Test
......@@ -182,7 +183,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
anExpression().build());
thrown.expect(OperationCreationException.class);
inputToOperation.toOperation(aBusinessData().withName("myEmployee").build(),
mapping, new NullProgressMonitor());
mapping, EditMode.EDIT, new NullProgressMonitor());
}
@Test
......@@ -195,7 +196,7 @@ public class FieldToContractInputMappingOperationBuilderTest {
anyBoolean())).thenReturn(
anExpression().build());
final Operation operation = inputToOperation.toOperation(aBusinessData().multiple().withName("employees").build(),
mapping, new NullProgressMonitor());
mapping, EditMode.EDIT, new NullProgressMonitor());
OperatorAssert.assertThat(operation.getOperator())
.hasType(ExpressionConstants.ASSIGNMENT_OPERATOR)
......
......@@ -65,7 +65,7 @@ public class MappingOperationScriptBuilderTest {
final String script = scriptBuilder.toScript();
assertThat(scriptBuilder.needsDataDependency()).isTrue();
assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator()
assertThat(script).isEqualTo("def addressVar = employee.address ?: new Address()" + System.lineSeparator()
+ "addressVar.street = address.street" + System.lineSeparator()
+ "return addressVar");
}
......@@ -85,7 +85,7 @@ public class MappingOperationScriptBuilderTest {
final String script = scriptBuilder.toScript();
assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator()
assertThat(script).isEqualTo("def addressVar = employee.address ?: new Address()" + System.lineSeparator()
+ "return addressVar");
}
......@@ -105,7 +105,7 @@ public class MappingOperationScriptBuilderTest {
final String script = scriptBuilder.toScript();
assertThat(script).isEqualTo("def addressVar = new Address()" + System.lineSeparator()
assertThat(script).isEqualTo("def addressVar = employee.address ?: new Address()" + System.lineSeparator()
+ "addressVar.street = address.street" + System.lineSeparator()
+ "addressVar.country = {" + System.lineSeparator()
+ SWT.TAB + "def countryVar = addressVar.country ?: new Country()" + System.lineSeparator()
......
......@@ -98,7 +98,7 @@ public class MultipleAggregationReferencePropertyInitializerTest {
.in(aContractInput().withName("employees").withType(ContractInputType.COMPLEX).multiple()).build());
context.setLocalVariableName("employeeVar");
context.setLocalListVariableName("employeeList");
context.setOnPool(true);
context.setCreateMode(true);
final MultipleAggregationReferencePropertyInitializer initializer = new MultipleAggregationReferencePropertyInitializer(
null, employeeBo, context);
......
......@@ -74,7 +74,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
.build());
context.setLocalVariableName("addressVar");
context.setLocalListVariableName("addressList");
context.setOnPool(true);
context.setCreateMode(true);
final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(
null, context);
......@@ -107,7 +107,7 @@ public class MultipleCompositionReferencePropertyInitializerTest {
.build());
context.setLocalVariableName("addressVar");
context.setLocalListVariableName("addressList");
context.setOnPool(true);
context.setCreateMode(true);
final BusinessObject employee = aBO("Employee").withField(field).build();
final MultipleCompositionReferencePropertyInitializer initializer = new MultipleCompositionReferencePropertyInitializer(
......
......@@ -45,7 +45,7 @@ public class NewBusinessObjectInitializerTest {
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple())
.build());
context.setLocalVariableName("addressVar");
context.setOnPool(true);
context.setCreateMode(true);
context.setCheckExistence(true);
final NewBusinessObjectInitializer propertyInitializer = new NewBusinessObjectInitializer(context);
......@@ -69,7 +69,7 @@ public class NewBusinessObjectInitializerTest {
.in(aContractInput().withName("employeeInput").withType(ContractInputType.COMPLEX).multiple())
.build());
context.setLocalVariableName("addressVar");
context.setOnPool(true);
context.setCreateMode(true);
context.setCheckExistence(true);
final NewBusinessObjectInitializer propertyInitializer = new NewBusinessObjectInitializer(context);
......
......@@ -93,7 +93,7 @@ public class NewBusinessObjectListInitializerTest {
.multiple().in(aContractInput().withName("employee").withType(ContractInputType.COMPLEX)).build());
context.setLocalVariableName("addressVar");
context.setLocalListVariableName("addressList");
context.setOnPool(true);
context.setCreateMode(true);
final AbstractBusinessObjectInitializer propertyInitializer = new NewBusinessObjectListInitializer(context);
propertyInitializer.addPropertyInitializer(new SimpleFieldPropertyInitializer(businessObject,
......
......@@ -24,7 +24,10 @@ 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.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Optional;
......@@ -34,8 +37,10 @@ import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelR
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.RootContractInputGenerator;
import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInputMappingExpressionBuilder;
import org.bonitasoft.studio.contract.core.mapping.operation.FieldToContractInputMappingOperationBuilder;
import org.bonitasoft.studio.contract.ui.wizard.GenerationOptions.EditMode;
import org.bonitasoft.studio.groovy.ui.viewer.GroovySourceViewerFactory;
import org.bonitasoft.studio.groovy.ui.viewer.GroovyViewer;
import org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder;
......@@ -50,6 +55,7 @@ import org.bonitasoft.studio.model.process.Task;
import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory;
import org.bonitasoft.studio.swt.rules.RealmWithDisplay;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
import org.eclipse.jface.preference.IPreferenceStore;
......@@ -259,7 +265,7 @@ public class ContractInputGenerationWizardTest {
when(preferenceStore.getString(ContractInputGenerationInfoDialogFactory.SHOW_GENERATION_SUCCESS_DIALOG))
.thenReturn("always");
when(operationBuilder.toOperation(any(BusinessObjectData.class), any(FieldToContractInputMapping.class),
any(IProgressMonitor.class))).thenReturn(anOperation().build());
any(EditMode.class), any(IProgressMonitor.class))).thenReturn(anOperation().build());
final ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(task, editingDomain(),
repositoryAccessor, operationBuilder,
......@@ -401,6 +407,28 @@ public class ContractInputGenerationWizardTest {
assertThat(wizard.createDocumentContractInput(document1).getDataReference()).isEqualTo("myDocument");
}
@Test
public void should_take_into_account_edit_mode_on_tasks() throws Exception {
ContractInputGenerationWizard wizard = new ContractInputGenerationWizard(aTask().build(), editingDomain(),
repositoryAccessor, operationBuilder,
expressionBuilder, preferenceStore, sharedImages, dialogFactory,
new ContractInputGenerationWizardPagesFactory(), sourceViewerFactory);
BusinessObjectData data = mock(BusinessObjectData.class);
RootContractInputGenerator generator = mock(RootContractInputGenerator.class);
wizard.getGenerationOptions().setEditMode(EditMode.CREATE);
wizard.buildContractOperationFromData(data, generator).run(new NullProgressMonitor());
verify(generator).build(any(BusinessObjectData.class), eq(EditMode.CREATE), any(IProgressMonitor.class));
verify(generator, times(0)).build(any(BusinessObjectData.class), eq(EditMode.EDIT), any(IProgressMonitor.class));
wizard.getGenerationOptions().setEditMode(EditMode.EDIT);
wizard.buildContractOperationFromData(data, generator).run(new NullProgressMonitor());
verify(generator).build(any(BusinessObjectData.class), eq(EditMode.EDIT), any(IProgressMonitor.class));
}
private EditingDomain editingDomain() {
return new TransactionalEditingDomainImpl(new ProcessItemProviderAdapterFactory());
}
......
/**
* Copyright (C) 2019 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;
import java.util.List;
import java.util.Objects;
import org.bonitasoft.engine.bdm.model.field.RelationField;
import org.bonitasoft.engine.bdm.model.field.RelationField.Type;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMappingFactory;
public class UngenerateAggregatedReferenceChildren {
public void apply(List<FieldToContractInputMapping> mappings) {
ungenerateAggregateReferencesChildren(mappings);
}
private void ungenerateAggregateReferencesChildren(List<FieldToContractInputMapping> mappings) {
for (FieldToContractInputMapping mapping : mappings) {
if (mapping.getField() instanceof RelationField
&& ((RelationField) mapping.getField()).getType() == Type.AGGREGATION) {
mapping.getChildren()
.stream()
.filter(childMapping -> !Objects.equals(childMapping.getField().getName(),
FieldToContractInputMappingFactory.PERSISTENCE_ID_STRING_FIELD_NAME))
.forEach(childMapping -> childMapping.setGenerated(false));
}
ungenerateAggregateReferencesChildren(mapping.getChildren());
}
}
}
......@@ -15,7 +15,6 @@
package org.bonitasoft.studio.contract.core.mapping;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bonitasoft.engine.bdm.model.field.Field;
......@@ -77,6 +76,7 @@ public abstract class FieldToContractInputMapping {
contractInput.setName(field.getName());
contractInput.setType(getContractInputType());
contractInput.setMultiple(field != null && field.isCollection());
contractInput.setCreateMode(parentInput == null || parentInput.isCreateMode());
if (parentInput != null) {
parentInput.getInputs().add(contractInput);
}
......
......@@ -26,6 +26,7 @@ import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInp
import org.bonitasoft.studio.contract.core.mapping.operation.BusinessObjectInstantiationException;
import org.bonitasoft.studio.contract.core.mapping.operation.FieldToContractInputMappingOperationBuilder;
import org.bonitasoft.studio.contract.core.mapping.operation.OperationCreationException;
import org.bonitasoft.studio.contract.ui.wizard.GenerationOptions.EditMode;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.process.BusinessObjectData;
......@@ -64,16 +65,17 @@ public class RootContractInputGenerator {
*/
public void buildForInstanciation(BusinessObjectData data, IProgressMonitor monitor)
throws OperationCreationException {
initContractInput(data);
initContractInput(data,EditMode.CREATE);
buildInitialValueExpression(data, monitor);
}
/**
* To be used if the contract is on a task -> operations will be generated
*/
public void build(BusinessObjectData data, IProgressMonitor monitor) throws OperationCreationException {
initContractInput(data);
buildOperations(data, monitor);
public void build(BusinessObjectData data, EditMode editMode, IProgressMonitor monitor)
throws OperationCreationException {
initContractInput(data,editMode);
buildOperations(data, editMode, monitor);
}
private void buildInitialValueExpression(BusinessObjectData data, IProgressMonitor monitor)
......@@ -88,12 +90,13 @@ public class RootContractInputGenerator {
monitor.done();
}
private void buildOperations(final BusinessObjectData data, IProgressMonitor monitor) throws OperationCreationException {
private void buildOperations(final BusinessObjectData data, EditMode editMode, IProgressMonitor monitor)
throws OperationCreationException {
monitor.beginTask("Building operations ...", children.size());
for (FieldToContractInputMapping mapping : children) {
if (mapping.isGenerated()) {
if (!contractInput.isMultiple()) {
mappingOperations.add(operationBuilder.toOperation(data, mapping, monitor));
mappingOperations.add(operationBuilder.toOperation(data, mapping, editMode, monitor));
}
} else {
allAttributesGenerated = false;
......@@ -101,16 +104,18 @@ public class RootContractInputGenerator {
}
if (contractInput.isMultiple()) {
mappingOperations
.add(operationBuilder.toOperation(data, createParentMapping(data, rootContractInputName), monitor));
.add(operationBuilder.toOperation(data, createParentMapping(data, rootContractInputName), editMode,
monitor));
}
monitor.done();
}
private void initContractInput(BusinessObjectData data) {
private void initContractInput(BusinessObjectData data, EditMode editMode) {
contractInput = ProcessFactory.eINSTANCE.createContractInput();
contractInput.setName(rootContractInputName);
contractInput.setType(ContractInputType.COMPLEX);
contractInput.setMultiple(data.isMultiple());
contractInput.setCreateMode(editMode == EditMode.CREATE);
contractInput.setDataReference(data.getName());
children.stream()
.filter(FieldToContractInputMapping::isGenerated)
......
......@@ -57,28 +57,28 @@ public class FieldToContractInputMappingExpressionBuilder {
this.expressionEditorService = expressionEditorService;
}
public Expression toExpression(BusinessObjectData data, FieldToContractInputMapping mapping, boolean isOnPool)
public Expression toExpression(BusinessObjectData data, FieldToContractInputMapping mapping, boolean createMode)
throws BusinessObjectInstantiationException, JavaModelException {
ContractInput contractInput = mapping.getContractInput();
MappingOperationScriptBuilder mappingOperationScriptBuilder = mapping.getScriptBuilder(data);
String script = getScriptText(isOnPool, mappingOperationScriptBuilder);
String script = getScriptText(createMode, mappingOperationScriptBuilder);
Expression scriptExpression = ExpressionHelper.createGroovyScriptExpression(script, mapping.getFieldType());
addScriptDependencies(mappingOperationScriptBuilder, mapping.getContractInput(), data, scriptExpression, isOnPool);
setGroovyScriptName(scriptExpression, data, contractInput, isOnPool);
addScriptDependencies(mappingOperationScriptBuilder, mapping.getContractInput(), data, scriptExpression, createMode);
setGroovyScriptName(scriptExpression, data, contractInput, createMode);
return scriptExpression;
}
protected String getScriptText(boolean isOnPool, MappingOperationScriptBuilder mappingOperationScriptBuilder)
protected String getScriptText(boolean createMode, MappingOperationScriptBuilder mappingOperationScriptBuilder)
throws BusinessObjectInstantiationException {
if (isOnPool) {
if (createMode) {
return mappingOperationScriptBuilder.toInstanciationScript();
}
return mappingOperationScriptBuilder.toScript();
}
private void setGroovyScriptName(final Expression scriptExpression, final BusinessObjectData data,
final ContractInput contractInput, final boolean isOnPool) {
if (isOnPool) {
final ContractInput contractInput, final boolean createMode) {
if (createMode) {
final String dataName = data.getName();
final String nameToUpperCase = dataName.length() > 1
? dataName.substring(0, 1).toUpperCase() + dataName.substring(1) : dataName.toUpperCase();
......
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.contract.core.mapping.operation;
import java.util.Collection;
import java.util.Objects;
import javax.inject.Inject;
......@@ -23,6 +24,7 @@ import org.bonitasoft.studio.common.emf.tools.ExpressionHelper;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.expression.FieldToContractInputMappingExpressionBuilder;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.contract.ui.wizard.GenerationOptions.EditMode;
import org.bonitasoft.studio.expression.editor.filter.ExpressionReturnTypeFilter;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.Operation;
......@@ -45,14 +47,16 @@ public class FieldToContractInputMappingOperationBuilder {
this.expressionBuilder = expressionBuilder;
}
public Operation toOperation(BusinessObjectData data, FieldToContractInputMapping mapping, IProgressMonitor monitor)
public Operation toOperation(BusinessObjectData data, FieldToContractInputMapping mapping, EditMode editMode,
IProgressMonitor monitor)
throws OperationCreationException {
monitor.setTaskName(String.format(Messages.creatingMappingOperation, mapping.getField().getName()));
Operation operation = ExpressionFactory.eINSTANCE.createOperation();
operation.setLeftOperand(ExpressionHelper.createVariableExpression(data));
operation.setOperator(operator(mapping, data));
try {
operation.setRightOperand(expressionBuilder.toExpression(data, mapping, false));
operation.setRightOperand(
expressionBuilder.toExpression(data, mapping, Objects.equals(editMode, EditMode.CREATE)));
} catch (BusinessObjectInstantiationException | JavaModelException e) {
throw new OperationCreationException("Failed to create right operand expression", e);
}
......
......@@ -61,10 +61,10 @@ public class MappingOperationScriptBuilder {
return toScript(false);
}
private String toScript(final boolean isOnPool) throws BusinessObjectInstantiationException {
private String toScript(final boolean createMode) throws BusinessObjectInstantiationException {
mapping.getContractInput();
return format(
buildPropertyInitializerTree(mapping, businessObjectInitializerFactory, data, isOnPool).getInitialValue());
buildPropertyInitializerTree(mapping, businessObjectInitializerFactory, data, createMode).getInitialValue());
}
private String format(final String initialValue) {
......
......@@ -26,7 +26,7 @@ public class InitializerContext {
private FieldToContractInputMapping mapping;
private Data data;
private boolean checkExistence;
private boolean isOnPool;
private boolean createMode;
private String localVariableName;
private String localListVariableName;
private ContractInput contractInput;
......@@ -68,12 +68,12 @@ public class InitializerContext {
this.mapping = mapping;
}
public boolean isOnPool() {
return isOnPool;
public boolean isCreateMode() {
return createMode;
}
public void setOnPool(final boolean isOnPool) {
this.isOnPool = isOnPool;
public void setCreateMode(final boolean createMode) {
this.createMode = createMode;
}
private String toRefName(final InitializerContext parentContext) {
......
......@@ -47,12 +47,12 @@ public abstract class AbsractInitializerFactory implements InitializerFactory {
protected InitializerContext createContext(final Data data,
final VariableNameResolver resolver,
final FieldToContractInputMapping mapping,
final boolean isOnPool) {
final boolean createMode) {
final InitializerContext context = new InitializerContext();
final BusinessObject businessObject = ((RelationField) mapping.getField()).getReference();
context.setMapping(mapping);
context.setCheckExistence(!isOnPool);
context.setOnPool(isOnPool);
context.setCheckExistence(!createMode);
context.setCreateMode(createMode);
context.setData(data);
context.setContractInput(mapping.getContractInput());
context.setLocalListVariableName(resolver.newListVarName(businessObject));
......
......@@ -26,7 +26,6 @@ import org.bonitasoft.studio.contract.core.mapping.operation.initializer.Multipl
import org.bonitasoft.studio.contract.core.mapping.operation.initializer.NewBusinessObjectInitializer;
import org.bonitasoft.studio.contract.core.mapping.operation.initializer.NewBusinessObjectListInitializer;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.ContractInput;
public class BusinessObjectInitializerFactory extends AbsractInitializerFactory {
......@@ -38,9 +37,9 @@ public class BusinessObjectInitializerFactory extends AbsractInitializerFactory
@Override
public IPropertyInitializer newPropertyInitializer(FieldToContractInputMapping mapping, BusinessObjectData data,
boolean isOnPool) {
boolean createMode) {
RelationField relationField = (RelationField) mapping.getField();
InitializerContext context = createContext(data, variableNameResolver, mapping, isOnPool);
InitializerContext context = createContext(data, variableNameResolver, mapping, createMode);
return relationField.getType() == Type.AGGREGATION
? newAggregatedObjectInitializer(context)
: newComposedObjectInitializer(context);
......@@ -54,11 +53,10 @@ public class BusinessObjectInitializerFactory extends AbsractInitializerFactory
private IPropertyInitializer newComposedObjectInitializer(InitializerContext context) {
if (context.getField().isCollection()) {
return context.isOnPool()
return context.isCreateMode()
? new NewBusinessObjectListInitializer(context)
: new MultipleCompositionBusinessObjectQueryInitializer(businessObject(context.getMapping()), context);
}
context.setCheckExistence(context.getMapping().getContractInput().eContainer() instanceof ContractInput);
return new NewBusinessObjectInitializer(context);
}
}
......@@ -35,8 +35,8 @@ public class RelationPropertyInitializerFactory extends AbsractInitializerFactor
@Override
public IPropertyInitializer newPropertyInitializer(FieldToContractInputMapping mapping,
BusinessObjectData data, boolean isOnPool) {
InitializerContext context = createContext(data, variableNameResolver, mapping, isOnPool);
BusinessObjectData data, boolean createMode) {
InitializerContext context = createContext(data, variableNameResolver, mapping, createMode);
return context.getField().getType() == Type.AGGREGATION
? newAggregatedReferenceInitializer(context)
: newComposedReferenceInitializer(context);
......
......@@ -37,9 +37,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
/**
* @author Romain Bioteau
*/
public class CreateFormFromContractOperation extends CreateUIDArtifactOperation {
private Contract contract;
......@@ -60,14 +58,10 @@ public class CreateFormFromContractOperation extends CreateUIDArtifactOperation
monitor.beginTask(Messages.creatingNewForm, IProgressMonitor.UNKNOWN);
try {
URL url = pageDesignerURLBuilder.newPageFromContract(formScope, artifactName);
TreeResult treeResult = new TreeResult();
if (formScope == FormScope.TASK) {
Pool parentPool = new ModelSearch(Collections::emptyList).getDirectParentOfType(contract, Pool.class);
ContractToBusinessDataResolver contractToBusinessDataResolver = new ContractToBusinessDataResolver(
new BusinessDataStore(parentPool, getRepositoryAccessor()));
treeResult = contractToBusinessDataResolver.resolve(contract);
}
Pool parentPool = new ModelSearch(Collections::emptyList).getDirectParentOfType(contract, Pool.class);
ContractToBusinessDataResolver contractToBusinessDataResolver = new ContractToBusinessDataResolver(
new BusinessDataStore(parentPool, getRepositoryAccessor()));
TreeResult treeResult = contractToBusinessDataResolver.resolve(contract);
Representation body = new JacksonRepresentation<>(new ToWebContract(treeResult).apply(contract));
responseObject = createArtifact(url, body);
} catch (MalformedURLException e) {
......
......@@ -27,6 +27,7 @@ import org.bonitasoft.studio.contract.core.mapping.treeMaching.TreeResult;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.web.designer.model.contract.DataReference;
import org.bonitasoft.web.designer.model.contract.EditMode;
import org.bonitasoft.web.designer.model.contract.LeafContractInput;
import org.bonitasoft.web.designer.model.contract.NodeContractInput;
......@@ -106,6 +107,7 @@ public class ToWebContract implements Function<Contract, org.bonitasoft.web.desi
private org.bonitasoft.web.designer.model.contract.ContractInput copyInputProperties(final ContractInput input,
final org.bonitasoft.web.designer.model.contract.ContractInput contractInput) {
contractInput.setMultiple(input.isMultiple());
contractInput.setMode(input.isCreateMode() ? EditMode.CREATE : EditMode.EDIT);
contractInput.setDescription(input.getDescription());
if (contractInput instanceof NodeContractInput) {
((NodeContractInput) contractInput).setDataReference(treeResult.getDataReference(input));
......
......@@ -35,7 +35,6 @@ import org.bonitasoft.studio.contract.core.mapping.operation.DocumentUpdateOpera
import org.bonitasoft.studio.contract.core.mapping.operation.FieldToContractInputMappingOperationBuilder;
import org.bonitasoft.studio.contract.core.mapping.operation.OperationCreationException;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.contract.ui.wizard.GenerationOptions.EditMode;
import org.bonitasoft.studio.groovy.ui.viewer.GroovySourceViewerFactory;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.process.AbstractProcess;
......@@ -108,7 +107,8 @@ public class ContractInputGenerationWizard extends Wizard {
generationOptions = new GenerationOptions();
this.editingDomain = editingDomain;
this.repositoryAccessor = repositoryAccessor;
fieldToContractInputMappingFactory = new FieldToContractInputMappingFactory(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class));
fieldToContractInputMappingFactory = new FieldToContractInputMappingFactory(
repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class));
this.operationBuilder = operationBuilder;
this.expressionBuilder = expressionBuilder;
this.preferenceStore = preferenceStore;
......@@ -120,8 +120,8 @@ public class ContractInputGenerationWizard extends Wizard {
@Override
public void addPages() {
selectedDataObservable = new WritableValue<Object>();
rootNameObservable = new WritableValue<String>();
selectedDataObservable = new WritableValue<>();
rootNameObservable = new WritableValue<>();
fieldToContractInputMappingsObservable = new WritableList(new ArrayList<FieldToContractInputMapping>(),
FieldToContractInputMapping.class);
availableBusinessData = availableBusinessData();
......@@ -136,7 +136,7 @@ public class ContractInputGenerationWizard extends Wizard {
availableDocuments = ModelHelper.getParentPool(contractContainer).getDocuments();
selectBusinessDataWizardPage = contractInputWizardPagesFactory.createSelectBusinessDataWizardPage(
contractContainer.getContract(),
availableBusinessData,
availableBusinessData,
availableDocuments,
selectedDataObservable,
rootNameObservable,
......@@ -146,7 +146,7 @@ public class ContractInputGenerationWizard extends Wizard {
contractInputFromBusinessObjectWizardPage = contractInputWizardPagesFactory
.createCreateContratInputFromBusinessObjectWizardPage(
contractContainer,
generationOptions,
generationOptions,
selectedDataObservable,
rootNameObservable,
fieldToContractInputMappingFactory,
......@@ -169,7 +169,6 @@ public class ContractInputGenerationWizard extends Wizard {
return newArrayList(filter(pool.getData(), instanceOf(BusinessObjectData.class)));
}
@Override
public boolean canFinish() {
if (availableBusinessData.isEmpty() && availableDocuments.isEmpty()) {
......@@ -178,7 +177,6 @@ public class ContractInputGenerationWizard extends Wizard {
return super.canFinish();
}
@Override
public boolean performFinish() {
final Object selectedData = selectedDataObservable.getValue();
......@@ -214,14 +212,14 @@ public class ContractInputGenerationWizard extends Wizard {
return false;
}
private IRunnableWithProgress buildContractOperationFromData(BusinessObjectData data,
protected IRunnableWithProgress buildContractOperationFromData(BusinessObjectData data,
RootContractInputGenerator contractInputGenerator) {
return monitor -> {
try {
if (contractContainer instanceof Pool) {
contractInputGenerator.buildForInstanciation(data, monitor);
} else {
contractInputGenerator.build(data, monitor);
contractInputGenerator.build(data, generationOptions.getEditMode(), monitor);
}
editingDomain.getCommandStack().execute(createCommand(contractInputGenerator, data));
} catch (final OperationCreationException e) {
......@@ -335,4 +333,8 @@ public class ContractInputGenerationWizard extends Wizard {
return contractInputFromBusinessObjectWizardPage;
}
protected GenerationOptions getGenerationOptions() {
return generationOptions;
}
}
......@@ -27,6 +27,7 @@ import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelF
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.common.ProductVersion;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.contract.UngenerateAggregatedReferenceChildren;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMappingFactory;
import org.bonitasoft.studio.contract.core.mapping.RemoveAggregateReferencesChildren;
......@@ -426,6 +427,7 @@ public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage
mappings = fieldToContractInputMappingFactory.createMappingForBusinessObjectType(contractContainer, data);
if (generationOptions.getEditMode() == EditMode.EDIT) {
lazyFieldStatusProvider.apply(mappings, data);
new UngenerateAggregatedReferenceChildren().apply(mappings);
} else if (generationOptions.getEditMode() == EditMode.CREATE) {
new RemoveAggregateReferencesChildren().apply(mappings);
}
......
......@@ -47,9 +47,10 @@ public class FieldToContractInputMappingViewerCheckStateManager implements IChec
* @see org.eclipse.jface.viewers.ICheckStateProvider#isGrayed(java.lang.Object)
*/
@Override
public boolean isGrayed(final Object element) {
final FieldToContractInputMapping mapping = (FieldToContractInputMapping) element;
return any(mapping.getChildren(), isGenerated()) && !Iterables.all(mapping.getChildren(), isGenerated());
public boolean isGrayed(Object element) {
FieldToContractInputMapping mapping = (FieldToContractInputMapping) element;
boolean isGrayed = any(mapping.getChildren(), isGenerated()) && !Iterables.all(mapping.getChildren(), isGenerated());
return isGrayed || mapping.getChildren().stream().anyMatch(this::isGrayed);
}
/*
......@@ -65,6 +66,7 @@ public class FieldToContractInputMappingViewerCheckStateManager implements IChec
setChildrenChecked(mapping, event.getChecked());
selectParentIfChildIsSelected(event, mapping, checkboxTreeViewer);
deselectParentIfNoChildSelected(event, mapping, checkboxTreeViewer);
checkboxTreeViewer.getControl().getDisplay().asyncExec(() -> checkboxTreeViewer.refresh());
}
private void setChildrenChecked(final FieldToContractInputMapping parent, final boolean state) {
......@@ -78,7 +80,8 @@ public class FieldToContractInputMappingViewerCheckStateManager implements IChec
}
}
private void deselectParentIfNoChildSelected(final CheckStateChangedEvent event, final FieldToContractInputMapping mapping,
private void deselectParentIfNoChildSelected(final CheckStateChangedEvent event,
final FieldToContractInputMapping mapping,
final CheckboxTreeViewer checkboxTreeViewer) {
final FieldToContractInputMapping parentMapping = mapping.getParent();
boolean deselect = true;
......
......@@ -15,9 +15,7 @@
package org.bonitasoft.studio.contract.ui.wizard.labelProvider;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.SimpleFieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.UnselectLazyReferencesInMultipleContainer;
import org.bonitasoft.studio.model.process.Task;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Image;
......
......@@ -756,3 +756,4 @@ _UI_TimeUnit_Year_literal = Year
_UI_RepartitionType_CONSTANT_literal = CONSTANT
_UI_RepartitionType_DIRECT_literal = DIRECT
_UI_ContractInput_dataReference_feature = Data Reference
_UI_ContractInput_createMode_feature = Create Mode
......@@ -85,6 +85,7 @@ public class ContractInputItemProvider
addDescriptionPropertyDescriptor(object);
addMultiplePropertyDescriptor(object);
addDataReferencePropertyDescriptor(object);
addCreateModePropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
......@@ -199,6 +200,28 @@ public class ContractInputItemProvider
null));
}
/**
* This adds a property descriptor for the Create Mode feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addCreateModePropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_ContractInput_createMode_feature"), //$NON-NLS-1$
getString("_UI_PropertyDescriptor_description", "_UI_ContractInput_createMode_feature", "_UI_ContractInput_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ProcessPackage.Literals.CONTRACT_INPUT__CREATE_MODE,
true,
false,
false,
ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
null,
null));
}
/**
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
......@@ -273,6 +296,7 @@ public class ContractInputItemProvider
case ProcessPackage.CONTRACT_INPUT__DESCRIPTION:
case ProcessPackage.CONTRACT_INPUT__MULTIPLE:
case ProcessPackage.CONTRACT_INPUT__DATA_REFERENCE:
case ProcessPackage.CONTRACT_INPUT__CREATE_MODE:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
case ProcessPackage.CONTRACT_INPUT__MAPPING:
......
......@@ -37,6 +37,7 @@ import org.eclipse.emf.ecore.EObject;
* <li>{@link org.bonitasoft.studio.model.process.ContractInput#getMapping <em>Mapping</em>}</li>
* <li>{@link org.bonitasoft.studio.model.process.ContractInput#getInputs <em>Inputs</em>}</li>
* <li>{@link org.bonitasoft.studio.model.process.ContractInput#getDataReference <em>Data Reference</em>}</li>
* <li>{@link org.bonitasoft.studio.model.process.ContractInput#isCreateMode <em>Create Mode</em>}</li>
* </ul>
*
* @see org.bonitasoft.studio.model.process.ProcessPackage#getContractInput()
......@@ -219,6 +220,33 @@ public interface ContractInput extends EObject {
*/
void setDataReference(String value);
/**
* Returns the value of the '<em><b>Create Mode</b></em>' attribute.
* The default value is <code>"true"</code>.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Create Mode</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Create Mode</em>' attribute.
* @see #setCreateMode(boolean)
* @see org.bonitasoft.studio.model.process.ProcessPackage#getContractInput_CreateMode()
* @model default="true"
* @generated
*/
boolean isCreateMode();
/**
* Sets the value of the '{@link org.bonitasoft.studio.model.process.ContractInput#isCreateMode <em>Create Mode</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Create Mode</em>' attribute.
* @see #isCreateMode()
* @generated
*/
void setCreateMode(boolean value);
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
......@@ -3430,6 +3430,15 @@ public interface ProcessPackage extends EPackage {
*/
int CONTRACT_INPUT__DATA_REFERENCE = 6;
/**
* The feature id for the '<em><b>Create Mode</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int CONTRACT_INPUT__CREATE_MODE = 7;
/**
* The number of structural features of the '<em>Contract Input</em>' class.
* <!-- begin-user-doc -->
......@@ -3437,7 +3446,7 @@ public interface ProcessPackage extends EPackage {
* @generated
* @ordered
*/
int CONTRACT_INPUT_FEATURE_COUNT = 7;
int CONTRACT_INPUT_FEATURE_COUNT = 8;
/**
* The meta object id for the '{@link org.bonitasoft.studio.model.process.impl.ContractConstraintImpl <em>Contract Constraint</em>}' class.
......@@ -10491,6 +10500,17 @@ public interface ProcessPackage extends EPackage {
*/
EAttribute getContractInput_DataReference();
/**
* Returns the meta object for the attribute '{@link org.bonitasoft.studio.model.process.ContractInput#isCreateMode <em>Create Mode</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the attribute '<em>Create Mode</em>'.
* @see org.bonitasoft.studio.model.process.ContractInput#isCreateMode()
* @see #getContractInput()
* @generated
*/
EAttribute getContractInput_CreateMode();
/**
* Returns the meta object for class '{@link org.bonitasoft.studio.model.process.ContractConstraint <em>Contract Constraint</em>}'.
* <!-- begin-user-doc -->
......@@ -13208,6 +13228,14 @@ public interface ProcessPackage extends EPackage {
*/
EAttribute CONTRACT_INPUT__DATA_REFERENCE = eINSTANCE.getContractInput_DataReference();
/**
* The meta object literal for the '<em><b>Create Mode</b></em>' attribute feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EAttribute CONTRACT_INPUT__CREATE_MODE = eINSTANCE.getContractInput_CreateMode();
/**
* The meta object literal for the '{@link org.bonitasoft.studio.model.process.impl.ContractConstraintImpl <em>Contract Constraint</em>}' class.
* <!-- begin-user-doc -->
......
......@@ -24,6 +24,7 @@ import org.bonitasoft.studio.model.process.ContractConstraint;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.ProcessPackage;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
......@@ -31,6 +32,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
......
......@@ -53,6 +53,7 @@ import org.eclipse.emf.ecore.util.InternalEList;
* <li>{@link org.bonitasoft.studio.model.process.impl.ContractInputImpl#getMapping <em>Mapping</em>}</li>
* <li>{@link org.bonitasoft.studio.model.process.impl.ContractInputImpl#getInputs <em>Inputs</em>}</li>
* <li>{@link org.bonitasoft.studio.model.process.impl.ContractInputImpl#getDataReference <em>Data Reference</em>}</li>
* <li>{@link org.bonitasoft.studio.model.process.impl.ContractInputImpl#isCreateMode <em>Create Mode</em>}</li>
* </ul>
*
* @generated
......@@ -178,6 +179,26 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
*/
protected String dataReference = DATA_REFERENCE_EDEFAULT;
/**
* The default value of the '{@link #isCreateMode() <em>Create Mode</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isCreateMode()
* @generated
* @ordered
*/
protected static final boolean CREATE_MODE_EDEFAULT = true;
/**
* The cached value of the '{@link #isCreateMode() <em>Create Mode</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isCreateMode()
* @generated
* @ordered
*/
protected boolean createMode = CREATE_MODE_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -370,6 +391,29 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
eNotify(new ENotificationImpl(this, Notification.SET, ProcessPackage.CONTRACT_INPUT__DATA_REFERENCE, oldDataReference, dataReference));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean isCreateMode() {
return createMode;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setCreateMode(boolean newCreateMode) {
boolean oldCreateMode = createMode;
createMode = newCreateMode;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ProcessPackage.CONTRACT_INPUT__CREATE_MODE, oldCreateMode, createMode));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -431,6 +475,8 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
return getInputs();
case ProcessPackage.CONTRACT_INPUT__DATA_REFERENCE:
return getDataReference();
case ProcessPackage.CONTRACT_INPUT__CREATE_MODE:
return isCreateMode();
}
return super.eGet(featureID, resolve, coreType);
}
......@@ -466,6 +512,9 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
case ProcessPackage.CONTRACT_INPUT__DATA_REFERENCE:
setDataReference((String)newValue);
return;
case ProcessPackage.CONTRACT_INPUT__CREATE_MODE:
setCreateMode((Boolean)newValue);
return;
}
super.eSet(featureID, newValue);
}
......@@ -499,6 +548,9 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
case ProcessPackage.CONTRACT_INPUT__DATA_REFERENCE:
setDataReference(DATA_REFERENCE_EDEFAULT);
return;
case ProcessPackage.CONTRACT_INPUT__CREATE_MODE:
setCreateMode(CREATE_MODE_EDEFAULT);
return;
}
super.eUnset(featureID);
}
......@@ -525,6 +577,8 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
return inputs != null && !inputs.isEmpty();
case ProcessPackage.CONTRACT_INPUT__DATA_REFERENCE:
return DATA_REFERENCE_EDEFAULT == null ? dataReference != null : !DATA_REFERENCE_EDEFAULT.equals(dataReference);
case ProcessPackage.CONTRACT_INPUT__CREATE_MODE:
return createMode != CREATE_MODE_EDEFAULT;
}
return super.eIsSet(featureID);
}
......@@ -549,6 +603,8 @@ public class ContractInputImpl extends EObjectImpl implements ContractInput {
result.append(multiple);
result.append(", dataReference: "); //$NON-NLS-1$
result.append(dataReference);
result.append(", createMode: "); //$NON-NLS-1$
result.append(createMode);
result.append(')');
return result.toString();
}
......
......@@ -1845,6 +1845,16 @@ public class ProcessPackageImpl extends EPackageImpl implements ProcessPackage {
return (EAttribute)contractInputEClass.getEStructuralFeatures().get(6);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EAttribute getContractInput_CreateMode() {
return (EAttribute)contractInputEClass.getEStructuralFeatures().get(7);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -3888,6 +3898,7 @@ public class ProcessPackageImpl extends EPackageImpl implements ProcessPackage {
createEReference(contractInputEClass, CONTRACT_INPUT__MAPPING);
createEReference(contractInputEClass, CONTRACT_INPUT__INPUTS);
createEAttribute(contractInputEClass, CONTRACT_INPUT__DATA_REFERENCE);
createEAttribute(contractInputEClass, CONTRACT_INPUT__CREATE_MODE);
contractConstraintEClass = createEClass(CONTRACT_CONSTRAINT);
createEAttribute(contractConstraintEClass, CONTRACT_CONSTRAINT__EXPRESSION);
......@@ -4420,6 +4431,7 @@ public class ProcessPackageImpl extends EPackageImpl implements ProcessPackage {
initEReference(getContractInput_Mapping(), this.getContractInputMapping(), null, "mapping", null, 0, 1, ContractInput.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEReference(getContractInput_Inputs(), this.getContractInput(), null, "inputs", null, 0, -1, ContractInput.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(getContractInput_DataReference(), ecorePackage.getEString(), "dataReference", null, 0, 1, ContractInput.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$
initEAttribute(getContractInput_CreateMode(), ecorePackage.getEBoolean(), "createMode", "true", 0, 1, ContractInput.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$ //$NON-NLS-2$
addEOperation(contractInputEClass, ecorePackage.getEString(), "getJavaType", 0, 1, IS_UNIQUE, IS_ORDERED); //$NON-NLS-1$