cdc.mf.checks.atts.id.AbstractIdIsMandatory Maven / Gradle / Ivy
The newest version!
package cdc.mf.checks.atts.id;
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.MfElement;
import cdc.util.strings.StringUtils;
/**
* Check that an {@link MfElement} has an id.
*
* @author Damien Carbonne
* @param The {@link MfElement} type.
*/
public abstract class AbstractIdIsMandatory extends MfAbstractRuleChecker {
public static final IssueSeverity SEVERITY = IssueSeverity.CRITICAL;
protected static String describe(String item) {
return RuleDescription.format("All {%wrap} must have a {%wrap}.",
item,
N_ID);
}
protected AbstractIdIsMandatory(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) {
final String id = object.getId();
if (StringUtils.isNullOrEmpty(id)) {
final IssueDescription.Builder description = IssueDescription.builder();
description.header(getHeader(object))
.violation("has no id");
add(issue().description(description)
.location(location)
.build());
return CheckResult.FAILURE;
} else {
return CheckResult.SUCCESS;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy