Commit 804c079d authored by Romain Bioteau's avatar Romain Bioteau Committed by Romain Bioteau

feat(Import): As Dave, I want to import an existing .bos file in another repository (#154)

Add interface to choose target repository when importing a file
(.bos,.bpmn...etc)

fixes [BS-14520](https://bonitasoft.atlassian.net/browse/BS-14520)
parent 035db5fe
......@@ -27,6 +27,7 @@ import com.google.common.base.Strings;
public class PathValidator extends TypedValidator<String, IStatus> {
private final String inputName;
private String message;
public PathValidator(final String inputName) {
this.inputName = inputName;
......@@ -35,14 +36,19 @@ public class PathValidator extends TypedValidator<String, IStatus> {
@Override
public IStatus doValidate(final String value) {
if (Strings.isNullOrEmpty(value)) {
return ValidationStatus.error(NLS.bind(Messages.invalidPath, inputName));
return ValidationStatus.error(message == null ? NLS.bind(Messages.invalidPath, inputName) : message);
}
final String path = value.toString();
final File file = Paths.get(new File(path).toURI()).toFile();
if (!file.exists()) {
return ValidationStatus.error(NLS.bind(Messages.pathDoesNotExist, inputName));
return ValidationStatus.error(message == null ? NLS.bind(Messages.pathDoesNotExist, inputName) : message);
}
return ValidationStatus.ok();
}
public PathValidator overrideMessage(String message) {
this.message = message;
return this;
}
}
......@@ -50,7 +50,7 @@ public class ValidatorFactory {
return new FileNameValidator(inputName);
}
public static IValidator pathValidator(final String inputName) {
public static PathValidator pathValidator(final String inputName) {
return new PathValidator(inputName);
}
......
......@@ -52,7 +52,7 @@ public class BosArchiveProcessor extends ToProcProcessor {
operation = new ImportBosArchiveOperation();
operation.setProgressDialog(progressDialog);
operation.setArchiveFile(archiveFile.getAbsolutePath());
operation.setCurrentRepository(RepositoryManager.getInstance().getCurrentRepository());
operation.setCurrentRepository(RepositoryManager.getInstance().getRepository(getRepository()));
return operation;
}
......
......@@ -29,7 +29,9 @@ Require-Bundle: org.eclipse.ui,
org.bonitasoft.studio.connectors.model;bundle-version="6.5.0",
com.google.guava;bundle-version="11.0.1",
org.junit;resolution:=optional,
org.mockito;bundle-version="1.9.5";resolution:=optional
org.mockito;bundle-version="1.9.5";resolution:=optional,
org.eclipse.jface.databinding,
org.eclipse.core.databinding.beans
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.importer,
......@@ -38,7 +40,8 @@ Export-Package: org.bonitasoft.studio.importer,
org.bonitasoft.studio.importer.builder,
org.bonitasoft.studio.importer.handler,
org.bonitasoft.studio.importer.processors,
org.bonitasoft.studio.importer.ui.dialog
org.bonitasoft.studio.importer.ui.dialog,
org.bonitasoft.studio.importer.ui.wizard
Bundle-ClassPath: .
Bundle-Localization: plugin
Import-Package: org.bonitasoft.engine.bpm.connector
......@@ -3,9 +3,9 @@ importFromBPMN=Import from BPMN...
importTitle=Import...
importFileTitle=Import file
importFileDescription=Import file from another {0}, or from another BPM application
selectImportLabel=Select the input format
fileFormat=File format
importDescriptionLabel=Description
selectFileToImport=Select a file to import
selectFileToImport=Select file
importButtonLabel=Import
browseButton_label=Browse...
importProcessTitle=Import a process
......@@ -18,4 +18,5 @@ importSucessfulMessage=Import successfully completed.
openDiagram=Open diagrams
skipValidation=Skip validation >>
importStatusMsg=Problems has been detected in imported content.
copyToClipboard=Copy to clipboard
\ No newline at end of file
copyToClipboard=Copy to clipboard
invalidFilePath=Invalid file path
\ No newline at end of file
......@@ -36,7 +36,6 @@
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.bonitasoft.studio.importer.handler.ImportHandler"
id="org.bonitasoft.studio.application.importCommand"
name="%importLabel">
</command>
......@@ -49,5 +48,17 @@
toolbarPosition="4">
</coolbarItem>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.bonitasoft.studio.importer.handler.ImportHandler"
commandId="org.bonitasoft.studio.application.importCommand">
<activeWhen>
<reference
definitionId="isABonitaProduct">
</reference>
</activeWhen>
</handler>
</extension>
</plugin>
\ No newline at end of file
</plugin>
......@@ -15,28 +15,27 @@
package org.bonitasoft.studio.importer.coolbar;
import org.bonitasoft.studio.common.extension.IBonitaContributionItem;
import org.bonitasoft.studio.importer.handler.ImportHandler;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.importer.i18n.Messages;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.pics.PicsConstants;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
/**
* @author Romain Bioteau
*/
public class ImportBarCoolbarItem extends ContributionItem implements IBonitaContributionItem {
private final ImportHandler importHandler;
public ImportBarCoolbarItem() {
importHandler = new ImportHandler();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.action.IContributionItem#getId()
......@@ -62,10 +61,19 @@ public class ImportBarCoolbarItem extends ContributionItem implements IBonitaCon
@Override
public void widgetSelected(final SelectionEvent e) {
importHandler.execute();
try {
getCommand().executeWithChecks(new ExecutionEvent());
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
BonitaStudioLog.error(e1);
}
}
});
}
private Command getCommand() {
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
return service.getCommand("org.bonitasoft.studio.application.importCommand");
}
}
......@@ -68,7 +68,7 @@ public class ImportHandler extends AbstractHandler {
}
public void execute() {
final ImportFileWizard importFileWizard = new ImportFileWizard();
final ImportFileWizard importFileWizard = createImportWizard();
new CustomWizardDialog(Display.getDefault().getActiveShell(), importFileWizard, Messages.importButtonLabel).open();
final String absoluteFilePath = importFileWizard.getSelectedFilePath();
if (absoluteFilePath == null) {
......@@ -76,7 +76,7 @@ public class ImportHandler extends AbstractHandler {
}
final File selectedFile = new File(absoluteFilePath);
final SkippableProgressMonitorJobsDialog progressManager = new SkippableProgressMonitorJobsDialog(Display.getDefault().getActiveShell());
final ImportFileOperation operation = new ImportFileOperation(importFileWizard.getSelectedTransfo(), selectedFile, progressManager);
final ImportFileOperation operation = createImportFileOperation(importFileWizard, selectedFile, progressManager);
try {
progressManager.run(true, false, operation);
} catch (final InvocationTargetException | InterruptedException e) {
......@@ -95,4 +95,13 @@ public class ImportHandler extends AbstractHandler {
PlatformUtil.openIntroIfNoOtherEditorOpen();
Display.getDefault().asyncExec(openStatusDialog(operation));
}
protected ImportFileOperation createImportFileOperation(final ImportFileWizard importFileWizard, final File selectedFile,
final SkippableProgressMonitorJobsDialog progressManager) {
return new ImportFileOperation(importFileWizard.getSelectedTransfo(), selectedFile, progressManager);
}
protected ImportFileWizard createImportWizard() {
return new ImportFileWizard();
}
}
......@@ -30,7 +30,7 @@ public class Messages extends NLS {
public static String importTitle;
public static String importFileTitle;
public static String importFileDescription;
public static String selectImportLabel;
public static String fileFormat;
public static String importDescriptionLabel;
public static String selectFileToImport;
public static String browseButton_label;
......@@ -46,5 +46,6 @@ public class Messages extends NLS {
public static String skipValidation;
public static String importStatusMsg;
public static String copyToClipboard;
public static String invalidFilePath;
}
......@@ -48,6 +48,7 @@ public class ImportFileOperation implements IRunnableWithProgress {
private IStatus status;
private ToProcProcessor processor;
private SkippableProgressMonitorJobsDialog progressDialog;
private String repository;
public List<DiagramFileStore> getFileStoresToOpen() {
return fileStoresToOpen;
......@@ -57,7 +58,7 @@ public class ImportFileOperation implements IRunnableWithProgress {
final File fileToImport) {
this.importerFactory = importerFactory;
this.fileToImport = fileToImport;
fileStoresToOpen = new ArrayList<DiagramFileStore>();
fileStoresToOpen = new ArrayList<>();
}
public ImportFileOperation(final ImporterFactory importerFactory,
......@@ -75,6 +76,11 @@ public class ImportFileOperation implements IRunnableWithProgress {
InterruptedException {
monitor.beginTask(Messages.importProcessProgressDialog, IProgressMonitor.UNKNOWN);
processor = importerFactory.createProcessor(fileToImport.getName());
if (repository != null) {
processor.setRepository(repository);
} else {
processor.setRepository(RepositoryManager.getInstance().getCurrentRepository().getName());
}
processor.setProgressDialog(progressDialog);
try {
processor.createDiagram(fileToImport.toURI().toURL(), monitor);
......@@ -133,4 +139,8 @@ public class ImportFileOperation implements IRunnableWithProgress {
return processor.getImportStatusDialogHandler(status);
}
public void setRepositroy(String repository) {
this.repository = repository;
}
}
......@@ -33,6 +33,7 @@ import org.eclipse.core.runtime.Status;
public abstract class ToProcProcessor {
protected String resourceName;
protected String repository;
protected SkippableProgressMonitorJobsDialog progressDialog;
public abstract File createDiagram(URL sourceFileURL, IProgressMonitor progressMonitor) throws Exception;
......@@ -41,6 +42,14 @@ public abstract class ToProcProcessor {
this.resourceName = resourceName;
}
public String getRepository() {
return repository;
}
public void setRepository(String repository) {
this.repository = repository;
}
/**
* @deprecated Use getDiagramFileStoresToOpen instead
*/
......
/**
* Copyright (C) 2016 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.importer.ui.wizard;
import org.bonitasoft.studio.importer.ImporterFactory;
public class ImportFileData {
private String filePath;
private ImporterFactory importerFactory;
public ImporterFactory getImporterFactory() {
return importerFactory;
}
public void setImporterFactory(ImporterFactory importerFactory) {
this.importerFactory = importerFactory;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
}
......@@ -21,43 +21,45 @@ import org.bonitasoft.studio.importer.ImporterFactory;
import org.bonitasoft.studio.importer.i18n.Messages;
import org.eclipse.jface.wizard.Wizard;
/**
* @author Mickael Istria
*
*/
public class ImportFileWizard extends Wizard {
private ImportFileWizardPage page;
private String filePath;
private ImporterFactory selectedTransfo;
private ImportFileData importFileData;
@Override
public String getWindowTitle() {
return Messages.importTitle ;
}
public void addPages() {
page = new ImportFileWizardPage();
addPage(page);
@Override
public void addPages() {
addPage(createPage());
}
@Override
protected ImportFileWizardPage createPage() {
return new ImportFileWizardPage(getImportFileData());
}
protected ImportFileData getImportFileData() {
if (importFileData == null) {
importFileData = createImportFileData();
}
return importFileData;
}
protected ImportFileData createImportFileData() {
return new ImportFileData();
}
@Override
public boolean performFinish() {
this.filePath = page.getSelectedFilePath();
this.selectedTransfo = page.getSelectedTransfo();
return true;
}
@Override
public boolean canFinish() {
return page.isPageComplete();
}
public String getSelectedFilePath() {
return this.filePath;
return importFileData.getFilePath();
}
public ImporterFactory getSelectedTransfo() {
return this.selectedTransfo;
return importFileData.getImporterFactory();
}
}
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