Skip to content

Commit

Permalink
Bug 571147 extend 'lic.net' with common facilities
Browse files Browse the repository at this point in the history
Prepare basic net request processing units to be moved to the
generalized `lic.net` bundle

Signed-off-by: eparovyshnaya <elena.parovyshnaya@gmail.com>
  • Loading branch information
eparovyshnaya committed Feb 14, 2021
1 parent fcbdcef commit 6b48376
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 23 deletions.
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2021 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.internal.lac.base;

final class CanUse {

}
Expand Up @@ -17,14 +17,14 @@
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;

final class Acquire extends ChoreDraft {
final class Acquire extends ChoreDraft<RawRequest> {

Acquire(RawRequest data) {
super(data);
}

@Override
protected NetResponse withProductUser(ProductUserRequest request) throws LicensingException {
protected NetResponse withProductUser(ProductUserRequest<RawRequest> request) throws LicensingException {
return new Acquisition(request).get();
}

Expand Down
Expand Up @@ -16,19 +16,19 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.internal.api.EvaluationInstructions;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.api.handle.Chore;
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.Failure;

abstract class ChoreDraft implements Chore {
abstract class ChoreDraft<R extends NetRequest> implements Chore {

protected final RawRequest data;
protected final R data;
protected final Logger log = LogManager.getLogger(getClass());

protected ChoreDraft(RawRequest request) {
protected ChoreDraft(R request) {
this.data = request;
}

Expand All @@ -44,9 +44,9 @@ public final NetResponse getDone() {
log.error("failed: ", e); //$NON-NLS-1$
return new Failure.ForeignServer(e.getMessage());
}
ProductUserRequest request;
ProductUserRequest<R> request;
try {
request = new ProductUserRequest(data);
request = new ProductUserRequest<R>(data);
} catch (LicensingException e) {
log.error("failed: ", e); //$NON-NLS-1$ ;
return failed(e.getMessage());
Expand All @@ -65,7 +65,7 @@ public final NetResponse getDone() {
}
}

protected abstract NetResponse withProductUser(ProductUserRequest request) throws LicensingException;
protected abstract NetResponse withProductUser(ProductUserRequest<R> request) throws LicensingException;

protected final NetResponse failed(String details) {
return new Failure.OperationFailed(getClass().getSimpleName(), details);
Expand Down
Expand Up @@ -16,14 +16,14 @@
import org.eclipse.passage.lbc.internal.base.mine.Conditions;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;

final class Mine extends ChoreDraft {
final class Mine extends ChoreDraft<RawRequest> {

Mine(RawRequest data) {
super(data);
}

@Override
protected NetResponse withProductUser(ProductUserRequest request) {
protected NetResponse withProductUser(ProductUserRequest<RawRequest> request) {
return new Conditions(request).get();
}

Expand Down
Expand Up @@ -14,21 +14,21 @@

import java.util.Optional;

import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.base.BaseLicensedProduct;
import org.eclipse.passage.lic.internal.base.ProductIdentifier;
import org.eclipse.passage.lic.internal.base.ProductVersion;
import org.eclipse.passage.lic.internal.net.LicenseUser;
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;

public final class ProductUserRequest {
public final class ProductUserRequest<R extends NetRequest> {

private final RawRequest raw;
private final R raw;
private final Optional<LicensedProduct> product;
private final Optional<String> user;

public ProductUserRequest(RawRequest raw) throws LicensingException {
public ProductUserRequest(R raw) throws LicensingException {
this.raw = raw;
this.product = extractProduct();
this.user = extractUser();
Expand All @@ -49,7 +49,7 @@ private Optional<String> extractUser() {
return new LicenseUser(raw::parameter).get();
}

public RawRequest raw() {
public R raw() {
return raw;
}

Expand Down
Expand Up @@ -17,14 +17,14 @@
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;

final class Release extends ChoreDraft {
final class Release extends ChoreDraft<RawRequest> {

Release(RawRequest data) {
super(data);
}

@Override
protected NetResponse withProductUser(ProductUserRequest request) throws LicensingException {
protected NetResponse withProductUser(ProductUserRequest<RawRequest> request) throws LicensingException {
return new Acquisition(request).returnBack();
}
}
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.passage.lbc.internal.base.PlainSuceess;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.api.Grants;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.floating.model.api.GrantAcqisition;
import org.eclipse.passage.lic.floating.model.meta.FloatingPackage;
import org.eclipse.passage.lic.internal.api.LicensingException;
Expand All @@ -34,10 +35,10 @@

public final class Acquisition {

private final ProductUserRequest data;
private final ProductUserRequest<RawRequest> data;
private final Logger log = LogManager.getLogger(getClass());

public Acquisition(ProductUserRequest data) {
public Acquisition(ProductUserRequest<RawRequest> data) {
Objects.requireNonNull(data, "Acquisition::data"); //$NON-NLS-1$
this.data = data;
}
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.apache.logging.log4j.Logger;
import org.eclipse.passage.lbc.internal.base.EObjectTransfer;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.floating.FloatingFileExtensions;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.PassageAction;
Expand All @@ -39,16 +40,16 @@

public final class Conditions implements Supplier<NetResponse> {

private final ProductUserRequest data;
private final ProductUserRequest<RawRequest> data;
private final Supplier<Path> source;
private final Logger log = LogManager.getLogger(getClass());

public Conditions(ProductUserRequest data, Supplier<Path> base) {
public Conditions(ProductUserRequest<RawRequest> data, Supplier<Path> base) {
this.data = data;
this.source = base;
}

public Conditions(ProductUserRequest data) {
public Conditions(ProductUserRequest<RawRequest> data) {
this(data, new LicensingFolder(new UserHomePath()));
}

Expand Down

0 comments on commit 6b48376

Please sign in to comment.