Commit a76b5683 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

generic builders

parent 1cb07e88
......@@ -5,12 +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
* 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/>.
*/
......@@ -24,11 +24,10 @@ import java.util.List;
import java.util.Map;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.parameter.ParameterFactory;
import org.bonitasoft.studio.model.expression.builders.ExpressionBuilder;
import org.bonitasoft.studio.model.parameter.builders.ParameterBuilder;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.builders.DataBuilder;
import org.bonitasoft.studio.refactoring.core.RefactoringOperationType;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
......@@ -38,22 +37,21 @@ import org.junit.Test;
/**
* @author Romain Bioteau
*
*
*/
public class DataScriptExpressionRefactoringActionTest {
private DataScriptExpressionRefactoringAction refactoringAction;
private Data oldData;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
List<DataRefactorPair> pairsToRefactor = new ArrayList<DataRefactorPair>();
oldData = ProcessFactory.eINSTANCE.createData();
oldData.setName("myData");
final List<DataRefactorPair> pairsToRefactor = new ArrayList<DataRefactorPair>();
oldData = DataBuilder.create().withName("myData").build();
pairsToRefactor.add(new DataRefactorPair(oldData, oldData));
refactoringAction = new DataScriptExpressionRefactoringAction(pairsToRefactor,
Collections.<Expression> emptyList(),
......@@ -71,15 +69,11 @@ public class DataScriptExpressionRefactoringActionTest {
@Test
public void should_retrieve_data_in_expression_dependencies() throws Exception {
Expression expr = ExpressionFactory.eINSTANCE.createExpression();
Data createData = ProcessFactory.eINSTANCE.createData();
createData.setName("myData");
Parameter parameter = ParameterFactory.eINSTANCE.createParameter();
parameter.setName("myData");
expr.getReferencedElements().add(parameter);
expr.getReferencedElements().add(createData);
Map<EObject,EObject> eObject = refactoringAction.getReferencedObjectInScriptsOperation(expr);
final Data createData = DataBuilder.create().withName("myData").build();
final Expression expr = ExpressionBuilder.create().
havingReferencedElements(createData,
ParameterBuilder.create().withName("myData").build()).build();
final Map<EObject,EObject> eObject = refactoringAction.getReferencedObjectInScriptsOperation(expr);
assertThat(eObject).isNotEmpty().containsEntry(createData, oldData);
}
}
......@@ -8,6 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.bonitasoft.studio.model.expression.assertions,
org.bonitasoft.studio.model.expression.builders,
org.bonitasoft.studio.model.form.builders,
org.bonitasoft.studio.model.parameter.builders,
org.bonitasoft.studio.model.process.assertions,
org.bonitasoft.studio.model.process.builders
Require-Bundle: assertj-core,
......
......@@ -24,27 +24,21 @@ import org.bonitasoft.studio.model.form.FormFactory;
* @author Romain Bioteau
*
*/
public class FileWidgetBuilder extends WidgetBuilder {
private final FileWidget fileWidget;
private FileWidgetBuilder(final FileWidget fileWidget) {
super(fileWidget);
this.fileWidget = fileWidget;
}
public class FileWidgetBuilder extends WidgetBuilder<FileWidget, FileWidgetBuilder> {
public static FileWidgetBuilder create() {
return new FileWidgetBuilder(FormFactory.eINSTANCE.createFileWidget());
return new FileWidgetBuilder();
}
public FileWidgetBuilder withInputType(final FileWidgetInputType type) {
fileWidget.setInputType(type);
return this;
getBuiltInstance().setInputType(type);
return getThis();
}
@Override
public FileWidget build() {
return fileWidget;
protected FileWidget newInstance() {
return FormFactory.eINSTANCE.createFileWidget();
}
}
......@@ -18,47 +18,29 @@ package org.bonitasoft.studio.model.form.builders;
import org.bonitasoft.studio.model.expression.builders.ExpressionBuilder;
import org.bonitasoft.studio.model.form.Widget;
import org.bonitasoft.studio.model.process.builders.ElementBuilder;
/**
* @author Romain Bioteau
*
*/
public abstract class WidgetBuilder {
public abstract class WidgetBuilder<T extends Widget, B extends WidgetBuilder<T, B>> extends ElementBuilder<T, B> {
private final Widget widget;
protected WidgetBuilder(final Widget widget) {
this.widget = widget;
}
public WidgetBuilder withName(final String name) {
widget.setName(name);
return this;
}
public WidgetBuilder withDocumentation(final String documentation) {
widget.setDocumentation(documentation);
return this;
}
public WidgetBuilder havingDisplayLabel(final ExpressionBuilder displayLabelExpression) {
widget.setDisplayLabel(displayLabelExpression.build());
return this;
public B havingDisplayLabel(final ExpressionBuilder displayLabelExpression) {
getBuiltInstance().setDisplayLabel(displayLabelExpression.build());
return getThis();
}
public WidgetBuilder havingInputExpression(final ExpressionBuilder inputExpression) {
widget.setInputExpression(inputExpression.build());
return this;
public B havingInputExpression(final ExpressionBuilder inputExpression) {
getBuiltInstance().setInputExpression(inputExpression.build());
return getThis();
}
public WidgetBuilder withReturnTypeModifier(final String returnTypeModifier) {
widget.setReturnTypeModifier(returnTypeModifier);
return this;
public B withReturnTypeModifier(final String returnTypeModifier) {
getBuiltInstance().setReturnTypeModifier(returnTypeModifier);
return getThis();
}
public Widget build() {
return widget;
}
}
/**
* Copyright (C) 2014 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.model.parameter.builders;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.parameter.ParameterFactory;
/**
* @author Romain Bioteau
*
*/
public class ParameterBuilder {
public static ParameterBuilder create() {
return new ParameterBuilder();
}
private final Parameter parameter;
private ParameterBuilder() {
parameter = ParameterFactory.eINSTANCE.createParameter();
}
public ParameterBuilder withName(final String name) {
parameter.setName(name);
return this;
}
public ParameterBuilder withDescription(final String description) {
parameter.setDescription(description);
return this;
}
public ParameterBuilder withType(final String className) {
parameter.setTypeClassname(className);
return this;
}
public ParameterBuilder withValue(final String value) {
parameter.setValue(value);
return this;
}
public Parameter build() {
return parameter;
}
}
/**
* Copyright (C) 2014 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.model.process.builders;
import org.bonitasoft.studio.model.expression.builders.ExpressionBuilder;
import org.bonitasoft.studio.model.process.Activity;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.MultiInstanceType;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class ActivityBuilder<T extends Activity, B extends ActivityBuilder<T, B>> extends FlowElementBuilder<T, B> {
public static ActivityBuilder<?, ?> create() {
return new ActivityBuilder();
}
public B withDuration(final String duration) {
getBuiltInstance().setDuration(duration);
return getThis();
}
public B withMultiInstanceType(final MultiInstanceType type) {
getBuiltInstance().setType(type);
return getThis();
}
public B havingCardinalityExpression(final ExpressionBuilder cardinalityExpression) {
getBuiltInstance().setCardinalityExpression(cardinalityExpression.build());
return getThis();
}
public B havingCompletionCondition(final ExpressionBuilder completionConditionExpression) {
getBuiltInstance().setCompletionCondition(completionConditionExpression.build());
return getThis();
}
public B havingLoopCondition(final ExpressionBuilder loopConditionExpression) {
getBuiltInstance().setLoopCondition(loopConditionExpression.build());
return getThis();
}
public B havingMaximumLoop(final ExpressionBuilder maximumLoopExpression) {
getBuiltInstance().setLoopMaximum(maximumLoopExpression.build());
return getThis();
}
public B havingIteratorExpression(final ExpressionBuilder iteratorExpression) {
getBuiltInstance().setIteratorExpression(iteratorExpression.build());
return getThis();
}
public B havingCollectionDataToMultiInstantiate(final Data data) {
getBuiltInstance().setCollectionDataToMultiInstantiate(data);
return getThis();
}
public B havingListDataContainingOutputResults(final Data data) {
getBuiltInstance().setListDataContainingOutputResults(data);
return getThis();
}
public B havingOutputData(final Data outputData) {
getBuiltInstance().setOutputData(outputData);
return getThis();
}
public B storeOutputResult() {
getBuiltInstance().setStoreOutput(true);
return getThis();
}
public B ignoreOutputResult() {
getBuiltInstance().setStoreOutput(false);
return getThis();
}
public B basedOnCardinality() {
getBuiltInstance().setUseCardinality(true);
return getThis();
}
public B basedOnCollection() {
getBuiltInstance().setUseCardinality(false);
return getThis();
}
public B testBefore() {
getBuiltInstance().setTestBefore(true);
return getThis();
}
public B testAfter() {
getBuiltInstance().setTestBefore(false);
return getThis();
}
public B havingData(final DataBuilder<?, ?>... data) {
if (data != null) {
for (final DataBuilder<?, ?> dataBuilder : data) {
getBuiltInstance().getData().add(dataBuilder.build());
}
}
return getThis();
}
@Override
protected T newInstance() {
return (T) ProcessFactory.eINSTANCE.createActivity();
}
}
/**
* Copyright (C) 2014 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.model.process.builders;
import org.bonitasoft.studio.model.process.BooleanType;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class BooleanDataTypeBuilder extends DataTypeBuilder<BooleanType, BooleanDataTypeBuilder> {
public static BooleanDataTypeBuilder create() {
return new BooleanDataTypeBuilder();
}
@Override
protected BooleanType newInstance() {
return ProcessFactory.eINSTANCE.createBooleanType();
}
}
/**
* Copyright (C) 2014 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.model.process.builders;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class BusinessObjectDataBuilder extends JavaObjectDataBuilder<BusinessObjectData, BusinessObjectDataBuilder> {
public static BusinessObjectDataBuilder create() {
return new BusinessObjectDataBuilder();
}
public BusinessObjectDataBuilder withBusinessDataRepositoryId(final String businessDataRepositoryId) {
getBuiltInstance().setBusinessDataRepositoryId(businessDataRepositoryId);
return getThis();
}
public BusinessObjectDataBuilder withEClassName(final String eClassName) {
getBuiltInstance().setEClassName(eClassName);
return getThis();
}
public BusinessObjectDataBuilder createNewInstance() {
getBuiltInstance().setCreateNewInstance(true);
return getThis();
}
public BusinessObjectDataBuilder doNotCreateNewInstance() {
getBuiltInstance().setCreateNewInstance(false);
return getThis();
}
@Override
protected BusinessObjectData newInstance() {
return ProcessFactory.eINSTANCE.createBusinessObjectData();
}
}
/**
* Copyright (C) 2014 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.model.process.builders;
import org.bonitasoft.studio.model.process.BusinessObjectType;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class BusinessObjectDataTypeBuilder extends DataTypeBuilder<BusinessObjectType, BusinessObjectDataTypeBuilder> {
public static BusinessObjectDataTypeBuilder createBusinessObjectDataType() {
return new BusinessObjectDataTypeBuilder();
}
@Override
protected BusinessObjectType newInstance() {
return ProcessFactory.eINSTANCE.createBusinessObjectType();
}
}
/**
* Copyright (C) 2014 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.model.process.builders;
import org.bonitasoft.studio.model.expression.builders.ExpressionBuilder;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.ProcessFactory;
/**
* @author Romain Bioteau
*
*/
public class DataBuilder<T extends Data, B extends DataBuilder<T, B>> extends ElementBuilder<T, B> {
public static DataBuilder<?, ?> create() {
return new DataBuilder();
}
public B withDatasourceId(final String datasourceId) {
getBuiltInstance().setDatasourceId(datasourceId);
return getThis();
}
public B isTransient() {
getBuiltInstance().setTransient(true);
return getThis();