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

#31 Config Verifier: Backend implementation

parent 5747f395
No related branches found
No related tags found
No related merge requests found
......@@ -5,9 +5,10 @@ Root path: <code>/api</code>
<h3>Verifications</h3>
<h4>Get all verifications from all verifiers with the given dmn table</h4>
The <i>token</i> parameter is optional for some metric statistics.
<ul>
<li>POST</li>
<li><code>/api/dmn/verification/</code></li>
<li><code>/api/dmn/verification?token={token}</code></li>
<li>Consumes: text/xml - the dmn table as xml string</li>
<li>Produces: application/json</li>
</ul>
......@@ -23,16 +24,17 @@ Root path: <code>/api</code>
</ul>
<h4>Get all verifications for the given verification classification</h4>
The <i>token</i> parameter is optional for some metric statistics.
<ul>
<li>POST</li>
<li><code>/api/dmn/verification/classifications/{classificationName}</code></li>
<li><code>/api/dmn/verification/classifications/{classificationName}?token={token}</code></li>
<li>Consumes: text/xml - the dmn table as xml string</li>
<li>Produces: application/json</li>
</ul>
<h3>Verification types</h3>
<h4>Get a list of all verification types</h4>
<h4>Get a list of all <b>active</b> verification types</h4>
<ul>
<li>GET</li>
<li>
......@@ -43,17 +45,39 @@ Root path: <code>/api</code>
</ul>
<h4>Get all verifications for the given verification types a and b</h4>
The <i>token</i> parameter is optional for some metric statistics.
<ul>
<li>POST</li>
<li><code>/api/dmn/verification/types?typeName={a}&typeName={b}</code></li>
<li><code>/api/dmn/verification/types?typeName={a}&typeName={b}&token={token}</code></li>
<li>Consumes: text/xml - the dmn table as xml string</li>
<li>Produces: application/json</li>
</ul>
<h3>Verification Config</h3>
<h4>Get all verification types and the boolean value of their active state</h4>
<ul>
<li>GET</li>
<li>
<code><a href="/api/dmn/verification/config"
target="_blank">/api/dmn/verification/config</a></code>
</li>
<li>Produces: application/json</li>
</ul>
<h4>Set the config to enable/disable a verification type</h4>
Set "true" or "false" for the active state of the verification. If "false", no verification will
be computed.
<ul>
<li>POST</li>
<li>
<code>/api/dmn/verification/config/{verificationName}/{active}</code>
</li>
</ul>
<h3>Metrics</h3>
<h4>Get some statistics about execution times</h4>
The token parameter is optional for some metric statistics. The default value is 'all'.
The <i>token</i> parameter is optional for some metric statistics. The default value is 'all'.
<ul>
<li>GET</li>
<li>
......@@ -63,7 +87,7 @@ The token parameter is optional for some metric statistics. The default value is
<li>Produces: application/json</li>
</ul>
<h3>Actions</h3>
<h3>Action Config</h3>
<h4>Get global the action config</h4>
Get "true" or "false" for the global action creation setting. If "false", no actions will be
......
......@@ -53,7 +53,7 @@ public class Verification {
}
/**
* Method to get all registered verification types.
* Method to get all active verification types.
*
* @return a list of {@link VerificationType} as a JSON String.
*/
......@@ -142,6 +142,31 @@ public class Verification {
return Response.accepted(dmnVerificationMetricsService.getMetrics(token)).build();
}
/**
* Method to get all registered {@link VerificationType}s. These types are mapped with a boolean,
* which indicates, if the verifier is active or not.
*/
@GET
@Path("/config")
@Produces(MediaType.APPLICATION_JSON)
public Response configVerificationTypes() {
return Response.accepted(dmnVerificationService.getVerificationTypesConfig()).build();
}
/**
* Method to get all registered {@link VerificationType}s. These types are mapped with a boolean,
* which indicates, if the verifier is active or not.
*/
@POST
@Path("/config/{verificationName}/{active}")
@Produces(MediaType.APPLICATION_JSON)
public Response configVerificationTypes(
@PathParam("verificationName") String verificationTypeName,
@PathParam("active") boolean value) {
dmnVerificationService.setVerificationTypesConfig(verificationTypeName, value);
return Response.accepted().build();
}
/**
* Method to get a boolean, if the actions are active or inactive
*
......
......@@ -10,7 +10,6 @@ import de.unikoblenz.fgbks.core.dmn.verification.result.VerifierResultSet.Builde
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;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.classification.Classification;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.classification.ClassificationType;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.config.AbstractDmnVerifierConfig;
......@@ -29,6 +28,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.apache.commons.lang3.Validate;
......@@ -59,14 +59,14 @@ public class DmnVerificationService {
private ExecutorService executor;
private Set<Class<?>> verifierClasses;
private List<VerificationType> verificationTypes;
@Inject
protected DmnVerificationMetricsService dmnVerificationMetricsService;
private List<ClassificationType> verificationClassificationTypes;
@Inject protected DmnService dmnService;
@Inject
protected DmnVerificationMetricsService dmnVerificationMetricsService;
@Inject
protected FixActionService fixActionService;
private Map<VerificationType, Boolean> verificationTypes;
protected DmnVerificationService() {
super();
......@@ -112,13 +112,42 @@ public class DmnVerificationService {
}
/**
* This function returns all currently registered {@link VerificationType}s as {@link
* This function returns all currently active {@link VerificationType}s as {@link
* Collections#unmodifiableList}.
*
* @return a list of {@link VerificationType}s
*/
public List<VerificationType> getVerificationTypes() {
return Collections.unmodifiableList(verificationTypes);
return Collections.unmodifiableList(
verificationTypes.keySet().stream()
.filter(v -> verificationTypes.get(v))
.collect(Collectors.toList()));
}
/**
* This function returns a map of all currently registered {@link VerificationType}s. The boolean
* value indicates, if the verifier is active or not.
*
* @return a map of {@link VerificationType}s (Name as {@link String}) and {@link Boolean}
*/
public Map<String, Boolean> getVerificationTypesConfig() {
return verificationTypes.keySet().stream()
.collect(Collectors.toMap(v -> v.getName().getValue(), v -> verificationTypes.get(v)));
}
/**
* This function sets a config for a currently registered {@link VerificationType}s. The boolean
* value indicates, if the verifier is active or not.
*
* @param verificationName the name of a registered VerificationType as String
* @param value the boolean value, if the verifier is active or not
*/
public void setVerificationTypesConfig(String verificationName, boolean value) {
// try to find a verifier
verificationTypes.keySet().stream()
.filter(v -> v.getName().getValue().equals(verificationName))
.findFirst()
.ifPresent(v -> verificationTypes.put(v, value));
}
/**
......@@ -143,8 +172,7 @@ public class DmnVerificationService {
LOGGER.info("Init verifier.");
Reflections reflections = new Reflections(packagePath);
verifierClasses = reflections.getTypesAnnotatedWith(DmnVerifier.class);
verificationTypes = new ArrayList<>();
verificationTypes = new ConcurrentHashMap<>();
Set<Class<?>> clVts = reflections.getTypesAnnotatedWith(Type.class);
for (Class<?> clVt : clVts) {
try {
......@@ -156,7 +184,7 @@ public class DmnVerificationService {
+ " ("
+ verificationType.getClassification().getName()
+ ")");
verificationTypes.add(verificationType);
verificationTypes.put(verificationType, true);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
......@@ -211,9 +239,8 @@ public class DmnVerificationService {
return resultBuilder.build();
}
LOGGER.info("Looking for verifiers. Id: " + verificationProcessId);
List<Future<VerifierResult>> results = new ArrayList<>(verifierClasses.size());
List<Verifier> executedVerifier = new ArrayList<>();
List<Future<VerifierResult>> results = new ArrayList<>(30);
List<VerificationType> activeVerifier = getVerificationTypes();
for (Class<?> verifierClass : verifierClasses) {
AbstractVerifier av = null;
try {
......@@ -222,16 +249,15 @@ public class DmnVerificationService {
LOGGER.error(e.getMessage());
}
if (av != null
&& activeVerifier.contains(av.getVerificationType())
&& (typeNames == null
|| typeNames.contains(av.getVerificationType().getName().getValue()))
&& (classificationName == null
|| av.getVerificationType()
.getClassification()
.getName()
.getValue()
.equals(classificationName))) {
// add verifier to list
executedVerifier.add(av);
|| av.getVerificationType()
.getClassification()
.getName()
.getValue()
.equals(classificationName))) {
// Create Configuration
AbstractDmnVerifierConfig verifierConfig =
configs.get(av.getClass().getAnnotation(DmnVerifier.class).verifierConfig());
......
......@@ -152,7 +152,7 @@
<h3>Verification types</h3>
<h4>Get a list of all verification types</h4>
<h4>Get a list of all <b>active</b> verification types</h4>
<ul>
<li>GET</li>
<li>
......@@ -171,6 +171,27 @@
<li>Produces: application/json</li>
</ul>
<h3>Verification Config</h3>
<h4>Get all verification types and the boolean value of their active state</h4>
<ul>
<li>GET</li>
<li>
<code><a href="/api/dmn/verification/config"
target="_blank">/api/dmn/verification/config</a></code>
</li>
<li>Produces: application/json</li>
</ul>
<h4>Set the config to enable/disable a verification type</h4>
Set "true" or "false" for the active state of the verification. If "false", no verification will
be computed.
<ul>
<li>POST</li>
<li>
<code>/api/dmn/verification/config/{verificationName}/{active}</code>
</li>
</ul>
<h3>Metrics</h3>
<h4>Get some statistics about execution times</h4>
......@@ -184,7 +205,7 @@
<li>Produces: application/json</li>
</ul>
<h3>Actions</h3>
<h3>Action Config</h3>
<h4>Get global the action config</h4>
Get "true" or "false" for the global action creation setting. If "false", no actions will be
......
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