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

Add domain for identifier

parent 0fe1aa0e
No related branches found
No related tags found
No related merge requests found
Showing
with 161 additions and 68 deletions
......@@ -7,7 +7,7 @@ import static org.apache.commons.lang3.Validate.notNull;
public abstract class AbstractStringValueObject extends AbstractSimpleValueObject<String> {
public static final int MIN_LEN = 1;
public static final int DEFAULT_MIN_LEN = 1;
protected AbstractStringValueObject() {}
......@@ -25,10 +25,10 @@ public abstract class AbstractStringValueObject extends AbstractSimpleValueObjec
if (handleBlanksAsNull() && super.getValue().trim().isEmpty()) {
return null;
}
return isBlankAllowed() ? super.getValue() : toStringTimTrailing();
return isBlankAllowed() ? super.getValue() : toStringTrim();
}
private String toStringTimTrailing() {
private String toStringTrim() {
return super.getValue().trim();
}
......@@ -54,7 +54,7 @@ public abstract class AbstractStringValueObject extends AbstractSimpleValueObjec
}
protected Integer getMinLength() {
return MIN_LEN;
return DEFAULT_MIN_LEN;
}
protected abstract Integer getMaxLength();
......
package de.unikoblenz.fgbks.core.dmn.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
public class Message extends AbstractStringValueObject {
public Message(String initialValue) {
super(initialValue);
}
@Override
protected Integer getMaxLength() {
return 500;
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
public abstract class AbstractId extends AbstractStringValueObject {
public AbstractId(String initialValue) {
super(initialValue);
}
@Override
protected Integer getMaxLength() {
return 100;
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
public class DecisionId extends AbstractId {
public DecisionId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("decisionTableId")
public class DecisionTableId extends AbstractId {
public DecisionTableId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("inputEntryId")
public class InputEntryId extends AbstractId {
public InputEntryId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("inputExpressionId")
public class InputExpressionId extends AbstractId {
public InputExpressionId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("inputId")
public class InputId extends AbstractId {
public InputId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface JsonIdentifier {
String value() default "id";
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("outputEntryId")
public class OutputEntryId extends AbstractId {
public OutputEntryId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("OutputId")
public class OutputId extends AbstractId {
public OutputId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.domain.id;
@JsonIdentifier("ruleId")
public class RuleId extends AbstractId {
public RuleId(String initialValue) {
super(initialValue);
}
}
package de.unikoblenz.fgbks.core.dmn.verfication.result;
import de.unikoblenz.fgbks.base.builder.DefaultBuilder;
import de.unikoblenz.fgbks.core.dmn.domain.Message;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
......@@ -17,7 +18,7 @@ public class VerificationResultEntry extends AbstractResultObject {
}
private Set<VerificationResultEntryElement> verificationResultEntryElements;
private String message;
private Message message;
private VerificationClassification verificationClassification;
protected VerificationResultEntry() {
......@@ -40,8 +41,8 @@ public class VerificationResultEntry extends AbstractResultObject {
}
@JsonbProperty("message")
public String getMessage() {
return message;
public Message getMessage() {
return new Message(message.getValue());
}
private void addVerificationResultEntry(
......@@ -61,8 +62,8 @@ public class VerificationResultEntry extends AbstractResultObject {
return this;
}
public Builder withMessage(String message) {
value.message = message;
public Builder withMessage(Message message) {
value.message = new Message(message.getValue());
return this;
}
......
package de.unikoblenz.fgbks.core.dmn.verfication.result;
import de.unikoblenz.fgbks.core.dmn.domain.id.AbstractId;
import de.unikoblenz.fgbks.core.dmn.domain.id.JsonIdentifier;
import java.util.HashMap;
import java.util.Map;
import javax.json.bind.annotation.JsonbProperty;
......@@ -8,71 +10,37 @@ import org.apache.commons.lang3.Validate;
// @JsonbTypeSerializer(VerificationResultEntryElementJsonSerializer.class)
public class VerificationResultEntryElement extends AbstractResultObject {
private static final String DECISION_ID = "decisionId";
private static final String DECISION_TABLE_ID = "decisionTableId";
private static final String INPUT_ID = "inputId";
private static final String INPUT_EXPRESSION_ID = "inputExpressionId";
private static final String OUTPUT_ID = "outputId";
private static final String RULE_ID = "ruleId";
private static final String INPUT_ENTRY_ID = "inputEntryId";
private static final String OUTPUT_ENTRY_ID = "outputEntryId";
private final Map<String, AbstractId> identifier;
private final Map<String, Object> properties;
@JsonbProperty("properties")
public Map<String, Object> getProperties() {
return new HashMap<>(properties);
@JsonbProperty("identifier")
public Map<String, Object> getIdentifier() {
return new HashMap<>(identifier);
}
private VerificationResultEntryElement() {
properties = new HashMap<>();
identifier = new HashMap<>();
}
public static VerificationResultEntryElement create() {
return new VerificationResultEntryElement();
}
public VerificationResultEntryElement withDecisionId(String decisionId) {
return withProperty(DECISION_ID, decisionId);
}
public VerificationResultEntryElement withIdentifier(AbstractId value) {
public VerificationResultEntryElement withDecisionTableId(String decisionTableId) {
return withProperty(DECISION_TABLE_ID, decisionTableId);
}
public VerificationResultEntryElement withInputId(String inputId) {
return withProperty(INPUT_ID, inputId);
}
public VerificationResultEntryElement withInputExpressionId(String inputExpressionId) {
return withProperty(INPUT_EXPRESSION_ID, inputExpressionId);
}
public VerificationResultEntryElement withOutputId(String outputId) {
return withProperty(OUTPUT_ID, outputId);
}
public VerificationResultEntryElement withRuleId(String ruleId) {
return withProperty(RULE_ID, ruleId);
}
public VerificationResultEntryElement withInputEntryId(String inputEntryId) {
return withProperty(INPUT_ENTRY_ID, inputEntryId);
}
public VerificationResultEntryElement withOutputEntryId(String outputEntryId) {
return withProperty(OUTPUT_ENTRY_ID, outputEntryId);
}
private VerificationResultEntryElement withProperty(String key, String value) {
// every properties can only be set once
// Check if annotation is present
Validate.isTrue(
value.getClass().isAnnotationPresent(JsonIdentifier.class),
"No annotation \"JsonIdentifier\" for AbstractId %s present.",
value.getClass().getSimpleName());
String keyValue = value.getClass().getAnnotation(JsonIdentifier.class).value();
// every identifier can only be set once
Validate.isTrue(
!properties.containsKey(key),
"Property %s with value %s in %s already set",
key,
!identifier.containsKey(keyValue),
"Identifier %s with value %s in %s already set.",
keyValue,
value,
VerificationResultEntryElement.class.getSimpleName());
properties.put(key, value);
identifier.put(keyValue, value);
return this;
}
}
package de.unikoblenz.fgbks.core.dmn.verfication.result;
import de.unikoblenz.fgbks.core.dmn.domain.Message;
import de.unikoblenz.fgbks.core.dmn.verfication.result.VerificationResultEntry.VerificationClassification;
import de.unikoblenz.fgbks.core.dmn.verfication.result.VerifierResult.Builder;
import org.apache.commons.lang3.Validate;
......@@ -37,11 +38,15 @@ public class VerificationResultEntryFactory {
public void addToEntry(
VerificationClassification verificationClassification, String message, Object... args) {
addToEntry(verificationClassification, new Message(String.format(message, args)));
}
public void addToEntry(VerificationClassification verificationClassification, Message message) {
Validate.notNull(
verificationResultEntryBuilder,
"First call \"addElement\" in VerificationResultEntryFactory before calling \"addToEntry\"");
verificationResultEntryBuilder.withClassification(verificationClassification);
verificationResultEntryBuilder.withMessage(String.format(Validate.notNull(message), args));
verificationResultEntryBuilder.withMessage(message);
verifierResultBuilder.addVerificationResultEntry(verificationResultEntryBuilder.build());
verificationResultEntryBuilder = null;
}
......
......@@ -3,6 +3,9 @@ package de.unikoblenz.fgbks.core.dmn.verfication.verifier;
import static de.unikoblenz.fgbks.core.dmn.verfication.VerificationType.IDENTICAL_BUSINESS_RULE_VERIFICATION;
import static de.unikoblenz.fgbks.core.dmn.verfication.result.VerificationResultEntry.VerificationClassification.*;
import de.unikoblenz.fgbks.core.dmn.domain.id.InputEntryId;
import de.unikoblenz.fgbks.core.dmn.domain.id.OutputEntryId;
import de.unikoblenz.fgbks.core.dmn.domain.id.RuleId;
import de.unikoblenz.fgbks.core.dmn.verfication.result.VerificationResultEntryElement;
public class SampleVerifier extends AbstractVerifier {
......@@ -15,15 +18,15 @@ public class SampleVerifier extends AbstractVerifier {
protected void doVerification() {
vref.addElement(
VerificationResultEntryElement.create()
.withDecisionId("hello workd")
.withInputEntryId("adsas")
.withRuleId("asdads"));
.withIdentifier(new InputEntryId("asdasda"))
.withIdentifier(new OutputEntryId("test"))
.withIdentifier(new RuleId("asdasd")));
vref.addElement(
VerificationResultEntryElement.create()
.withDecisionId("hello workd")
.withInputEntryId("adsas")
.withRuleId("asdads"));
vref.addToEntry(ERROR, "Asd");
.withIdentifier(new InputEntryId("asdasda"))
.withIdentifier(new OutputEntryId("test"))
.withIdentifier(new RuleId("asdasd")));
vref.addToEntry(ERROR, "My sample message");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
......
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