Skip to content
Snippets Groups Projects
Commit d0d7faab authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

#30 Enable/Disable Actions

parent 9d0a3346
No related branches found
No related tags found
No related merge requests found
Showing
with 289 additions and 70 deletions
......@@ -2,6 +2,7 @@ package de.unikoblenz.fgbks.api;
import de.unikoblenz.fgbks.base.wordnet.WordnetService;
import de.unikoblenz.fgbks.core.dmn.verification.DmnVerificationService;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.FixActionService;
import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;
import javax.enterprise.context.ApplicationScoped;
......@@ -16,16 +17,25 @@ public class AppLifecycleBean {
@Inject
DmnVerificationService dmnVerificationService;
@Inject
FixActionService fixActionService;
private static final Logger LOGGER = LoggerFactory.getLogger("AppLifecycle");
@ConfigProperty(name = "wordnet.path")
private String wordnetPath;
@ConfigProperty(name = "verifier.fixes.active", defaultValue = "true")
private String activeFixes;
void onStart(@Observes StartupEvent ev) {
LOGGER.info("The dmn verification application is starting...");
// Init wordnet
LOGGER.info("Starting initialization of wordnet...");
WordnetService.getInstance(true, wordnetPath);
LOGGER.info("Generating fix values at init: ..");
fixActionService.setGlobalActive(Boolean.parseBoolean(activeFixes));
LOGGER.info("... " + fixActionService.isGlobalActive());
LOGGER.info("Starting initialization of verifier...");
dmnVerificationService.initVerifier();
}
......
......@@ -6,6 +6,9 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import de.unikoblenz.fgbks.core.dmn.verification.DmnVerificationService;
import de.unikoblenz.fgbks.core.dmn.verification.metrics.DmnVerificationMetricsService;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResultSet;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionScope;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionType;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.FixActionService;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.classification.ClassificationType;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.VerificationType;
import java.util.List;
......@@ -31,6 +34,8 @@ public class Verification {
@Inject protected DmnVerificationService dmnVerificationService;
@Inject
protected DmnVerificationMetricsService dmnVerificationMetricsService;
@Inject
protected FixActionService fixActionService;
/**
* Method to generate all verifications for a dmn with all registered verifiers.
......@@ -113,6 +118,17 @@ public class Verification {
dmnVerificationService.generateFromClassification(classificationName, payload, token));
}
private Response checkResult(VerifierResultSet resultSet) {
if (resultSet.getAmountOfVerifier() == 0) {
return Response.status(
BAD_REQUEST.getStatusCode(),
"The dmn syntax is not correct. The dmn can not be parsed.")
.build();
} else {
return Response.accepted(resultSet).build();
}
}
/**
* Method to get all registered classification types.
*
......@@ -126,14 +142,85 @@ public class Verification {
return Response.accepted(dmnVerificationMetricsService.getMetrics(token)).build();
}
private Response checkResult(VerifierResultSet resultSet) {
if (resultSet.getAmountOfVerifier() == 0) {
return Response.status(
BAD_REQUEST.getStatusCode(),
"The dmn syntax is not correct. The dmn can not be parsed.")
.build();
} else {
return Response.accepted(resultSet).build();
/**
* Method to get a boolean, if the actions are active or inactive
*
* @return true, if the actions are active
*/
@GET
@Path("/actions/global")
@Produces(MediaType.TEXT_PLAIN)
public Response getActionsGlobal() {
return Response.accepted(fixActionService.isGlobalActive()).build();
}
/**
* Method to set a boolean, if the actions is active or inactive
*
* @return true, if the actions are active
*/
@POST
@Path("/actions/global/{active}")
@Produces(MediaType.TEXT_PLAIN)
public Response setActionsGlobal(@PathParam("active") boolean active) {
fixActionService.setGlobalActive(active);
return Response.accepted(fixActionService.isGlobalActive()).build();
}
/**
* Method to get all allowed actions
*
* @return a map of allowed actions
*/
@GET
@Path("/actions/allowedActions")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllowedActions() {
return Response.accepted(fixActionService.getAllowedActions()).build();
}
/**
* Method to get all action types
*
* @return a map of allowed actions
*/
@GET
@Path("/actions/actionTypes")
@Produces(MediaType.APPLICATION_JSON)
public Response getActionsTypes() {
return Response.accepted(fixActionService.getActionTypes()).build();
}
/**
* Method to get all action scopes
*
* @return a list of actions scopes
*/
@GET
@Path("/actions/actionScopes")
@Produces(MediaType.APPLICATION_JSON)
public Response getActionsScopes() {
return Response.accepted(fixActionService.getActionScopes()).build();
}
/**
* Method to set a boolean, if the actions type are active or inactive
*
* @return true, if the request was successful
*/
@POST
@Path("/actions/allowedActions/{scope}/{type}/{value}")
@Produces(MediaType.TEXT_PLAIN)
public Response setAllowedActions(
@PathParam("scope") String actionScope,
@PathParam("type") String actionType,
@PathParam("value") Boolean value) {
try {
fixActionService.setValue(
ActionScope.valueOf(actionScope), ActionType.valueOf(actionType), value);
return Response.accepted(true).build();
} catch (Exception e) {
return Response.accepted(false).build();
}
}
}
......@@ -105,7 +105,7 @@ public class VDmnDefinitionsImpl extends AbstractVDmnElement implements VDmnDefi
public VDmnDefinitionsImpl build() {
// save all Ids and elements in the element map
// add the definition
value.elements.put(getId(), this.value);
value.elements.put(value.getId(), this.value);
// add the input data
value.getVDmnInputData().forEach(inData -> value.elements.put(inData.getId(), inData));
// add all decisions
......
......@@ -7,6 +7,7 @@ import de.unikoblenz.fgbks.core.dmn.verification.metrics.DmnVerificationMetricsS
import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResult;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResultSet;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResultSet.Builder;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.FixActionService;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.AbstractVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.DmnVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.Verifier;
......@@ -64,6 +65,8 @@ public class DmnVerificationService {
@Inject protected DmnService dmnService;
@Inject
protected DmnVerificationMetricsService dmnVerificationMetricsService;
@Inject
protected FixActionService fixActionService;
protected DmnVerificationService() {
super();
......@@ -90,8 +93,7 @@ public class DmnVerificationService {
* @param token the token for metrics
* @return a {@link VerifierResultSet} containing all verifications of the selected verifier.
*/
public VerifierResultSet generateFromTypes(List<String> types, String dmnXml,
String token) {
public VerifierResultSet generateFromTypes(List<String> types, String dmnXml, String token) {
return generateWithFilter(dmnXml, types, null, token);
}
......@@ -99,7 +101,6 @@ public class DmnVerificationService {
* Create a {@link VerifierResultSet} by executing the verifiers, which is registered in the
* current deployment and has the name of the {@code type} parameter.
*
*
* @param classification the type as String. Should be the name of a {@link ClassificationType}.
* @param dmnXml the XML of the DMN as String
* @param token the token for metrics
......@@ -188,6 +189,7 @@ public class DmnVerificationService {
DefaultConfiguration.getBuilder()
.withVerificationProcessId(verificationProcessId)
.withDmnObjectContainer(dmnObjectContainerFromXml.get())
.withFixActionService(fixActionService)
.build());
return map;
}
......@@ -257,8 +259,8 @@ public class DmnVerificationService {
.getVerifierResults()
.forEach(
r ->
dmnVerificationMetricsService.addExecutionTime(token,
r.getVerificationType(), r.getExecutionTime(), r.getAmountOfEntries()));
dmnVerificationMetricsService.addExecutionTime(
token, r.getVerificationType(), r.getExecutionTime(), r.getAmountOfEntries()));
// return the result set
return resultSet;
......
......@@ -3,35 +3,40 @@ package de.unikoblenz.fgbks.core.dmn.verification.result;
import de.unikoblenz.fgbks.base.domain.Message;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntry.VerificationClassification;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResult.Builder;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.FixActionService;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.VerificationFix;
import org.apache.commons.lang3.Validate;
/**
* A factory to help creating a {@link VerifierResult}. First, call {@link
* VerificationResultEntryFactory#create(Builder)} with and instance of the {@link
* VerifierResult.Builder}. Than, for each new result for one verifier first call {@link
* VerificationResultEntryFactory#addElement(VerificationResultEntryElement)} for every element you
* want to add. Finally call {@link
* A factory to help creating a {@link VerifierResult}. First, create a new instance with the
* instance of the {@link VerifierResult.Builder}. Than, for each new result for one verifier first
* call {@link VerificationResultEntryFactory#addElement(VerificationResultEntryElement)} for every
* element you want to add. Finally call {@link
* VerificationResultEntryFactory#addToEntry(VerificationClassification, String)} to add the result.
*/
public class VerificationResultEntryFactory {
private FixActionService fixActionService;
private VerifierResult.Builder verifierResultBuilder;
private VerificationResultEntry.Builder verificationResultEntryBuilder;
private VerificationResultEntryFactory(Builder verifierResultBuilder) {
/**
* Create a new {@link VerificationResultEntryFactory}.
*
* @param verifierResultBuilder the instance of a {@link Builder}
*/
public VerificationResultEntryFactory(Builder verifierResultBuilder) {
this.verifierResultBuilder = Validate.notNull(verifierResultBuilder);
verificationResultEntryBuilder = null;
}
/**
* Create a new {@link VerificationResultEntryFactory}.
* Set the fix Action service.
*
* @param verifierResultBuilder the instance of a {@link VerifierResult.Builder}
* @return the new {@link VerificationResultEntryFactory}
* @param fixActionService the {@link FixActionService}
*/
public static VerificationResultEntryFactory create(Builder verifierResultBuilder) {
return new VerificationResultEntryFactory(verifierResultBuilder);
public void setFixActionService(FixActionService fixActionService) {
this.fixActionService = Validate.notNull(fixActionService);
}
private VerificationResultEntry.Builder getCurrentOrCreate() {
......@@ -48,7 +53,9 @@ public class VerificationResultEntryFactory {
* @return the current {@link VerificationResultEntryFactory}
*/
public VerificationResultEntryFactory addVerificationFix(VerificationFix verificationFix) {
getCurrentOrCreate().addVerificationFix(verificationFix);
if (fixActionService == null || fixActionService.isValid(verificationFix)) {
getCurrentOrCreate().addVerificationFix(verificationFix);
}
return this;
}
......
......@@ -4,5 +4,5 @@ public enum ActionType {
UPDATE,
CREATE,
DELETE,
SHOW // READ
SHOW
}
package de.unikoblenz.fgbks.core.dmn.verification.result.actions;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class FixActionService {
private boolean globalActive;
private Map<ActionScope, Map<ActionType, Boolean>> allowedActions;
public FixActionService() {
}
@PostConstruct
private void init() {
allowedActions = new HashMap<>();
for (ActionScope actionScope : ActionScope.values()) {
Map<ActionType, Boolean> types = new HashMap<>();
allowedActions.put(actionScope, types);
for (ActionType actionType : ActionType.values()) {
types.put(actionType, true);
}
}
}
public boolean isGlobalActive() {
return globalActive;
}
public void setGlobalActive(boolean globalActive) {
this.globalActive = globalActive;
}
public Map<ActionScope, Map<ActionType, Boolean>> getAllowedActions() {
return new HashMap<>(allowedActions);
}
public void setValue(ActionScope actionScope, ActionType actionType, Boolean value) {
allowedActions.get(actionScope).put(actionType, value);
}
public List<ActionScope> getActionScopes() {
return Arrays.asList(ActionScope.values());
}
public List<ActionType> getActionTypes() {
return Arrays.asList(ActionType.values());
}
public boolean isValid(VerificationFix verificationFix) {
if (!globalActive) {
return false;
}
for (Action action : verificationFix.getActions()) {
if (!allowedActions.get(action.getActionScope()).get(action.getActionType())) {
return false;
}
}
return true;
}
}
......@@ -17,7 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The abstract verifier is a implementation staring point for the {@link Verifier} interface and
* The abstract verifier is a implementation starting point for the {@link Verifier} interface and
* contains the needed components for the final implementation of verifiers.
*/
public abstract class AbstractVerifier implements Verifier {
......@@ -42,20 +42,6 @@ public abstract class AbstractVerifier implements Verifier {
return verificationType;
}
/**
* Load the configuration, which contains the necessary information for the verifier. E.g. the dmn
* model.
*
* @param configuration the configuration object
* @return the current instance of the verifier
*/
public final AbstractVerifier withConfiguration(AbstractDmnVerifierConfig configuration) {
this.verifierConfig = Validate.notNull(configuration);
this.dmnObjectContainer =
this.verifierConfig.getConfiguration(DefaultConfiguration.KEY_DMN_OBJECT_CONTAINER);
return this;
}
protected AbstractVerifier() {
try {
this.verificationType =
......@@ -69,7 +55,23 @@ public abstract class AbstractVerifier implements Verifier {
e.printStackTrace();
}
resultBuilder = VerifierResult.getBuilder().fromVerifier(this);
vreFactory = VerificationResultEntryFactory.create(resultBuilder);
vreFactory = new VerificationResultEntryFactory(resultBuilder);
}
/**
* Load the configuration, which contains the necessary information for the verifier. E.g. the dmn
* model.
*
* @param configuration the configuration object
* @return the current instance of the verifier
*/
public final AbstractVerifier withConfiguration(AbstractDmnVerifierConfig configuration) {
verifierConfig = Validate.notNull(configuration);
dmnObjectContainer =
verifierConfig.getConfiguration(DefaultConfiguration.KEY_DMN_OBJECT_CONTAINER);
vreFactory.setFixActionService(
verifierConfig.getConfiguration(DefaultConfiguration.KEY_FIX_ACTIONS));
return this;
}
/** {@inheritDoc} */
......
......@@ -2,12 +2,14 @@ package de.unikoblenz.fgbks.core.dmn.verification.verifier.config;
import de.unikoblenz.fgbks.base.builder.DefaultBuilder;
import de.unikoblenz.fgbks.core.dmn.utils.DmnObjectContainer;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.FixActionService;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.Validate;
public class DefaultConfiguration extends AbstractDmnVerifierConfig {
public static final String KEY_DMN_OBJECT_CONTAINER = "dmnDecisions";
public static final String KEY_FIX_ACTIONS = "fixActionsConfig";
public static final String KEY_SHARED_MAP = "sharedMap";
protected DefaultConfiguration() {
......@@ -20,8 +22,8 @@ public class DefaultConfiguration extends AbstractDmnVerifierConfig {
public class Builder extends DefaultBuilder<DefaultConfiguration> {
public Builder withDmnObjectContainer(DmnObjectContainer x) {
value.withConfigurationProperty(KEY_DMN_OBJECT_CONTAINER, x);
public Builder withDmnObjectContainer(DmnObjectContainer dmnObjectContainer) {
value.withConfigurationProperty(KEY_DMN_OBJECT_CONTAINER, dmnObjectContainer);
return this;
}
......@@ -30,6 +32,12 @@ public class DefaultConfiguration extends AbstractDmnVerifierConfig {
return this;
}
public Builder withFixActionService(FixActionService fixActionService) {
value.withConfigurationProperty(KEY_FIX_ACTIONS, fixActionService);
value.verificationProcessId = verificationProcessId;
return this;
}
@Override
protected void validate() {
super.validate();
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Actions - Configuration</title>
<style>
body {
font-family: 'Open Sans', sans-serif;
}
</style>
</head>
<body>
<div id="metricContainer">
<h1>Actions - Configuration</h1>
<div id="configContent"></div>
</div>
<!-- load jquery -->
<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
loadData();
});
const $checkbox = $(`<input type="checkbox" onchange="update()"/>"`);
const rootUrl = 'http://' + window.location.hostname + ':8080/';
const dmnApi = rootUrl + 'api/dmn/';
function loadData() {
let $root = $('#configContent');
$root.empty();
$.ajax({
timeout: 1000,
url: dmnApi + 'verification/actions/global',
type: 'GET',
error: function (err) {
alert("No connection.");
},
success: function (active) {
$root.append("<label>Active:</label>");
$root.append($checkbox);
$checkbox[0].checked = (active === 'true');
}
});
}
function update() {
$.ajax({
timeout: 1000,
url: dmnApi + 'verification/actions/global/' + $checkbox[0].checked,
type: 'POST',
error: function (err) {
alert("No connection.");
},
success: function (active) {
}
});
}
</script>
</body>
</html>
......@@ -73,7 +73,7 @@ function performVerificationFix(verificationEntry, fix, id, $callerButton) {
}
if (cud) {
$callerButton.css('display', 'none');
if ($checkBoxReverify.is(":checked")) {
if ($checkBoxReverify[0].checked) {
checkVerifications();
}
}
......
......@@ -7,30 +7,6 @@
body {
font-family: 'Open Sans', sans-serif;
}
table {
width: 100%;
margin: 20px auto;
table-layout: auto;
}
th {
text-align: left;
}
td {
padding: 2px;
padding-right: 10px;
}
tr > th {
border-bottom: solid 2px #a7a7a7;
}
tr > td {
border-bottom: solid 1px #a7a7a7;
}
#metricContainer {
max-width: 1300px;
padding-left: 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment