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

565011 - API revision | permission | rebuild the core of condition expression evaluation #294

Merged
merged 3 commits into from
Jul 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*******************************************************************************/
package org.eclipse.passage.lic.api.access;

import org.eclipse.passage.lic.internal.api.conditions.evaluation.EmittedPermissionsRegistry;
import org.eclipse.passage.lic.internal.api.conditions.evaluation.PermissionEmittersRegistry;

/**
* Takes care of all {@link PermissionEmitter} services registered at runtime.
*
* @since 0.4.0
* @deprecated use {@link EmittedPermissionsRegistry}
* @deprecated use {@link PermissionEmittersRegistry}
*/
@Deprecated
public interface PermissionEmitterRegistry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.util.Objects;

import org.eclipse.passage.lic.internal.api.registry.ServiceId;

/**
* <p>
* Defines the way the condition will be evaluated in a running environment. For
Expand All @@ -25,7 +27,7 @@
* Designed to be a <i>data-class</i>.
* </p>
*/
public abstract class EvaluationType {
public abstract class EvaluationType implements ServiceId {

private final String identifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.passage.lic.internal.api.conditions.evaluation;

import java.util.Collection;
import java.util.Objects;

/**
* Report {@linkplain Condition}s evaluation results.
Expand Down Expand Up @@ -51,6 +52,7 @@ public static final class Successful implements Emission {
private final Collection<Permission> permissions;

public Successful(Collection<Permission> permissions) {
Objects.requireNonNull(permissions, "Emission.Successful::permissions"); //$NON-NLS-1$
this.permissions = permissions;
}

Expand All @@ -76,6 +78,7 @@ public static final class Failed implements Emission {
private final EmissionFailureDiagnostic diagnose;

public Failed(EmissionFailureDiagnostic diagnose) {
Objects.requireNonNull(diagnose, "Emission.Failed::diagnose"); //$NON-NLS-1$
this.diagnose = diagnose;
}

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

import org.eclipse.passage.lic.internal.api.registry.Service;

public interface ExpressionEvaluationService extends Service<ExpressionProtocol> {

boolean evaluate(ParsedExpression expression, ExpressionTokenAssessmentService assessor);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* 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.conditions.evaluation;

import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.registry.Registry;

public interface ExpressionEvaluatorsRegistry
extends Supplier<Registry<ExpressionProtocol, ExpressionEvaluationService>> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* 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.conditions.evaluation;

@SuppressWarnings("serial")
public final class ExpressionParsingException extends Exception {

public ExpressionParsingException(String message, Throwable cause) {
super(message, cause);
}

public ExpressionParsingException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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.conditions.evaluation;

import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.registry.Registry;

public interface ExpressionPasringRegistry extends Supplier<Registry<ExpressionProtocol, ExpressionPasringService>> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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.conditions.evaluation;

import org.eclipse.passage.lic.internal.api.registry.Service;

public interface ExpressionPasringService extends Service<ExpressionProtocol> {

ParsedExpression parsed(String expression) throws ExpressionParsingException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* 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.conditions.evaluation;

import java.util.Objects;

import org.eclipse.passage.lic.internal.api.registry.ServiceId;

public abstract class ExpressionProtocol implements ServiceId {

private final String identifier;

protected ExpressionProtocol(String identifier) {
Objects.requireNonNull(identifier, "ExpressionProtocol::identifier"); //$NON-NLS-1$
this.identifier = identifier.trim().toLowerCase();
}

public final String identifier() {
return identifier;
}

@Override
public final int hashCode() {
return Objects.hash(identifier());
}

@Override
public final boolean equals(Object object) {
if (!ExpressionProtocol.class.isInstance(object)) {
return false;
}
return identifier.equals(((ExpressionProtocol) object).identifier);
}

@Override
public final String toString() {
return identifier;
}

public static final class Ands extends ExpressionProtocol {

public Ands() {
super("ands"); //$NON-NLS-1$
}

}

public static final class Default extends ExpressionProtocol {

public Default() {
super(new Ands().identifier());
}

}

public static final class Of extends ExpressionProtocol {

public Of(String identifier) {
super(identifier);
}

}

}
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.internal.api.conditions.evaluation;

import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;
import org.eclipse.passage.lic.internal.api.registry.Service;

/**
* <p>
* Condition expression parsing, depending on the protocol used, can boil down
* to a sophisticated construction of predicates.
* </p>
* <p>
* But at the bottom of the evaluation of such a construction there are quite
* simple questions for the runtime environment: is current operating system is
* Linux-like? is the hard disk serial equal to this precise value? - that kind
* of asking.
* </p>
* <p>
* Implementation of this interface for a particular {@linkplain EvaluationType}
* must answer only these simple questions. the rest of the evaluation logic is
* on {@linkplain ExpressionProtocol}-aware services.
* </p>
*/
public interface ExpressionTokenAssessmentService extends Service<EvaluationType> {

boolean equal(String key, String value);

// contains ()

// startsWith ()

// all the things we will ever need -> slice to [Operation]s

}
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.conditions.evaluation;

import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;
import org.eclipse.passage.lic.internal.api.registry.Registry;

public interface ExpressionTokenAssessorsRegistry
extends Supplier<Registry<EvaluationType, ExpressionTokenAssessmentService>> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* 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.conditions.evaluation;

public interface ParsedExpression {

ExpressionProtocol protocol();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
import org.eclipse.passage.lic.internal.api.registry.Registry;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;

public interface EmittedPermissionsRegistry extends Supplier<Registry<StringServiceId, EmittedPermissions>> {
public interface PermissionEmittersRegistry extends Supplier<Registry<StringServiceId, PermissionEmittingService>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.passage.lic.internal.api.registry.Service;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;

public interface EmittedPermissions extends Service<StringServiceId> {
public interface PermissionEmittingService extends Service<StringServiceId> {

/**
* <p>
Expand Down Expand Up @@ -47,6 +47,6 @@ public interface EmittedPermissions extends Service<StringServiceId> {
* reported in the returned {@linkplain Emission} instance.
* </p>
*/
Emission get(Collection<Condition> conditions, LicensedProduct product);
Emission emit(Collection<Condition> conditions, LicensedProduct product);

}