Browse Source

fix: disable auto sync after delete project/group (#5)

master
vran 3 years ago
committed by GitHub
parent
commit
82feab3f1a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      core/src/main/java/com/databasir/core/domain/group/service/GroupService.java
  2. 11
      core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java
  3. 14
      dao/src/main/java/com/databasir/dao/impl/ProjectDao.java
  4. 18
      dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java

10
core/src/main/java/com/databasir/core/domain/group/service/GroupService.java

@ -4,10 +4,7 @@ import com.databasir.core.domain.DomainErrors;
import com.databasir.core.domain.group.converter.GroupPojoConverter;
import com.databasir.core.domain.group.converter.GroupResponseConverter;
import com.databasir.core.domain.group.data.*;
import com.databasir.dao.impl.GroupDao;
import com.databasir.dao.impl.ProjectDao;
import com.databasir.dao.impl.UserDao;
import com.databasir.dao.impl.UserRoleDao;
import com.databasir.dao.impl.*;
import com.databasir.dao.tables.pojos.GroupPojo;
import com.databasir.dao.tables.pojos.UserPojo;
import com.databasir.dao.tables.pojos.UserRolePojo;
@ -36,6 +33,8 @@ public class GroupService {
private final ProjectDao projectDao;
private final ProjectSyncRuleDao projectSyncRuleDao;
private final GroupPojoConverter groupPojoConverter;
private final GroupResponseConverter groupResponseConverter;
@ -78,6 +77,9 @@ public class GroupService {
public void delete(Integer groupId) {
groupDao.deleteById(groupId);
userRoleDao.deleteByGroupId(groupId);
List<Integer> projectIds = projectDao.selectProjectIdsByGroupId(groupId);
projectSyncRuleDao.disableAutoSyncByProjectIds(projectIds);
projectDao.deleteByGroupId(groupId);
}
public Page<GroupPageResponse> list(Pageable pageable, GroupPageCondition condition) {

11
core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java

@ -49,11 +49,11 @@ public class ProjectService {
public ProjectDetailResponse getOne(Integer id) {
return projectDao.selectOptionalById(id)
.map(schemaSource -> {
DataSourcePojo dataSource = dataSourceDao.selectByProjectId(id);
List<DataSourcePropertyPojo> properties = dataSourcePropertyDao.selectByDataSourceId(dataSource.getId());
ProjectDetailResponse.DataSourceResponse dataSourceResponse = projectResponseConverter.toResponse(dataSource, properties);
ProjectSyncRulePojo rule = projectSyncRuleDao.selectByProjectId(id);
ProjectDetailResponse.ProjectSyncRuleResponse ruleResponse = projectResponseConverter.toResponse(rule);
var dataSource = dataSourceDao.selectByProjectId(id);
var properties = dataSourcePropertyDao.selectByDataSourceId(dataSource.getId());
var dataSourceResponse = projectResponseConverter.toResponse(dataSource, properties);
var projectSyncRule = projectSyncRuleDao.selectOptionalByProjectId(id).orElse(null);
var ruleResponse = projectResponseConverter.toResponse(projectSyncRule);
return projectResponseConverter.toResponse(schemaSource, dataSourceResponse, ruleResponse);
})
.orElseThrow(DomainErrors.PROJECT_NOT_FOUND::exception);
@ -125,6 +125,7 @@ public class ProjectService {
public void delete(Integer projectId) {
projectDao.updateDeletedById(true, projectId);
projectSyncRuleDao.disableAutoSyncByProjectId(projectId);
}
public Page<ProjectSimpleResponse> list(Pageable page, ProjectListCondition condition) {

14
dao/src/main/java/com/databasir/dao/impl/ProjectDao.java

@ -86,4 +86,18 @@ public class ProjectDao extends BaseDao<ProjectRecord, ProjectPojo> {
+ " where project.deleted = false and `group`.id in " + groupIdIn + " group by `group`.id;";
return dslContext.resultQuery(sql).fetchInto(GroupProjectCountPojo.class);
}
public void deleteByGroupId(Integer groupId) {
dslContext
.update(PROJECT).set(PROJECT.DELETED, true)
.where(PROJECT.GROUP_ID.eq(groupId).and(PROJECT.DELETED.eq(false)))
.execute();
}
public List<Integer> selectProjectIdsByGroupId(Integer groupId) {
return dslContext
.select(PROJECT.ID).from(PROJECT)
.where(PROJECT.GROUP_ID.eq(groupId).and(PROJECT.DELETED.eq(false)))
.fetchInto(Integer.class);
}
}

18
dao/src/main/java/com/databasir/dao/impl/ProjectSyncRuleDao.java

@ -95,4 +95,22 @@ public class ProjectSyncRuleDao extends BaseDao<ProjectSyncRuleRecord, ProjectSy
PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId)
.and(PROJECT_SYNC_RULE.AUTO_SYNC_CRON.eq(cron)));
}
public void disableAutoSyncByProjectId(Integer projectId) {
dslContext
.update(PROJECT_SYNC_RULE).set(PROJECT_SYNC_RULE.IS_AUTO_SYNC, false)
.where(PROJECT_SYNC_RULE.PROJECT_ID.eq(projectId))
.execute();
}
public void disableAutoSyncByProjectIds(List<Integer> projectIds) {
if (projectIds == null || projectIds.isEmpty()) {
return;
}
dslContext
.update(PROJECT_SYNC_RULE).set(PROJECT_SYNC_RULE.IS_AUTO_SYNC, false)
.where(PROJECT_SYNC_RULE.PROJECT_ID.in(projectIds))
.execute();
}
}

Loading…
Cancel
Save