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 568632 Implement feature grant acquire/release #540

Merged
merged 2 commits into from
Nov 10, 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
1 change: 1 addition & 0 deletions bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ConditionMiningTarget> {

ServiceInvocationResult<Boolean> acquire();

ServiceInvocationResult<Boolean> release();

}
Original file line number Diff line number Diff line change
@@ -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<Registry<ConditionMiningTarget, LicenseAcquisitionService>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>::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<NamedData> parameters() throws LicensingException {
return Arrays.asList(//
generalParameters(), //
actionParameters()).stream() //
.flatMap(List::stream)//
.collect(Collectors.toList());
}

@SuppressWarnings("rawtypes")
private List<NamedData> 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 {
Expand All @@ -44,4 +81,9 @@ protected String encode(String value) throws LicensingException {
}
}

protected abstract ConditionAction action() throws LicensingException;

@SuppressWarnings("rawtypes")
protected abstract List<NamedData> actionParameters() throws LicensingException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NamedData> actionParameters() throws LicensingException {
return Collections.singletonList(new ProductIdentifier(encode(feature)));
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> acquire() {

return null;
}

@Override
public ServiceInvocationResult<Boolean> release() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,31 @@
*******************************************************************************/
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;
super(product, access);
}

@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<NamedData> actionParameters() throws LicensingException {
return Collections.emptyList();
}

}