Skip to content

Commit

Permalink
Fix resource delete bug (DataLinkDC#2401)
Browse files Browse the repository at this point in the history
* fix resource && resource config

* fix resource
 file

* fix resource
 file

* fix resource
 file

* fix resource
 file

* fix resource && resource config

* fix resource delete bug

* Spotless Apply

---------

Co-authored-by: zhu-mingye <[email protected]>
  • Loading branch information
Zzm0809 and zhu-mingye authored Oct 18, 2023
1 parent 21772f1 commit 0d2d3d5
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dinky.data.dto.ResourcesDTO;
import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.Resources;
import org.dinky.data.result.Result;
import org.dinky.service.resource.ResourcesService;
Expand Down Expand Up @@ -140,6 +141,8 @@ public Result<Void> uploadFile(Integer pid, String desc, @RequestParam("file") M
@ApiImplicitParam(name = "id", value = "Resource ID", required = true, dataType = "Integer", paramType = "query")
@SaCheckPermission(PermissionConstants.REGISTRATION_RESOURCE_DELETE)
public Result<Void> remove(Integer id) {
return resourcesService.remove(id) ? Result.succeed() : Result.failed();
return resourcesService.remove(id)
? Result.succeed(Status.DELETE_SUCCESS)
: Result.failed(Status.DELETE_FAILED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -157,7 +156,7 @@ private static TreeNodeDTO convertTree(Resources resources) {
@Override
public String getContentByResourceId(Integer id) {
Resources resources = getById(id);
Assert.notNull(resources, () -> new BusException("resource is not exists!"));
Assert.notNull(resources, () -> new BusException(Status.RESOURCE_DIR_OR_FILE_NOT_EXIST));
Assert.isFalse(resources.getSize() > ALLOW_MAX_CAT_CONTENT_SIZE, () -> new BusException("file is too large!"));
return getBaseResourceManager().getFileContent(resources.getFullName());
}
Expand Down Expand Up @@ -218,22 +217,23 @@ public boolean remove(Integer id) {
remove(new LambdaQueryWrapper<Resources>().ne(Resources::getId, 0));
}
Resources byId = getById(id);
if (!isExistsChildren(id)) {
removeById(id);
}
getBaseResourceManager().remove(byId.getFullName());
if (byId.getIsDirectory()) {
List<Resources> resourceByPidToChildren = getResourceByPidToChildren(new ArrayList<>(), byId.getId());
removeBatchByIds(resourceByPidToChildren);
if (isExistsChildren(id)) {
getBaseResourceManager().remove(byId.getFullName());
if (byId.getIsDirectory()) {
List<Resources> resourceByPidToChildren =
getResourceByPidToChildren(new ArrayList<>(), byId.getId());
removeBatchByIds(resourceByPidToChildren);
}
List<Resources> resourceByPidToParent = getResourceByPidToParent(new ArrayList<>(), byId.getPid());
resourceByPidToParent.forEach(x -> x.setSize(x.getSize() - byId.getSize()));
updateBatchById(resourceByPidToParent);
getBaseResourceManager().remove(byId.getFullName());
return removeById(id);
}
List<Resources> resourceByPidToParent = getResourceByPidToParent(new ArrayList<>(), byId.getPid());
resourceByPidToParent.forEach(x -> x.setSize(x.getSize() - byId.getSize()));
updateBatchById(resourceByPidToParent);
return removeById(id);
} catch (Exception e) {
throw new BusException(Status.DELETE_FAILED);
}

return removeById(id);
}

private boolean isExistsChildren(Integer id) {
Expand Down Expand Up @@ -305,8 +305,7 @@ private List<Resources> buildResourcesTree(List<Resources> resourcesList) {

List<Resources> returnList = new ArrayList<>();

for (Iterator<Resources> iterator = resourcesList.iterator(); iterator.hasNext(); ) {
Resources resources = iterator.next();
for (Resources resources : resourcesList) {
// get all child catalogue of parent catalogue id , the -1 is root catalogue
if (resources.getPid() == -1) {
recursionBuildResourcesAndChildren(resourcesList, resources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,99 @@
*
*/

import {getCurrentData} from '@/pages/DataStudio/function';
import {StateType, STUDIO_MODEL} from '@/pages/DataStudio/model';
import {SWITCH_OPTIONS} from '@/services/constants';
import {l} from '@/utils/intl';
import {InfoCircleOutlined} from '@ant-design/icons';
import {ProForm, ProFormDigit, ProFormGroup, ProFormSelect, ProFormSwitch} from '@ant-design/pro-components';
import {useForm} from 'antd/es/form/Form';
import {connect} from 'umi';
import {DataSources} from "@/types/RegCenter/data";
import {TagAlignLeft} from "@/components/StyledComponents";
import {Tag} from "antd";
import React from "react";
import { TagAlignLeft } from '@/components/StyledComponents';
import { getCurrentData } from '@/pages/DataStudio/function';
import { StateType, STUDIO_MODEL } from '@/pages/DataStudio/model';
import { DataSources } from '@/types/RegCenter/data';
import { l } from '@/utils/intl';
import { ProForm, ProFormDigit, ProFormGroup, ProFormSelect } from '@ant-design/pro-components';
import { Tag } from 'antd';
import { useForm } from 'antd/es/form/Form';
import React from 'react';
import { connect } from 'umi';

const ExecuteConfigCommonSql = (props: any) => {
const {
dispatch,
tabs: {panes, activeKey},
databaseData
} = props;
const [form] = useForm();
const current = getCurrentData(panes, activeKey);
const data: Record<number, React.ReactNode> = {};
const databaseDataList = databaseData as DataSources.DataSource[];
databaseDataList.filter(x => x.type.toLowerCase() === current?.dialect.toLowerCase()).forEach((item: DataSources.DataSource) => {
data[item.id] = (
<TagAlignLeft><Tag key={item.id} color={item.enabled ? 'processing' : 'error'}>{item.type}</Tag>{item.name}
</TagAlignLeft>
)
const {
dispatch,
tabs: { panes, activeKey },
databaseData
} = props;
const [form] = useForm();
const current = getCurrentData(panes, activeKey);
const data: Record<number, React.ReactNode> = {};
const databaseDataList = databaseData as DataSources.DataSource[];
databaseDataList
.filter((x) => x.type.toLowerCase() === current?.dialect.toLowerCase())
.forEach((item: DataSources.DataSource) => {
data[item.id] = (
<TagAlignLeft>
<Tag key={item.id} color={item.enabled ? 'processing' : 'error'}>
{item.type}
</Tag>
{item.name}
</TagAlignLeft>
);
});

form.setFieldsValue({...current, databaseId: String(current?.databaseId ?? "")});
const onValuesChange = (change: any, all: any) => {
for (let i = 0; i < panes.length; i++) {
if (panes[i].key === activeKey) {
for (const key in change) {
if (key === 'databaseId') {
panes[i].params.taskData[key] = Number(all[key]);
continue;
}
panes[i].params.taskData[key] = all[key];
}
break;
}
form.setFieldsValue({ ...current, databaseId: String(current?.databaseId ?? '') });
const onValuesChange = (change: any, all: any) => {
for (let i = 0; i < panes.length; i++) {
if (panes[i].key === activeKey) {
for (const key in change) {
if (key === 'databaseId') {
panes[i].params.taskData[key] = Number(all[key]);
continue;
}
panes[i].params.taskData[key] = all[key];
}
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: {...props.tabs}
});
};
break;
}
}
dispatch({
type: STUDIO_MODEL.saveTabs,
payload: { ...props.tabs }
});
};

return (
<>
<ProForm
initialValues={{
maxRowNum: 100
}}
style={{padding: '10px'}}
form={form}
submitter={false}
layout='vertical'
onValuesChange={onValuesChange}
>
<ProFormGroup>
<ProFormSelect
width={'lg'}
name={'databaseId'}
label={l('pages.datastudio.label.execConfig.selectDatabase')}
valueEnum={data}
initialValue={1}
placeholder="Please select a country"
rules={[{required: true, message: 'Please select your country!'}]}
/>
</ProFormGroup>
<ProFormGroup>
<ProFormDigit
width={'xs'}
label={l('pages.datastudio.label.execConfig.maxrow')}
name='maxRowNum'
tooltip={l('pages.datastudio.label.execConfig.maxrow.tip')}
min={1}
max={9999}
/>
</ProFormGroup>
</ProForm>
</>
);
return (
<>
<ProForm
initialValues={{
maxRowNum: 100
}}
style={{ padding: '10px' }}
form={form}
submitter={false}
layout='vertical'
onValuesChange={onValuesChange}
>
<ProFormGroup>
<ProFormSelect
width={'lg'}
name={'databaseId'}
label={l('pages.datastudio.label.execConfig.selectDatabase')}
valueEnum={data}
initialValue={1}
placeholder='Please select a country'
rules={[{ required: true, message: 'Please select your country!' }]}
/>
</ProFormGroup>
<ProFormGroup>
<ProFormDigit
width={'xs'}
label={l('pages.datastudio.label.execConfig.maxrow')}
name='maxRowNum'
tooltip={l('pages.datastudio.label.execConfig.maxrow.tip')}
min={1}
max={9999}
/>
</ProFormGroup>
</ProForm>
</>
);
};

export default connect(({Studio}: { Studio: StateType }) => ({
tabs: Studio.tabs,
databaseData: Studio.database.dbData
export default connect(({ Studio }: { Studio: StateType }) => ({
tabs: Studio.tabs,
databaseData: Studio.database.dbData
}))(ExecuteConfigCommonSql);
Loading

0 comments on commit 0d2d3d5

Please sign in to comment.