
redora.service.BusinessRuleViolation Maven / Gradle / Ivy
/*
* Copyright 2009-2010 Nanjing RedOrange ltd (http://www.red-orange.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package redora.service;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import redora.api.Persistable;
import java.util.List;
/**
* Container for a business rule violation. Holds information on what rule
* has been violated, when, for which object and what id.
* The rule id is set in the object model where the business rules are
* defined (see the manual for more about the object model).
* Redora generates standard rules, like the NotNull rule. These rules
* have a negative rule id and they are defined in the StandardRule enum.
* From the rule id the matching error message can be found. Also the error
* message is set in the object model and available in the generated
* properties files.
*
* When creating custom business rules you must not only define the rule in the
* object model. It must also be implemented in the [modelName]BusinessRules class.
*
* @author Nanjing RedOrange (http://www.red-orange.cn)
*/
public class BusinessRuleViolation {
/**
* Standard (usually generated) business rules, available for all projects
* using this library.
*/
public enum StandardRule {
/** Check if the attribute has null value. */
NotNull(-1),
/** Check if the attribute's value is larger than max length. */
MaxLength(-2),
/**
* Check if the attribute's value match the "regexp" string defined in
* model.
*/
MatchRegexp(-3),
/** Wrapper for unique key exception from the database. */
UniqueKey(-4);
public final Integer ruleId;
private StandardRule(Integer ruleId) {
this.ruleId = ruleId;
}
}
/** CrUD Action. */
public enum Action {
Insert, Update, Delete
}
public BusinessRuleViolation(@NotNull Persistable persistable, @Nullable Enum> field,
@NotNull Integer businessRuleId, @NotNull Action action) {
super();
this.persistable = persistable;
this.field = field;
this.businessRuleId = businessRuleId;
this.action = action;
}
public BusinessRuleViolation(@NotNull Persistable persistable, @Nullable Enum> field,
@NotNull Integer businessRuleId, @NotNull Action action, @Nullable List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy