Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

567032 issue floating license configuration wizard #472

Merged
merged 7 commits into from
Oct 13, 2020
Merged
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Export-Package: org.eclipse.passage.lic.internal.base;
org.eclipse.passage.lic.internal.base.conditions;x-friends:="org.eclipse.passage.lbc.base,org.eclipse.passage.lic.json,org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.internal.base.conditions.evaluation;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions.mining;x-friends:="org.eclipse.passage.lic.jface,org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.internal.base.diagnostic;x-friends:="org.eclipse.passage.lic.equinox.tests,org.eclipse.passage.lic.equinox",
org.eclipse.passage.lic.internal.base.diagnostic;x-friends:="org.eclipse.passage.lic.equinox.tests,org.eclipse.passage.lic.equinox,org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.lic.internal.base.diagnostic.code;x-friends:="org.eclipse.passage.lic.hc,org.eclipse.passage.lic.equinox",
org.eclipse.passage.lic.internal.base.i18n;x-internal:=true,
org.eclipse.passage.lic.internal.base.inspection;x-internal:=true,
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.email/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Bundle-Version: 1.0.1.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.passage.lic.email;x-friends:="org.eclipse.passage.lic.mail"
Export-Package: org.eclipse.passage.lic.email;x-friends:="org.eclipse.passage.lic.mail,org.eclipse.passage.loc.dashboard.ui"
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.emf/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0",
org.eclipse.emf.edit;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.passage.lic.base;bundle-version="0.0.0"
Export-Package: org.eclipse.passage.lic.emf.ecore;x-internal:=true,
Export-Package: org.eclipse.passage.lic.emf.ecore;x-friends:="org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.lic.emf.ecore.util;x-internal:=true,
org.eclipse.passage.lic.emf.edit;x-internal:=true,
org.eclipse.passage.lic.internal.emf.i18n;x-internal:=true
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.eclipse.passage.lic.jface/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.passage.lic.base;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.passage.lic.equinox;bundle-version="0.4.0"
Export-Package: org.eclipse.passage.lic.internal.jface;x-internal:=true,
org.eclipse.passage.lic.internal.jface.dialogs.licensing;x-friends:="org.eclipse.passage.lic.e4.ui",
org.eclipse.passage.lic.internal.jface.dialogs.licensing;x-friends:="org.eclipse.passage.lic.e4.ui,org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.lic.internal.jface.i18n;x-internal:=true,
org.eclipse.passage.lic.jface;x-internal:=true,
org.eclipse.passage.lic.jface.actions,
org.eclipse.passage.lic.jface.resource;x-internal:=true,
org.eclipse.passage.lic.jface.resource;x-friends:="org.eclipse.passage.loc.dashboard.ui,org.eclipse.passage.loc.workbench",
org.eclipse.passage.lic.jface.widgets;x-internal:=true
Bundle-ActivationPolicy: lazy
3 changes: 2 additions & 1 deletion bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Export-Package: org.eclipse.passage.loc.internal.api;
x-friends:="org.eclipse.passage.loc.workbench,
org.eclipse.passage.loc.licenses.ui,
org.eclipse.passage.loc.users.ui,
org.eclipse.passage.loc.products.ui",
org.eclipse.passage.loc.products.ui,
org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.loc.internal.emf;x-internal:=true
Require-Bundle: org.eclipse.e4.core.services;bundle-version="0.0.0",
org.eclipse.emf.edit;bundle-version="2.16.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2019, 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.internal.api;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

/**
*
* Experimental API to select existing or create new instance of given type.
*
*/
public final class ZeroOrMany<C> {

private final Supplier<Collection<C>> supplier;

public ZeroOrMany(Supplier<Collection<C>> input) {
this.supplier = input;
}

/**
*
* @param create the supplier of new instances. If no {@code input} elements are
* supplies then a singleton collection of a newly created one is
* returned. The supplier can potentially return nothing - then
* the output collection is to be empty.
* @param select the filtering selector callback which takes existing instances
* ({@code input}) and does a filtering of any complexity,
* possibly invoking UI.
* @return collection of {@code select}-ed instances, a singleton
* {@code new instance} collection or an empty collection.
*/
public Collection<C> choose(Supplier<Optional<C>> create, Function<Collection<C>, Collection<C>> select) {
Collection<C> input = supplier.get();
if (input.isEmpty()) {
return create.get()//
.map(Collections::singleton)//
.orElse(Collections.emptySet());
}
return select.apply(input);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* Experimental API to select existing or create new instance of given type.
*
*/
public final class ZeroOneMany<C> {
public final class ZeroOrOne<C> {

private final Supplier<Iterable<C>> supplier;

public ZeroOneMany(Supplier<Iterable<C>> input) {
public ZeroOrOne(Supplier<Iterable<C>> input) {
this.supplier = input;
}

Expand All @@ -50,8 +50,8 @@ public Optional<C> choose(Supplier<Optional<C>> create, Function<Iterable<C>, Op
return Optional.ofNullable(first);
}

private Optional<C> optional(Optional<C> untrasted) {
return Optional.ofNullable(untrasted).orElse(Optional.empty());
private Optional<C> optional(Optional<C> untrusted) {
return Optional.ofNullable(untrusted).orElse(Optional.empty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.passage.lic.jface.resource.LicensingImages;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage;
import org.eclipse.passage.lic.products.ProductVersionDescriptor;
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.loc.dashboard.ui.wizards.floating.FloatingDataPack;
import org.eclipse.passage.loc.dashboard.ui.wizards.floating.IssueFloatingLicenseWizard;
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;
import org.eclipse.swt.widgets.Shell;
Expand All @@ -33,16 +35,23 @@ public class DashboardIssueFloatingLicenseHandler {

@Execute
public void execute(IEclipseContext context,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional LicensePlanDescriptor licensePlan,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional LicensePlanDescriptor plan,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional UserDescriptor user,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ProductVersionDescriptor productVersion) {
Shell shell = context.get(Shell.class);
IssueFloatingLicenseWizard wizard = new IssueFloatingLicenseWizard(context);
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.create();
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ProductVersionDescriptor product) {
open(context, //
new IssueFloatingLicenseWizard(//
context, //
new FloatingDataPack(//
java.util.Optional.ofNullable(plan), //
java.util.Optional.ofNullable(user), //
java.util.Optional.ofNullable(product))) //
);
}

Shell createdShell = dialog.getShell();
createdShell.setImage(LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePack().getName()));
private void open(IEclipseContext context, Wizard wizard) {
WizardDialog dialog = new WizardDialog(context.get(Shell.class), wizard);
dialog.create();
dialog.getShell().setImage(LicensingImages.getImage(LicensesPackage.eINSTANCE.getLicensePack().getName()));
dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
dialog.open();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@
import org.eclipse.passage.lic.products.ProductVersionDescriptor;
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.loc.dashboard.ui.wizards.IssueLicenseWizard;
import org.eclipse.passage.loc.dashboard.ui.wizards.PersonalDataPack;
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;
import org.eclipse.swt.widgets.Shell;

public class DashboardIssueLicenseHandler {

@Execute
public void execute(IEclipseContext context,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional LicensePlanDescriptor licensePlan,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional LicensePlanDescriptor plan,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional UserDescriptor user,
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ProductVersionDescriptor productVersion) {
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ProductVersionDescriptor product) {
Shell shell = context.get(Shell.class);
IssueLicenseWizard wizard = new IssueLicenseWizard(context);
wizard.init(licensePlan, user, productVersion);
IssueLicenseWizard wizard = new IssueLicenseWizard(context, new PersonalDataPack(//
java.util.Optional.ofNullable(plan), //
java.util.Optional.ofNullable(user), //
java.util.Optional.ofNullable(product)//
));
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*******************************************************************************
* 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;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Supplier;

import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.products.ProductVersionDescriptor;
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.loc.internal.api.LicensingRequest;

final class CollectedLicensingRequest implements LicensingRequest {

private final ZoneId zone = ZoneId.systemDefault();
private final String uuid = UUID.randomUUID().toString();
private final Date stamp = new Date();

private final Supplier<Optional<LicensePlanDescriptor>> plan;
private final Supplier<Optional<UserDescriptor>> user;
private final Supplier<Optional<ProductVersionDescriptor>> product;
private final Supplier<Optional<List<LocalDate>>> period;

CollectedLicensingRequest(//
Supplier<Optional<LicensePlanDescriptor>> plan, //
Supplier<Optional<UserDescriptor>> user, //
Supplier<Optional<ProductVersionDescriptor>> product, //
Supplier<Optional<List<LocalDate>>> period) {
this.plan = plan;
this.user = user;
this.product = product;
this.period = period;
}

@Override
public Date getValidUntil() {
return Date.from(period.get().get().get(1).atStartOfDay(zone).toInstant());
}

@Override
public Date getValidFrom() {
return Date.from(period.get().get().get(0).atStartOfDay(zone).toInstant());
}

@Override
public String getUserIdentifier() {
return user.get().get().getEmail();
}

@Override
public String getUserFullName() {
return user.get().get().getFullName();
}

@Override
public String getProductVersion() {
return product.get().get().getVersion();
}

@Override
public String getProductIdentifier() {
return product.get().get().getProduct().getIdentifier();
}

@Override
public String getPlanIdentifier() {
return plan.get().get().getIdentifier();
}

@Override
public String getIdentifier() {
return uuid;
}

@Override
public Date getCreationDate() {
return stamp;
}

@Override
public String getConditionType() {
return user.get().get().getPreferredConditionType();
}

@Override
public String getConditionExpression() {
return user.get().get().getPreferredConditionExpression();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.passage.loc.dashboard.ui.wizards;

import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.eclipse.e4.core.contexts.IEclipseContext;
Expand All @@ -33,15 +34,15 @@
public class IssueLicenseDetailsPage extends WizardPage {

private final IEclipseContext context;

private LicensePackDescriptor licensePack;
private final Supplier<LicensePackDescriptor> data;
private Text info;
private Text from;
private String mailFrom = ""; //$NON-NLS-1$

protected IssueLicenseDetailsPage(String pageName, IEclipseContext context) {
protected IssueLicenseDetailsPage(String pageName, Supplier<LicensePackDescriptor> data, IEclipseContext context) {
super(pageName);
this.context = context;
this.data = data;
setTitle(IssueLicensePageMessages.IssueLicenseDetailsPage_page_title);
setDescription(IssueLicensePageMessages.IssueLicenseDetailsPage_page_description);
}
Expand Down Expand Up @@ -70,10 +71,6 @@ private void createEmlButton(Composite parent) {
from.addModifyListener(e -> mailFrom = from.getText().trim());
}

void init(LicensePackDescriptor pack) {
this.licensePack = pack;
}

@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
Expand All @@ -85,7 +82,7 @@ public void setVisible(boolean visible) {
if (mailing == null) {
return;
}
info.setText(new EmailTemplate(mailing).details(licensePack).stream()//
info.setText(new EmailTemplate(mailing).details(data.get()).stream()//
.collect(Collectors.joining(System.lineSeparator())));
}
}
Expand Down
Loading