Commit 948917d3 authored by Romain Bioteau's avatar Romain Bioteau Committed by Adrien

feat(migration) update process configuration after migration (#1751)

Closes BST-295
parent 6b7fdd6b
......@@ -272,6 +272,7 @@ public class Repository implements IRepository, IJavaContainer, IRenamable {
projectListeners.stream().forEach(l -> l.projectOpened(this, monitor));
if (migrationEnabled()) {
try {
RepositoryManager.getInstance().setCurrentRepository(this);
migrate(monitor);
} catch (final MigrationException | CoreException e) {
BonitaStudioLog.error(e, CommonRepositoryPlugin.PLUGIN_ID);
......
......@@ -47,7 +47,6 @@ public class RepositoryManager {
private static final String PROJECT_LISTENER_PROVIDER_ID = "org.bonitasoft.studio.common.repository.projectListenerProvider";
private static final String PRIORITY = "priority";
private static final String CLASS = "class";
private static final Object LOCK = new Object();
private static RepositoryManager INSTANCE;
......@@ -260,4 +259,8 @@ public class RepositoryManager {
return repository != null;
}
public void setCurrentRepository(Repository repository) {
this.repository = repository;
}
}
......@@ -50,5 +50,11 @@
</command>
</menuContribution>
</extension>
<extension
point="org.bonitasoft.studio.diagram.custom.configurationSynchronizer">
<synchronizer
class="org.bonitasoft.studio.configuration.ConfigurationSynchronizer">
</synchronizer>
</extension>
</plugin>
......@@ -20,15 +20,21 @@ import java.util.List;
import org.bonitasoft.studio.common.FragmentTypes;
import org.bonitasoft.studio.common.ModelVersion;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManager;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.bonitasoft.studio.configuration.extension.IConfigurationSynchronizer;
import org.bonitasoft.studio.configuration.extension.IProcessConfigurationWizardPage;
import org.bonitasoft.studio.configuration.i18n.Messages;
import org.bonitasoft.studio.configuration.preferences.ConfigurationPreferenceConstants;
import org.bonitasoft.studio.configuration.ui.wizard.page.JavaDependenciesConfigurationWizardPage;
import org.bonitasoft.studio.diagram.custom.repository.ProcessConfigurationRepositoryStore;
import org.bonitasoft.studio.diagram.custom.repository.Synchronizer;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.ConfigurationFactory;
import org.bonitasoft.studio.model.configuration.ConfigurationPackage;
......@@ -36,6 +42,7 @@ import org.bonitasoft.studio.model.configuration.FragmentContainer;
import org.bonitasoft.studio.model.configuration.util.ConfigurationAdapterFactory;
import org.bonitasoft.studio.model.configuration.util.ConfigurationResourceFactoryImpl;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.model.process.ProcessPackage;
import org.bonitasoft.studio.model.process.util.ProcessAdapterFactory;
import org.eclipse.core.runtime.CoreException;
......@@ -56,25 +63,28 @@ import org.eclipse.emf.transaction.util.TransactionUtil;
/**
* @author Romain Bioteau
*/
public class ConfigurationSynchronizer {
public class ConfigurationSynchronizer implements Synchronizer {
private final AbstractProcess process;
private final Configuration configuration;
private AbstractProcess process;
private Configuration configuration;
private AdapterFactoryEditingDomain editingDomain;
private ComposedAdapterFactory adapterFactory;
private final boolean synchronizeLocalConfiguraiton;
private final ActiveOrganizationProvider activeOrganizationProvider;
private boolean synchronizeLocalConfiguraiton;
private final ActiveOrganizationProvider activeOrganizationProvider = new ActiveOrganizationProvider();
private static ArrayList<IConfigurationSynchronizer> synchronizers;
private static ArrayList<IProcessConfigurationWizardPage> wizardPages;
private static final String CONFIGURATION_WIZARD_PAGE_ID = "org.bonitasoft.studio.configuration.wizardPage";
private static final String CLASS_ATTRIBUTE = "class";
public ConfigurationSynchronizer(final AbstractProcess process, final Configuration configuration) {
this();
this.process = process;
this.configuration = configuration;
synchronizeLocalConfiguraiton = ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON.equals(configuration.getName()) || configuration.getName() == null;
editingDomain = (AdapterFactoryEditingDomain) TransactionUtil.getEditingDomain(process);
activeOrganizationProvider = new ActiveOrganizationProvider();
}
public ConfigurationSynchronizer() {
initializaSynchronizers();
initializaWizardPages();
}
......@@ -128,6 +138,15 @@ public class ConfigurationSynchronizer {
public void synchronize() {
synchronize(Repository.NULL_PROGRESS_MONITOR);
}
@Override
public void synchronize(Pool process, Configuration configuration) {
this.process = process;
this.configuration = configuration;
synchronizeLocalConfiguraiton = ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON.equals(configuration.getName()) || configuration.getName() == null;
editingDomain = (AdapterFactoryEditingDomain) TransactionUtil.getEditingDomain(process);
synchronize();
}
public void synchronize(final IProgressMonitor monitor) {
monitor.beginTask(Messages.synchronizingConfiguration, IProgressMonitor.UNKNOWN);
......@@ -227,5 +246,5 @@ public class ConfigurationSynchronizer {
public Configuration getConfiguration() {
return configuration;
}
}
......@@ -5,5 +5,6 @@ bin.includes = META-INF/,\
messages*.properties,\
icons/,\
plugin*.properties,\
fragment.e4xmi
fragment.e4xmi,\
schema/
source.. = src/
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<extension-point id="configurationSynchronizer" name="configurationSynchronizer" schema="schema/synchronizer.exsd"/>
<extension
point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
......
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.bonitasoft.studio.diagram.custom" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.bonitasoft.studio.diagram.custom" id="configurationSynchronizer" name="configurationSynchronizer"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="synchronizer"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="synchronizer">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.bonitasoft.studio.diagram.custom.repository.Synchronizer"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
......@@ -44,9 +44,12 @@ import org.bonitasoft.studio.common.editingdomain.BonitaEditingDomainUtil;
import org.bonitasoft.studio.common.emf.tools.EMFResourceUtil;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.emf.tools.RemoveDanglingReferences;
import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManager;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.CopyInputStream;
import org.bonitasoft.studio.common.repository.ImportArchiveData;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.store.AbstractEMFRepositoryStore;
import org.bonitasoft.studio.diagram.custom.Activator;
......@@ -64,6 +67,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
......@@ -98,11 +102,26 @@ public class DiagramRepositoryStore extends
private AdapterFactoryLabelProvider labelProvider;
private final Map<String, String> eObjectIdToLabel = new HashMap<>();
private Synchronizer synchronizer;
@Override
public void createRepositoryStore(IRepository repository) {
super.createRepositoryStore(repository);
synchronizer = loadSynchronizer();
}
private Synchronizer loadSynchronizer() {
for (IConfigurationElement elem : BonitaStudioExtensionRegistryManager.getInstance()
.getConfigurationElements("org.bonitasoft.studio.diagram.custom.configurationSynchronizer")) {
try {
return (Synchronizer) elem.createExecutableExtension("class");
} catch (CoreException e) {
BonitaStudioLog.error(e);
}
}
return null;
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.common.repository.IRepositoryStore#getName()
*/
@Override
public String getName() {
return STORE_NAME;
......@@ -430,7 +449,8 @@ public class DiagramRepositoryStore extends
final Iterator<EObject> iterator = mainProcess.iterator();
final MainProcess diagram = (MainProcess) iterator.next();
if (iterator.hasNext()) {
throw new IOException("Resource content is invalid. There should be only one MainProcess per .proc file.");
throw new IOException(
"Resource content is invalid. There should be only one MainProcess per .proc file.");
}
if (diagram == null) {
throw new IOException("Resource content is null.");
......@@ -446,6 +466,22 @@ public class DiagramRepositoryStore extends
.ifPresent(d -> new RemoveDanglingReferences(d).execute());
diagram.eResource().getContents().removeIf(eObject -> isFormDiagram(eObject));
updateConfigurationId(diagramResource, diagram);
ProcessConfigurationRepositoryStore confStore = RepositoryManager.getInstance()
.getRepositoryStore(ProcessConfigurationRepositoryStore.class);
for (Pool process : ModelHelper.getAllElementOfTypeIn(diagram, Pool.class)) {
ProcessConfigurationFileStore file = confStore.getChild(ModelHelper.getEObjectID(process) + ".conf");
if (file != null) {
synchronizer.synchronize(process,file.getContent());
}
process.getConfigurations().stream().forEach(conf -> synchronizer.synchronize(process, conf));
}
try {
diagramResource.save(ProcessDiagramEditorUtil.getSaveOptions());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
return new FileInputStream(new File(diagramResource.getURI()
.toFileString()));
} finally {
......@@ -478,11 +514,6 @@ public class DiagramRepositoryStore extends
diagram.setAuthor(System.getProperty("user.name",
"Unknown"));
}
try {
diagramResource.save(ProcessDiagramEditorUtil.getSaveOptions());
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
protected InputStream openError(final String fileName) {
......
......@@ -26,20 +26,25 @@ import java.util.Map;
import java.util.Set;
import org.bonitasoft.studio.common.ModelVersion;
import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManager;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.CopyInputStream;
import org.bonitasoft.studio.common.repository.CommonRepositoryPlugin;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.common.repository.store.AbstractEMFRepositoryStore;
import org.bonitasoft.studio.diagram.custom.i18n.Messages;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.configuration.util.ConfigurationAdapterFactory;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.pics.PicsConstants;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMIResource;
......@@ -60,15 +65,30 @@ public class ProcessConfigurationRepositoryStore extends AbstractEMFRepositorySt
public static final String STORE_NAME = "process_configurations";
private static final Set<String> extensions = new HashSet<String>();
public static final String CONF_EXT = "conf";
private Synchronizer synchronizer;
static {
extensions.add(CONF_EXT);
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.common.repository.IRepositoryStore#getName()
*/
@Override
public void createRepositoryStore(IRepository repository) {
super.createRepositoryStore(repository);
synchronizer = loadSynchronizer();
}
private Synchronizer loadSynchronizer() {
for (IConfigurationElement elem : BonitaStudioExtensionRegistryManager.getInstance()
.getConfigurationElements("org.bonitasoft.studio.diagram.custom.configurationSynchronizer")) {
try {
return (Synchronizer) elem.createExecutableExtension("class");
} catch (CoreException e) {
BonitaStudioLog.error(e);
}
}
return null;
}
@Override
public String getName() {
return STORE_NAME;
......@@ -111,10 +131,12 @@ public class ProcessConfigurationRepositoryStore extends AbstractEMFRepositorySt
if (file.exists()) {
String fileNameLabel = fileName;
final String processUUID = fileName.substring(0, fileName.lastIndexOf("."));
final DiagramRepositoryStore diagramStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
final DiagramRepositoryStore diagramStore = RepositoryManager.getInstance()
.getRepositoryStore(DiagramRepositoryStore.class);
final AbstractProcess process = diagramStore.getProcessByUUID(processUUID);
if (process != null) {
fileNameLabel = Messages.bind(Messages.localConfigurationFor, process.getName() + " (" + process.getVersion() + ")");
fileNameLabel = Messages.bind(Messages.localConfigurationFor,
process.getName() + " (" + process.getVersion() + ")");
}
if (FileActionDialog.overwriteQuestion(fileNameLabel)) {
file.setContents(inputStream, true, false, Repository.NULL_PROGRESS_MONITOR);
......@@ -174,7 +196,8 @@ public class ProcessConfigurationRepositoryStore extends AbstractEMFRepositorySt
}
@Override
protected InputStream handlePreImport(final String fileName, final InputStream inputStream) throws MigrationException, IOException {
protected InputStream handlePreImport(final String fileName, final InputStream inputStream)
throws MigrationException, IOException {
CopyInputStream copyIs = null;
try {
final InputStream is = super.handlePreImport(fileName, inputStream);
......@@ -194,6 +217,11 @@ public class ProcessConfigurationRepositoryStore extends AbstractEMFRepositorySt
if (!ModelVersion.CURRENT_VERSION.equals(mVersion)) {
configuration.setVersion(ModelVersion.CURRENT_VERSION);
}
DiagramRepositoryStore diagramStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
AbstractProcess process = diagramStore.getProcessByUUID(fileName.substring(0, fileName.length() - 5));
if(process != null) {
synchronizer.synchronize((Pool) process, configuration);
}
try {
r.save(Collections.EMPTY_MAP);
} catch (final IOException e) {
......
/**
* Copyright (C) 2019 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.diagram.custom.repository;
import org.bonitasoft.studio.model.configuration.Configuration;
import org.bonitasoft.studio.model.process.Pool;
public interface Synchronizer {
void synchronize(Pool process, Configuration configuration) ;
}
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