Skip to content

Commit

Permalink
Bug 565011 rebuild the core of condition expression evaluation
Browse files Browse the repository at this point in the history
 - design set of interfaces for the flexible condition expression
evaluation

 Signed-off-by: elena.parovyshnaya <elena.parovyshnaya@gmail.com>
  • Loading branch information
eparovyshnaya committed Jul 8, 2020
1 parent cf62f6a commit c2f87a0
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 3 deletions.
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
@@ -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);

}
@@ -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>> {

}
@@ -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);
}

}
@@ -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>> {

}
@@ -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;

}
@@ -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);
}

}

}
@@ -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

}
@@ -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>> {

}
@@ -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();

}
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>> {

}
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);

}

0 comments on commit c2f87a0

Please sign in to comment.