Commit 9c7a755b authored by Bonita CI's avatar Bonita CI Committed by Adrien

chore(uid) update UI Designer version to 1.7.47 (#1182)

parent 9c0feaa7
/**
* Copyright (C) 2018 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.application.actions;
import java.io.File;
import java.util.Optional;
import org.bonitasoft.studio.application.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.designer.core.UIDesignerServerManager;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
public class OpenUIDLogCommand extends AbstractHandler implements IHandler {
private static final long MAX_FILE_SIZE = 1000000 * 40; //40Mo
@Override
public Boolean execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile();
if (logFile.isPresent() && logFile.get().exists()) {
try {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI());
final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
final long fileSize = localFile.length();
if (fileSize < MAX_FILE_SIZE) {
IDE.openEditorOnFileStore(page, fileStore);
} else {
Program textEditor = Program.findProgram("log");
if (textEditor == null) {
textEditor = Program.findProgram("txt");
}
if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) {
showWarningMessage(localFile);
}
}
return true;
} catch (final Exception e) {
BonitaStudioLog.error(e);
return false;
}
}
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
return false;
}
protected void showWarningMessage(File localFile) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.failedToOpenLogTitle,
Messages.bind(Messages.failedToOpenLogMessage, localFile.getAbsolutePath(),
org.bonitasoft.studio.common.Messages.bonitaStudioModuleName));
}
}
/**
* Copyright (C) 2018 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.application.actions;
import java.io.File;
import java.util.Optional;
import org.bonitasoft.studio.application.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.designer.core.UIDesignerServerManager;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
public class OpenUIDLogCommand extends AbstractHandler implements IHandler {
private static final long MAX_FILE_SIZE = 1000000 * 40; //40Mo
@Override
public Boolean execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile();
if (logFile.isPresent() && logFile.get().exists()) {
try {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI());
final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
final long fileSize = localFile.length();
if (fileSize < MAX_FILE_SIZE) {
IDE.openEditorOnFileStore(page, fileStore);
} else {
Program textEditor = Program.findProgram("log");
if (textEditor == null) {
textEditor = Program.findProgram("txt");
}
if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) {
showWarningMessage(localFile);
}
}
return true;
} catch (final Exception e) {
BonitaStudioLog.error(e);
return false;
}
}
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
return false;
}
protected void showWarningMessage(File localFile) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.failedToOpenLogTitle,
Messages.bind(Messages.failedToOpenLogMessage, localFile.getAbsolutePath(),
org.bonitasoft.studio.common.Messages.bonitaStudioModuleName));
}
}
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_jKdtYNKdEeaEE_Umqe0dXA">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_tWbyINKdEeaEE_Umqe0dXA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_0n838NKdEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.new.command" commandName="%newApplication"/>
<elements xsi:type="commands:Command" xmi:id="_dHtcoP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.open.command" commandName="%openApplication"/>
<elements xsi:type="commands:Command" xmi:id="_2helYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.delete.command" commandName="%deleteApplication"/>
<elements xsi:type="commands:Command" xmi:id="_YHf6AAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.export.command" commandName="%exportApplication"/>
<elements xsi:type="commands:Command" xmi:id="_g4OJ8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.import.command" commandName="%importApplication"/>
<elements xsi:type="commands:Command" xmi:id="_pL3WsPnPEea-3Os5NcIV0g" elementId="org.bonitasoft.studio.la.deploy.command" commandName="%deployApplication"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_--2aUNKdEeaEE_Umqe0dXA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_BKi10NKeEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.newHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.NewApplicationHandler" command="_0n838NKdEeaEE_Umqe0dXA"/>
<elements xsi:type="commands:Handler" xmi:id="_jUDDEP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.openHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.OpenApplicationHandler" command="_dHtcoP3SEeanhv23kWy-6w"/>
<elements xsi:type="commands:Handler" xmi:id="_57EXYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.deleteHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeleteApplicationHandler" command="_2helYP6PEeaqYIbFhsSGFw"/>
<elements xsi:type="commands:Handler" xmi:id="_cIN9cAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.exportHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ExportApplicationHandler" command="_YHf6AAomEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_kWFX8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.importHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ImportApplicationhandler" command="_g4OJ8ApAEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_JVGowM6fEee2rb_HhIZr1w" elementId="org.bonitasoft.studio.la.handler.deployapplication" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeployApplicationHandler" command="_pL3WsPnPEea-3Os5NcIV0g"/>
</fragments>
</fragment:ModelFragments>
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_jKdtYNKdEeaEE_Umqe0dXA">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_tWbyINKdEeaEE_Umqe0dXA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_0n838NKdEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.new.command" commandName="%newApplication"/>
<elements xsi:type="commands:Command" xmi:id="_dHtcoP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.open.command" commandName="%openApplication"/>
<elements xsi:type="commands:Command" xmi:id="_2helYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.delete.command" commandName="%deleteApplication"/>
<elements xsi:type="commands:Command" xmi:id="_YHf6AAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.export.command" commandName="%exportApplication"/>
<elements xsi:type="commands:Command" xmi:id="_g4OJ8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.import.command" commandName="%importApplication"/>
<elements xsi:type="commands:Command" xmi:id="_pL3WsPnPEea-3Os5NcIV0g" elementId="org.bonitasoft.studio.la.deploy.command" commandName="%deployApplication"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_--2aUNKdEeaEE_Umqe0dXA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_BKi10NKeEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.newHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.NewApplicationHandler" command="_0n838NKdEeaEE_Umqe0dXA"/>
<elements xsi:type="commands:Handler" xmi:id="_jUDDEP3SEeanhv23kWy-6w" elementId="org.bonitasoft.studio.la.openHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.OpenApplicationHandler" command="_dHtcoP3SEeanhv23kWy-6w"/>
<elements xsi:type="commands:Handler" xmi:id="_57EXYP6PEeaqYIbFhsSGFw" elementId="org.bonitasoft.studio.la.deleteHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeleteApplicationHandler" command="_2helYP6PEeaqYIbFhsSGFw"/>
<elements xsi:type="commands:Handler" xmi:id="_cIN9cAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.exportHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ExportApplicationHandler" command="_YHf6AAomEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_kWFX8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.importHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ImportApplicationhandler" command="_g4OJ8ApAEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_JVGowM6fEee2rb_HhIZr1w" elementId="org.bonitasoft.studio.la.handler.deployapplication" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeployApplicationHandler" command="_pL3WsPnPEea-3Os5NcIV0g"/>
</fragments>
</fragment:ModelFragments>
/**
* Copyright (C) 2017 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.la.application.core;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationSearchDescriptor;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.exception.DeletionException;
import org.bonitasoft.engine.exception.SearchException;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
public class DeleteApplicationRunnable implements IRunnableWithProgress {
private final ApplicationAPI applicationAPI;
private final ApplicationNode applicationNode;
private IStatus status;
private boolean ignoreErrors = false;
public DeleteApplicationRunnable(ApplicationAPI applicationAPI, ApplicationNode applicationNode) {
this.applicationAPI = requireNonNull(applicationAPI);
this.applicationNode = requireNonNull(applicationNode);
}
public DeleteApplicationRunnable ignoreErrors() {
this.ignoreErrors = true;
return this;
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(String.format(Messages.deletingApplication, applicationNode.getDisplayName()));
status = delete(applicationNode);
monitor.worked(1);
}
public IStatus getStatus() {
return status;
}
private SearchOptions withToken(String token) {
return new SearchOptionsBuilder(0, 1).filter(ApplicationSearchDescriptor.TOKEN, token).done();
}
private IStatus delete(ApplicationNode applicationNode) {
try {
final long applicationId = applicationAPI.searchApplications(withToken(applicationNode.getToken()))
.getResult().stream()
.mapToLong(Application::getId)
.findFirst()
.orElseThrow(ApplicationDescriptorNotFoundException::new);
applicationAPI.deleteApplication(applicationId);
} catch (final SearchException | ApplicationDescriptorNotFoundException e) {
return ignoreErrors ? Status.OK_STATUS : new Status(IStatus.ERROR, LivingApplicationPlugin.PLUGIN_ID,
String.format("Cannot find application descriptor with token '%s'", applicationNode.getToken()), e);
} catch (final DeletionException e) {
return new Status(IStatus.ERROR, LivingApplicationPlugin.PLUGIN_ID,
String.format("Failed to delete application descriptor: '%s'", e.getContext()), e);
}
return Status.OK_STATUS;
}
}
/**
* Copyright (C) 2017 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.la.application.core;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationSearchDescriptor;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.exception.DeletionException;
import org.bonitasoft.engine.exception.SearchException;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
public class DeleteApplicationRunnable implements IRunnableWithProgress {
private final ApplicationAPI applicationAPI;
private final ApplicationNode applicationNode;
private IStatus status;
private boolean ignoreErrors = false;
public DeleteApplicationRunnable(ApplicationAPI applicationAPI, ApplicationNode applicationNode) {
this.applicationAPI = requireNonNull(applicationAPI);
this.applicationNode = requireNonNull(applicationNode);
}
public DeleteApplicationRunnable ignoreErrors() {
this.ignoreErrors = true;
return this;
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.setTaskName(String.format(Messages.deletingApplication, applicationNode.getDisplayName()));
status = delete(applicationNode);
monitor.worked(1);
}
public IStatus getStatus() {
return status;
}
private SearchOptions withToken(String token) {
return new SearchOptionsBuilder(0, 1).filter(ApplicationSearchDescriptor.TOKEN, token).done();
}
private IStatus delete(ApplicationNode applicationNode) {
try {
final long applicationId = applicationAPI.searchApplications(withToken(applicationNode.getToken()))
.getResult().stream()
.mapToLong(Application::getId)
.findFirst()
.orElseThrow(ApplicationDescriptorNotFoundException::new);
applicationAPI.deleteApplication(applicationId);
} catch (final SearchException | ApplicationDescriptorNotFoundException e) {
return ignoreErrors ? Status.OK_STATUS : new Status(IStatus.ERROR, LivingApplicationPlugin.PLUGIN_ID,
String.format("Cannot find application descriptor with token '%s'", applicationNode.getToken()), e);
} catch (final DeletionException e) {
return new Status(IStatus.ERROR, LivingApplicationPlugin.PLUGIN_ID,
String.format("Failed to delete application descriptor: '%s'", e.getContext()), e);
}
return Status.OK_STATUS;
}
}
/**
* Copyright (C) 2017 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.la.application.core;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.xml.bind.JAXBException;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.ApplicationImportPolicy;
import org.bonitasoft.engine.business.application.exporter.ApplicationNodeContainerConverter;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.business.application.xml.ApplicationNodeContainer;
import org.bonitasoft.engine.exception.AlreadyExistsException;
import org.bonitasoft.engine.exception.ImportException;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.xml.sax.SAXException;
public class DeployApplicationDescriptorRunnable implements IRunnableWithProgress {
protected final ApplicationAPI applicationAPI;
protected final ApplicationNodeContainer applicationNodeContainer;
protected MultiStatus status = new MultiStatus(LivingApplicationPlugin.PLUGIN_ID, 0, "", null);
protected final ApplicationNodeContainerConverter converter;
public DeployApplicationDescriptorRunnable(ApplicationAPI applicationAPI,
ApplicationNodeContainer applicationNodeContainer,
ApplicationNodeContainerConverter converter) {
this.applicationAPI = requireNonNull(applicationAPI);
this.applicationNodeContainer = requireNonNull(applicationNodeContainer);
this.converter = requireNonNull(converter);
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.deployingLivingApplication, IProgressMonitor.UNKNOWN);
status.add(deleteBeforeDeploy(monitor));
if (status.isOK()) {
deployApplications(monitor);
}
}
protected void deployApplications(IProgressMonitor monitor) {
try {
applicationAPI.importApplications(converter.marshallToXML(applicationNodeContainer),
ApplicationImportPolicy.FAIL_ON_DUPLICATES);
monitor.worked(1);
if (status.isMultiStatus()) {
final MultiStatus mStatus = status;
applicationNodeContainer.getApplications().stream()
.map(ApplicationNode::getDisplayName)
.map(name -> new Status(IStatus.OK, LivingApplicationPlugin.PLUGIN_ID,
String.format(Messages.applicationDescriptorDeployed,
name)))
.forEach(mStatus::add);
}
} catch (AlreadyExistsException | ImportException | IOException | JAXBException | SAXException e) {
if (status.isMultiStatus()) {
status.add(new Status(IStatus.ERROR, LivingApplicationPlugin.PLUGIN_ID,
"Failed to deploy application.", e));
}
} finally {
monitor.done();
}
}
public IStatus deleteBeforeDeploy(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final DeleteApplicationContainerRunnable deleteApplicationRunnable = new DeleteApplicationContainerRunnable(
applicationAPI,
applicationNodeContainer).ignoreErrors();
deleteApplicationRunnable.run(monitor);
return deleteApplicationRunnable.getStatus();
}
public MultiStatus getStatus() {
return status;
}
}
/**
* Copyright (C) 2017 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.la.application.core;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.xml.bind.JAXBException;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.business.application.ApplicationImportPolicy;
import org.bonitasoft.engine.business.application.exporter.ApplicationNodeContainerConverter;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.business.application.xml.ApplicationNodeContainer;
import org.bonitasoft.engine.exception.AlreadyExistsException;
import org.bonitasoft.engine.exception.ImportException;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.xml.sax.SAXException;
public class DeployApplicationDescriptorRunnable implements IRunnableWithProgress {
protected final ApplicationAPI applicationAPI;
protected final ApplicationNodeContainer applicationNodeContainer;
protected MultiStatus status = new MultiStatus(LivingApplicationPlugin.PLUGIN_ID, 0, "", null);
protected final ApplicationNodeContainerConverter converter;
public DeployApplicationDescriptorRunnable(ApplicationAPI applicationAPI,
ApplicationNodeContainer applicationNodeContainer,
ApplicationNodeContainerConverter converter) {
this.applicationAPI = requireNonNull(applicationAPI);
this.applicationNodeContainer = requireNonNull(applicationNodeContainer);
this.converter = requireNonNull(converter);
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.deployingLivingApplication, IProgressMonitor.UNKNOWN);
status.add(deleteBeforeDeploy(monitor));
if (status.isOK()) {
deployApplications(monitor);
}
}
protected void deployApplications(IProgressMonitor monitor) {
try {
applicationAPI.importApplications(converter.marshallToXML(applicationNodeContainer),
ApplicationImportPolicy.FAIL_ON_DUPLICATES);
monitor.worked(1);
if (status.isMultiStatus()) {
final MultiStatus mStatus = status;
applicationNodeContainer.getApplications().stream()
.map(ApplicationNode::getDisplayName)
.map(name -> new Status(IStatus.OK, LivingApplicationPlugin.PLUGIN_ID,
String.format(Messages.applicationDescriptorDeployed,
name)))
.forEach(mStatus::add);
}
} catch (AlreadyExistsException | ImportException | IOException | JAXBException | SAXException e) {
if (status.isMultiStatus()) {
status.add(new Status(IStatus.ERROR, LivingApplicationPlugin.PLUGIN_ID,
"Failed to deploy application.", e));
}
} finally {
monitor.done();
}
}
public IStatus deleteBeforeDeploy(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final DeleteApplicationContainerRunnable deleteApplicationRunnable = new DeleteApplicationContainerRunnable(
applicationAPI,
applicationNodeContainer).ignoreErrors();
deleteApplicationRunnable.run(monitor);
return deleteApplicationRunnable.getStatus();
}
public MultiStatus getStatus() {
return status;
}
}
/**
* Copyright (C) 2017 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.la.application.handler;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.la.application.core.DeployApplicationAction;
import org.bonitasoft.studio.la.application.repository.ApplicationRepositoryStore;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.swt.widgets.Shell;
public class DeployApplicationHandler {
@Execute
public void execute(RepositoryAccessor repositoryAccessor, Shell shell) {
new DeployApplicationAction(repositoryAccessor).selectAndDeploy(shell);
}
@CanExecute
public boolean canExecute(RepositoryAccessor repositoryAccessor) {
return repositoryAccessor.getCurrentRepository().isLoaded()
&& !repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class).getChildren().isEmpty();
}
}
/**
* Copyright (C) 2017 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/>.