Commit 48328967 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

fix(model) clear children inputs from COMPLEX contract input (#528)

Closes BS-16705
parent 61f125fc
......@@ -14437,5 +14437,8 @@
</changes>
</changes>
</releases>
<releases xmi:id="_zVbFAEzvEee-aqxzWrdt2g" date="2017-06-09T11:43:27.494+0200" label="7.5.2-001">
<changes xsi:type="history:MigrationChange" xmi:id="_2bs5cEzvEee-aqxzWrdt2g" migration="org.bonitasoft.studio.migration.custom.migration.DependenciesCopyCustomMigration"/>
</releases>
<releases xmi:id="_15TmyGnREeaTLbmqFFisdA"/>
</history:History>
......@@ -39,6 +39,7 @@ import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.BusinessObjectType;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.ContractInputType;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.DataType;
import org.bonitasoft.studio.model.process.Document;
......@@ -148,7 +149,8 @@ public class ExpressionHelper {
return exp;
}
public static Expression createConstantExpression(final String name, final String content, final String returnClassName) {
public static Expression createConstantExpression(final String name, final String content,
final String returnClassName) {
final Expression exp = createConstantExpression(content, returnClassName);
exp.setName(name);
return exp;
......@@ -167,9 +169,20 @@ public class ExpressionHelper {
if (dependency instanceof SearchIndex) {
return createSearchIndexDependency(dependency);
}
if (dependency instanceof ContractInput) {
return createContractInputependency(dependency);
}
return EcoreUtil.copy(dependency);
}
private static EObject createContractInputependency(EObject dependency) {
final ContractInput contractInputDependency = (ContractInput) EcoreUtil.copy(dependency);
if (contractInputDependency.getType() == ContractInputType.COMPLEX) {
contractInputDependency.getInputs().clear();
}
return contractInputDependency;
}
private static EObject createSearchIndexDependency(final EObject dependency) {
final SearchIndex searchIndexDependency = (SearchIndex) ProcessFactory.eINSTANCE.create(dependency.eClass());
final Expression name = ((SearchIndex) dependency).getName();
......@@ -212,13 +225,17 @@ public class ExpressionHelper {
}
final CompoundCommand cc = new CompoundCommand("Clear Expression");
if (!ExpressionConstants.CONDITION_TYPE.equals(expr.getType())) {
cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__TYPE, ExpressionConstants.CONSTANT_TYPE));
cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__TYPE,
ExpressionConstants.CONSTANT_TYPE));
}
cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__NAME, ""));
cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__CONTENT, ""));
cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE, returnType));
cc.append(RemoveCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS, expr.getReferencedElements()));
cc.append(RemoveCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__CONNECTORS, expr.getConnectors()));
cc.append(
SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE, returnType));
cc.append(RemoveCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS,
expr.getReferencedElements()));
cc.append(RemoveCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__CONNECTORS,
expr.getConnectors()));
return cc;
} else {
clearExpression(expr);
......@@ -260,7 +277,8 @@ public class ExpressionHelper {
return expression;
}
public static Expression createExpression(final String name, final String content, final String type, final String returnType, final boolean fixedReturnType) {
public static Expression createExpression(final String name, final String content, final String type,
final String returnType, final boolean fixedReturnType) {
final Expression expression = ExpressionFactory.eINSTANCE.createExpression();
expression.setType(type);
expression.setReturnType(returnType);
......@@ -403,7 +421,8 @@ public class ExpressionHelper {
public static Operation createDefaultConnectorOutputOperation(final Output output) {
final Operation operation = ExpressionFactory.eINSTANCE.createOperation();
final Operator assignment = ExpressionFactory.eINSTANCE.createOperator();
assignment.setType(isDocumentValue(output) ? ExpressionConstants.SET_DOCUMENT_OPERATOR : ExpressionConstants.ASSIGNMENT_OPERATOR);
assignment.setType(isDocumentValue(output) ? ExpressionConstants.SET_DOCUMENT_OPERATOR
: ExpressionConstants.ASSIGNMENT_OPERATOR);
operation.setOperator(assignment);
final Expression rightOperand = ExpressionFactory.eINSTANCE.createExpression();
......@@ -423,7 +442,8 @@ public class ExpressionHelper {
return Objects.equals(DocumentValue.class.getName(), output.getType());
}
public static Data dataFromIteratorExpression(final MultiInstantiable parentFlowElement, final Expression iteratorExpression, final MainProcess mainProcess) {
public static Data dataFromIteratorExpression(final MultiInstantiable parentFlowElement,
final Expression iteratorExpression, final MainProcess mainProcess) {
final String returnType = iteratorExpression.getReturnType();
Data d = null;
if (returnType != null) {
......@@ -443,7 +463,8 @@ public class ExpressionHelper {
return d;
}
private static DataType getDataTypeFrom(final String returnType, final MainProcess mainProcess, final MultiInstantiable parentFlowElement) {
private static DataType getDataTypeFrom(final String returnType, final MainProcess mainProcess,
final MultiInstantiable parentFlowElement) {
if (parentFlowElement.getCollectionDataToMultiInstantiate() instanceof BusinessObjectData) {
return find(mainProcess.getDatatypes(), instanceOf(BusinessObjectType.class), null);
} else {
......
......@@ -42,7 +42,7 @@ public class RemoveDanglingReferences {
public void execute() {
removeDanglingReferences(root);
// removeSequenceFlowWithoutSourceAndTarget(root);
removeSequenceFlowWithoutSourceAndTarget(root);
}
private void removeSequenceFlowWithoutSourceAndTarget(EObject element) {
......
......@@ -5,14 +5,12 @@
* 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.migration.custom.migration;
......@@ -25,62 +23,70 @@ import org.eclipse.emf.edapt.spi.migration.Instance;
import org.eclipse.emf.edapt.spi.migration.Metamodel;
import org.eclipse.emf.edapt.spi.migration.Model;
/**
* @author Romain Bioteau
*
*/
public class DependenciesCopyCustomMigration extends CustomMigration {
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.eclipse.emf.edapt.migration.CustomMigration#migrateAfter(org.eclipse.emf.edapt.spi.migration.Model, org.eclipse.emf.edapt.migration.Metamodel)
*/
@Override
public void migrateAfter(final Model model, final Metamodel metamodel) throws MigrationException {
final List<Instance> allReferencesToBeDeleted = new ArrayList<Instance>();
for(final Instance expInstance : model.getAllInstances("expression.Expression")){
final List<Instance> allReferencesToBeDeleted = new ArrayList<>();
for (final Instance expInstance : model.getAllInstances("expression.Expression")) {
final List<Instance> referencedElements = expInstance.get("referencedElements");
final List<Instance> newReferencedElements = new ArrayList<Instance>();
final List<Instance> referencesToBeDeleted = new ArrayList<Instance>();
for(final Instance refElement : referencedElements){
final List<Instance> newReferencedElements = new ArrayList<>();
final List<Instance> referencesToBeDeleted = new ArrayList<>();
for (final Instance refElement : referencedElements) {
Instance newCleanedDependency = null;
if(refElement.instanceOf("form.Widget")){
newCleanedDependency = newCleanedWidgetDependency(refElement,model);
if (refElement.instanceOf("form.Widget")) {
newCleanedDependency = newCleanedWidgetDependency(refElement, model);
referencesToBeDeleted.add(refElement);
} else if (refElement.instanceOf("process.Data")) {
newCleanedDependency = newCleaneDataDependency(refElement);
referencesToBeDeleted.add(refElement);
}else if(refElement.instanceOf("process.Data")){
newCleanedDependency = newCleaneDataDependency(refElement,model);
} else if (refElement.instanceOf("process.Document")) {
newCleanedDependency = newCleanedDocumentDependency(refElement, model);
referencesToBeDeleted.add(refElement);
}else if(refElement.instanceOf("process.Document")){
newCleanedDependency = newCleanedDocumentDependency(refElement,model);
} else if (model.getMetamodel().getEClass("process.ContractInput") != null
&& refElement.instanceOf("process.ContractInput")) {
newCleanedDependency = newCleanedContractInputDependency(refElement, model);
referencesToBeDeleted.add(refElement);
}
if(newCleanedDependency != null){
if (newCleanedDependency != null) {
newReferencedElements.add(newCleanedDependency);
}
}
for(final Instance instanceToDelete : referencesToBeDeleted){
for (final Instance instanceToDelete : referencesToBeDeleted) {
expInstance.remove("referencedElements", instanceToDelete);
}
allReferencesToBeDeleted.addAll(referencesToBeDeleted);
for(final Instance newInstance : newReferencedElements){
for (final Instance newInstance : newReferencedElements) {
expInstance.add("referencedElements", newInstance);
}
}
for(final Instance instance : allReferencesToBeDeleted){
for (final Instance instance : allReferencesToBeDeleted) {
model.delete(instance);
}
allReferencesToBeDeleted.clear();
for(final Instance expInstance : model.getAllInstances("expression.Expression")){
if(expInstance.getContainer() == null){
for (final Instance expInstance : model.getAllInstances("expression.Expression")) {
if (expInstance.getContainer() == null) {
allReferencesToBeDeleted.add(expInstance);
}
}
for(final Instance instance : allReferencesToBeDeleted){
for (final Instance instance : allReferencesToBeDeleted) {
model.delete(instance);
}
allReferencesToBeDeleted.clear();
}
private Instance newCleanedContractInputDependency(Instance refElement, final Model model) {
final Instance newInstance = refElement.copy();
((List<Instance>) newInstance.get("inputs")).stream().forEach(model::delete);
return newInstance;
}
protected Instance newCleanedDocumentDependency(final Instance refElement, final Model model) {
final Instance newInstance = model.newInstance(refElement.getEClass());
......@@ -88,23 +94,21 @@ public class DependenciesCopyCustomMigration extends CustomMigration {
return newInstance;
}
protected Instance newCleaneDataDependency(final Instance refElement, final Model model) {
protected Instance newCleaneDataDependency(final Instance refElement) {
final Instance newInstance = refElement.copy();
newInstance.set("defaultValue", null);
return newInstance;
}
protected Instance newCleanedWidgetDependency(final Instance refElement, final Model model) {
final Instance newInstance = model.newInstance(refElement.getEClass());
newInstance.set("name", refElement.get("name"));
Object modifier = refElement.get("returnTypeModifier");
if(modifier == null){
if (modifier == null) {
modifier = String.class.getName();
}
newInstance.set("returnTypeModifier", modifier);
if(newInstance.instanceOf("form.Duplicable")){
if (newInstance.instanceOf("form.Duplicable")) {
newInstance.set("duplicate", refElement.get("duplicate"));
}
return newInstance;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment