From 7eba35706e1f62eda63b993ca310285c75753bb4 Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Tue, 10 Nov 2020 15:20:27 +0300 Subject: [PATCH 1/2] Bug 568632 Implement feature grant acquire/release Invite Acquiring/releasing service interfaces Signed-off-by: eparovyshnaya --- .../META-INF/MANIFEST.MF | 1 + .../acquire/LicenseAcquisitionService.java | 25 ++++++++++ .../LicenseAcquisitionServiceRegistry.java | 23 +++++++++ .../hc/remote/impl/RequestParameters.java | 48 +++++++++++++++++-- .../acquire/AcquireRequestParameters.java | 34 +++++-------- .../impl/acquire/RemoteAcquiringService.java | 39 +++++++++++++++ .../impl/mine/MineRequestParameters.java | 36 ++++++-------- 7 files changed, 159 insertions(+), 47 deletions(-) create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionService.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionServiceRegistry.java create mode 100644 bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/RemoteAcquiringService.java diff --git a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF index 1896fa02e..7d435db3c 100644 --- a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF @@ -27,6 +27,7 @@ Export-Package: org.eclipse.passage.lic.internal.api; org.eclipse.passage.lbc.base.tests, org.eclipse.passage.loc.licenses.core, org.eclipse.passage.lic.net", + org.eclipse.passage.lic.internal.api.acquire;x-friends:="org.eclipse.passage.lic.hc", org.eclipse.passage.lic.internal.api.conditions; x-friends:="org.eclipse.passage.lbc.api, org.eclipse.passage.lbc.base, diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionService.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionService.java new file mode 100644 index 000000000..2902adca4 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionService.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.internal.api.acquire; + +import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; +import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget; +import org.eclipse.passage.lic.internal.api.registry.Service; + +public interface LicenseAcquisitionService extends Service { + + ServiceInvocationResult acquire(); + + ServiceInvocationResult release(); + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionServiceRegistry.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionServiceRegistry.java new file mode 100644 index 000000000..c82676eac --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/acquire/LicenseAcquisitionServiceRegistry.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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.internal.api.acquire; + +import java.util.function.Supplier; + +import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget; +import org.eclipse.passage.lic.internal.api.registry.Registry; + +public interface LicenseAcquisitionServiceRegistry + extends Supplier> { + +} diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java index e28f16c83..197cd5c4f 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java @@ -15,26 +15,63 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess; +import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; +import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; +import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; import org.eclipse.passage.lic.internal.base.NamedData; +import org.eclipse.passage.lic.internal.base.ProductIdentifier; +import org.eclipse.passage.lic.internal.base.ProductVersion; +import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; import org.eclipse.passage.lic.internal.hc.i18n.AccessMessages; +import org.eclipse.passage.lic.internal.net.LicenseUser; +import org.eclipse.passage.lic.internal.net.LicensingAction; +import org.eclipse.passage.lic.internal.net.ServerAuthenticationExpression; +import org.eclipse.passage.lic.internal.net.ServerAuthenticationType; public abstract class RequestParameters { - protected RequestParameters() { + private final LicensedProduct product; + private final FloatingLicenseAccess access; + + protected RequestParameters(LicensedProduct product, FloatingLicenseAccess access) { + this.product = product; + this.access = access; } public final String query() throws LicensingException { StringBuilder params = new StringBuilder(); - Arrays.stream(parameters())// + parameters().stream()// .map(NamedData.Writable::new)// .forEach(writable -> writable.write(params, "=", "&")); //$NON-NLS-1$ //$NON-NLS-2$ return '?' + params.toString(); } @SuppressWarnings("rawtypes") - protected abstract NamedData[] parameters() throws LicensingException; + private List parameters() throws LicensingException { + return Arrays.asList(// + generalParameters(), // + actionParameters()).stream() // + .flatMap(List::stream)// + .collect(Collectors.toList()); + } + + @SuppressWarnings("rawtypes") + private List generalParameters() throws LicensingException { + return Arrays.asList( // + new ProductIdentifier(encode(product.identifier())), // + new ProductVersion(encode(product.version())), // + new LicensingAction(action()), // + new LicensingContentType(new ContentType.Xml()), // + new LicenseUser(access.getUser()), // + new ServerAuthenticationType(access.getServer()), // + new ServerAuthenticationExpression(access.getServer())); + + } protected String encode(String value) throws LicensingException { try { @@ -44,4 +81,9 @@ protected String encode(String value) throws LicensingException { } } + protected abstract ConditionAction action() throws LicensingException; + + @SuppressWarnings("rawtypes") + protected abstract List actionParameters() throws LicensingException; + } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/AcquireRequestParameters.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/AcquireRequestParameters.java index 31a017e2d..d8d9ed55c 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/AcquireRequestParameters.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/AcquireRequestParameters.java @@ -12,46 +12,34 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.hc.remote.impl.acquire; +import java.util.Collections; +import java.util.List; + import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; -import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; -import org.eclipse.passage.lic.internal.base.FeatureIdentifier; import org.eclipse.passage.lic.internal.base.NamedData; import org.eclipse.passage.lic.internal.base.ProductIdentifier; -import org.eclipse.passage.lic.internal.base.ProductVersion; -import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters; -import org.eclipse.passage.lic.internal.net.LicenseUser; -import org.eclipse.passage.lic.internal.net.LicensingAction; -import org.eclipse.passage.lic.internal.net.ServerAuthenticationExpression; -import org.eclipse.passage.lic.internal.net.ServerAuthenticationType; final class AcquireRequestParameters extends RequestParameters { - private final LicensedProduct product; private final String feature; - private final FloatingLicenseAccess access; AcquireRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access) { - this.product = product; + super(product, access); this.feature = feature; - this.access = access; } @Override - @SuppressWarnings("rawtypes") - protected NamedData[] parameters() throws LicensingException { - return new NamedData[] { // - new ProductIdentifier(encode(product.identifier())), // - new ProductVersion(encode(product.version())), // - new FeatureIdentifier(encode(feature)), // - new LicensingAction(new ConditionAction.Acquire()), // - new LicensingContentType(new ContentType.Xml()), // - new LicenseUser(access.getUser()), // - new ServerAuthenticationType(access.getServer()), // - new ServerAuthenticationExpression(access.getServer()) }; + protected ConditionAction action() { + return new ConditionAction.Acquire(); } + @SuppressWarnings("rawtypes") + @Override + protected List actionParameters() throws LicensingException { + return Collections.singletonList(new ProductIdentifier(encode(feature))); + } } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/RemoteAcquiringService.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/RemoteAcquiringService.java new file mode 100644 index 000000000..4d8b894c5 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/acquire/RemoteAcquiringService.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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.internal.hc.remote.impl.acquire; + +import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; +import org.eclipse.passage.lic.internal.api.acquire.LicenseAcquisitionService; +import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget; + +public final class RemoteAcquiringService implements LicenseAcquisitionService { + + private final ConditionMiningTarget target = new ConditionMiningTarget.Remote(); + + @Override + public ConditionMiningTarget id() { + return target; + } + + @Override + public ServiceInvocationResult acquire() { + + return null; + } + + @Override + public ServiceInvocationResult release() { + return null; + } + +} diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java index 01c93cad0..3a5e27f2b 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java @@ -12,41 +12,35 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.hc.remote.impl.mine; +import java.util.Collections; +import java.util.List; + import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; -import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; import org.eclipse.passage.lic.internal.base.NamedData; import org.eclipse.passage.lic.internal.base.ProductIdentifier; -import org.eclipse.passage.lic.internal.base.ProductVersion; -import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters; -import org.eclipse.passage.lic.internal.net.LicenseUser; -import org.eclipse.passage.lic.internal.net.LicensingAction; -import org.eclipse.passage.lic.internal.net.ServerAuthenticationExpression; -import org.eclipse.passage.lic.internal.net.ServerAuthenticationType; final class MineRequestParameters extends RequestParameters { - private final LicensedProduct product; - private final FloatingLicenseAccess access; - MineRequestParameters(LicensedProduct product, FloatingLicenseAccess access) { - this.product = product; - this.access = access; + private final String feature; + + MineRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access) { + super(product, access); + this.feature = feature; } @Override + protected ConditionAction action() { + return new ConditionAction.Mine(); + } + @SuppressWarnings("rawtypes") - protected NamedData[] parameters() throws LicensingException { - return new NamedData[] { // - new ProductIdentifier(encode(product.identifier())), // - new ProductVersion(encode(product.version())), // - new LicensingAction(new ConditionAction.Mine()), // - new LicensingContentType(new ContentType.Xml()), // - new LicenseUser(access.getUser()), // - new ServerAuthenticationType(access.getServer()), // - new ServerAuthenticationExpression(access.getServer()) }; + @Override + protected List actionParameters() throws LicensingException { + return Collections.singletonList(new ProductIdentifier(encode(feature))); } } From 6ecd7c800b99f7dec753c99215234d589f3d7829 Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Tue, 10 Nov 2020 17:26:02 +0300 Subject: [PATCH 2/2] Bug 568632 Implement feature grant acquire/release Invite Acquiring/releasing service interfaces Signed-off-by: eparovyshnaya --- .../hc/remote/impl/mine/MineRequestParameters.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java index 3a5e27f2b..7a234d2ff 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/mine/MineRequestParameters.java @@ -20,16 +20,12 @@ import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.conditions.ConditionAction; import org.eclipse.passage.lic.internal.base.NamedData; -import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters; final class MineRequestParameters extends RequestParameters { - private final String feature; - - MineRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access) { + MineRequestParameters(LicensedProduct product, FloatingLicenseAccess access) { super(product, access); - this.feature = feature; } @Override @@ -40,7 +36,7 @@ protected ConditionAction action() { @SuppressWarnings("rawtypes") @Override protected List actionParameters() throws LicensingException { - return Collections.singletonList(new ProductIdentifier(encode(feature))); + return Collections.emptyList(); } }