Browse Source

Merge pull request #7 from vran-dev/feature/vran

feature: add cron validation
master
vran 3 years ago
committed by GitHub
parent
commit
aba33b0533
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      README.md
  2. 5
      api/src/main/java/com/databasir/api/ProjectController.java
  3. 33
      api/src/main/java/com/databasir/api/validator/CronExpressionValidator.java
  4. 2
      api/src/main/resources/static/index.html
  5. 2
      api/src/main/resources/static/js/app.5749a94b.js
  6. 1
      api/src/main/resources/static/js/app.5749a94b.js.map
  7. 2
      api/src/main/resources/static/js/chunk-abb10c56.2eac1d1a.js
  8. 1
      api/src/main/resources/static/js/chunk-abb10c56.2eac1d1a.js.map
  9. 3
      core/src/main/java/com/databasir/core/domain/DomainErrors.java

1
README.md

@ -6,6 +6,7 @@
- [ ] 表字段协同注释
- [ ] 操作审计日志
- [ ] 文档导出功能
## 简介

5
api/src/main/java/com/databasir/api/ProjectController.java

@ -1,5 +1,6 @@
package com.databasir.api;
import com.databasir.api.validator.CronExpressionValidator;
import com.databasir.common.JsonData;
import com.databasir.core.domain.project.data.*;
import com.databasir.core.domain.project.service.ProjectService;
@ -21,9 +22,12 @@ public class ProjectController {
private final ProjectService projectService;
private final CronExpressionValidator cronExpressionValidator;
@PostMapping(Routes.GroupProject.CREATE)
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#request.groupId, 'GROUP_MEMBER?groupId='+#request.groupId)")
public JsonData<Void> create(@RequestBody @Valid ProjectCreateRequest request) {
cronExpressionValidator.isValidCron(request);
projectService.create(request);
return JsonData.ok();
}
@ -32,6 +36,7 @@ public class ProjectController {
@PreAuthorize("hasAnyAuthority('SYS_OWNER', 'GROUP_OWNER?groupId='+#groupId, 'GROUP_MEMBER?groupId='+#groupId)")
public JsonData<Void> update(@RequestBody @Valid ProjectUpdateRequest request,
@PathVariable Integer groupId) {
cronExpressionValidator.isValidCron(request);
projectService.update(groupId, request);
return JsonData.ok();
}

33
api/src/main/java/com/databasir/api/validator/CronExpressionValidator.java

@ -0,0 +1,33 @@
package com.databasir.api.validator;
import com.databasir.core.domain.DomainErrors;
import com.databasir.core.domain.project.data.ProjectCreateRequest;
import com.databasir.core.domain.project.data.ProjectUpdateRequest;
import org.quartz.CronExpression;
import org.springframework.stereotype.Component;
import java.text.ParseException;
@Component
public class CronExpressionValidator {
public void isValidCron(ProjectUpdateRequest request) {
if (request.getProjectSyncRule().getIsAutoSync()) {
isValidCron(request.getProjectSyncRule().getAutoSyncCron());
}
}
public void isValidCron(ProjectCreateRequest request) {
if (request.getProjectSyncRule().getIsAutoSync()) {
isValidCron(request.getProjectSyncRule().getAutoSyncCron());
}
}
public void isValidCron(String cron) {
try {
new CronExpression(cron);
} catch (ParseException pe) {
throw DomainErrors.INVALID_CRON_EXPRESSION.exception("错误的 CRON 表达式:" + pe.getMessage(), pe);
}
}
}

2
api/src/main/resources/static/index.html

@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><link href="/css/chunk-0e34b2c6.06814884.css" rel="prefetch"><link href="/css/chunk-588dbed6.e51aa148.css" rel="prefetch"><link href="/css/chunk-7efe8be4.00ac37b1.css" rel="prefetch"><link href="/js/chunk-0e34b2c6.7af33675.js" rel="prefetch"><link href="/js/chunk-2d0a47bb.baec3bc7.js" rel="prefetch"><link href="/js/chunk-2d0cc811.c5d1ef9e.js" rel="prefetch"><link href="/js/chunk-48cebeac.162363c9.js" rel="prefetch"><link href="/js/chunk-588dbed6.ba7725b2.js" rel="prefetch"><link href="/js/chunk-7efe8be4.815f1aa1.js" rel="prefetch"><link href="/js/chunk-9622a6d8.d116da54.js" rel="prefetch"><link href="/js/chunk-abb10c56.c12963e3.js" rel="prefetch"><link href="/js/chunk-fffb1b64.1ffb9f27.js" rel="prefetch"><link href="/css/app.fc57c576.css" rel="preload" as="style"><link href="/css/chunk-vendors.d4aa889d.css" rel="preload" as="style"><link href="/js/app.d3ac1eb1.js" rel="preload" as="script"><link href="/js/chunk-vendors.42fcab1c.js" rel="preload" as="script"><link href="/css/chunk-vendors.d4aa889d.css" rel="stylesheet"><link href="/css/app.fc57c576.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.42fcab1c.js"></script><script src="/js/app.d3ac1eb1.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><link href="/css/chunk-0e34b2c6.06814884.css" rel="prefetch"><link href="/css/chunk-588dbed6.e51aa148.css" rel="prefetch"><link href="/css/chunk-7efe8be4.00ac37b1.css" rel="prefetch"><link href="/js/chunk-0e34b2c6.7af33675.js" rel="prefetch"><link href="/js/chunk-2d0a47bb.baec3bc7.js" rel="prefetch"><link href="/js/chunk-2d0cc811.c5d1ef9e.js" rel="prefetch"><link href="/js/chunk-48cebeac.162363c9.js" rel="prefetch"><link href="/js/chunk-588dbed6.ba7725b2.js" rel="prefetch"><link href="/js/chunk-7efe8be4.815f1aa1.js" rel="prefetch"><link href="/js/chunk-9622a6d8.d116da54.js" rel="prefetch"><link href="/js/chunk-abb10c56.2eac1d1a.js" rel="prefetch"><link href="/js/chunk-fffb1b64.1ffb9f27.js" rel="prefetch"><link href="/css/app.fc57c576.css" rel="preload" as="style"><link href="/css/chunk-vendors.d4aa889d.css" rel="preload" as="style"><link href="/js/app.5749a94b.js" rel="preload" as="script"><link href="/js/chunk-vendors.42fcab1c.js" rel="preload" as="script"><link href="/css/chunk-vendors.d4aa889d.css" rel="stylesheet"><link href="/css/app.fc57c576.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.42fcab1c.js"></script><script src="/js/app.5749a94b.js"></script></body></html>

2
api/src/main/resources/static/js/app.5749a94b.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/app.5749a94b.js.map

File diff suppressed because one or more lines are too long

2
api/src/main/resources/static/js/chunk-abb10c56.2eac1d1a.js

File diff suppressed because one or more lines are too long

1
api/src/main/resources/static/js/chunk-abb10c56.2eac1d1a.js.map

File diff suppressed because one or more lines are too long

3
core/src/main/java/com/databasir/core/domain/DomainErrors.java

@ -22,7 +22,8 @@ public enum DomainErrors implements DatabasirErrors {
PROJECT_NAME_DUPLICATE("A_10008", "项目名称已被占用"),
CANNOT_UPDATE_SELF_ROLE("A_10009", "无法对自己执行角色变更的操作"),
UPDATE_PASSWORD_CONFIRM_FAILED("A_10010", "两次密码输入不一致"),
ORIGIN_PASSWORD_NOT_CORRECT("A_10011", "原密码不正确");
ORIGIN_PASSWORD_NOT_CORRECT("A_10011", "原密码不正确"),
INVALID_CRON_EXPRESSION("A_10012", "不合法的 cron 表达式");
private final String errCode;

Loading…
Cancel
Save