Skip to content

Commit

Permalink
Merge pull request #513 from eclipse-passage/567032-4
Browse files Browse the repository at this point in the history
Bug 567032 issue floating license configuration wizard
  • Loading branch information
eparovyshnaya authored Nov 7, 2020
2 parents 3bc4f00 + 39d045b commit 17e8f7d
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ _UI_CreateSibling_description = Create a new sibling of type {0} for the selecte
_UI_PropertyDescriptor_description = The {0} of the {1}
_UI_FloatingLicensePack_type = License Pack
_UI_LicenseRequisites_type = License Requisites
_UI_LicenseRequisites_type_detailed = License issued for {1} over product {2} of version {3}
_UI_LicenseRequisites_type_detailed = License issued for {0} over product {1} of version {2}
_UI_ProductRef_type = Product Reference
_UI_ProductRef_type_detailed = Product {0} version {1}
_UI_FloatingServer_type = Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ Export-Package: org.eclipse.passage.lic.floating.model.api;
x-friends:="org.eclipse.passage.lic.floating.e4.ui,
org.eclipse.passage.lic.floating.edit,
org.eclipse.passage.loc.licenses.core,
org.eclipse.passage.loc.floating.emfforms",
org.eclipse.passage.lic.floating.model.util;
x-friends:="org.eclipse.passage.lic.floating.edit",
org.eclipse.passage.lic.internal.floating.model;
x-friends:="org.eclipse.passage.loc.dashboard.ui"
org.eclipse.passage.loc.floating.emfforms,
org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.lic.floating.model.util;x-friends:="org.eclipse.passage.lic.floating.edit",
org.eclipse.passage.lic.internal.floating.model;x-friends:="org.eclipse.passage.loc.dashboard.ui"
Bundle-ClassPath: .
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,31 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.api;

import java.util.Collection;
import java.util.Optional;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;

/**
*
* @since 0.5.0
*
*/
public interface OperatorLicenseService {

/**
* Create new instance of Personal License Pack to be verified and issued
*
* @since 0.5.0
*/
LicensePackDescriptor createLicensePack(PersonalLicenseRequest request);

/**
* Physically issue new Personal License Pack according to all the data supplied
* by the given data.
*
* @since 0.5.0
*/
ServiceInvocationResult<IssuedLicense> issueLicensePack(PersonalLicenseRequest request,
LicensePackDescriptor template);
Expand All @@ -41,14 +45,20 @@ ServiceInvocationResult<IssuedLicense> issueLicensePack(PersonalLicenseRequest r
* Create new instance of Floating License Pack to be verified and issued. Base
* data comes from the request, the rest can come from the existing license
* pack.
*
* @since 1.1.0
*/
FloatingLicensePack createFloatingLicensePack(FloatingLicenseRequest request,
Optional<FloatingLicensePack> template);

/**
* Physically issue new Floating License Pack according to all the data supplied
* by the given data.
* by the given data, optionally accompanied with the personal Floating License
* Access files.
*
* @since 1.1.0
*/
ServiceInvocationResult<IssuedFloatingLicense> issueFloatingLicensePack(FloatingLicenseRequest request,
FloatingLicensePack template);
ServiceInvocationResult<IssuedFloatingLicense> issueFloatingLicensePack(FloatingLicensePack pack,
Collection<FloatingLicenseAccess> configs);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.osgi.util.NLS;
Expand All @@ -30,6 +28,7 @@
import org.eclipse.passage.lic.internal.jface.dialogs.licensing.DiagnosticDialog;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;
import org.eclipse.passage.lic.users.model.api.UserLicense;
import org.eclipse.passage.loc.dashboard.ui.wizards.license.WizardInfoBar;
import org.eclipse.passage.loc.internal.api.IssuedLicense;
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;
import org.eclipse.passage.loc.internal.dashboard.ui.i18n.IssueLicensePageMessages;
Expand Down Expand Up @@ -81,11 +80,11 @@ public boolean performFinish() {
LicensePackDescriptor licensePack = pack.pack();
ServiceInvocationResult<IssuedLicense> result = licenseService.issueLicensePack(request.request(), licensePack);
if (!new NoSevereErrors().test(result.diagnostic())) {
setErrorMessage("Export failed"); //$NON-NLS-1$
new WizardInfoBar(this).installError("Export failed"); //$NON-NLS-1$
new DiagnosticDialog(getShell(), result.diagnostic()).open();
return false;
} else {
setErrorMessage(null);
new WizardInfoBar(this).wipe();
int kind = new NoErrors().test(result.diagnostic()) ? MessageDialog.INFORMATION : MessageDialog.WARNING;
MessageDialog.open(kind, getShell(), //
IssueLicensePageMessages.IssueLicenseWizard_ok_licensed_title,
Expand Down Expand Up @@ -126,12 +125,4 @@ private void broadcast(IssuedLicense result) {
broker.post(LocWokbench.TOPIC_SHOW, userLicense);
}

private void setErrorMessage(String message) {
IWizardContainer container = getContainer();
if (container instanceof TitleAreaDialog) {
TitleAreaDialog dialog = (TitleAreaDialog) container;
dialog.setErrorMessage(message);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.dashboard.ui.wizards.floating;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.floating.model.api.FloatingServerConnection;
import org.eclipse.passage.lic.floating.model.api.UserGrant;
import org.eclipse.passage.lic.floating.model.meta.FloatingFactory;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.loc.internal.api.IssuedFloatingLicense;
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;

final class IssueCommand {

private final IEclipseContext context;
private final FloatingLicensePack pack;
private final ServerConfigsRequest config;

IssueCommand(IEclipseContext context, FloatingLicensePack pack, ServerConfigsRequest config) {
this.context = context;
this.pack = pack;
this.config = config;
}

ServiceInvocationResult<IssuedFloatingLicense> issue() {
List<FloatingLicenseAccess> personals = personalAccessConfigs();
return context.get(OperatorLicenseService.class).issueFloatingLicensePack(pack, personals);
}

private List<FloatingLicenseAccess> personalAccessConfigs() {
if (!config.generate()) {
return Collections.emptyList();
}
return pack.getUsers().stream()//
.map(UserGrant::getUser) //
.map(this::personalAccess)//
.collect(Collectors.toList());
}

private FloatingLicenseAccess personalAccess(String user) {
FloatingLicenseAccess access = FloatingFactory.eINSTANCE.createFloatingLicenseAccess();
access.setUser(user);
access.setOriginLicensePack(pack.getLicense().getIdentifier());
access.setServer(server());
return access;
}

private FloatingServerConnection server() {
FloatingServerConnection connection = FloatingFactory.eINSTANCE.createFloatingServerConnection();
connection.setIp(config.ip());
connection.setPort(config.port());
connection.setAuthentication(EcoreUtil.copy(pack.getHost().getAuthentication()));
return connection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@
*******************************************************************************/
package org.eclipse.passage.loc.dashboard.ui.wizards.floating;

import java.util.function.Supplier;

import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.diagnostic.NoSevereErrors;
import org.eclipse.passage.lic.internal.jface.dialogs.licensing.DiagnosticDialog;
import org.eclipse.passage.loc.dashboard.ui.wizards.license.WizardInfoBar;
import org.eclipse.passage.loc.internal.api.IssuedFloatingLicense;
import org.eclipse.passage.loc.internal.dashboard.ui.i18n.IssueLicensePageMessages;

public final class IssueFloatingLicenseWizard extends Wizard {

private final IEclipseContext context;
private final FloatingDataPack initial;
private Supplier<FloatingLicensePack> license;
private Supplier<ServerConfigsRequest> personals;

public IssueFloatingLicenseWizard(IEclipseContext context, FloatingDataPack initial) {
this.context = context;
Expand All @@ -35,11 +45,20 @@ public void addPages() {
addPage(pack);
IssueUserConfigsRequestPage configs = new IssueUserConfigsRequestPage(context);
addPage(configs.get());
personals = configs::request;
license = pack::pack;
}

@Override
public boolean performFinish() {
return false;
ServiceInvocationResult<IssuedFloatingLicense> result = new IssueCommand(context, license.get(),
personals.get()).issue();
if (!new NoSevereErrors().test(result.diagnostic())) {
new WizardInfoBar(this).installError(IssueLicensePageMessages.IssueFloatingLicenseWizard_failure);
new DiagnosticDialog(getShell(), result.diagnostic()).open();
return false;
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

public class IssueLicensePackPage extends WizardPage {
public final class IssueLicensePackPage extends WizardPage {

private final IEclipseContext context;
private final Supplier<FloatingLicenseRequest> data;
Expand All @@ -52,30 +52,20 @@ public void notifyChanged(Notification notification) {
private VViewModelProperties properties;
private Composite base;

protected IssueLicensePackPage(String name, Supplier<FloatingLicenseRequest> data, IEclipseContext context) {
IssueLicensePackPage(String name, Supplier<FloatingLicenseRequest> data, IEclipseContext context) {
super(name);
this.context = context;
this.data = data;
setTitle(IssueLicensePageMessages.IssueLicensePackPage_page_title);
setDescription(IssueLicensePageMessages.IssueLicensePackPage_page_description);
}

private void init() {
boolean render = license == null;
createLicensePack();
if (render) {
updatePage();
}
}

private void createLicensePack() {
if (license != null) {
license.eAdapters().remove(update);
} else {
license = context.get(OperatorLicenseService.class)//
.createFloatingLicensePack(data.get(), Optional.ofNullable(license));
license.eAdapters().add(update);
@Override
public void setVisible(boolean visible) {
if (visible) {
init();
}
super.setVisible(visible);
}

@Override
Expand All @@ -94,12 +84,22 @@ public void createControl(Composite parent) {
Dialog.applyDialogFont(composite);
}

@Override
public void setVisible(boolean visible) {
if (visible) {
init();
private void init() {
boolean render = license == null;
createLicensePack();
if (render) {
updatePage();
}
}

private void createLicensePack() {
if (license != null) {
license.eAdapters().remove(update);
} else {
license = context.get(OperatorLicenseService.class)//
.createFloatingLicensePack(data.get(), Optional.ofNullable(license));
license.eAdapters().add(update);
}
super.setVisible(visible);
}

private void updatePage() {
Expand All @@ -123,7 +123,7 @@ protected boolean validatePage() {
return errors == null;
}

public FloatingLicensePack pack() {
FloatingLicensePack pack() {
return license;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public final class IssueUserConfigsRequestPage implements Supplier<IWizardPage>
generate = switcher.switcher();
}

ServerConfigsRequest request() {
return new ServerConfigsRequest.Of(generate, ip, port).get();
}

@Override
public IWizardPage get() {
return page.get();
Expand Down
Loading

0 comments on commit 17e8f7d

Please sign in to comment.