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

feat(builder) add bonita-la-builder (#1004)

* integrate a new maven artifact to build la in a standalone way

Closes BS-18072
parent c29f0618
......@@ -414,6 +414,9 @@ public class BonitaStudioWorkbenchAdvisor extends WorkbenchAdvisor implements IS
}
protected void doInitWorkspace() {
//Avoid deadlock when starting engine caused by ProcessConsoleManger triggering some UI dependent code in a non UI thread.
DebugUIPlugin.getDefault().getProcessConsoleManager();
SourceLookupManager.getDefault();
WorkspaceInitializationJob workspaceInitializationJob = new WorkspaceInitializationJob(repositoryAccessor);
workspaceInitializationJob.addJobChangeListener(new JobChangeAdapter() {
......
......@@ -82,6 +82,7 @@ Export-Package: org.bonitasoft.studio.common,
org.bonitasoft.studio.common.jface.dialog,
org.bonitasoft.studio.common.jface.selection,
org.bonitasoft.studio.common.log,
org.bonitasoft.studio.common.model,
org.bonitasoft.studio.common.palette,
org.bonitasoft.studio.common.perspectives,
org.bonitasoft.studio.common.platform.tools,
......
......@@ -17,11 +17,18 @@ package org.bonitasoft.studio.common.emf.tools;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.expression.assertions.ExpressionAssert.assertThat;
import static org.bonitasoft.studio.model.expression.builders.ExpressionBuilder.anExpression;
import static org.bonitasoft.studio.model.process.builders.BooleanDataTypeBuilder.aBooleanDataType;
import static org.bonitasoft.studio.model.process.builders.DateDataTypeBuilder.aDateDataType;
import static org.bonitasoft.studio.model.process.builders.DoubleDataTypeBuilder.aDoubleDataType;
import static org.bonitasoft.studio.model.process.builders.IntegerDataTypeBuilder.anIntegerDataType;
import static org.bonitasoft.studio.model.process.builders.JavaDataTypeBuilder.aJavaDataType;
import static org.bonitasoft.studio.model.process.builders.LongDataTypeBuilder.aLongDataType;
import static org.bonitasoft.studio.model.process.builders.MainProcessBuilder.aMainProcess;
import static org.bonitasoft.studio.model.process.builders.StringDataTypeBuilder.aStringDataType;
import static org.bonitasoft.studio.model.process.builders.TaskBuilder.aTask;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -34,7 +41,6 @@ import org.bonitasoft.studio.connector.model.definition.Output;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.expression.provider.ExpressionItemProviderAdapterFactory;
import org.bonitasoft.studio.model.form.DateFormField;
import org.bonitasoft.studio.model.form.Duplicable;
import org.bonitasoft.studio.model.form.FormFactory;
......@@ -43,20 +49,23 @@ import org.bonitasoft.studio.model.form.TextFormField;
import org.bonitasoft.studio.model.form.Widget;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.parameter.ParameterFactory;
import org.bonitasoft.studio.model.process.BooleanType;
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.DateType;
import org.bonitasoft.studio.model.process.Document;
import org.bonitasoft.studio.model.process.DoubleType;
import org.bonitasoft.studio.model.process.IntegerType;
import org.bonitasoft.studio.model.process.JavaObjectData;
import org.bonitasoft.studio.model.process.JavaType;
import org.bonitasoft.studio.model.process.LongType;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.SearchIndex;
import org.bonitasoft.studio.model.process.StringType;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.junit.Test;
/**
......@@ -173,76 +182,6 @@ public class ExpressionHelperTest {
assertThat(expression.getReturnType()).isEqualTo(String.class.getName());
}
@Test
public void shouldClearExpressionWithEditingDomain_SetEmptyExpression() throws Exception {
final Expression expression = ExpressionFactory.eINSTANCE.createExpression();
expression.setName("Toto");
expression.setContent("Titi2014");
expression.setType(ExpressionConstants.SCRIPT_TYPE);
expression.setReturnType(DocumentValue.class.getName());
expression.getReferencedElements().add(ProcessFactory.eINSTANCE.createData());
final CompoundCommand compoundCommand = ExpressionHelper.clearExpression(expression, new AdapterFactoryEditingDomain(
new ExpressionItemProviderAdapterFactory(), new BasicCommandStack()));
assertThat(compoundCommand).isNotNull();
assertThat(compoundCommand.canExecute()).isTrue();
compoundCommand.execute();
assertThat(expression.getName()).isEmpty();
assertThat(expression.getContent()).isEmpty();
assertThat(expression.getType()).isEqualTo(ExpressionConstants.CONSTANT_TYPE);
assertThat(expression.getReferencedElements()).isEmpty();
assertThat(expression.getReturnType()).isEqualTo(String.class.getName());
}
@Test
public void shouldClearExpressionWithEditingDomain_SetEmptyExpressionButKeeptFixedReturnType() throws Exception {
final Expression expression = ExpressionFactory.eINSTANCE.createExpression();
expression.setName("Toto");
expression.setContent("Titi2014");
expression.setType(ExpressionConstants.SCRIPT_TYPE);
expression.setReturnType(DocumentValue.class.getName());
expression.setReturnTypeFixed(true);
expression.getReferencedElements().add(ProcessFactory.eINSTANCE.createData());
final CompoundCommand compoundCommand = ExpressionHelper.clearExpression(expression, new AdapterFactoryEditingDomain(
new ExpressionItemProviderAdapterFactory(), new BasicCommandStack()));
assertThat(compoundCommand).isNotNull();
assertThat(compoundCommand.canExecute()).isTrue();
compoundCommand.execute();
assertThat(expression.getName()).isEmpty();
assertThat(expression.getContent()).isEmpty();
assertThat(expression.getType()).isEqualTo(ExpressionConstants.CONSTANT_TYPE);
assertThat(expression.getReferencedElements()).isEmpty();
assertThat(expression.getReturnType()).isEqualTo(DocumentValue.class.getName());
}
@Test
public void shouldClearExpressionWithEditingDomain_SetEmptyExpressionKeepingConditionType() throws Exception {
final Expression expression = ExpressionFactory.eINSTANCE.createExpression();
expression.setName("Toto");
expression.setContent("Titi2014");
expression.setType(ExpressionConstants.CONDITION_TYPE);
expression.setReturnType(DocumentValue.class.getName());
expression.setReturnTypeFixed(true);
expression.getReferencedElements().add(ProcessFactory.eINSTANCE.createData());
final CompoundCommand compoundCommand = ExpressionHelper.clearExpression(expression, new AdapterFactoryEditingDomain(
new ExpressionItemProviderAdapterFactory(), new BasicCommandStack()));
assertThat(compoundCommand).isNotNull();
assertThat(compoundCommand.canExecute()).isTrue();
compoundCommand.execute();
assertThat(expression.getName()).isEmpty();
assertThat(expression.getContent()).isEmpty();
assertThat(expression.getType()).isEqualTo(ExpressionConstants.CONDITION_TYPE);
assertThat(expression.getReferencedElements()).isEmpty();
assertThat(expression.getReturnType()).isEqualTo(DocumentValue.class.getName());
}
@Test(expected = IllegalArgumentException.class)
public void shouldClearExpression_ThrowIllegalArgumentException() throws Exception {
......@@ -488,4 +427,53 @@ public class ExpressionHelperTest {
assertThat(data.getDataType()).isEqualTo(stringDataType);
}
@Test
public void should_get_StringType_for_String_classname() throws Exception {
final StringType stringDataType = aStringDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(stringDataType).build(),
String.class.getName())).isEqualTo(stringDataType);
}
@Test
public void should_get_BooleanType_for_Boolean_classname() throws Exception {
final BooleanType booleanDataType = aBooleanDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(booleanDataType).build(),
Boolean.class.getName())).isEqualTo(booleanDataType);
}
@Test
public void should_get_IntegerType_for_Integer_classname() throws Exception {
final IntegerType integerDataType = anIntegerDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(integerDataType).build(),
Integer.class.getName())).isEqualTo(integerDataType);
}
@Test
public void should_get_DoubleType_for_Double_classname() throws Exception {
final DoubleType doubleDataType = aDoubleDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(doubleDataType).build(),
Double.class.getName())).isEqualTo(doubleDataType);
}
@Test
public void should_get_LongType_for_Long_classname() throws Exception {
final LongType longDataType = aLongDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(longDataType).build(),
Long.class.getName())).isEqualTo(longDataType);
}
@Test
public void should_get_DateType_for_Date_classname() throws Exception {
final DateType dataDataType = aDateDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(dataDataType).build(),
Date.class.getName())).isEqualTo(dataDataType);
}
@Test
public void should_get_JavaType_for_Other_classname() throws Exception {
final JavaType javaDataType = aJavaDataType().build();
assertThat(ExpressionHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(javaDataType).build(),
Object.class.getName())).isEqualTo(javaDataType);
}
}
......@@ -15,21 +15,11 @@
package org.bonitasoft.studio.common.emf.tools;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.studio.model.process.builders.BooleanDataTypeBuilder.aBooleanDataType;
import static org.bonitasoft.studio.model.process.builders.DateDataTypeBuilder.aDateDataType;
import static org.bonitasoft.studio.model.process.builders.DoubleDataTypeBuilder.aDoubleDataType;
import static org.bonitasoft.studio.model.process.builders.IntegerDataTypeBuilder.anIntegerDataType;
import static org.bonitasoft.studio.model.process.builders.JavaDataTypeBuilder.aJavaDataType;
import static org.bonitasoft.studio.model.process.builders.LongDataTypeBuilder.aLongDataType;
import static org.bonitasoft.studio.model.process.builders.MainProcessBuilder.aMainProcess;
import static org.bonitasoft.studio.model.process.builders.StringDataTypeBuilder.aStringDataType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.Operation;
......@@ -39,18 +29,11 @@ import org.bonitasoft.studio.model.form.TextFormField;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.parameter.ParameterFactory;
import org.bonitasoft.studio.model.process.Activity;
import org.bonitasoft.studio.model.process.BooleanType;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.DateType;
import org.bonitasoft.studio.model.process.Document;
import org.bonitasoft.studio.model.process.DoubleType;
import org.bonitasoft.studio.model.process.Element;
import org.bonitasoft.studio.model.process.IntegerType;
import org.bonitasoft.studio.model.process.JavaType;
import org.bonitasoft.studio.model.process.LongType;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.StringType;
import org.bonitasoft.studio.model.process.Task;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
......@@ -491,52 +474,4 @@ public class ModelHelperTest {
assertFalse(ModelHelper.isSameElement(data, refData));
}
@Test
public void should_get_StringType_for_String_classname() throws Exception {
final StringType stringDataType = aStringDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(stringDataType).build()
, String.class.getName())).isEqualTo(stringDataType);
}
@Test
public void should_get_BooleanType_for_Boolean_classname() throws Exception {
final BooleanType booleanDataType = aBooleanDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(booleanDataType).build()
, Boolean.class.getName())).isEqualTo(booleanDataType);
}
@Test
public void should_get_IntegerType_for_Integer_classname() throws Exception {
final IntegerType integerDataType = anIntegerDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(integerDataType).build()
, Integer.class.getName())).isEqualTo(integerDataType);
}
@Test
public void should_get_DoubleType_for_Double_classname() throws Exception {
final DoubleType doubleDataType = aDoubleDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(doubleDataType).build()
, Double.class.getName())).isEqualTo(doubleDataType);
}
@Test
public void should_get_LongType_for_Long_classname() throws Exception {
final LongType longDataType = aLongDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(longDataType).build()
, Long.class.getName())).isEqualTo(longDataType);
}
@Test
public void should_get_DateType_for_Date_classname() throws Exception {
final DateType dataDataType = aDateDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(dataDataType).build()
, Date.class.getName())).isEqualTo(dataDataType);
}
@Test
public void should_get_JavaType_for_Other_classname() throws Exception {
final JavaType javaDataType = aJavaDataType().build();
assertThat(ModelHelper.getDataTypeByClassName(aMainProcess().havingDatatypes(javaDataType).build()
, Object.class.getName())).isEqualTo(javaDataType);
}
}
......@@ -14,10 +14,15 @@
*/
package org.bonitasoft.studio.common.emf.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.find;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Objects;
......@@ -28,7 +33,6 @@ import org.bonitasoft.studio.common.Messages;
import org.bonitasoft.studio.connector.model.definition.Output;
import org.bonitasoft.studio.model.expression.Expression;
import org.bonitasoft.studio.model.expression.ExpressionFactory;
import org.bonitasoft.studio.model.expression.ExpressionPackage;
import org.bonitasoft.studio.model.expression.Operation;
import org.bonitasoft.studio.model.expression.Operator;
import org.bonitasoft.studio.model.form.Duplicable;
......@@ -36,27 +40,29 @@ import org.bonitasoft.studio.model.form.FormFactory;
import org.bonitasoft.studio.model.form.GroupIterator;
import org.bonitasoft.studio.model.form.Widget;
import org.bonitasoft.studio.model.parameter.Parameter;
import org.bonitasoft.studio.model.process.BooleanType;
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.DateType;
import org.bonitasoft.studio.model.process.Document;
import org.bonitasoft.studio.model.process.DoubleType;
import org.bonitasoft.studio.model.process.EnumType;
import org.bonitasoft.studio.model.process.IntegerType;
import org.bonitasoft.studio.model.process.JavaObjectData;
import org.bonitasoft.studio.model.process.JavaType;
import org.bonitasoft.studio.model.process.LongType;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.model.process.MultiInstantiable;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.SearchIndex;
import org.bonitasoft.studio.model.process.StringType;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
/**
* @author Romain Bioteau
......@@ -217,32 +223,6 @@ public class ExpressionHelper {
return widgetDependency;
}
public static CompoundCommand clearExpression(final Expression expr, final EditingDomain editingDomain) {
if (editingDomain != null) {
String returnType = expr.getReturnType();
if (!expr.isReturnTypeFixed() || expr.getReturnType() == null) {
returnType = String.class.getName();
}
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__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()));
return cc;
} else {
clearExpression(expr);
return null;
}
}
public static void clearExpression(final Expression expr) {
Assert.isLegal(expr != null, "Expression cannot be null.");
expr.setName("");
......@@ -466,9 +446,32 @@ public class ExpressionHelper {
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);
return mainProcess.getDatatypes().stream()
.filter(BusinessObjectType.class::isInstance)
.findFirst().orElse(null);
} else {
return getDataTypeByClassName(mainProcess, returnType);
}
}
static DataType getDataTypeByClassName(final MainProcess dataTypeContainer, final String returnTypeClassname) {
checkArgument(dataTypeContainer != null);
checkArgument(returnTypeClassname != null);
if (returnTypeClassname.equals(Boolean.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(BooleanType.class), null);
} else if (returnTypeClassname.equals(String.class.getName())) {
return find(dataTypeContainer.getDatatypes(), and(instanceOf(StringType.class), not(instanceOf(DateType.class))),
null);
} else if (returnTypeClassname.equals(Double.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(DoubleType.class), null);
} else if (returnTypeClassname.equals(Long.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(LongType.class), null);
} else if (returnTypeClassname.equals(Integer.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(IntegerType.class), null);
} else if (returnTypeClassname.equals(Date.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(DateType.class), null);
} else {
return ModelHelper.getDataTypeByClassName(mainProcess, returnType);
return find(dataTypeContainer.getDatatypes(), instanceOf(JavaType.class), null);
}
}
......
......@@ -15,16 +15,9 @@
package org.bonitasoft.studio.common.emf.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.find;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -474,26 +467,6 @@ public class ModelHelper {
return null;
}
public static DataType getDataTypeByClassName(final MainProcess dataTypeContainer, final String returnTypeClassname) {
checkArgument(dataTypeContainer != null);
checkArgument(returnTypeClassname != null);
if (returnTypeClassname.equals(Boolean.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(BooleanType.class), null);
} else if (returnTypeClassname.equals(String.class.getName())) {
return find(dataTypeContainer.getDatatypes(), and(instanceOf(StringType.class), not(instanceOf(DateType.class))),
null);
} else if (returnTypeClassname.equals(Double.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(DoubleType.class), null);
} else if (returnTypeClassname.equals(Long.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(LongType.class), null);
} else if (returnTypeClassname.equals(Integer.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(IntegerType.class), null);
} else if (returnTypeClassname.equals(Date.class.getName())) {
return find(dataTypeContainer.getDatatypes(), instanceOf(DateType.class), null);
} else {
return find(dataTypeContainer.getDatatypes(), instanceOf(JavaType.class), null);
}
}
public static List<Data> getMessageSourceAccessibleData(final MessageFlow messageFlow) {
final List<Data> datas = new ArrayList<Data>();
......
/**
* Copyright (C) 2018 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.common.model;
import java.util.List;
import java.util.Optional;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Data;
import org.eclipse.emf.ecore.EObject;
public interface IModelSearch {
<T> List<T> getAllItemsOfType(EObject parent, Class<T> type);
boolean isInEvenementialSubProcessPool(EObject element);
<T> T getDirectParentOfType(EObject element, Class<T> type);
Optional<AbstractProcess> findProcess(String name, String version);
String getEObjectID(EObject element);
List<Data> getAccessibleData(EObject context);
}
/**
* Copyright (C) 2018 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.common.model;
import java.util.List;
import org.bonitasoft.studio.model.process.AbstractProcess;
public interface IProcessContextProvider {
List<AbstractProcess> getAllProcesses();
}
/**
* Copyright (C) 2018 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.common.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.DataAware;
import org.bonitasoft.studio.model.process.SequenceFlow;
import org.bonitasoft.studio.model.process.SubProcessEvent;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
public class ModelSearch implements IModelSearch {
private IProcessContextProvider processContextProvider;
public ModelSearch(IProcessContextProvider processContextProvider) {
this.processContextProvider = processContextProvider;
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.engine.export.IModelSearch#getAllItemsOfType(org.eclipse.emf.ecore.EObject, java.lang.Class)
*/
@Override
public <T> List<T> getAllItemsOfType(EObject parent, Class<T> type) {
final List<T> res = new ArrayList<T>();
addAllElementOfContainer(parent, res, type);
return res;
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.engine.export.IModelSearch#isInEvenementialSubProcessPool(org.eclipse.emf.ecore.EObject)
*/
@Override
public boolean isInEvenementialSubProcessPool(EObject element) {
EObject current = element;
while (current != null && !(current instanceof SubProcessEvent)) {
current = current.eContainer();
}
return current instanceof SubProcessEvent;
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.engine.export.IModelSearch#getDirectParentOfType(org.eclipse.emf.ecore.EObject, java.lang.Class)
*/
@Override
public <T> T getDirectParentOfType(EObject element, Class<T> type) {
EObject result = element;
while (result != null && !type.isAssignableFrom(result.getClass())) {
result = result.eContainer();
}
return type.isAssignableFrom(result.getClass()) ? (T) result : null;
}
private static <T> void addAllElementOfContainer(final EObject parent, final List<T> res,
final Class<T> type) {
if (parent != null) {
if (type.isAssignableFrom(parent.getClass())) {
res.add((T) parent);
}
for (final EObject child : parent.eContents()) {
addAllElementOfContainer(child, res, type);
}
}
}