Commit 08534c20 authored by Aurelien Pupier's avatar Aurelien Pupier
Browse files

Merge pull request #249 from bonitasoft/fix/BS-14187_delete_bdm

BS-14187 enable deletion of bdm
parents 323c7a6e b56d81fd
......@@ -145,4 +145,5 @@ disabledMandatoryTooltip=A multiple attribute cannot be mandatory.
defaultValue=Default value
defaultValueReturnTypeValidationMessage=Default value expression returns {0} but {1} is expected
addBusinessObjectDataWindowTitle=New business variable
defaultValueBusinessDataTooltip=Business data can be initialized with existing Business Objects using a query\nor by creating a new one using a Groovy Script and the provided dao variable (XXXDAO.newInstance()).
\ No newline at end of file
defaultValueBusinessDataTooltip=Business data can be initialized with existing Business Objects using a query\nor by creating a new one using a Groovy Script and the provided dao variable (XXXDAO.newInstance()).
cleaningBusinessObjects=Cleaning Business data model...
\ No newline at end of file
......@@ -19,6 +19,7 @@ import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
......@@ -83,6 +84,7 @@ public class DeployBDMOperationTest {
when(manager.getTenantAdministrationAPI((APISession) anyObject())).thenReturn(tenantAdminAPI);
doReturn(manager).when(operationUnderTest).getBOSEngineManagerEx();
doNothing().when(operationUnderTest).updateDependency(any(byte[].class));
doNothing().when(operationUnderTest).removeDependency();
parentFolder = new File("test");
parentFolder.mkdirs();
doReturn(parentFolder).when(operationUnderTest).getTargetFolder();
......@@ -131,4 +133,20 @@ public class DeployBDMOperationTest {
verify(tenantAdminAPI).getClientBDMZip();
}
@Test
public void should_uninstall_bdm_from_tenant_when_bdm_is_empty() throws Exception {
final BusinessObjectModel emptyBom = new BusinessObjectModel();
doReturn(emptyBom).when(bdmFileStore).getContent();
doReturn(parentFolder).when(operationUnderTest).getTargetFolder();
operationUnderTest.run(Repository.NULL_PROGRESS_MONITOR);
verify(manager).loginDefaultTenant(Repository.NULL_PROGRESS_MONITOR);
verify(bdmFileStore).getContent();
final InOrder inOrder = inOrder(tenantAdminAPI);
inOrder.verify(tenantAdminAPI).pause();
inOrder.verify(tenantAdminAPI).uninstallBusinessDataModel();
inOrder.verify(tenantAdminAPI).resume();
verify(operationUnderTest).removeDependency();
verify(tenantAdminAPI, never()).installBusinessDataModel(any(byte[].class));
}
}
......@@ -23,6 +23,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.bonitasoft.engine.api.TenantAdministrationAPI;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.business.data.BusinessDataRepositoryDeploymentException;
import org.bonitasoft.engine.exception.UpdateException;
import org.bonitasoft.engine.session.APISession;
......@@ -93,18 +94,20 @@ public class DeployBDMOperation implements IRunnableWithProgress {
}
}
private String progressMessage(BusinessObjectModel bom) {
return containsBusinessObjects(bom) ? Messages.deployingBusinessObjects : Messages.cleaningBusinessObjects;
}
protected void doDeployBDM(IProgressMonitor monitor) throws InvocationTargetException {
if (monitor == null) {
monitor = Repository.NULL_PROGRESS_MONITOR;
}
if (fileStore.getContent().getBusinessObjects().isEmpty()) {
return;
}
monitor.beginTask(Messages.deployingBusinessObjects, IProgressMonitor.UNKNOWN);
BonitaStudioLog.debug(Messages.deployingBusinessObjects, BusinessObjectPlugin.PLUGIN_ID);
final BusinessObjectModel bom = fileStore.getContent();
final String progressMessage = progressMessage(bom);
monitor.beginTask(progressMessage, IProgressMonitor.UNKNOWN);
BonitaStudioLog.debug(progressMessage, BusinessObjectPlugin.PLUGIN_ID);
final BOSEngineManager engineManagerEx = getBOSEngineManagerEx();
TenantAdministrationAPI tenantManagementAPI = null;
try {
tenantManagementAPI = engineManagerEx.getTenantAdministrationAPI(session);
......@@ -120,12 +123,19 @@ public class DeployBDMOperation implements IRunnableWithProgress {
} catch (final BusinessDataRepositoryDeploymentException bdrde) {
// ignore exception
}
tenantManagementAPI.installBusinessDataModel(fileStore.toByteArray());
if (containsBusinessObjects(bom)) {
tenantManagementAPI.installBusinessDataModel(fileStore.toByteArray());
}
tenantManagementAPI.resume();
final byte[] zipContent = tenantManagementAPI.getClientBDMZip();
final byte[] jarContent = retrieveModelJarContent(zipContent);
updateDependency(jarContent);
if (containsBusinessObjects(bom)) {
final byte[] zipContent = tenantManagementAPI.getClientBDMZip();
final byte[] jarContent = retrieveModelJarContent(zipContent);
updateDependency(jarContent);
} else {
removeDependency();
}
} catch (final Exception e) {
BonitaStudioLog.error(e);
try {
......@@ -150,6 +160,19 @@ public class DeployBDMOperation implements IRunnableWithProgress {
}
}
protected void removeDependency() {
final DependencyRepositoryStore dependencyRepositoryStore = RepositoryManager.getInstance()
.getRepositoryStore(DependencyRepositoryStore.class);
final DependencyFileStore bdmFileStore = dependencyRepositoryStore.getChild(BusinessObjectModelFileStore.DEFAULT_BDM_FILENAME);
if (bdmFileStore != null) {
bdmFileStore.delete();
}
}
private boolean containsBusinessObjects(final BusinessObjectModel bom) {
return bom != null && !bom.getBusinessObjects().isEmpty();
}
protected boolean dropDBOnInstall() {
final IPreferenceStore preferenceStore = EnginePlugin.getDefault().getPreferenceStore();
return preferenceStore.getBoolean(EnginePreferenceConstants.DROP_BUSINESS_DATA_DB_ON_INSTALL);
......
......@@ -314,6 +314,7 @@ public class Messages extends NLS {
public static String addBusinessObjectDataWindowTitle;
public static String editBusinessObjectDataWindowTitle;
public static String defaultValueBusinessDataTooltip;
public static String cleaningBusinessObjects;
private Messages() {
}
......
......@@ -107,30 +107,33 @@ public class ManageBusinessDataModelWizard extends Wizard {
return false;
}
private boolean validateAndSaveBDM() {
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.validatingBDM, IProgressMonitor.UNKNOWN);
if (businessObjectModel.getBusinessObjects().isEmpty()) {
throw new InvocationTargetException(new Exception(Messages.atLeastOneBusinessObjectShouldExists));
}
for (final BusinessObject bo : businessObjectModel.getBusinessObjects()) {
if (bo.getFields().isEmpty()) {
throw new InvocationTargetException(new Exception(Messages.bind(Messages.atLeastOneAttributeShouldExists,
NamingUtils.getSimpleName(bo.getQualifiedName()))));
}
for (final Index index : bo.getIndexes()) {
validateIndex(index, bo);
}
for (final UniqueConstraint uc : bo.getUniqueConstraints()) {
validateUniqueConstraint(uc, bo);
fStore.delete();
} else {
monitor.beginTask(Messages.validatingBDM, IProgressMonitor.UNKNOWN);
for (final BusinessObject bo : businessObjectModel.getBusinessObjects()) {
if (bo.getFields().isEmpty()) {
throw new InvocationTargetException(new Exception(Messages.bind(Messages.atLeastOneAttributeShouldExists,
NamingUtils.getSimpleName(bo.getQualifiedName()))));
}
for (final Index index : bo.getIndexes()) {
validateIndex(index, bo);
}
for (final UniqueConstraint uc : bo.getUniqueConstraints()) {
validateUniqueConstraint(uc, bo);
}
}
monitor.setTaskName(Messages.saving);
fStore.save(businessObjectModel);
monitor.done();
}
monitor.beginTask(Messages.saving, IProgressMonitor.UNKNOWN);
fStore.save(businessObjectModel);
}
});
} catch (final InvocationTargetException e) {
......@@ -155,7 +158,7 @@ public class ManageBusinessDataModelWizard extends Wizard {
} catch (final InvocationTargetException e) {
new BonitaErrorDialog(Display.getDefault().getActiveShell(), Messages.installFailedTitle, Messages.installFailedMessage,
handleTargetExceptionStacktrace(e))
.open();
.open();
return false;
} catch (final InterruptedException e) {
return false;
......
Supports Markdown
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