Commit 22da19df authored by Romain Bioteau's avatar Romain Bioteau

BS-12121

Fix apis
parent 50217725
......@@ -42,13 +42,13 @@ Require-Bundle: org.bonitasoft.studio.engine;bundle-version="1.0.0",
Export-Package: org.bonitasoft.studio.businessobject.core.operation,or
g.bonitasoft.studio.businessobject.core.repository,org.bonitasoft.stu
dio.businessobject.ui,org.bonitasoft.studio.businessobject.ui.wizard
Import-Package: com.bonitasoft.engine.api,
com.bonitasoft.engine.bdm,
com.bonitasoft.engine.bdm.dao,
com.bonitasoft.engine.bdm.model,
com.bonitasoft.engine.bdm.model.field,
com.bonitasoft.engine.bdm.validator,
com.bonitasoft.engine.businessdata,
Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.bdm,
org.bonitasoft.engine.bdm.dao,
org.bonitasoft.engine.bdm.model,
org.bonitasoft.engine.bdm.model.field,
org.bonitasoft.engine.bdm.validator,
org.bonitasoft.engine.business.data,
org.bonitasoft.engine.exception,
org.bonitasoft.engine.platform,
org.bonitasoft.engine.session
......@@ -24,11 +24,11 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import com.bonitasoft.engine.bdm.model.Query;
import com.bonitasoft.engine.bdm.model.field.FieldType;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -27,6 +25,11 @@ import static org.mockito.Mockito.when;
import java.io.File;
import org.bonitasoft.engine.api.TenantAdministrationAPI;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.common.repository.Repository;
......@@ -39,15 +42,8 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.api.TenantManagementAPI;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import com.bonitasoft.engine.bdm.model.field.FieldType;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
*
*/
@RunWith(MockitoJUnitRunner.class)
public class DeployBDMOperationTest {
......@@ -58,7 +54,7 @@ public class DeployBDMOperationTest {
private BOSEngineManager manager;
@Mock
private TenantManagementAPI tenantManagementAPI;
private TenantAdministrationAPI tenantAdminAPI;
@Mock
private BusinessObjectModelFileStore bdmFileStore;
......@@ -84,7 +80,7 @@ public class DeployBDMOperationTest {
doReturn(bom).when(bdmFileStore).getContent();
doReturn(new byte[512]).when(operationUnderTest).retrieveModelJarContent(any(byte[].class));
doReturn(false).when(operationUnderTest).dropDBOnInstall();
when(manager.getTenantManagementAPI((APISession) anyObject())).thenReturn(tenantManagementAPI);
when(manager.getTenantAdministrationAPI((APISession) anyObject())).thenReturn(tenantAdminAPI);
doReturn(manager).when(operationUnderTest).getBOSEngineManagerEx();
doNothing().when(operationUnderTest).updateDependency(any(byte[].class));
parentFolder = new File("test");
......@@ -112,12 +108,12 @@ public class DeployBDMOperationTest {
operationUnderTest.run(Repository.NULL_PROGRESS_MONITOR);
verify(manager).loginDefaultTenant(Repository.NULL_PROGRESS_MONITOR);
verify(bdmFileStore).getContent();
final InOrder inOrder = inOrder(tenantManagementAPI);
inOrder.verify(tenantManagementAPI).pause();
inOrder.verify(tenantManagementAPI).uninstallBusinessDataModel();
inOrder.verify(tenantManagementAPI).installBusinessDataModel(any(byte[].class));
inOrder.verify(tenantManagementAPI).resume();
verify(tenantManagementAPI).getClientBDMZip();
final InOrder inOrder = inOrder(tenantAdminAPI);
inOrder.verify(tenantAdminAPI).pause();
inOrder.verify(tenantAdminAPI).uninstallBusinessDataModel();
inOrder.verify(tenantAdminAPI).installBusinessDataModel(any(byte[].class));
inOrder.verify(tenantAdminAPI).resume();
verify(tenantAdminAPI).getClientBDMZip();
}
@Test
......@@ -127,12 +123,12 @@ public class DeployBDMOperationTest {
operationUnderTest.run(Repository.NULL_PROGRESS_MONITOR);
verify(manager).loginDefaultTenant(Repository.NULL_PROGRESS_MONITOR);
verify(bdmFileStore).getContent();
final InOrder inOrder = inOrder(tenantManagementAPI);
inOrder.verify(tenantManagementAPI).pause();
inOrder.verify(tenantManagementAPI).cleanAndUninstallBusinessDataModel();
inOrder.verify(tenantManagementAPI).installBusinessDataModel(any(byte[].class));
inOrder.verify(tenantManagementAPI).resume();
verify(tenantManagementAPI).getClientBDMZip();
final InOrder inOrder = inOrder(tenantAdminAPI);
inOrder.verify(tenantAdminAPI).pause();
inOrder.verify(tenantAdminAPI).cleanAndUninstallBusinessDataModel();
inOrder.verify(tenantAdminAPI).installBusinessDataModel(any(byte[].class));
inOrder.verify(tenantAdminAPI).resume();
verify(tenantAdminAPI).getClientBDMZip();
}
}
......@@ -32,10 +32,10 @@ import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import com.bonitasoft.engine.bdm.model.field.FieldType;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -42,10 +42,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import com.bonitasoft.engine.bdm.model.field.FieldType;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -29,7 +29,7 @@ import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObject;
/**
* @author Romain Bioteau
......
......@@ -31,7 +31,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
/**
......
......@@ -43,7 +43,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObject;
/**
* @author Romain Bioteau
......
......@@ -34,9 +34,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import com.bonitasoft.engine.bdm.model.UniqueConstraint;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.UniqueConstraint;
/**
......
......@@ -22,8 +22,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bonitasoft.engine.bdm.model.field.FieldType;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -23,7 +23,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -23,7 +23,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -23,9 +23,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bonitasoft.engine.bdm.model.field.RelationField;
import com.bonitasoft.engine.bdm.model.field.RelationField.Type;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.field.RelationField;
import org.bonitasoft.engine.bdm.model.field.RelationField.Type;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -22,9 +22,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.field.Field;
import com.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.field.Field;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -19,6 +17,8 @@ package org.bonitasoft.studio.businessobject.core.expression;
import java.util.HashSet;
import java.util.Set;
import org.bonitasoft.engine.bdm.dao.BusinessObjectDAO;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.studio.businessobject.BusinessObjectPlugin;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
......@@ -39,12 +39,8 @@ import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.graphics.Image;
import com.bonitasoft.engine.bdm.dao.BusinessObjectDAO;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
/**
* @author Romain Bioteau
*
*/
public class DAOExpressionProvider implements IExpressionProvider {
......
......@@ -13,6 +13,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.bonitasoft.engine.bdm.BDMQueryUtil;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.engine.bdm.model.QueryParameter;
import org.bonitasoft.studio.businessobject.BusinessObjectPlugin;
import org.bonitasoft.studio.businessobject.core.expression.model.BusinessObjectExpressionQuery;
import org.bonitasoft.studio.businessobject.core.expression.model.QueryExpressionModel;
......@@ -32,15 +37,8 @@ import org.bonitasoft.studio.pics.Pics;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.graphics.Image;
import com.bonitasoft.engine.bdm.BDMQueryUtil;
import com.bonitasoft.engine.bdm.model.BusinessObject;
import com.bonitasoft.engine.bdm.model.BusinessObjectModel;
import com.bonitasoft.engine.bdm.model.Query;
import com.bonitasoft.engine.bdm.model.QueryParameter;
/**
* @author Romain Bioteau
*
*/
public class QueryExpressionProvider implements IExpressionProvider {
......@@ -49,17 +47,17 @@ public class QueryExpressionProvider implements IExpressionProvider {
* @see org.bonitasoft.studio.expression.editor.provider.IExpressionProvider#getExpressions(org.eclipse.emf.ecore.EObject)
*/
@Override
public Set<Expression> getExpressions(EObject context) {
public Set<Expression> getExpressions(final EObject context) {
return Collections.emptySet();
}
public QueryExpressionModel buildQueryExpressionModel() {
BusinessObjectModel businessObjectModel = getBusinessObjectModel();
QueryExpressionModel queryExpressionModel = new QueryExpressionModel();
final BusinessObjectModel businessObjectModel = getBusinessObjectModel();
final QueryExpressionModel queryExpressionModel = new QueryExpressionModel();
if (businessObjectModel != null) {
for (BusinessObject bo : businessObjectModel.getBusinessObjects()) {
BusinessObjectExpressionQuery boQuery = new BusinessObjectExpressionQuery(bo.getQualifiedName());
List<Expression> expressions = getExpressions(bo);
for (final BusinessObject bo : businessObjectModel.getBusinessObjects()) {
final BusinessObjectExpressionQuery boQuery = new BusinessObjectExpressionQuery(bo.getQualifiedName());
final List<Expression> expressions = getExpressions(bo);
if (!expressions.isEmpty()) {
boQuery.getQueryExpressions().addAll(expressions);
queryExpressionModel.getBusinessObjects().add(boQuery);
......@@ -69,57 +67,57 @@ public class QueryExpressionProvider implements IExpressionProvider {
return queryExpressionModel;
}
protected List<Expression> getExpressions(BusinessObject bo) {
List<Expression> result = new ArrayList<Expression>();
for (Query q : BDMQueryUtil.createProvidedQueriesForBusinessObject(bo)) {
protected List<Expression> getExpressions(final BusinessObject bo) {
final List<Expression> result = new ArrayList<Expression>();
for (final Query q : BDMQueryUtil.createProvidedQueriesForBusinessObject(bo)) {
result.add(createExpression(bo, q));
}
for (Query q : bo.getQueries()) {
for (final Query q : bo.getQueries()) {
result.add(createExpression(bo, q));
}
return result;
}
private Expression createExpression(BusinessObject bo, Query q) {
Expression query = ExpressionFactory.eINSTANCE.createExpression();
String queryName = toQueryName(bo, q);
private Expression createExpression(final BusinessObject bo, final Query q) {
final Expression query = ExpressionFactory.eINSTANCE.createExpression();
final String queryName = toQueryName(bo, q);
query.setName(queryName);
query.setContent(q.getContent());
query.setReturnType(q.getReturnType());
query.setType(getExpressionType());
for (QueryParameter param : q.getQueryParameters()) {
for (final QueryParameter param : q.getQueryParameters()) {
query.getReferencedElements().add(createQueryParameterExpression(param, ""));
}
if (List.class.getName().equals(q.getReturnType())) {// Add pagination parameters
QueryParameter startIndexParam = new QueryParameter(BDMQueryUtil.START_INDEX_PARAM_NAME, Integer.class.getName());
final QueryParameter startIndexParam = new QueryParameter(BDMQueryUtil.START_INDEX_PARAM_NAME, Integer.class.getName());
query.getReferencedElements().add(createQueryParameterExpression(startIndexParam, "0"));
QueryParameter maxResultsParam = new QueryParameter(BDMQueryUtil.MAX_RESULTS_PARAM_NAME, Integer.class.getName());
final QueryParameter maxResultsParam = new QueryParameter(BDMQueryUtil.MAX_RESULTS_PARAM_NAME, Integer.class.getName());
query.getReferencedElements().add(createQueryParameterExpression(maxResultsParam, "20"));
}
return query;
}
private String toQueryName(BusinessObject bo, Query q) {
String name = NamingUtils.getSimpleName(bo.getQualifiedName());
private String toQueryName(final BusinessObject bo, final Query q) {
final String name = NamingUtils.getSimpleName(bo.getQualifiedName());
return name + "." + q.getName();
}
private Expression createQueryParameterExpression(QueryParameter param, String defaultValue) {
Expression queryParameter = ExpressionFactory.eINSTANCE.createExpression();
private Expression createQueryParameterExpression(final QueryParameter param, final String defaultValue) {
final Expression queryParameter = ExpressionFactory.eINSTANCE.createExpression();
queryParameter.setName(param.getName());
queryParameter.setContent(param.getName());
queryParameter.setType("QUERY_PARAM_TYPE");
queryParameter.setReturnTypeFixed(true);
queryParameter.setReturnType(param.getClassName());
Expression constantExpression = ExpressionHelper.createConstantExpression(defaultValue, param.getClassName());
final Expression constantExpression = ExpressionHelper.createConstantExpression(defaultValue, param.getClassName());
constantExpression.setReturnTypeFixed(true);
queryParameter.getReferencedElements().add(constantExpression);
return queryParameter;
}
protected BusinessObjectModel getBusinessObjectModel() {
BusinessObjectModelRepositoryStore repositoryStore = RepositoryManager.getInstance().getRepositoryStore(BusinessObjectModelRepositoryStore.class);
BusinessObjectModelFileStore fileStore = repositoryStore.getChild(BusinessObjectModelFileStore.DEFAULT_BDM_FILENAME);
final BusinessObjectModelRepositoryStore repositoryStore = RepositoryManager.getInstance().getRepositoryStore(BusinessObjectModelRepositoryStore.class);
final BusinessObjectModelFileStore fileStore = repositoryStore.getChild(BusinessObjectModelFileStore.DEFAULT_BDM_FILENAME);
if (fileStore != null) {
return fileStore.getContent();
}
......@@ -140,7 +138,7 @@ public class QueryExpressionProvider implements IExpressionProvider {
* @see org.bonitasoft.studio.expression.editor.provider.IExpressionProvider#getIcon(org.bonitasoft.studio.model.expression.Expression)
*/
@Override
public Image getIcon(Expression expression) {
public Image getIcon(final Expression expression) {
return Pics.getImage("query.png", BusinessObjectPlugin.getDefault());
}
......@@ -158,7 +156,7 @@ public class QueryExpressionProvider implements IExpressionProvider {
* @see org.bonitasoft.studio.expression.editor.provider.IExpressionProvider#getProposalLabel(org.bonitasoft.studio.model.expression.Expression)
*/
@Override
public String getProposalLabel(Expression expression) {
public String getProposalLabel(final Expression expression) {
return null;
}
......@@ -167,8 +165,8 @@ public class QueryExpressionProvider implements IExpressionProvider {
* @see org.bonitasoft.studio.expression.editor.provider.IExpressionProvider#isRelevantFor(org.eclipse.emf.ecore.EObject)
*/
@Override
public boolean isRelevantFor(EObject context) {
QueryExpressionModel buildQueryExpressionModel = buildQueryExpressionModel();
public boolean isRelevantFor(final EObject context) {
final QueryExpressionModel buildQueryExpressionModel = buildQueryExpressionModel();
return !buildQueryExpressionModel.getBusinessObjects().isEmpty();
}
......@@ -187,7 +185,7 @@ public class QueryExpressionProvider implements IExpressionProvider {
* org.eclipse.emf.ecore.EObject)
*/
@Override
public IExpressionEditor getExpressionEditor(Expression expression, EObject context) {
public IExpressionEditor getExpressionEditor(final Expression expression, final EObject context) {
return new QueryExpressionEditor();
}
......
......@@ -5,12 +5,10 @@
* 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,6 +22,8 @@ import java.lang.reflect.InvocationTargetException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.bonitasoft.engine.api.TenantAdministrationAPI;
import org.bonitasoft.engine.business.data.BusinessDataRepositoryDeploymentException;
import org.bonitasoft.engine.exception.UpdateException;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.businessobject.BusinessObjectPlugin;
......@@ -43,12 +43,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import com.bonitasoft.engine.api.TenantManagementAPI;
import com.bonitasoft.engine.businessdata.BusinessDataRepositoryDeploymentException;
/**
* @author Romain Bioteau
*
*/
public class DeployBDMOperation implements IRunnableWithProgress {
......@@ -104,10 +100,10 @@ public class DeployBDMOperation implements IRunnableWithProgress {
BonitaStudioLog.debug(Messages.deployingBusinessObjects, BusinessObjectPlugin.PLUGIN_ID);
final BOSEngineManager engineManagerEx = getBOSEngineManagerEx();
TenantManagementAPI tenantManagementAPI = null;
TenantAdministrationAPI tenantManagementAPI = null;
try {
tenantManagementAPI = engineManagerEx.getTenantManagementAPI(session);