Compare commits
3 Commits
246e27677e
...
7584ca3736
| Author | SHA1 | Date | |
|---|---|---|---|
| 7584ca3736 | |||
| 851fc02ce5 | |||
| e76236be62 |
@@ -1,26 +1,26 @@
|
||||
const information = {
|
||||
debug: false,
|
||||
// baseUrl: '',
|
||||
baseUrl: 'http://127.0.0.1:20080',
|
||||
title: '可信供给中心',
|
||||
debug: false,
|
||||
// baseUrl: '',
|
||||
baseUrl: 'http://127.0.0.1:20080',
|
||||
title: '可信供给中心',
|
||||
}
|
||||
|
||||
export function useAmis(amisObject) {
|
||||
document.title = information.title
|
||||
let amis = amisRequire('amis/embed')
|
||||
amis.embed(
|
||||
'#app',
|
||||
amisObject(information),
|
||||
{
|
||||
data: {
|
||||
base: information.baseUrl,
|
||||
},
|
||||
},
|
||||
{
|
||||
theme: 'antd',
|
||||
enableAMISDebug: information.debug,
|
||||
}
|
||||
)
|
||||
document.title = information.title
|
||||
let amis = amisRequire('amis/embed')
|
||||
amis.embed(
|
||||
'#app',
|
||||
amisObject(information),
|
||||
{
|
||||
data: {
|
||||
base: information.baseUrl,
|
||||
},
|
||||
},
|
||||
{
|
||||
theme: 'antd',
|
||||
enableAMISDebug: information.debug,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function crudCommonOptions() {
|
||||
@@ -187,3 +187,26 @@ export function apiGet(url) {
|
||||
export function apiPost(url) {
|
||||
return api('post', url)
|
||||
}
|
||||
|
||||
export function roleCheck(roles) {
|
||||
return `\${ARRAYINCLUDES(['${roles.join("','")}'], role)}`
|
||||
}
|
||||
|
||||
export const role = {
|
||||
administrator: 'ADMINISTRATOR',
|
||||
checker: 'CHECKER',
|
||||
provider: 'PROVIDER',
|
||||
customer: 'CUSTOMER',
|
||||
}
|
||||
|
||||
export const administratorOnly = roleCheck([role.administrator])
|
||||
export const checkerOnly = roleCheck([role.administrator, role.checker])
|
||||
export const userOnly = roleCheck([role.administrator, role.provider, role.customer])
|
||||
export const providerOnly = roleCheck([role.administrator, role.provider])
|
||||
export const customerOnly = roleCheck([role.administrator, role.customer])
|
||||
|
||||
|
||||
export const formInputClearable = {
|
||||
clearable: true,
|
||||
clearValueOnEmpty: true,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
textarea {
|
||||
resize: none !important;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import './dialog-permission.css'
|
||||
import {apiPost, horizontalFormOptions} from "../constants.js";
|
||||
|
||||
function detailForm() {
|
||||
return {
|
||||
id: 'resource_data_form',
|
||||
type: 'form',
|
||||
...horizontalFormOptions(),
|
||||
horizontal: {
|
||||
left: 2,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'hidden',
|
||||
name: 'id',
|
||||
},
|
||||
{
|
||||
type: 'textarea',
|
||||
label: '确权说明',
|
||||
name: 'description',
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export function permissionAddDialog() {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '新增确权申请',
|
||||
size: 'md',
|
||||
actions: [
|
||||
{
|
||||
type: 'reset',
|
||||
label: '重置',
|
||||
},
|
||||
{
|
||||
type: 'submit',
|
||||
label: '确定',
|
||||
level: 'primary',
|
||||
}
|
||||
],
|
||||
body: {
|
||||
debug: true,
|
||||
...detailForm(),
|
||||
api: apiPost('${base}/confirmation/save'),
|
||||
data: {
|
||||
add: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,13 @@ import './dialog-resource.css'
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
formInputClearable,
|
||||
horizontalFormOptions,
|
||||
inputFileFormItemCommonOptions,
|
||||
size1GB,
|
||||
size500MB
|
||||
} from "../constants.js";
|
||||
|
||||
const clearable = {
|
||||
clearable: true,
|
||||
clearValueOnEmpty: true,
|
||||
}
|
||||
|
||||
function inputFileFormItemUpdateFieldOptions(target) {
|
||||
let value = {}
|
||||
value[target] = '${event.data.value}'
|
||||
@@ -51,13 +47,13 @@ function detailForm() {
|
||||
name: 'name',
|
||||
label: '资源名称',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'textarea',
|
||||
name: 'description',
|
||||
label: '资源描述',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
showCounter: true,
|
||||
trimContents: true,
|
||||
minRows: 2,
|
||||
@@ -90,19 +86,19 @@ function detailForm() {
|
||||
label: 'API地址',
|
||||
name: 'apiUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'apiUsername',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'apiPassword',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -149,19 +145,19 @@ function detailForm() {
|
||||
label: 'JDBC',
|
||||
name: 'databaseJdbc',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'databaseUsername',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'databasePassword',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -210,33 +206,33 @@ function detailForm() {
|
||||
label: 'FTP地址',
|
||||
name: 'ftpUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'FTP账号',
|
||||
name: 'ftpUsername',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: 'FTP密码',
|
||||
name: 'ftpPassword',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '相对路径',
|
||||
name: 'ftpPath',
|
||||
description: '若为空,则使用用户根目录',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '文件筛选',
|
||||
name: 'ftpRegexFilter',
|
||||
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {apiGet, useAmis} from '../../components/constants.js'
|
||||
import {userChangePasswordDialog} from "../../components/user/dialog-user-change-password.js";
|
||||
import {tabUser} from "./tab-user.js";
|
||||
import {tabMarket} from "./tab-market.js";
|
||||
import {tabData} from "./tab-data.js";
|
||||
import {tabSettings} from "./tab-settings.js";
|
||||
import {tabCheck} from "./tab-check.js";
|
||||
import {tabPermissions} from "./tab-permissions.js";
|
||||
|
||||
useAmis(information => {
|
||||
return {
|
||||
@@ -56,9 +57,11 @@ useAmis(information => {
|
||||
type: 'tabs',
|
||||
tabsMode: 'vertical',
|
||||
tabs: [
|
||||
tabData(),
|
||||
// tabOverview(),
|
||||
tabMarket(),
|
||||
// tabMarket(),
|
||||
tabPermissions(),
|
||||
tabData(),
|
||||
tabCheck(),
|
||||
tabUser(),
|
||||
tabSettings(),
|
||||
]
|
||||
|
||||
12
gringotts-frontend/pages/index/tab-check.js
Normal file
12
gringotts-frontend/pages/index/tab-check.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import {checkerOnly} from "../../components/constants.js";
|
||||
|
||||
export function tabCheck() {
|
||||
return {
|
||||
visibleOn: checkerOnly,
|
||||
title: '审核审查',
|
||||
icon: 'fa fa-shield-halved',
|
||||
body: [
|
||||
'hello world'
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,24 +3,25 @@ import {
|
||||
resourceDetailDialog,
|
||||
resourceEditeDialog
|
||||
} from "../../components/resource/dialog-resource.js";
|
||||
import {apiGet, apiPost, crudCommonOptions} from "../../components/constants.js";
|
||||
import {apiGet, crudCommonOptions, userOnly} from "../../components/constants.js";
|
||||
|
||||
export function tabData() {
|
||||
return {
|
||||
visibleOn: userOnly,
|
||||
title: '数据资源',
|
||||
icon: 'fa fa-database',
|
||||
body: [
|
||||
{
|
||||
type: 'crud',
|
||||
api: {
|
||||
...apiPost('${base}/data_resource/list')
|
||||
...apiGet('${base}/data_resource/list')
|
||||
},
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
{
|
||||
type: 'action',
|
||||
label: '新增数据资源',
|
||||
label: '',
|
||||
icon: 'fa fa-plus',
|
||||
...resourceAddDialog()
|
||||
},
|
||||
@@ -44,7 +45,7 @@ export function tabData() {
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
width: 200,
|
||||
width: 100,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
@@ -62,14 +63,26 @@ export function tabData() {
|
||||
...resourceEditeDialog(),
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '删除',
|
||||
type: 'dropdown-button',
|
||||
level: 'link',
|
||||
className: 'text-danger',
|
||||
confirmTitle: '确认删除',
|
||||
confirmText: '确认删除名称为「${name}」的数据资源吗?',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/data_resource/remove/${id}')
|
||||
icon: 'fa fa-ellipsis-h',
|
||||
hideCaret: true,
|
||||
trigger: 'hover',
|
||||
buttons: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '申请确权',
|
||||
level: 'link',
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '删除',
|
||||
confirmTitle: '确认删除',
|
||||
confirmText: '确认删除名称为「${name}」的数据资源吗?',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/data_resource/remove/${id}')
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
76
gringotts-frontend/pages/index/tab-permissions.js
Normal file
76
gringotts-frontend/pages/index/tab-permissions.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import {apiGet, crudCommonOptions, providerOnly, userOnly} from "../../components/constants.js";
|
||||
import {permissionAddDialog} from "../../components/permission/dialog-permission.js";
|
||||
|
||||
export function tabPermissions() {
|
||||
return {
|
||||
visibleOn: userOnly,
|
||||
title: '权属管理',
|
||||
icon: 'fa fa-user-shield',
|
||||
body: {
|
||||
type: 'tabs',
|
||||
tabs: [
|
||||
{
|
||||
visibleOn: providerOnly,
|
||||
title: '确权管理',
|
||||
body: {
|
||||
type: 'crud',
|
||||
api: {
|
||||
...apiGet('${base}/confirmation/list')
|
||||
},
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
{
|
||||
type: 'action',
|
||||
label: '',
|
||||
icon: 'fa fa-plus',
|
||||
...permissionAddDialog()
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
label: '名称',
|
||||
name: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
label: '描述',
|
||||
name: 'description',
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
width: 150,
|
||||
align: 'center',
|
||||
type: 'tpl',
|
||||
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
width: 100,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '编辑',
|
||||
level: 'link',
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '授权管理',
|
||||
body: []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import {administratorOnly} from "../../components/constants.js";
|
||||
|
||||
export function tabSettings() {
|
||||
return {
|
||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
||||
visibleOn: administratorOnly,
|
||||
title: '系统管理',
|
||||
icon: 'fa fa-gear',
|
||||
body: [
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
administratorOnly,
|
||||
apiGet,
|
||||
copyField,
|
||||
crudCommonOptions,
|
||||
@@ -11,7 +12,7 @@ import {userAdministratorRegisterDialog} from "../../components/user/dialog-user
|
||||
|
||||
export function tabUser() {
|
||||
return {
|
||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
||||
visibleOn: administratorOnly,
|
||||
title: '用户管理',
|
||||
icon: 'fa fa-user',
|
||||
body: [
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
public abstract class SimpleController<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
||||
protected static final String SAVE = "/save";
|
||||
protected static final String LIST = "/list";
|
||||
protected static final String DETAIL = "/detail/{id}";
|
||||
protected static final String REMOVE = "/remove/{id}";
|
||||
|
||||
protected final SimpleService<ENTITY> service;
|
||||
|
||||
public SimpleController(SimpleService<ENTITY> service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@PostMapping(SAVE)
|
||||
public AmisResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||
return AmisResponse.responseSuccess(service.save(fromSaveItem(item)));
|
||||
}
|
||||
|
||||
@GetMapping(LIST)
|
||||
public AmisResponse<ImmutableSet<LIST_ITEM>> list() {
|
||||
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
||||
try {
|
||||
return toListItem(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@GetMapping(DETAIL)
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||
return AmisResponse.responseSuccess(toDetailItem(service.detail(id)));
|
||||
}
|
||||
|
||||
@GetMapping(REMOVE)
|
||||
public AmisResponse<Object> remove(@PathVariable Long id) {
|
||||
service.remove(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
protected abstract ENTITY fromSaveItem(SAVE_ITEM item) throws Exception;
|
||||
|
||||
protected abstract LIST_ITEM toListItem(ENTITY entity) throws Exception;
|
||||
|
||||
protected abstract DETAIL_ITEM toDetailItem(ENTITY entity) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public abstract class SimpleDetailItem<ENTITY> {
|
||||
private Long id;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public abstract class SimpleListItem<ENTITY> {
|
||||
private Long id;
|
||||
private String createdUsername;
|
||||
private LocalDateTime createdTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public abstract class SimpleSaveItem<ENTITY> {
|
||||
private Long id;
|
||||
}
|
||||
@@ -1,25 +1,79 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import java.util.Optional;
|
||||
import javax.transaction.Transactional;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
public abstract class SimpleService<E, ID> {
|
||||
protected abstract SimpleRepository<E, ID> repository();
|
||||
public abstract class SimpleService<ENTITY extends SimpleEntity> {
|
||||
protected final SimpleRepository<ENTITY, Long> repository;
|
||||
protected final UserService userService;
|
||||
|
||||
public ImmutableList<E> list() {
|
||||
return Lists.immutable.ofAll(repository().findAll());
|
||||
public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) {
|
||||
this.repository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public E detail(ID id) {
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public Long save(ENTITY entity) {
|
||||
User user = userService.currentLoginUser();
|
||||
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
||||
entity.setCreatedUser(user);
|
||||
}
|
||||
entity.setModifiedUser(user);
|
||||
entity = repository.saveOrUpdateByNotNullProperties(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
public ImmutableSet<ENTITY> list() {
|
||||
return Sets.immutable.ofAll(repository.findAll());
|
||||
}
|
||||
|
||||
public ImmutableSet<ENTITY> list(ImmutableSet<Long> ids) {
|
||||
return Sets.immutable.ofAll(repository.findAllById(ids.select(ObjectUtil::isNotNull)));
|
||||
}
|
||||
|
||||
public ENTITY detail(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return null;
|
||||
}
|
||||
return repository().findById(id).orElse(null);
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Optional<ENTITY> detailOptional(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return repository.findById(id);
|
||||
}
|
||||
|
||||
public ENTITY detailOrThrow(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
throw new IdNotFoundException(id);
|
||||
}
|
||||
return repository.findById(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void remove(Long id) {
|
||||
if (ObjectUtil.isNotNull(id)) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class IdNotFoundException extends RuntimeException {
|
||||
public IdNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的资源不存在", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.controller;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService;
|
||||
import com.eshore.gringotts.web.domain.resource.service.DataResourceService;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("confirmation")
|
||||
public class ConfirmationController extends SimpleController<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public ConfirmationController(ConfirmationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||
super(service);
|
||||
this.dataResourceService = dataResourceService;
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Confirmation fromSaveItem(SaveItem item) {
|
||||
Confirmation confirmation = new Confirmation();
|
||||
confirmation.setId(item.getId());
|
||||
confirmation.setDescription(item.getDescription());
|
||||
confirmation.setTarget(dataResourceService.detailOrThrow(item.getTargetId()));
|
||||
confirmation.setEvidences(dataFileService.list(item.getEvidenceIds()).toSet());
|
||||
return confirmation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListItem toListItem(Confirmation entity) {
|
||||
ListItem item = new ListItem();
|
||||
item.setId(entity.getId());
|
||||
item.setName(entity.getTarget().getName());
|
||||
item.setDescription(entity.getDescription());
|
||||
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(entity.getCreatedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItem toDetailItem(Confirmation entity) throws Exception {
|
||||
return new DetailItem(entity);
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SaveItem extends SimpleSaveItem<Confirmation> {
|
||||
private Long targetId;
|
||||
private String description;
|
||||
private ImmutableSet<Long> evidenceIds;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleListItem<Confirmation> {
|
||||
private String name;
|
||||
private String description;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class DetailItem extends SaveItem {
|
||||
public DetailItem(Confirmation confirmation) {
|
||||
this.setId(confirmation.getId());
|
||||
this.setDescription(confirmation.getDescription());
|
||||
this.setEvidenceIds(Sets.immutable.ofAll(confirmation.getEvidences()).collect(DataFile::getId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* 确权
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@Table(name = Constants.TABLE_PREFIX + "confirmation")
|
||||
@NamedEntityGraph(name = "confirmation.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "target"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "confirmation.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "target"),
|
||||
@NamedAttributeNode(value = "evidences"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
public class Confirmation extends SimpleEntity {
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataResource target;
|
||||
private String description;
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private Set<DataFile> evidences;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.CHECKING;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* 审查中
|
||||
*/
|
||||
CHECKING,
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* 禁用
|
||||
*/
|
||||
DISABLED,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.repository;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface ConfirmationRepository extends SimpleRepository<Confirmation, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Confirmation> findAll();
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Confirmation> findById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.confirmation.repository.ConfirmationRepository;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ConfirmationService extends SimpleService<Confirmation> {
|
||||
public ConfirmationService(ConfirmationRepository repository, UserService userService) {
|
||||
super(repository, userService);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,9 @@ package com.eshore.gringotts.web.domain.resource.controller;
|
||||
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisListResponse;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.CsvResourceFormat;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.JsonLineResourceFormat;
|
||||
@@ -26,14 +27,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -46,43 +41,174 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/data_resource")
|
||||
public class DataResourceController {
|
||||
public class DataResourceController extends SimpleController<DataResource, DataResourceController.SaveItem, DataResourceController.ListItem, DataResourceController.DetailItem> {
|
||||
private final ObjectMapper mapper;
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public DataResourceController(Jackson2ObjectMapperBuilder builder, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||
this.mapper = builder.build();
|
||||
this.dataResourceService = dataResourceService;
|
||||
public DataResourceController(DataResourceService dataResourceService, DataFileService dataFileService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(dataResourceService);
|
||||
this.dataFileService = dataFileService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
|
||||
log.info("Save request: {}", request);
|
||||
ResourceType type = request.generateResourceType(dataFileService);
|
||||
ResourceFormat format = request.generateResourceFormat(mapper);
|
||||
dataResourceService.create(request.id, request.name, request.description, type, format, dataFileService.detail(request.exampleFileId));
|
||||
@Override
|
||||
protected DataResource fromSaveItem(SaveItem item) throws JsonProcessingException {
|
||||
ResourceType type = generateResourceType(item);
|
||||
ResourceFormat format = generateResourceFormat(item);
|
||||
DataResource dataResource = new DataResource();
|
||||
dataResource.setId(item.getId());
|
||||
dataResource.setName(item.getName());
|
||||
dataResource.setDescription(item.getDescription());
|
||||
dataResource.setType(type);
|
||||
dataResource.setFormat(format);
|
||||
dataResource.setExample(dataFileService.detail(item.getExampleFileId()));
|
||||
return dataResource;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public AmisListResponse list() {
|
||||
return AmisResponse.responseListData(dataResourceService.list().collect(DataResourceListItem::new));
|
||||
@Override
|
||||
protected ListItem toListItem(DataResource dataResource) {
|
||||
ListItem item = new ListItem();
|
||||
item.setId(dataResource.getId());
|
||||
item.setName(dataResource.getName());
|
||||
item.setDescription(dataResource.getDescription());
|
||||
item.setType(dataResource.getType().getResourceType().name());
|
||||
item.setFormat(dataResource.getFormat().getFormatType().name());
|
||||
item.setCreatedUser(dataResource.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(dataResource.getCreatedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
public AmisResponse<DataResourceDetail> detail(@PathVariable Long id) throws JsonProcessingException {
|
||||
return AmisResponse.responseSuccess(new DataResourceDetail(mapper, dataResourceService.detail(id)));
|
||||
@Override
|
||||
protected DetailItem toDetailItem(DataResource dataResource) throws Exception {
|
||||
DetailItem item = new DetailItem();
|
||||
item.setId(dataResource.getId());
|
||||
item.setResourceTypeId(dataResource.getType().getId());
|
||||
item.setResourceFormatId(dataResource.getFormat().getId());
|
||||
item.setName(dataResource.getName());
|
||||
item.setDescription(dataResource.getDescription());
|
||||
item.setResourceType(dataResource.getType().getResourceType());
|
||||
switch (dataResource.getType().getResourceType()) {
|
||||
case API:
|
||||
ApiResourceType apiType = (ApiResourceType) dataResource.getType();
|
||||
item.setApiUrl(apiType.getUrl());
|
||||
item.setApiUsername(apiType.getUsername());
|
||||
item.setApiPassword(apiType.getPassword());
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||
item.setFileId(fileType.getFile().getId());
|
||||
item.setFilename(fileType.getFile().getFilename());
|
||||
break;
|
||||
case DATABASE:
|
||||
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
||||
item.setDatabaseType(databaseType.getDatabaseType().name());
|
||||
item.setDatabaseJdbc(databaseType.getJdbc());
|
||||
item.setDatabaseUsername(databaseType.getUsername());
|
||||
item.setDatabasePassword(databaseType.getPassword());
|
||||
break;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||
item.setCoreSiteFileId(hdfsType.getCoreSite().getId());
|
||||
item.setCoreSiteFilename(hdfsType.getCoreSite().getFilename());
|
||||
item.setHdfsSiteFileId(hdfsType.getHdfsSite().getId());
|
||||
item.setHdfsSiteFilename(hdfsType.getHdfsSite().getFilename());
|
||||
break;
|
||||
case FTP:
|
||||
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
||||
item.setFtpUrl(ftpType.getUrl());
|
||||
item.setFtpUsername(ftpType.getUsername());
|
||||
item.setFtpPassword(ftpType.getPassword());
|
||||
item.setFtpPath(ftpType.getPath());
|
||||
item.setFtpRegexFilter(ftpType.getRegexFilter());
|
||||
break;
|
||||
}
|
||||
item.setFormatType(dataResource.getFormat().getFormatType());
|
||||
switch (dataResource.getFormat().getFormatType()) {
|
||||
case NONE:
|
||||
case LINE:
|
||||
break;
|
||||
case JSON:
|
||||
JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat();
|
||||
item.setJsonSchemaText(jsonFormat.getSchema());
|
||||
item.setJsonSchema(mapper.readValue(jsonFormat.getSchema(), Map.class));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
|
||||
item.setJsonLineSchemaText(jsonLineFormat.getSchema());
|
||||
item.setJsonLineSchema(mapper.readValue(jsonLineFormat.getSchema(), Map.class));
|
||||
break;
|
||||
case CSV:
|
||||
CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat();
|
||||
item.setCsvSchemaText(csvFormat.getSchema());
|
||||
item.setCsvSchema(mapper.readValue(csvFormat.getSchema(), Map.class));
|
||||
break;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||
item.setExampleFileId(dataResource.getExample().getId());
|
||||
item.setExampleFilename(dataResource.getExample().getFilename());
|
||||
}
|
||||
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(dataResource.getCreatedTime());
|
||||
item.setModifiedUsername(dataResource.getModifiedUser().getUsername());
|
||||
item.setModifiedTime(dataResource.getModifiedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/remove/{id}")
|
||||
public void remove(@PathVariable Long id) {
|
||||
dataResourceService.remove(id);
|
||||
private ResourceType generateResourceType(SaveItem item) {
|
||||
ResourceType type = null;
|
||||
switch (item.getResourceType()) {
|
||||
case API:
|
||||
type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword());
|
||||
break;
|
||||
case FILE:
|
||||
DataFile dataFile = dataFileService.detail(item.getFileId());
|
||||
type = new FileResourceType(dataFile);
|
||||
break;
|
||||
case DATABASE:
|
||||
type = new DatabaseResourceType(
|
||||
item.getDatabaseJdbc(),
|
||||
item.getDatabaseUsername(),
|
||||
item.getDatabasePassword(),
|
||||
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, item.getDatabaseType())
|
||||
);
|
||||
break;
|
||||
case HDFS:
|
||||
type = new HDFSResourceType(dataFileService.detail(item.getCoreSiteFileId()), dataFileService.detail(item.getHdfsSiteFileId()));
|
||||
break;
|
||||
case FTP:
|
||||
type = new FtpResourceType(item.getFtpUrl(), item.getFtpUsername(), item.getFtpPassword(), item.getFtpPath(), item.getFtpRegexFilter());
|
||||
break;
|
||||
}
|
||||
type.setId(item.getResourceTypeId());
|
||||
return type;
|
||||
}
|
||||
|
||||
private ResourceFormat generateResourceFormat(SaveItem item) throws JsonProcessingException {
|
||||
ResourceFormat format = null;
|
||||
switch (item.getFormatType()) {
|
||||
case NONE:
|
||||
format = new NoneResourceFormat();
|
||||
break;
|
||||
case LINE:
|
||||
format = new LineResourceFormat();
|
||||
break;
|
||||
case JSON:
|
||||
format = new JsonResourceFormat(mapper.writeValueAsString(item.getJsonSchema()));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
format = new JsonLineResourceFormat(mapper.writeValueAsString(item.getJsonLineSchema()));
|
||||
break;
|
||||
case CSV:
|
||||
format = new CsvResourceFormat(mapper.writeValueAsString(item.getCsvSchema()));
|
||||
break;
|
||||
}
|
||||
format.setId(item.getResourceFormatId());
|
||||
return format;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CreateRequest {
|
||||
protected Long id;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SaveItem extends SimpleSaveItem<DataResource> {
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected Long resourceTypeId;
|
||||
@@ -111,62 +237,11 @@ public class DataResourceController {
|
||||
protected Map<?, ?> csvSchema;
|
||||
protected String csvSchemaText;
|
||||
protected Long exampleFileId;
|
||||
|
||||
public ResourceType generateResourceType(DataFileService dataFileService) {
|
||||
ResourceType type = null;
|
||||
switch (resourceType) {
|
||||
case API:
|
||||
type = new ApiResourceType(apiUrl, apiUsername, apiPassword);
|
||||
break;
|
||||
case FILE:
|
||||
DataFile dataFile = dataFileService.detail(fileId);
|
||||
type = new FileResourceType(dataFile);
|
||||
break;
|
||||
case DATABASE:
|
||||
type = new DatabaseResourceType(
|
||||
databaseJdbc,
|
||||
databaseUsername,
|
||||
databasePassword,
|
||||
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, databaseType)
|
||||
);
|
||||
break;
|
||||
case HDFS:
|
||||
type = new HDFSResourceType(dataFileService.detail(coreSiteFileId), dataFileService.detail(hdfsSiteFileId));
|
||||
break;
|
||||
case FTP:
|
||||
type = new FtpResourceType(ftpUrl, ftpUsername, ftpPassword, ftpPath, ftpRegexFilter);
|
||||
break;
|
||||
}
|
||||
type.setId(resourceTypeId);
|
||||
return type;
|
||||
}
|
||||
|
||||
public ResourceFormat generateResourceFormat(ObjectMapper mapper) throws JsonProcessingException {
|
||||
ResourceFormat format = null;
|
||||
switch (formatType) {
|
||||
case NONE:
|
||||
format = new NoneResourceFormat();
|
||||
break;
|
||||
case LINE:
|
||||
format = new LineResourceFormat();
|
||||
break;
|
||||
case JSON:
|
||||
format = new JsonResourceFormat(mapper.writeValueAsString(jsonSchema));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
format = new JsonLineResourceFormat(mapper.writeValueAsString(jsonLineSchema));
|
||||
break;
|
||||
case CSV:
|
||||
format = new CsvResourceFormat(mapper.writeValueAsString(csvSchema));
|
||||
break;
|
||||
}
|
||||
format.setId(resourceFormatId);
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class DataResourceListItem {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class ListItem extends SimpleListItem<DataResource> {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
@@ -174,23 +249,11 @@ public class DataResourceController {
|
||||
private String format;
|
||||
private String createdUser;
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
public DataResourceListItem(DataResource dataResource) {
|
||||
this.id = dataResource.getId();
|
||||
this.name = dataResource.getName();
|
||||
this.description = dataResource.getDescription();
|
||||
this.type = dataResource.getType().getResourceType().name();
|
||||
this.format = dataResource.getFormat().getFormatType().name();
|
||||
this.createdUser = dataResource.getCreatedUser().getUsername();
|
||||
this.createdTime = dataResource.getCreatedTime();
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public static final class DataResourceDetail extends CreateRequest {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class DetailItem extends SaveItem {
|
||||
private Long id;
|
||||
private Long fileId;
|
||||
private String filename;
|
||||
@@ -201,79 +264,5 @@ public class DataResourceController {
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
private String modifiedUsername;
|
||||
|
||||
public DataResourceDetail(ObjectMapper mapper, DataResource dataResource) throws JsonProcessingException {
|
||||
this.id = dataResource.getId();
|
||||
this.resourceTypeId = dataResource.getType().getId();
|
||||
this.resourceFormatId = dataResource.getFormat().getId();
|
||||
this.name = dataResource.getName();
|
||||
this.description = dataResource.getDescription();
|
||||
this.resourceType = dataResource.getType().getResourceType();
|
||||
switch (dataResource.getType().getResourceType()) {
|
||||
case API:
|
||||
ApiResourceType apiType = (ApiResourceType) dataResource.getType();
|
||||
this.apiUrl = apiType.getUrl();
|
||||
this.apiUsername = apiType.getUsername();
|
||||
this.apiPassword = apiType.getPassword();
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||
this.fileId = fileType.getFile().getId();
|
||||
this.filename = fileType.getFile().getFilename();
|
||||
break;
|
||||
case DATABASE:
|
||||
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
||||
this.databaseType = databaseType.getDatabaseType().name();
|
||||
this.databaseJdbc = databaseType.getJdbc();
|
||||
this.databaseUsername = databaseType.getUsername();
|
||||
this.databasePassword = databaseType.getPassword();
|
||||
break;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||
this.coreSiteFileId = hdfsType.getCoreSite().getId();
|
||||
this.coreSiteFilename = hdfsType.getCoreSite().getFilename();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getId();
|
||||
this.hdfsSiteFilename = hdfsType.getHdfsSite().getFilename();
|
||||
break;
|
||||
case FTP:
|
||||
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
||||
this.ftpUrl = ftpType.getUrl();
|
||||
this.ftpUsername = ftpType.getUsername();
|
||||
this.ftpPassword = ftpType.getPassword();
|
||||
this.ftpPath = ftpType.getPath();
|
||||
this.ftpRegexFilter = ftpType.getRegexFilter();
|
||||
break;
|
||||
}
|
||||
this.formatType = dataResource.getFormat().getFormatType();
|
||||
switch (dataResource.getFormat().getFormatType()) {
|
||||
case NONE:
|
||||
case LINE:
|
||||
break;
|
||||
case JSON:
|
||||
JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat();
|
||||
this.jsonSchemaText = jsonFormat.getSchema();
|
||||
this.jsonSchema = mapper.readValue(jsonFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
|
||||
this.jsonLineSchemaText = jsonLineFormat.getSchema();
|
||||
this.jsonLineSchema = mapper.readValue(jsonLineFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case CSV:
|
||||
CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat();
|
||||
this.csvSchemaText = csvFormat.getSchema();
|
||||
this.csvSchema = mapper.readValue(csvFormat.getSchema(), Map.class);
|
||||
break;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||
this.exampleFileId = dataResource.getExample().getId();
|
||||
this.exampleFilename = dataResource.getExample().getFilename();
|
||||
}
|
||||
|
||||
this.createdUsername = dataResource.getCreatedUser().getUsername();
|
||||
this.createdTime = dataResource.getCreatedTime();
|
||||
this.modifiedUsername = dataResource.getModifiedUser().getUsername();
|
||||
this.modifiedTime = dataResource.getModifiedTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.eshore.gringotts.web.domain.resource.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat;
|
||||
@@ -9,10 +7,7 @@ import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
|
||||
import com.eshore.gringotts.web.domain.resource.repository.DataResourceRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import com.eshore.gringotts.web.helper.EntityHelper;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,47 +18,22 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataResourceService extends SimpleService<DataResource, Long> {
|
||||
private final DataResourceRepository dataResourceRepository;
|
||||
public class DataResourceService extends SimpleService<DataResource> {
|
||||
private final ResourceTypeRepository resourceTypeRepository;
|
||||
private final ResourceFormatRepository resourceFormatRepository;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public DataResourceService(DataResourceRepository dataResourceRepository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
||||
this.dataResourceRepository = dataResourceRepository;
|
||||
public DataResourceService(DataResourceRepository repository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
||||
super(repository, userService);
|
||||
this.resourceTypeRepository = resourceTypeRepository;
|
||||
this.resourceFormatRepository = resourceFormatRepository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleRepository<DataResource, Long> repository() {
|
||||
return dataResourceRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(Long id, String name, String description, ResourceType type, ResourceFormat format, DataFile example) {
|
||||
type = resourceTypeRepository.save(type);
|
||||
format = resourceFormatRepository.save(format);
|
||||
DataResource dataResource = EntityHelper.fillCreatorAndModifier(new DataResource(), userService);
|
||||
dataResource.setId(id);
|
||||
dataResource.setName(name);
|
||||
dataResource.setDescription(description);
|
||||
dataResource.setType(type);
|
||||
dataResource.setFormat(format);
|
||||
dataResource.setExample(example);
|
||||
dataResourceRepository.saveOrUpdateByNotNullProperties(dataResource);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remove(Long id) {
|
||||
dataResourceRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public static final class DataResourceNotFoundException extends RuntimeException {
|
||||
public DataResourceNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的数据资源未找到", id));
|
||||
}
|
||||
public Long save(DataResource entity) {
|
||||
ResourceType type = resourceTypeRepository.save(entity.getType());
|
||||
ResourceFormat format = resourceFormatRepository.save(entity.getFormat());
|
||||
entity.setType(type);
|
||||
entity.setFormat(format);
|
||||
return super.save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.upload.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.upload.repository.DataFileRepository;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -16,21 +14,11 @@ import org.springframework.stereotype.Service;
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataFileService extends SimpleService<DataFile, Long> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataFileService.class);
|
||||
|
||||
private final DataFileRepository dataFileRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
|
||||
this.dataFileRepository = dataFileRepository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleRepository<DataFile, Long> repository() {
|
||||
return dataFileRepository;
|
||||
public class DataFileService extends SimpleService<DataFile> {
|
||||
public DataFileService(DataFileRepository repository, UserService userService) {
|
||||
super(repository, userService);
|
||||
}
|
||||
|
||||
public DataFile detail(String id) {
|
||||
@@ -46,17 +34,17 @@ public class DataFileService extends SimpleService<DataFile, Long> {
|
||||
User loginUser = userService.currentLoginUser();
|
||||
dataFile.setCreatedUser(loginUser);
|
||||
dataFile.setModifiedUser(loginUser);
|
||||
return dataFileRepository.save(dataFile).getId();
|
||||
return repository.save(dataFile).getId();
|
||||
}
|
||||
|
||||
public void updateDataFile(Long id, String path, Long size, String md5) {
|
||||
DataFile dataFile = dataFileRepository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
|
||||
DataFile dataFile = repository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
|
||||
dataFile.setSize(size);
|
||||
dataFile.setMd5(md5);
|
||||
dataFile.setPath(path);
|
||||
User loginUser = userService.currentLoginUser();
|
||||
dataFile.setModifiedUser(loginUser);
|
||||
dataFileRepository.save(dataFile);
|
||||
repository.save(dataFile);
|
||||
}
|
||||
|
||||
public static final class DataFileNotFoundException extends RuntimeException {
|
||||
|
||||
Reference in New Issue
Block a user