Commit 1272a346 authored by Romain Bioteau's avatar Romain Bioteau

BS-14390

Install BDM dependencies on deploy
parent 56c1ebf5
......@@ -40,7 +40,9 @@ Require-Bundle: org.bonitasoft.studio.engine;bundle-version="1.0.0",
org.eclipse.emf.transaction,
org.eclipse.emf.databinding,
org.bonitasoft.studio.browser;bundle-version="6.5.0",
com.google.guava
com.google.guava,
org.eclipse.e4.core.services,
org.eclipse.osgi.services;bundle-version="3.4.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
......
......@@ -35,6 +35,7 @@ import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelFileStore;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.engine.BOSEngineManager;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -64,6 +65,9 @@ public class DeployBDMOperationTest {
private BusinessObjectModel bom;
@Mock
private IEventBroker eventBroker;
/**
* @throws java.lang.Exception
*/
......@@ -78,8 +82,9 @@ public class DeployBDMOperationTest {
bo.getFields().add(firstName);
bom.getBusinessObjects().add(bo);
operationUnderTest = spy(new DeployBDMOperation(bdmFileStore));
doReturn(eventBroker).when(operationUnderTest).eventBroker();
doReturn(bom).when(bdmFileStore).getContent();
doReturn(new byte[512]).when(operationUnderTest).retrieveModelJarContent(any(byte[].class));
doReturn(new byte[512]).when(operationUnderTest).retrieveContent(any(byte[].class));
doReturn(false).when(operationUnderTest).dropDBOnInstall();
when(manager.getTenantAdministrationAPI((APISession) anyObject())).thenReturn(tenantAdminAPI);
doReturn(manager).when(operationUnderTest).getBOSEngineManagerEx();
......@@ -125,11 +130,12 @@ public class DeployBDMOperationTest {
operationUnderTest.run(Repository.NULL_PROGRESS_MONITOR);
verify(manager).loginDefaultTenant(Repository.NULL_PROGRESS_MONITOR);
verify(bdmFileStore).getContent();
final InOrder inOrder = inOrder(tenantAdminAPI);
final InOrder inOrder = inOrder(tenantAdminAPI, eventBroker);
inOrder.verify(tenantAdminAPI).pause();
inOrder.verify(tenantAdminAPI).cleanAndUninstallBusinessDataModel();
inOrder.verify(tenantAdminAPI).installBusinessDataModel(any(byte[].class));
inOrder.verify(tenantAdminAPI).resume();
inOrder.verify(eventBroker).post("bdm/deployed", null);
verify(tenantAdminAPI).getClientBDMZip();
}
......
/**
* Copyright (C) 2013 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* Copyright (C) 2013-2015 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
......@@ -14,11 +14,15 @@
*/
package org.bonitasoft.studio.businessobject.core.operation;
import static com.google.common.io.ByteStreams.toByteArray;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
......@@ -42,16 +46,24 @@ import org.bonitasoft.studio.engine.EnginePlugin;
import org.bonitasoft.studio.engine.preferences.EnginePreferenceConstants;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.PlatformUI;
import com.google.common.base.Preconditions;
/**
* @author Romain Bioteau
*/
public class DeployBDMOperation implements IRunnableWithProgress {
private static final String BDM_DEPLOYED_TOPIC = "bdm/deployed";
private static final String BDM_CLIENT = "bdm-client";
private static final String BDM_DAO = "bdm-dao";
private static final String MODEL = "model";
private final BusinessObjectModelFileStore fileStore;
private APISession session;
......@@ -131,8 +143,12 @@ public class DeployBDMOperation implements IRunnableWithProgress {
if (containsBusinessObjects(bom)) {
final byte[] zipContent = tenantManagementAPI.getClientBDMZip();
final byte[] jarContent = retrieveModelJarContent(zipContent);
updateDependency(jarContent);
final Map<String, byte[]> jarContent = retrieveContent(zipContent);
updateDependency(jarContent.get(BDM_CLIENT));
final Map<String, Object> data = new HashMap<>();
data.put(MODEL, bom);
data.put(BDM_DAO, jarContent.get(BDM_DAO));
eventBroker().post(BDM_DEPLOYED_TOPIC, data);
} else {
removeDependency();
}
......@@ -160,6 +176,10 @@ public class DeployBDMOperation implements IRunnableWithProgress {
}
}
protected IEventBroker eventBroker() {
return (IEventBroker) PlatformUI.getWorkbench().getService(IEventBroker.class);
}
protected void removeDependency() {
final DependencyRepositoryStore dependencyRepositoryStore = RepositoryManager.getInstance()
.getRepositoryStore(DependencyRepositoryStore.class);
......@@ -178,25 +198,23 @@ public class DeployBDMOperation implements IRunnableWithProgress {
return preferenceStore.getBoolean(EnginePreferenceConstants.DROP_BUSINESS_DATA_DB_ON_INSTALL);
}
protected byte[] retrieveModelJarContent(final byte[] zipContent) throws IOException {
protected Map<String, byte[]> retrieveContent(final byte[] zipContent) throws IOException {
Assert.isNotNull(zipContent);
ByteArrayInputStream is = null;
ZipInputStream zis = null;
ByteArrayOutputStream out = null;
final ByteArrayOutputStream out = null;
final Map<String, byte[]> result = new HashMap<>();
try {
is = new ByteArrayInputStream(zipContent);
zis = new ZipInputStream(is);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
final String entryName = entry.getName();
if (entryName.contains("model") && entryName.endsWith(".jar")) {
out = new ByteArrayOutputStream();
int len = 0;
final byte[] buffer = new byte[1024];
while ((len = zis.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
return out.toByteArray();
if (entryName.contains(MODEL) && entryName.endsWith(".jar")) {
result.put(BDM_CLIENT, toByteArray(zis));
}
if (entryName.contains("dao") && entryName.endsWith(".jar")) {
result.put(BDM_DAO, toByteArray(zis));
}
}
} finally {
......@@ -211,9 +229,10 @@ public class DeployBDMOperation implements IRunnableWithProgress {
}
}
return null;
return result;
}
protected void updateDependency(final byte[] jarContent) throws InvocationTargetException {
ByteArrayInputStream is = null;
try {
......
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