Commit a712807b authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-8914

parent 4d57b1eb
......@@ -13,6 +13,8 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="modelVersion" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral=""/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ConnectorParameter">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="key" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
......
......@@ -201,7 +201,7 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValueIdOfDocumentStore"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="documentType" lowerBound="1"
eType="#//DocumentType" defaultValueLiteral="0"/>
eType="#//DocumentType" defaultValueLiteral="NONE"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="multiple" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Boolean"
defaultValueLiteral="false"/>
......
......@@ -94,6 +94,7 @@
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute connector-configuration.ecore#//ConnectorConfiguration/definitionId"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute connector-configuration.ecore#//ConnectorConfiguration/version"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute connector-configuration.ecore#//ConnectorConfiguration/name"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute connector-configuration.ecore#//ConnectorConfiguration/modelVersion"/>
</genClasses>
<genClasses ecoreClass="connector-configuration.ecore#//ConnectorParameter">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute connector-configuration.ecore#//ConnectorParameter/key"/>
......
......@@ -8672,5 +8672,44 @@
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.migration.custom.migration.document.DocumentDefaultReturnTypeModifierMigration"/>
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.migration.custom.migration.form.FileWidgetDocumentMigration"/>
</releases>
<releases date="2014-10-23T11:45:10.092+0200" label="6.4.0-003">
<changes xsi:type="history:MigrationChange" migration="org.bonitasoft.studio.migration.custom.migration.connector.InitializeConnectorConfigurationModelVersion">
<changes xsi:type="history:OperationChange">
<changes xsi:type="history:Create" target="connector-configuration.ecore#//ConnectorConfiguration"
referenceName="eStructuralFeatures" element="connector-configuration.ecore#//ConnectorConfiguration/modelVersion">
<changes xsi:type="history:Set" element="connector-configuration.ecore#//ConnectorConfiguration/modelVersion"
featureName="name" dataValue="modelVersion"/>
<changes xsi:type="history:Set" element="connector-configuration.ecore#//ConnectorConfiguration/modelVersion"
featureName="defaultValueLiteral" dataValue=""/>
<changes xsi:type="history:Set" element="connector-configuration.ecore#//ConnectorConfiguration/modelVersion"
featureName="eType" referenceValue="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</changes>
<operation name="newAttribute">
<parameters name="eClass">
<referenceValue element="connector-configuration.ecore#//ConnectorConfiguration"/>
</parameters>
<parameters name="name">
<dataValue>modelVersion</dataValue>
</parameters>
<parameters name="type">
<referenceValue element="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</parameters>
<parameters name="lowerBound">
<dataValue>0</dataValue>
</parameters>
<parameters name="upperBound">
<dataValue>1</dataValue>
</parameters>
<parameters name="defaultValue">
<dataValue></dataValue>
</parameters>
</operation>
</changes>
</changes>
<changes xsi:type="history:CompositeChange">
<changes xsi:type="history:Set" element="process.ecore#//Document/documentType"
featureName="defaultValueLiteral" dataValue="NONE" oldDataValue="0"/>
</changes>
</releases>
<releases/>
</history:History>
......@@ -16,19 +16,40 @@
*/
package org.bonitasoft.studio.actors.repository;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.common.ModelVersion;
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.filestore.DefinitionConfigurationFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.store.AbstractEMFRepositoryStore;
import org.bonitasoft.studio.model.connectorconfiguration.ConnectorConfiguration;
import org.bonitasoft.studio.model.connectorconfiguration.util.ConnectorConfigurationAdapterFactory;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.XMLOptions;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMLOptionsImpl;
import org.eclipse.emf.edapt.history.Release;
import org.eclipse.emf.edapt.migration.MigrationException;
import org.eclipse.emf.edapt.migration.execution.Migrator;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.swt.graphics.Image;
......@@ -50,7 +71,7 @@ public class ActorFilterConfRepositoryStore extends AbstractEMFRepositoryStore<D
* @see org.bonitasoft.studio.common.repository.model.IRepositoryStore#createRepositoryFileStore(java.lang.String)
*/
@Override
public DefinitionConfigurationFileStore createRepositoryFileStore(String fileName) {
public DefinitionConfigurationFileStore createRepositoryFileStore(final String fileName) {
return new DefinitionConfigurationFileStore(fileName, this);
}
......@@ -87,18 +108,17 @@ public class ActorFilterConfRepositoryStore extends AbstractEMFRepositoryStore<D
return extensions;
}
public List<ConnectorConfiguration> getConnectorConfigurations() {
List<ConnectorConfiguration> result = new ArrayList<ConnectorConfiguration>() ;
for(IRepositoryFileStore child : getChildren()){
public List<ConnectorConfiguration> getFilterConfigurations() {
final List<ConnectorConfiguration> result = new ArrayList<ConnectorConfiguration>();
for (final IRepositoryFileStore child : getChildren()) {
result.add((ConnectorConfiguration) child.getContent()) ;
}
return result ;
}
public List<ConnectorConfiguration> getConnectorConfigurationsFor(String defintionId,String definitionVersion) {
List<ConnectorConfiguration> result = new ArrayList<ConnectorConfiguration>() ;
for(ConnectorConfiguration child : getConnectorConfigurations()){
public List<ConnectorConfiguration> getFilterConfigurationsFor(final String defintionId, final String definitionVersion) {
final List<ConnectorConfiguration> result = new ArrayList<ConnectorConfiguration>();
for (final ConnectorConfiguration child : getFilterConfigurations()) {
if(child.getDefinitionId().equals(defintionId) && child.getVersion().equals(definitionVersion) ){
result.add(child) ;
}
......@@ -106,9 +126,97 @@ public class ActorFilterConfRepositoryStore extends AbstractEMFRepositoryStore<D
return result ;
}
@Override
protected Release getRelease(final Migrator targetMigrator, final Resource resource) {
final Map<Object, Object> loadOptions = new HashMap<Object, Object>();
//Ignore unknown features
loadOptions.put(XMIResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
final XMLOptions options = new XMLOptionsImpl();
options.setProcessAnyXML(true);
loadOptions.put(XMLResource.OPTION_XML_OPTIONS, options);
try {
resource.load(loadOptions);
} catch (final IOException e) {
BonitaStudioLog.error(e, CommonRepositoryPlugin.PLUGIN_ID);
}
final String modelVersion = getModelVersion(resource);
for (final Release release : targetMigrator.getReleases()) {
if (release.getLabel().equals(modelVersion)) {
return release;
}
}
return targetMigrator.getReleases().iterator().next(); //First release of all time
}
protected String getModelVersion(final Resource resource) {
final String modelVersion = ModelVersion.VERSION_6_0_0_ALPHA;
for (final EObject root : resource.getContents()) {
if (root instanceof ConnectorConfiguration) {
final String version = ((ConnectorConfiguration) root).getModelVersion();
if (version != null) {
return version;
}
}
}
return modelVersion;
}
@Override
protected InputStream handlePreImport(final String fileName, final InputStream inputStream) throws MigrationException, IOException {
CopyInputStream copyIs = null;
try {
final InputStream is = super.handlePreImport(fileName, inputStream);
copyIs = new CopyInputStream(is);
final Resource r = getTmpEMFResource("beforeImport",
copyIs.getCopy());
try {
r.load(Collections.EMPTY_MAP);
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
if (!r.getContents().isEmpty()) {
final ConnectorConfiguration configuration = (ConnectorConfiguration) r.getContents()
.get(0);
if (configuration != null) {
final String mVersion = configuration.getVersion();
if (!ModelVersion.CURRENT_VERSION.equals(mVersion)) {
configuration.setModelVersion(ModelVersion.CURRENT_VERSION);
}
try {
r.save(Collections.EMPTY_MAP);
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
try {
return new FileInputStream(new File(r.getURI()
.toFileString()));
} catch (final FileNotFoundException e) {
BonitaStudioLog.error(e);
} finally {
copyIs.close();
try {
r.delete(Collections.EMPTY_MAP);
} catch (final IOException e) {
BonitaStudioLog.error(e);
}
}
} else {
return null;
}
}
return copyIs.getCopy();
} catch (final IOException e) {
BonitaStudioLog.error(e);
return null;
} finally {
if (copyIs != null) {
copyIs.close();
}
}
}
@Override
protected void addAdapterFactory(ComposedAdapterFactory adapterFactory) {
protected void addAdapterFactory(final ComposedAdapterFactory adapterFactory) {
adapterFactory.addAdapterFactory(new ConnectorConfigurationAdapterFactory());
}
......
......@@ -66,8 +66,6 @@ import org.eclipse.swt.graphics.Image;
*/
public class OrganizationRepositoryStore extends AbstractEMFRepositoryStore<OrganizationFileStore> {
private static final String NAMESPACE_6_3_0 = "xmlns:organization=\"http://documentation.bonitasoft.com/organization-xml-schema\"";
private static final String NAMESPACE_6_0_0_BETA_016 = "xmlns:organization=\"http://www.bonitasoft.org/ns/organization/6.0.0-beta-016\"";
private static final String STORE_NAME = "organizations";
public static final String ORGANIZATION_EXT = "organization";
private static final Set<String> extensions = new HashSet<String>() ;
......@@ -207,10 +205,6 @@ public class OrganizationRepositoryStore extends AbstractEMFRepositoryStore<Orga
final Resource resource = new XMLResourceImpl(resourceURI);
final DocumentRoot root = OrganizationFactory.eINSTANCE.createDocumentRoot();
final Organization orga = EcoreUtil.copy(((DocumentRoot) r.getContents().get(0)).getOrganization());
// List<PasswordType> passwords = ModelHelper.getAllItemsOfType(orga, OrganizationPackage.Literals.PASSWORD_TYPE);
// for(PasswordType p : passwords){
// p.setEncrypted(p.isEncrypted());
// }
root.setOrganization(orga);
resource.getContents().add(root);
final Map<String, String> options = new HashMap<String, String>();
......
......@@ -130,7 +130,7 @@ public class Repository implements IRepository {
}
@Override
public void create() {
public void create(final boolean migrateStoreIfNeeded) {
try {
final long init = System.currentTimeMillis();
if (BonitaStudioLog.isLoggable(IStatus.OK)) {
......@@ -144,9 +144,9 @@ public class Repository implements IRepository {
open();
if (!projectExists) {
initializeProject(project);
}
initRepositoryStores();
initRepositoryStores(migrateStoreIfNeeded);
refreshClasspath(project);
enableBuild();
......@@ -165,6 +165,11 @@ public class Repository implements IRepository {
}
}
@Override
public void create() {
create(false);
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.common.repository.IRepository#getName()
......@@ -239,7 +244,7 @@ public class Repository implements IRepository {
}
}
protected synchronized void initRepositoryStores() {
protected synchronized void initRepositoryStores(final boolean migrateStoreIfNeeded) {
if (stores == null || stores.isEmpty()) {
disableBuild();
stores = new TreeMap<Class<?>, IRepositoryStore<? extends IRepositoryFileStore>>(new Comparator<Class<?>>() {
......@@ -254,6 +259,13 @@ public class Repository implements IRepository {
for (final IConfigurationElement configuration : elements) {
try {
final IRepositoryStore<? extends IRepositoryFileStore> store = createRepositoryStore(configuration);
if (migrateStoreIfNeeded) {
try {
store.migrate();
} catch (final MigrationException e) {
BonitaStudioLog.error(e, CommonRepositoryPlugin.PLUGIN_ID);
}
}
stores.put(store.getClass(), store);
} catch (final CoreException e) {
BonitaStudioLog.error(e);
......@@ -563,7 +575,7 @@ public class Repository implements IRepository {
@Override
public IRepositoryStore<? extends IRepositoryFileStore> getRepositoryStore(final Class<?> repositoryStoreClass) {
if (stores == null || stores.isEmpty()) {
initRepositoryStores();
initRepositoryStores(false);
enableBuild();
}
return stores.get(repositoryStoreClass);
......@@ -605,9 +617,9 @@ public class Repository implements IRepository {
}
@Override
public List<IRepositoryStore<? extends IRepositoryFileStore>> getAllStores() {
public synchronized List<IRepositoryStore<? extends IRepositoryFileStore>> getAllStores() {
if (stores == null) {
initRepositoryStores();
initRepositoryStores(false);
enableBuild();
}
final List<IRepositoryStore<? extends IRepositoryFileStore>> result = new ArrayList<IRepositoryStore<? extends IRepositoryFileStore>>(stores.values());
......
......@@ -26,6 +26,7 @@ import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.model.IRepository;
import org.bonitasoft.studio.common.repository.preferences.RepositoryPreferenceConstant;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
......@@ -142,6 +143,8 @@ public class RepositoryManager {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
result.add(repository) ;
workspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
workspace.getRoot().getProjects();
for(final IProject p : workspace.getRoot().getProjects()){
if(p.exists() && p.getLocation() != null && p.getLocation().toFile().exists()){
try {
......@@ -173,6 +176,10 @@ public class RepositoryManager {
}
public void setRepository(final String repositoryName) {
setRepository(repositoryName, false);
}
public void setRepository(final String repositoryName, final boolean migrateIfNeeded) {
if(repository != null && repository.getName().equals(repositoryName)){
return;
}else{
......@@ -182,7 +189,7 @@ public class RepositoryManager {
if(repository == null){
repository = createRepository(repositoryName) ;
}
repository.create();
repository.create(migrateIfNeeded);
repository.open();
preferenceStore.setValue(RepositoryPreferenceConstant.CURRENT_REPOSITORY,repositoryName) ;
}
......
......@@ -43,7 +43,7 @@ public interface IRepository extends IFileStoreChangeListener {
IProject getProject() ;
void create() ;
void create(boolean migrateStoreIfNeeded);
void delete() ;
......@@ -76,7 +76,7 @@ public interface IRepository extends IFileStoreChangeListener {
IRepositoryStore<? extends IRepositoryFileStore> getRepositoryStore(IResource resource);
boolean isBuildEnable() ;
void disableBuild();
void enableBuild();
......@@ -89,4 +89,6 @@ public interface IRepository extends IFileStoreChangeListener {
IRepositoryFileStore asRepositoryFileStore(IFile res);
void migrate() throws CoreException, MigrationException;
void create();
}
......@@ -80,7 +80,7 @@ public abstract class AbstractEMFRepositoryStore<T extends EMFFileStore>
/**
* public for test purpose
*
*
* @return
*/
public Migrator initializeMigrator() {
......@@ -159,6 +159,8 @@ public abstract class AbstractEMFRepositoryStore<T extends EMFFileStore>
final Release release = getRelease(targetMigrator, resource);
if (release != null && !release.isLatestRelease()) {
try {
BonitaStudioLog.debug("Perfroming migration on " + fileName + " from " + release.getLabel() + " to latest...",
CommonRepositoryPlugin.PLUGIN_ID);
performMigration(targetMigrator, resourceURI, release);
} catch (final MigrationException e) {
if (tmpFile != null) {
......
......@@ -59,9 +59,9 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
private IRepository repository;
@Override
public void createRepositoryStore(IRepository repository){
public void createRepositoryStore(final IRepository repository){
this.repository = repository ;
IProject project = repository.getProject() ;
final IProject project = repository.getProject() ;
this.folder = project.getFolder(getName()) ;
if(!this.folder.exists()){
try {
......@@ -72,29 +72,29 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
this.folder.create(true, true, Repository.NULL_PROGRESS_MONITOR) ;
}
processDefaultContribution() ;
} catch (CoreException e) {
} catch (final CoreException e) {
BonitaStudioLog.error(e) ;
}
}
}
}
private void processDefaultContribution() {
IConfigurationElement[] elements = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements("org.bonitasoft.studio.repository.fileContribution") ;
for(IConfigurationElement element : elements){
final IConfigurationElement[] elements = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements("org.bonitasoft.studio.repository.fileContribution") ;
for(final IConfigurationElement element : elements){
IFileStoreContribution contribution;
try {
contribution = (IFileStoreContribution) element.createExecutableExtension(CLASS);
if(contribution.appliesTo(this)){
contribution.execute(this) ;
}
} catch (CoreException e) {
} catch (final CoreException e) {
BonitaStudioLog.error(e) ;
}
}
}
@Override
public final T importInputStream(String fileName,InputStream inputStream) {
public final T importInputStream(final String fileName,final InputStream inputStream) {
Assert.isNotNull(inputStream);
Assert.isNotNull(fileName);
InputStream newIs = null;
......@@ -123,9 +123,9 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
}
return null;
}
if(newIs == null){
return null;
}
......@@ -134,20 +134,20 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
}
@Override
public final T importIResource(String fileName,IResource resource) {
IResource newResource = handlePreImport(fileName,resource) ;
public final T importIResource(final String fileName,final IResource resource) {
final IResource newResource = handlePreImport(fileName,resource) ;
final T store = doImportIResource(fileName,newResource) ;
return store;
}
protected T doImportIResource(String fileName,IResource resource) {
protected T doImportIResource(final String fileName,final IResource resource) {
try{
if(resource instanceof IFile){
return importInputStream(fileName, ((IFile) resource).getContents()) ;
}else if(resource instanceof IFolder){
IPath path = getResource().getFullPath().append(fileName) ;
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot() ;
IFolder targetFolder = root.getFolder(path);
final IPath path = getResource().getFullPath().append(fileName) ;
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot() ;
final IFolder targetFolder = root.getFolder(path);
if(targetFolder.exists()){
if(FileActionDialog.overwriteQuestion(fileName)){
targetFolder.delete(true, Repository.NULL_PROGRESS_MONITOR) ;
......@@ -157,7 +157,7 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
}
resource.copy(getResource().getFullPath().append(fileName), true, Repository.NULL_PROGRESS_MONITOR) ;
}
}catch (Exception e) {
}catch (final Exception e) {
BonitaStudioLog.error(e) ;
}
return createRepositoryFileStore(fileName);
......@@ -169,7 +169,7 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
* @param resource
* @return A the IResource with a migrated content
*/
protected IResource handlePreImport(String fileName, IResource resource) {
protected IResource handlePreImport(final String fileName, final IResource resource) {
return resource;
}
......@@ -179,17 +179,17 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
* @param inputStream
* @return A new InputStream with a migrated content
*/
protected InputStream handlePreImport(String fileName, InputStream inputStream) throws MigrationException, IOException{
protected InputStream handlePreImport(final String fileName, final InputStream inputStream) throws MigrationException, IOException{
return inputStream ;
}
/**
*
*
* @param fileName
* @param inputStream , read and closed inside this method
* @return IRepositoryFileStore
*/
protected T doImportInputStream(String fileName, InputStream inputStream) {
protected T doImportInputStream(final String fileName, final InputStream inputStream) {
final IFile file = getResource().getFile(fileName);
try{
if(file.exists()){
......@@ -200,14 +200,14 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
return createRepositoryFileStore(fileName);