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

Bug 567032 issue floating license configuration wizard #508

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bundles/org.eclipse.passage.lic.floating.edit/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ _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_ProductRef_type = Product Reference
_UI_ProductRef_type_detailed = Product {0} version {1}
_UI_FloatingServer_type = Server
_UI_UserGrant_type = User {0} authenticated by {1}: {2}
_UI_FeatureGrant_type = Feature {0} {1} ({2}): {3} grants valid from {4} till {5} for {6} minutes
_UI_UserGrant_type = User Grant
_UI_UserGrant_type_detailed = User {0} authenticated by {1}: {2}
_UI_FeatureGrant_type = Feature Grant
_UI_FeatureGrant_type_detailed = Feature {0} {1} ({2}): {3} grants valid from {4} until {5} for {6} minutes
_UI_ValidityPeriod_type = Validity Period
_UI_ValidityPeriodClosed_type = Validity Period Closed
_UI_ValidityPeriodClosed_type_detailed=From {0} until {1}
_UI_EvaluationInstructions_type = Evaluation Instructions
_UI_EvaluationInstructions_type_detailed=Assess expression [{0}] by {1} environment
_UI_VersionMatch_type = Version Match
_UI_Unknown_type = Object
_UI_Unknown_datatype= Value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* 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.lic.floating.edit.providers;

import java.util.Date;
import java.util.function.Function;

import org.eclipse.passage.lic.floating.model.api.ValidityPeriod;
import org.eclipse.passage.lic.floating.model.api.ValidityPeriodClosed;

final class ClosedPeriodPrinted {

private final String from;
private final String until;

// FIXME: no code in constructor. It's work for CachingFunction.
ClosedPeriodPrinted(ValidityPeriod valid) {
ValidityPeriodClosed period = closed(valid);
this.from = date(period, ValidityPeriodClosed::getFrom);
this.until = date(period, ValidityPeriodClosed::getUntil);
}

private String date(ValidityPeriodClosed period, Function<ValidityPeriodClosed, Date> date) {
return period == null //
? "unknown" //$NON-NLS-1$
: new DatePrinted(date.apply(period)).get();
}

private ValidityPeriodClosed closed(ValidityPeriod period) {
if (period instanceof ValidityPeriodClosed) {
return (ValidityPeriodClosed) period;
}
return null;
}

String from() {
return from;
}

String until() {
return until;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* 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.lic.floating.edit.providers;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;

final class DatePrinted implements Supplier<String> {

private final Optional<Date> date;

public DatePrinted(Optional<Date> date) {
Objects.requireNonNull(date, "DatePrinted::date"); //$NON-NLS-1$
this.date = date;
}

/**
* @param date nullable
*/
public DatePrinted(Date date) {
this(Optional.ofNullable(date));
}

@Override
public String get() {
return date//
.map(d -> LocalDateTime.ofInstant(d.toInstant(), ZoneId.systemDefault()).toLocalDate().toString()) //
.orElse("unknown");//$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ protected boolean shouldComposeCreationImage() {
*/
@Override
public String getText(Object object) {
String label = ((EvaluationInstructions) object).getType();
return label == null || label.length() == 0 ? getString("_UI_EvaluationInstructions_type") : //$NON-NLS-1$
getString("_UI_EvaluationInstructions_type") + " " + label; //$NON-NLS-1$ //$NON-NLS-2$
EvaluationInstructions eval = (EvaluationInstructions) object;
return getString("_UI_EvaluationInstructions_type_detailed", //$NON-NLS-1$
new Object[] { //
new GetOrUnknown(eval.getExpression()).get(), //
new GetOrUnknown(eval.getType()).get()//
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
*******************************************************************************/
package org.eclipse.passage.lic.floating.edit.providers;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;

Expand All @@ -34,8 +31,6 @@
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.passage.lic.floating.edit.FLoatingLicensesEditPlugin;
import org.eclipse.passage.lic.floating.model.api.FeatureGrant;
import org.eclipse.passage.lic.floating.model.api.ValidityPeriod;
import org.eclipse.passage.lic.floating.model.api.ValidityPeriodClosed;
import org.eclipse.passage.lic.floating.model.api.VersionMatch;
import org.eclipse.passage.lic.floating.model.meta.FloatingPackage;

Expand Down Expand Up @@ -207,33 +202,14 @@ protected boolean shouldComposeCreationImage() {
@Override
public String getText(Object object) {
FeatureGrant grant = (FeatureGrant) object;
String feature = grant.getFeature() == null ? "unknown" : grant.getFeature(); //$NON-NLS-1$
String feature = new GetOrUnknown(grant.getFeature()).get();
Optional<VersionMatch> match = Optional.of(grant.getVersion());
String version = match.map(VersionMatch::getVersion).orElse("unknown"); //$NON-NLS-1$
String rule = match.map(VersionMatch::getRule).orElse("unknown"); //$NON-NLS-1$
ValidityPeriodClosed period = closed(grant.getValid());
String from = period == null ? "unknown" : date(period.getFrom()); //$NON-NLS-1$
String until = period == null ? "unknown" : date(period.getUntil()); //$NON-NLS-1$
return getString("_UI_FeatureGrant_type", //$NON-NLS-1$
new Object[] { feature, version, rule, grant.getCapacity(), from, until, grant.getVivid() });
}

/**
* @generated NOT
*/
private ValidityPeriodClosed closed(ValidityPeriod period) {
if (period instanceof ValidityPeriodClosed) {
return (ValidityPeriodClosed) period;
}
return null;
}

/**
* @generated NOT
*/
private String date(Date source) {
return source == null ? "unknown" //$NON-NLS-1$
: LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault()).toLocalDate().toString();
ClosedPeriodPrinted period = new ClosedPeriodPrinted(grant.getValid());
return getString("_UI_FeatureGrant_type_detailed", //$NON-NLS-1$
new Object[] { feature, version, rule, grant.getCapacity(), //
period.from(), period.until(), grant.getVivid() });
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* 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.lic.floating.edit.providers;

import java.util.function.Supplier;

final class GetOrUnknown implements Supplier<String> {

private final String nullable;

GetOrUnknown(String nullable) {
this.nullable = nullable;
}

@Override
public String get() {
return nullable == null ? "unknown" : nullable; //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
Expand All @@ -30,6 +31,7 @@
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.passage.lic.floating.edit.FLoatingLicensesEditPlugin;
import org.eclipse.passage.lic.floating.model.api.LicenseRequisites;
import org.eclipse.passage.lic.floating.model.api.ProductRef;
import org.eclipse.passage.lic.floating.model.meta.FloatingPackage;

/**
Expand Down Expand Up @@ -176,16 +178,27 @@ protected boolean shouldComposeCreationImage() {
}

/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* This returns the label text for the adapted class. <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*
* @generated NOT
*/
@Override
public String getText(Object object) {
String label = ((LicenseRequisites) object).getIdentifier();
return label == null || label.length() == 0 ? getString("_UI_LicenseRequisites_type") : //$NON-NLS-1$
getString("_UI_LicenseRequisites_type") + " " + label; //$NON-NLS-1$ //$NON-NLS-2$
LicenseRequisites license = (LicenseRequisites) object;
String company = license.getCompany() == null ? "unknown" : license.getCompany(); //$NON-NLS-1$
String product = Optional.ofNullable(license.getProduct())//
.map(ProductRef::getProduct) //
.orElse("unknown"); //$NON-NLS-1$
String version = Optional.ofNullable(license.getProduct())//
.map(ProductRef::getVersion) //
.orElse("unknown"); //$NON-NLS-1$
return getString("_UI_LicenseRequisites_type_detailed", //$NON-NLS-1$
new Object[] { //
company,//
product,//
version
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,20 @@ protected boolean shouldComposeCreationImage() {
}

/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* This returns the label text for the adapted class. <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*
* @generated NOT
*/
@Override
public String getText(Object object) {
String label = ((ProductRef) object).getProduct();
return label == null || label.length() == 0 ? getString("_UI_ProductRef_type") : //$NON-NLS-1$
getString("_UI_ProductRef_type") + " " + label; //$NON-NLS-1$ //$NON-NLS-2$
ProductRef product = (ProductRef) object;
return getString("_UI_ProductRef_type_detailed", //$NON-NLS-1$
new Object[] { //
new GetOrUnknown(product.getProduct()).get(), //
new GetOrUnknown(product.getVersion()).get() //
});

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ protected boolean shouldComposeCreationImage() {
@Override
public String getText(Object object) {
UserGrant grant = (UserGrant) object;
String user = grant.getUser() == null ? "unknown" : grant.getUser(); //$NON-NLS-1$
String user = new GetOrUnknown(grant.getUser()).get();
Optional<EvaluationInstructions> auth = Optional.ofNullable(grant.getAuthentication());
String env = auth.map(EvaluationInstructions::getType).orElse("undefined"); //$NON-NLS-1$
String expression = auth.map(EvaluationInstructions::getExpression).orElse("undefined"); //$NON-NLS-1$
return getString("_UI_UserGrant_type", new Object[] { user, env, expression }); //$NON-NLS-1$
return getString("_UI_UserGrant_type_detailed", new Object[] { user, env, expression }); //$NON-NLS-1$
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.passage.lic.floating.edit.providers;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
Expand Down Expand Up @@ -118,10 +117,12 @@ protected boolean shouldComposeCreationImage() {
*/
@Override
public String getText(Object object) {
Date labelValue = ((ValidityPeriodClosed) object).getFrom();
String label = labelValue == null ? null : labelValue.toString();
return label == null || label.length() == 0 ? getString("_UI_ValidityPeriodClosed_type") : //$NON-NLS-1$
getString("_UI_ValidityPeriodClosed_type") + " " + label; //$NON-NLS-1$ //$NON-NLS-2$
ValidityPeriodClosed period = (ValidityPeriodClosed) object;
return getString("_UI_ValidityPeriodClosed_type_detailed", //$NON-NLS-1$
new Object[] { //
new DatePrinted(period.getFrom()).get(), //
new DatePrinted(period.getUntil()).get() //
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<domainModelEFeature xsi:type="ecore:EAttribute" href="http://www.eclipse.org/passage/lic/floating/0.1.0#//LicenseRequisites/identifier"/>
</domainModelReference>
</children>
<children xsi:type="org.eclipse.emf.ecp.view.model:Control" xmi:id="_4QMGwhrKEeuMV_ofZRuPaw" name="Control issueDate">
<children xsi:type="org.eclipse.emf.ecp.view.model:Control" xmi:id="_4QMGwhrKEeuMV_ofZRuPaw" name="Control issueDate" readonly="true">
<domainModelReference xsi:type="org.eclipse.emf.ecp.view.model:FeaturePathDomainModelReference" xmi:id="_4QMGwxrKEeuMV_ofZRuPaw">
<domainModelEFeature xsi:type="ecore:EAttribute" href="http://www.eclipse.org/passage/lic/floating/0.1.0#//LicenseRequisites/issueDate"/>
</domainModelReference>
Expand All @@ -26,7 +26,7 @@
<domainModelEFeature xsi:type="ecore:EReference" href="http://www.eclipse.org/passage/lic/floating/0.1.0#//LicenseRequisites/product"/>
</domainModelReference>
</children>
<children xsi:type="org.eclipse.emf.ecp.view.model:Control" xmi:id="_4QMGyhrKEeuMV_ofZRuPaw" name="Control valid">
<children xsi:type="org.eclipse.emf.ecp.view.model:Control" xmi:id="_4QMGyhrKEeuMV_ofZRuPaw" name="Control valid" readonly="true">
<domainModelReference xsi:type="org.eclipse.emf.ecp.view.model:FeaturePathDomainModelReference" xmi:id="_4QMGyxrKEeuMV_ofZRuPaw">
<domainModelEFeature xsi:type="ecore:EReference" href="http://www.eclipse.org/passage/lic/floating/0.1.0#//LicenseRequisites/valid"/>
</domainModelReference>
Expand Down