All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.mf.checks.atts.cardinality.AbstractCardinalityMustBeWellFormed 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.MfCardinality;
import cdc.mf.model.MfCardinalityItem;

/**
 * Check that if an {@link MfCardinalityItem} has a cardinality, it is well formed.
 *
 * @author Damien Carbonne
 */
public class AbstractCardinalityMustBeWellFormed extends MfAbstractRuleChecker {
    public static final IssueSeverity SEVERITY = IssueSeverity.CRITICAL;

    protected static String describe() {
        return RuleDescription.format("All defined {%wrap} must be well formed.",
                                      N_CARDINALITIES);
    }

    protected AbstractCardinalityMustBeWellFormed(SnapshotManager manager,
                                                  Rule rule) {
        super(manager,
              MfCardinalityItem.class,
              rule);
    }

    @Override
    protected final String getHeader(MfCardinalityItem object) {
        return getTheCardinalityOfHeader(object);
    }

    @Override
    public CheckResult check(CheckContext context,
                             MfCardinalityItem object,
                             Location location) {
        final MfCardinality cardinality = object.getCardinality();
        if (cardinality != null
                && cardinality.isMalformed()) {
            final IssueDescription.Builder description = IssueDescription.builder();

            description.header(getHeader(object))
                       .value(cardinality.getText())
                       .violation("is malformed");

            add(issue().description(description)
                       .location(location)
                       .build());
            return CheckResult.FAILURE;
        } else {
            return CheckResult.SUCCESS;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy