Commit aeac892f authored by alachambre's avatar alachambre Committed by Romain Bioteau

feat(bos_import) change repository (#270)

closes BS-16140
parent 7ac048ce
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean tycho-eclipserun:eclipse-run"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value="generate"/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="true"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.diagram&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.diagram.form&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.model&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.model.edit&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/org.bonitasoft.studio-models}"/>
</launchConfiguration>
......@@ -36,7 +36,7 @@ public class OpenIntroAddon {
Object part = event.getProperty(UIEvents.EventTags.ELEMENT);
if (part instanceof MPart) {
if (((MPart) part).getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) {
PlatformUtil.openIntroIfNoOtherEditorOpen();
PlatformUtil.openIntroIfNoOtherEditorOpen();
}
}
}
......
......@@ -14,6 +14,8 @@
*/
package org.bonitasoft.studio.common.repository;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
......@@ -80,4 +82,12 @@ public class RepositoryAccessor {
return getCurrentRepository().getProject().getWorkspace();
}
public Repository getRepository(String targetRepository) {
return repositoryManagerInstance.getRepository(targetRepository);
}
public List<IRepository> getAllRepositories() {
return repositoryManagerInstance.getAllRepositories();
}
}
......@@ -94,7 +94,8 @@ public class RepositoryManager {
public Repository createRepository(final String name, final boolean migrationEnabled) {
try {
final IRepositoryFactory repositoryFactory = (IRepositoryFactory) repositoryImplementationElement.createExecutableExtension(CLASS);
final IRepositoryFactory repositoryFactory = (IRepositoryFactory) repositoryImplementationElement
.createExecutableExtension(CLASS);
return repositoryFactory.newRepository(name, migrationEnabled);
} catch (final CoreException e) {
BonitaStudioLog.error(e);
......@@ -102,6 +103,10 @@ public class RepositoryManager {
return null;
}
/**
* @deprecated See {@link RepositoryAccessor}
*/
@Deprecated
public static RepositoryManager getInstance() {
if (RepositoryManager.INSTANCE == null) {
synchronized (RepositoryManager.class) {
......
......@@ -15,6 +15,8 @@
package org.bonitasoft.studio.common.platform.tools;
import static org.assertj.core.api.Assertions.filter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -125,74 +127,50 @@ public class PlatformUtil {
public static void openIntroIfNoOtherEditorOpen() {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
final Display display = workbench.getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
if (activePage != null) {
/* Open intro if there is no other editor opened */
final IEditorReference[] editors = activePage.getEditorReferences();
if (editors.length == 0) {// if there is no other editor opened
final String productId = Platform.getProduct().getId();
if (isABonitaProduct(productId)) {// and that we are in BOS or BOS-SP
openIntro();
} else {
closeIntro();
}
workbench.getDisplay().syncExec(() -> Optional.ofNullable(PlatformUI.getWorkbench())
.map(IWorkbench::getActiveWorkbenchWindow)
.map(IWorkbenchWindow::getActivePage)
.map(page -> page.getEditorReferences().length)
.filter(nbEditors -> nbEditors == 0)
.ifPresent(nbEditors -> {
// and that we are in BOS or BOS-SP
if (isABonitaProduct(Platform.getProduct().getId())) {
showIntroPart();
} else {
hideIntroPart();
}
}
}
});
}));
}
}
/**
* Open the intro
*/
public static void openIntro() {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
final Display display = workbench.getDisplay();
display.asyncExec(openIntroRunnable(workbench));
workbench.getDisplay().asyncExec(PlatformUtil::showIntroPart);
}
}
public static Runnable openIntroRunnable(final IWorkbench workbench) {
return new Runnable() {
@Override
public void run() {
final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null && window.getActivePage() != null) {
final IWorkbenchPage activePage = window.getActivePage();
final IIntroManager introManager = workbench.getIntroManager();
//colse intro to reload content if already opened
if (introManager.getIntro() != null) {
introManager.closeIntro(introManager.getIntro());
} else if (activePage != null) {
final IViewPart view = activePage.findView(INTROVIEW_ID);
if (view != null) {
activePage.hideView(view);
}
}
final IntroModelRoot model = IntroPlugin.getDefault().getIntroModelRoot();
if (model != null
&& introManager.getIntro() != null
&& ((CustomizableIntroPart) introManager.getIntro()).getControl() != null) {
model.getPresentation().navigateHome();
}
introManager.showIntro(
window,
false);
if (window != null) {
PlatformUtil.maximizeWindow(window.getActivePage());
}
}
}
public static void showIntroPart() {
Optional.ofNullable(PlatformUI.getWorkbench())
.map(IWorkbench::getActiveWorkbenchWindow)
.map(IWorkbenchWindow::getActivePage)
.ifPresent(PlatformUtil::showIntroPart);
}
};
public static void showIntroPart(IWorkbenchPage page) {
final IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
//colse intro to reload content if already opened
hideIntroPart();
final IntroModelRoot model = IntroPlugin.getDefault().getIntroModelRoot();
if (model != null
&& introManager.getIntro() != null
&& ((CustomizableIntroPart) introManager.getIntro()).getControl() != null) {
model.getPresentation().navigateHome();
}
introManager.showIntro(
page.getWorkbenchWindow(),
false);
PlatformUtil.maximizeWindow(page);
}
/**
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean generate-resources"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="true"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="true"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.connectors&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.contract&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/org.bonitasoft.studio.connectors}"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean install -U"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="false"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="true"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.console.libs&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/org.bonitasoft.studio.console.libs}"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean generate-resources"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="true"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.contract&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/org.bonitasoft.studio.designer.war}"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean generate-resources"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="true"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.bonitasoft.studio.contract&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/org.bonitasoft.studio.designer}"/>
</launchConfiguration>
......@@ -8,10 +8,12 @@ Bundle-Vendor: BonitaSoft S.A.
Bundle-Localization: plugin
Export-Package: org.bonitasoft.studio.importer.bos.factory,
org.bonitasoft.studio.importer.bos.i18n,
org.bonitasoft.studio.importer.bos.handler,
org.bonitasoft.studio.importer.bos.model,
org.bonitasoft.studio.importer.bos.operation,
org.bonitasoft.studio.importer.bos.status,
org.bonitasoft.studio.importer.bos.validator
org.bonitasoft.studio.importer.bos.validator,
org.bonitasoft.studio.importer.bos.wizard
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.bonitasoft.studio.importer;bundle-version="1.0.0",
......
......@@ -11,6 +11,7 @@ import java.util.Optional;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
......@@ -21,32 +22,46 @@ import org.bonitasoft.studio.importer.bos.wizard.ImportBosArchiveControlSupplier
import org.bonitasoft.studio.importer.ui.dialog.SkippableProgressMonitorJobsDialog;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ImportBosHandler {
@Execute
public void execute(Shell activeShell, RepositoryAccessor repositoryAccessor) {
final ImportBosArchiveControlSupplier bosArchiveControlSupplier = newImportBosArchiveControlSupplier();
final Optional<ImportArchiveModel> archiveModel = WizardBuilder.<ImportArchiveModel> newWizard()
.withTitle(Messages.importBosArchiveTitle)
.havingPage(newPage()
.withTitle(Messages.importFileTitle)
.withDescription(
Messages.bind(Messages.importFileDescription, new Object[] { bonitaStudioModuleName }))
.withControl(bosArchiveControlSupplier))
.onFinish(() -> Optional.ofNullable(bosArchiveControlSupplier.getArchiveModel()))
.open(activeShell, Messages.importButtonLabel);
try {
final ImportBosArchiveControlSupplier bosArchiveControlSupplier = newImportBosArchiveControlSupplier(
repositoryAccessor);
final Optional<ImportArchiveModel> archiveModel = WizardBuilder.<ImportArchiveModel> newWizard()
.withTitle(Messages.importBosArchiveTitle)
.needProgress()
.havingPage(newPage()
.withTitle(Messages.importFileTitle)
.withDescription(
Messages.bind(Messages.importFileDescription, new Object[] { bonitaStudioModuleName }))
.withControl(bosArchiveControlSupplier))
.onFinish(() -> onFinishOperation(bosArchiveControlSupplier, repositoryAccessor))
.open(activeShell, Messages.importButtonLabel);
archiveModel
.ifPresent(model -> importArchive(activeShell, model, new File(bosArchiveControlSupplier.getFilePath()),
repositoryAccessor));
archiveModel
.ifPresent(model -> importArchive(activeShell, model, new File(bosArchiveControlSupplier.getFilePath()),
repositoryAccessor));
} catch (final RuntimeException re) {
new BonitaErrorDialog(Display.getCurrent().getActiveShell(), "Runtime Exception",
re.getMessage(), re).open();
}
}
protected Optional<ImportArchiveModel> onFinishOperation(ImportBosArchiveControlSupplier bosArchiveControlSupplier,
RepositoryAccessor repositoryAccessor) {
return Optional.ofNullable(bosArchiveControlSupplier.getArchiveModel());
}
private void importArchive(Shell activeShell, ImportArchiveModel model, File archive,
RepositoryAccessor repositoryAccessor) {
SkippableProgressMonitorJobsDialog progressManager = new SkippableProgressMonitorJobsDialog(activeShell);
final SkippableProgressMonitorJobsDialog progressManager = new SkippableProgressMonitorJobsDialog(activeShell);
final ImportBosArchiveOperation operation = new ImportBosArchiveOperation(archive, progressManager, model);
operation.setCurrentRepository(getTargetRepository(repositoryAccessor));
try {
progressManager.run(true, false, operation);
} catch (final InvocationTargetException | InterruptedException e) {
......@@ -67,8 +82,12 @@ public class ImportBosHandler {
.open(activeShell));
}
private ImportBosArchiveControlSupplier newImportBosArchiveControlSupplier() {
return new ImportBosArchiveControlSupplier();
protected Repository getTargetRepository(RepositoryAccessor repositoryAccessor) {
return repositoryAccessor.getCurrentRepository();
}
protected ImportBosArchiveControlSupplier newImportBosArchiveControlSupplier(RepositoryAccessor repositoryAccessor) {
return new ImportBosArchiveControlSupplier(repositoryAccessor);
}
}
......@@ -2,9 +2,6 @@ package org.bonitasoft.studio.importer.bos.model;
import static java.util.Objects.requireNonNull;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.swt.graphics.Image;
......@@ -53,11 +50,11 @@ public abstract class AbstractFileModel extends AbstractImportModel implements I
@Override
public Image getImage() {
final Optional<IRepositoryStore<IRepositoryFileStore>> repositoryStore = getParentRepositoryStore();
return repositoryStore.map(store -> {
final IRepositoryFileStore fileStore = store.createRepositoryFileStore(getFileName());
return fileStore != null ? fileStore.getIcon() : store.getIcon();
}).orElse(null);
return getParentRepositoryStore().map(IRepositoryStore::getIcon).orElse(null);
}
public void resetStatus() {
this.status = ConflictStatus.NONE;
}
}
package org.bonitasoft.studio.importer.bos.model;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
......@@ -44,7 +45,22 @@ public abstract class AbstractFolderModel extends AbstractImportModel implements
}
public Object[] getChildren() {
return Stream.concat(getFolders().stream(), getFiles().stream()).toArray();
return Stream.concat(getFolders().stream(),
getFiles()
.stream()
.sorted(conflictingFirst()))
.toArray();
}
private Comparator<? super AbstractFileModel> conflictingFirst() {
return (f1, f2) -> {
if (f1.isConflicting() && !f2.isConflicting()) {
return -1;
} else if (f2.isConflicting() && !f1.isConflicting()) {
return 1;
}
return f1.getFileName().compareTo(f2.getFileName());
};
}
@Override
......@@ -52,4 +68,10 @@ public abstract class AbstractFolderModel extends AbstractImportModel implements
return displayName.orElse(getFolderName());
}
public void resetStatus() {
this.status = ConflictStatus.NONE;
getFolders().stream().forEach(folder -> folder.resetStatus());
getFiles().stream().forEach(file -> file.resetStatus());
}
}
......@@ -25,6 +25,7 @@ public class ImportArchiveModel {
}
public List<ImportStoreModel> getStores() {
Collections.sort(stores, (f1, f2) -> f1.getFolderName().compareTo(f2.getFolderName()));
return Collections.unmodifiableList(stores);
}
......@@ -35,4 +36,11 @@ public class ImportArchiveModel {
public BosArchive getBosArchive() {
return bosArchive;
}
/**
* set all the conflict status to none
*/
public void resetStatus() {
stores.stream().forEach(store -> store.resetStatus());
}
}
......@@ -6,6 +6,7 @@ import java.util.zip.ZipFile;
import org.bonitasoft.studio.common.repository.ImportArchiveData;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.graphics.Image;
......@@ -22,10 +23,7 @@ public class ImportFolderFileStoreModel extends AbstractFolderModel implements I
*/
@Override
public Image getImage() {
return getParentRepositoryStore().map(store -> {
final IRepositoryFileStore fileStore = store.createRepositoryFileStore(getFolderName());
return fileStore != null ? fileStore.getIcon() : store.getIcon();
}).orElse(null);
return getParentRepositoryStore().map(IRepositoryStore::getIcon).orElse(null);
}
/*
......
......@@ -79,7 +79,7 @@ public class ImportBosArchiveOperation implements IRunnableWithProgress {
progressDialog = progressManager;
archive = selectedFile;
currentRepository = RepositoryManager.getInstance().getCurrentRepository();
this.archiveModel = Optional.ofNullable(root);
archiveModel = Optional.ofNullable(root);
this.launchValidationafterImport = launchValidationafterImport;
}
......
......@@ -3,15 +3,12 @@ package org.bonitasoft.studio.importer.bos.operation;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;
import java.util.zip.ZipEntry;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
......@@ -22,7 +19,6 @@ import org.bonitasoft.studio.importer.bos.model.ConflictStatus;
import org.bonitasoft.studio.importer.bos.model.ImportAction;
import org.bonitasoft.studio.importer.bos.model.ImportArchiveModel;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gef.tools.AbstractTool.Input;
public class ImportConflictsChecker {
......
......@@ -16,25 +16,31 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
public class ParseBosArchiveOperation implements IRunnableWithProgress {
private IStatus status;
private File archiveFile;
private final File archiveFile;
private ImportArchiveModel archiveModel;
protected Repository currentRepository;
protected Repository repository;
public ParseBosArchiveOperation(File archiveFile, Repository repository) {
Objects.requireNonNull(archiveFile);
Assert.isTrue(archiveFile.exists());
Objects.requireNonNull(repository);
this.archiveFile = archiveFile;
currentRepository = repository;
this.repository = repository;
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ImportConflictsChecker parser = new ImportConflictsChecker(currentRepository);
final boolean isOpen = repository.getProject().isOpen();
repository.open(monitor);
final ImportConflictsChecker parser = new ImportConflictsChecker(repository);
try {
archiveModel = parser.checkConflicts(new BosArchive(archiveFile), monitor);
} catch (IOException e) {
} catch (final IOException e) {
throw new InvocationTargetException(e);
} finally {
if (!isOpen) {
repository.close();
}
}
}
......
package org.bonitasoft.studio.importer.bos.provider;
import java.util.stream.Collectors;
import org.bonitasoft.studio.importer.bos.model.AbstractFolderModel;
import org.bonitasoft.studio.importer.bos.model.AbstractImportModel;
import org.bonitasoft.studio.importer.bos.model.ImportArchiveModel;
......
......@@ -8,7 +8,6 @@
*******************************************************************************/
package org.bonitasoft.studio.importer.bos.wizard;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.bonitasoft.studio.common.jface.databinding.UpdateStrategyFactory.updateValueStrategy;
import static org.bonitasoft.studio.common.jface.databinding.validator.ValidatorFactory.pathValidator;
......@@ -17,9 +16,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import java.util.stream.Stream;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.importer.ImporterPlugin;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
import org.bonitasoft.studio.importer.bos.model.AbstractFolderModel;
......@@ -29,7 +26,6 @@ import org.bonitasoft.studio.importer.bos.provider.ActionLabelProvider;
import org.bonitasoft.studio.importer.bos.provider.ArchiveTreeContentProvider;
import org.bonitasoft.studio.importer.bos.provider.ImportActionEditingSupport;
import org.bonitasoft.studio.importer.bos.provider.ImportModelLabelProvider;
import org.bonitasoft.studio.importer.ui.dialog.SkippableProgressMonitorJobsDialog;
import org.bonitasoft.studio.ui.ColorConstants;
import org.bonitasoft.studio.ui.widget.ButtonWidget;
import org.bonitasoft.studio.ui.widget.TextWidget;
......@@ -48,6 +44,7 @@ import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
......@@ -66,40 +63,51 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier {
private static final String BOS_EXTENSION = "*.bos";
private static final String LAST_IMPORT_PATH = null;
private TreeViewer viewer;
protected TreeViewer viewer;
private String filePath;
private ButtonWidget importAllButton;
private ButtonWidget keepAllButton;
protected ButtonWidget importAllButton;
protected ButtonWidget keepAllButton;
private ArchiveTreeContentProvider provider;
private ImportArchiveModel archiveModel;
private TextWidget textWidget;
private Section treeSection;
private Label descriptionLabel;
protected ImportArchiveModel archiveModel;
protected TextWidget textWidget;
protected Section treeSection;
protected Label descriptionLabel;
private Color errorColor;
private Color successColor;
private ImportActionSelector importActionSelector;
protected RepositoryAccessor repositoryAccessor;
protected IWizardContainer wizardContainer;
public ImportBosArchiveControlSupplier(RepositoryAccessor repositoryAccessor) {
this.repositoryAccessor = repositoryAccessor;