mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-04 11:52:41 +08:00
增加重复数据验证
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2016 http://www.hswebframework.org
|
||||
*
|
||||
* 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 org.hswebframework.web.authorization.access;
|
||||
|
||||
/**
|
||||
* 重复数据验证器,验证数据是否重复
|
||||
*
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface DuplicateValidator {
|
||||
Result doValidate(DuplicateValidatorConfig validator, ParamContext context);
|
||||
|
||||
/**
|
||||
* 验证结果
|
||||
*/
|
||||
class Result {
|
||||
//是否存在重复的数据
|
||||
boolean exists;
|
||||
//存在的数据,不存在时值为null
|
||||
Object data;
|
||||
|
||||
public Result() {
|
||||
}
|
||||
|
||||
public Result(boolean exists, Object data) {
|
||||
this.exists = exists;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean isExists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
public void setExists(boolean exists) {
|
||||
this.exists = exists;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2016 http://www.hswebframework.org
|
||||
*
|
||||
* 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 org.hswebframework.web.authorization.access;
|
||||
|
||||
import org.hswebframework.web.authorization.Permission;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 重复数据验证配置
|
||||
*
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface DuplicateValidatorConfig extends Serializable {
|
||||
/**
|
||||
* 对数据的操作事件
|
||||
*
|
||||
* @return 操作时间
|
||||
* @see Permission#ACTION_UPDATE
|
||||
* @see Permission#ACTION_ADD
|
||||
*/
|
||||
String getAction();
|
||||
|
||||
/**
|
||||
* @return 验证未通过时返回的消息
|
||||
*/
|
||||
String getErrorMessage();
|
||||
|
||||
/**
|
||||
* @return 验证方式
|
||||
*/
|
||||
String getType();
|
||||
|
||||
interface DefaultType {
|
||||
String SCRIPT = "SCRIPT";
|
||||
String FIELDS = "FIELDS";
|
||||
String CUSTOM = "CUSTOM";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2016 http://www.hswebframework.org
|
||||
*
|
||||
* 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 org.hswebframework.web.authorization.access;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 根据字段判断是否存在重复的数据
|
||||
*
|
||||
* @author zhouhao
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface FiledDuplicateValidatorConfig extends DuplicateValidatorConfig {
|
||||
@Override
|
||||
default String getType() {
|
||||
return DefaultType.FIELDS;
|
||||
}
|
||||
|
||||
List<String> getFields();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2016 http://www.hswebframework.org
|
||||
*
|
||||
* 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 org.hswebframework.web.authorization.access;
|
||||
|
||||
/**
|
||||
* 通过脚本来控制数据重复
|
||||
*
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface ScriptDuplicateValidatorConfig extends DuplicateValidatorConfig {
|
||||
default String getType() {
|
||||
return DefaultType.SCRIPT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 脚本语言: javascript(js),groovy
|
||||
*
|
||||
* @return 语言
|
||||
*/
|
||||
String getScriptLanguage();
|
||||
|
||||
/**
|
||||
* 脚本内容,在进行验证的时候会执行脚本,如果存在重复数据脚本应当返回false。否则返回true
|
||||
*
|
||||
* @return 脚本
|
||||
*/
|
||||
String getScript();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2016 http://www.hswebframework.org
|
||||
*
|
||||
* 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 org.hswebframework.web.authorization.annotation;
|
||||
|
||||
import org.hswebframework.web.authorization.Permission;
|
||||
import org.hswebframework.web.authorization.access.DataAccessConfig;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 重复数据验证
|
||||
*
|
||||
* @author zhouhao
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface RequiresDuplicate {
|
||||
|
||||
/**
|
||||
* @return permission id
|
||||
* @see Permission#getId()
|
||||
*/
|
||||
String permission();
|
||||
|
||||
/**
|
||||
* @return action array
|
||||
* @see DataAccessConfig#getAction()
|
||||
*/
|
||||
String[] action() default {};
|
||||
|
||||
/**
|
||||
* @return 自定义控制器bean名称
|
||||
*/
|
||||
String controllerBeanName() default "";
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user