cdc.mf.checks.atts.cardinality.AbstractCardinalityIsMandatory Maven / Gradle / Ivy
The newest version!
package cdc.mf.checks.atts.cardinality;
import cdc.issues.IssueSeverity;
import cdc.issues.checks.CheckContext;
import cdc.issues.checks.CheckResult;
import cdc.issues.checks.SnapshotManager;
import cdc.issues.locations.Location;
import cdc.issues.rules.Rule;
import cdc.issues.rules.RuleDescription;
import cdc.mf.checks.IssueDescription;
import cdc.mf.checks.MfAbstractRuleChecker;
import cdc.mf.model.MfCardinalityItem;
/**
* Check that an {@link MfCardinalityItem} has a cardinality.
*
* @author Damien Carbonne
* @param The {@link MfCardinalityItem} type.
*/
public abstract class AbstractCardinalityIsMandatory extends MfAbstractRuleChecker {
public static final IssueSeverity SEVERITY = IssueSeverity.MAJOR;
protected static String describe(String item) {
return RuleDescription.format("All {%wrap} must have a {%wrap}.",
item,
N_CARDINALITY);
}
protected static String describe(String item1,
String item2) {
return RuleDescription.format("All {%wrap} {%wrap} must have a {%wrap}.",
item1,
item2,
N_CARDINALITY);
}
protected AbstractCardinalityIsMandatory(SnapshotManager manager,
Class objectClass,
Rule rule) {
super(manager,
objectClass,
rule);
}
@Override
protected final String getHeader(O object) {
return getTheItemHeader(object);
}
@Override
public CheckResult check(CheckContext context,
O object,
Location location) {
if (object.getCardinality() == null) {
final IssueDescription.Builder description = IssueDescription.builder();
description.header(getHeader(object))
.violation("has no cardinality");
add(issue().description(description)
.location(location)
.build());
return CheckResult.FAILURE;
} else {
return CheckResult.SUCCESS;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy