1
0

5 Commits

18 changed files with 423 additions and 171 deletions

View File

@@ -1,5 +1,5 @@
const information = {
debug: false,
debug: true,
// baseUrl: '',
baseUrl: 'http://127.0.0.1:20080',
title: '可信供给中心',
@@ -170,6 +170,13 @@ export const userStateMapping = [
mappingItem('禁用', 'DISABLED', 'bg-danger'),
]
export const confirmationStateMapping = [
mappingItem('草稿', 'DRAFT', 'bg-primary'),
mappingItem('审查中', 'CHECKING', 'bg-warning'),
mappingItem('通过', 'NORMAL', 'bg-success'),
mappingItem('驳回', 'REJECT', 'bg-danger'),
]
function api(method, url) {
return {
method: method,
@@ -210,3 +217,55 @@ export const formInputClearable = {
clearable: true,
clearValueOnEmpty: true,
}
const formInputFileStaticColumns = [
{
name: 'filename',
label: '文件名',
},
{
type: 'operation',
label: '操作',
width: 140,
buttons: [
{
type: 'action',
label: '预览',
level: 'link',
icon: 'fas fa-eye'
},
{
type: 'action',
label: '下载',
level: 'link',
icon: 'fa fa-download'
}
]
}
]
export function formInputSingleFileStatic(field, label) {
return {
visibleOn: '${detail}',
type: 'control',
label: label,
required: true,
body: {
type: 'table',
source: `\${${field}|asArray}`,
columns: formInputFileStaticColumns,
}
}
}
export function formInputMultiFileStatic(field, label) {
return {
visibleOn: '${detail}',
type: 'input-table',
label: label,
name: field,
required: true,
resizable: false,
columns: formInputFileStaticColumns,
}
}

View File

@@ -1,27 +1,15 @@
import './dialog-permission.css'
import {apiGet, apiPost, horizontalFormOptions, inputFileFormItemCommonOptions, size100MB} from "../constants.js";
import {
apiGet,
apiPost,
formInputClearable,
formInputMultiFileStatic,
horizontalFormOptions,
inputFileFormItemCommonOptions,
size100MB
} from "../constants.js";
import {resourceList} from "../../pages/index/tab-data.js";
function inputFileFormItemUpdateFieldOptions(target) {
let value = {}
value[target] = '${event.data.value}'
return {
onEvent: {
success: {
actions: [
// {
// actionType: 'setValue',
// componentId: 'permission_form',
// args: {
// value: value
// }
// }
]
}
}
}
}
function detailForm() {
return {
id: 'permission_form',
@@ -41,7 +29,7 @@ function detailForm() {
label: '数据资源',
required: true,
multiple: false,
size: 'lg',
size: 'md',
valueField: 'id',
labelField: 'name',
source: apiGet('${base}/data_resource/list'),
@@ -53,14 +41,17 @@ function detailForm() {
type: 'textarea',
label: '确权说明',
name: 'description',
...formInputClearable,
},
formInputMultiFileStatic('evidenceFiles', '相关材料'),
{
visibleOn: '${!detail}',
type: 'input-file',
label: '相关材料',
name: 'evidenceIds',
name: 'evidenceFiles',
multiple: true,
required: true,
extractValue: true,
joinValues: false,
...inputFileFormItemCommonOptions(undefined, size100MB),
}
]
@@ -85,7 +76,6 @@ export function permissionAddDialog() {
}
],
body: {
debug: true,
...detailForm(),
api: apiPost('${base}/confirmation/save'),
data: {
@@ -96,17 +86,16 @@ export function permissionAddDialog() {
}
}
export function permissionDetailDialog() {
export function permissionDetailDialog(field = 'id') {
return {
actionType: 'dialog',
dialog: {
title: '新增确权申请',
title: '确权申请详情',
size: 'md',
actions: [],
body: {
debug: true,
...detailForm(),
initApi: apiGet('${base}/confirmation/detail/${id}'),
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
static: true,
data: {
detail: true,
@@ -115,3 +104,32 @@ export function permissionDetailDialog() {
}
}
}
export function permissionEditeDialog(field = 'id') {
return {
actionType: 'dialog',
dialog: {
title: '确权申请详情',
size: 'md',
actions: [
{
type: 'reset',
label: '重置',
},
{
type: 'submit',
label: '确定',
level: 'primary',
}
],
body: {
...detailForm(),
api: apiPost('${base}/confirmation/save'),
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
data: {
edit: true,
}
},
}
}
}

View File

@@ -3,35 +3,15 @@ import {
apiGet,
apiPost,
formInputClearable,
formInputSingleFileStatic,
horizontalFormOptions,
inputFileFormItemCommonOptions,
size1GB,
size500MB
} from "../constants.js";
function inputFileFormItemUpdateFieldOptions(target) {
let value = {}
value[target] = '${event.data.value}'
return {
onEvent: {
success: {
actions: [
{
actionType: 'setValue',
componentId: 'resource_data_form',
args: {
value: value
}
}
]
}
}
}
}
function detailForm() {
return {
id: 'resource_data_form',
type: 'form',
...horizontalFormOptions(),
horizontal: {
@@ -106,22 +86,17 @@ function detailForm() {
visibleOn: "${resourceType === 'FILE'}",
type: 'fieldSet',
body: [
formInputSingleFileStatic('file', '数据文件'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: '数据文件',
description: '只适合小于1GB的资源文件使用大文件请使用其他资源类型',
name: 'filename',
name: 'file',
multiple: false,
required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.zip', size1GB),
...inputFileFormItemUpdateFieldOptions('fileId'),
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'filename',
},
]
},
@@ -165,35 +140,27 @@ function detailForm() {
visibleOn: "${resourceType === 'HDFS'}",
type: 'fieldSet',
body: [
formInputSingleFileStatic('coreSiteFile', 'core-site.xml'),
{
visibleOn: "${!static}",
visibleOn: "${!detail}",
type: 'input-file',
label: 'core-site.xml',
name: 'coreSiteFilename',
name: 'coreSiteFile',
multiple: false,
required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.xml'),
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
},
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'coreSiteFilename',
},
{
visibleOn: "${!static}",
visibleOn: "${!detail}",
type: 'input-file',
label: 'hdfs-site.xml',
name: 'hdfsSiteFilename',
name: 'hdfsSiteFile',
multiple: false,
required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.xml'),
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'hdfsSiteFilename',
},
]
},
@@ -313,20 +280,16 @@ function detailForm() {
label: 'JSON格式',
language: 'json',
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '资源示例',
name: 'exampleFilename',
},
formInputSingleFileStatic('exampleFile', '资源示例'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: '资源示例',
name: 'exampleFilename',
name: 'exampleFile',
description: '可以上传用于作为格式示范的样例数据',
multiple: false,
joinValues: false,
...inputFileFormItemCommonOptions(undefined, size500MB),
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
},
]
}

View File

@@ -19,6 +19,9 @@ export function resourceList() {
...resourceAddDialog()
},
],
rowSelection: {
disableOn: '${confirmationId}',
},
columns: [
{
label: '名称',
@@ -57,14 +60,16 @@ export function resourceList() {
trigger: 'hover',
buttons: [
{
disabledOn: '${confirmationId}',
type: 'action',
label: '编辑',
level: 'link',
...resourceEditeDialog(),
},
{
disabledOn: '${confirmationId}',
type: 'action',
label: '删除',
label: "删除",
confirmTitle: '确认删除',
confirmText: '确认删除名称为「${name}」的数据资源吗?',
actionType: 'ajax',

View File

@@ -1,5 +1,16 @@
import {apiGet, crudCommonOptions, providerOnly, userOnly} from "../../components/constants.js";
import {permissionAddDialog, permissionDetailDialog} from "../../components/permission/dialog-permission.js";
import {
apiGet,
confirmationStateMapping,
crudCommonOptions,
mappingField,
providerOnly,
userOnly
} from "../../components/constants.js";
import {
permissionAddDialog,
permissionDetailDialog,
permissionEditeDialog
} from "../../components/permission/dialog-permission.js";
export function tabPermissions() {
return {
@@ -37,6 +48,12 @@ export function tabPermissions() {
label: '描述',
name: 'description',
},
{
label: '状态',
width: 80,
align: 'center',
...mappingField('state', confirmationStateMapping)
},
{
label: '创建时间',
width: 150,
@@ -58,9 +75,49 @@ export function tabPermissions() {
...permissionDetailDialog(),
},
{
visibleOn: "${state === 'CHECKING'}",
type: 'action',
label: '编辑',
label: '撤销',
level: 'link',
confirmTitle: '确认撤销',
confirmText: '确认撤销名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/confirmation/retract/${id}'),
},
{
visibleOn: "${state === 'DRAFT' || state === 'REJECT'}",
type: 'action',
label: '提交',
level: 'link',
confirmTitle: '确认提交',
confirmText: '确认提交名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/confirmation/submit/${id}'),
},
{
type: 'dropdown-button',
level: 'link',
icon: 'fa fa-ellipsis-h',
hideCaret: true,
trigger: 'hover',
buttons: [
{
disabledOn: "${state === 'CHECKING'}",
type: 'action',
label: '编辑',
level: 'link',
...permissionEditeDialog(),
},
{
disabledOn: "${state === 'CHECKING'}",
type: 'action',
label: "删除",
confirmTitle: '确认删除',
confirmText: '确认删除名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/confirmation/remove/${id}'),
},
]
},
]
},

View File

@@ -19,7 +19,7 @@ public abstract class SimpleController<ENTITY extends SimpleEntity, SAVE_ITEM, L
protected static final String DETAIL = "/detail/{id}";
protected static final String REMOVE = "/remove/{id}";
protected final SimpleService<ENTITY> service;
private final SimpleService<ENTITY> service;
public SimpleController(SimpleService<ENTITY> service) {
this.service = service;

View File

@@ -1,5 +1,13 @@
package com.eshore.gringotts.web.domain.base.entity;
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -7,10 +15,37 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonDeserialize(using = FileInfo.FileInfoDeserializer.class)
public final class FileInfo {
private Long id;
private String id;
private String name;
private String filename;
private Long value;
private String state;
public FileInfo(DataFile dataFile) {
this.id = dataFile.getId().toString();
this.name = dataFile.getFilename();
this.filename = dataFile.getFilename();
this.value = dataFile.getId();
this.state = "uploaded";
}
public static final class FileInfoDeserializer extends JsonDeserializer<FileInfo> {
@Override
public FileInfo deserialize(JsonParser parser, DeserializationContext context) throws IOException {
TreeNode root = parser.readValueAsTree();
if (root instanceof ObjectNode) {
ObjectNode node = (ObjectNode) root;
return new FileInfo(
node.get("id").asText(),
node.get("name").asText(),
node.get("filename").asText(),
node.get("value").asLong(),
node.get("state").asText()
);
}
return null;
}
}
}

View File

@@ -1,5 +1,7 @@
package com.eshore.gringotts.web.domain.base.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
@@ -8,6 +10,7 @@ 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 lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.set.ImmutableSet;
@@ -15,9 +18,10 @@ import org.eclipse.collections.api.set.ImmutableSet;
* @author lanyuanxiaoyao
* @date 2024-11-21
*/
@Slf4j
public abstract class SimpleService<ENTITY extends SimpleEntity> {
protected final SimpleRepository<ENTITY, Long> repository;
protected final UserService userService;
private final SimpleRepository<ENTITY, Long> repository;
private final UserService userService;
public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) {
this.repository = repository;
@@ -26,12 +30,23 @@ public abstract class SimpleService<ENTITY extends SimpleEntity> {
@Transactional(rollbackOn = Throwable.class)
public Long save(ENTITY entity) {
if (ObjectUtil.isNotNull(entity.getId())) {
Long id = entity.getId();
ENTITY targetEntity = repository.findById(entity.getId()).orElseThrow(() -> new IdNotFoundException(id));
BeanUtil.copyProperties(
entity,
targetEntity,
CopyOptions.create()
.setIgnoreProperties("id", "createdUser", "createdTime", "modifiedUser", "modifiedTime")
);
entity = targetEntity;
}
User user = userService.currentLoginUser();
if (ObjectUtil.isNull(entity.getCreatedUser())) {
entity.setCreatedUser(user);
}
entity.setModifiedUser(user);
entity = repository.saveOrUpdateByNotNullProperties(entity);
entity = repository.save(entity);
return entity.getId();
}

View File

@@ -1,8 +1,8 @@
package com.eshore.gringotts.web.domain.confirmation.controller;
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.FileInfo;
import com.eshore.gringotts.web.domain.base.entity.SimpleDetailItem;
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;
@@ -14,6 +14,8 @@ 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -25,22 +27,36 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("confirmation")
public class ConfirmationController extends SimpleController<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
private final ConfirmationService confirmationService;
private final DataResourceService dataResourceService;
private final DataFileService dataFileService;
public ConfirmationController(ConfirmationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
public ConfirmationController(ConfirmationService service, ConfirmationService confirmationService, DataResourceService dataResourceService, DataFileService dataFileService) {
super(service);
this.confirmationService = confirmationService;
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService;
}
@GetMapping("/submit/{id}")
public AmisResponse<Object> submit(@PathVariable Long id) {
confirmationService.submit(id);
return AmisResponse.responseSuccess();
}
@GetMapping("/retract/{id}")
public AmisResponse<Object> retract(@PathVariable Long id) {
confirmationService.retract(id);
return AmisResponse.responseSuccess();
}
@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());
confirmation.setEvidences(dataFileService.list(item.getEvidenceFiles().collect(FileInfo::getValue)).toSet());
return confirmation;
}
@@ -50,13 +66,14 @@ public class ConfirmationController extends SimpleController<Confirmation, Confi
item.setId(entity.getId());
item.setName(entity.getTarget().getName());
item.setDescription(entity.getDescription());
item.setState(entity.getState().name());
item.setCreatedUsername(entity.getCreatedUser().getUsername());
item.setCreatedTime(entity.getCreatedTime());
return item;
}
@Override
protected DetailItem toDetailItem(Confirmation entity) throws Exception {
protected DetailItem toDetailItem(Confirmation entity) {
return new DetailItem(entity);
}
@@ -65,7 +82,7 @@ public class ConfirmationController extends SimpleController<Confirmation, Confi
public static class SaveItem extends SimpleSaveItem<Confirmation> {
private Long targetId;
private String description;
private ImmutableSet<Long> evidenceIds;
private ImmutableSet<FileInfo> evidenceFiles;
}
@Data
@@ -73,31 +90,20 @@ public class ConfirmationController extends SimpleController<Confirmation, Confi
public static class ListItem extends SimpleListItem<Confirmation> {
private String name;
private String description;
private String state;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class DetailItem extends SimpleDetailItem<Confirmation> {
private Long targetId;
public static final class DetailItem extends SaveItem {
private String targetName;
private String description;
private ImmutableSet<FileInfo> evidenceIds;
public DetailItem(Confirmation confirmation) {
this.setId(confirmation.getId());
this.setTargetId(confirmation.getTarget().getId());
this.setTargetName(confirmation.getTarget().getName());
this.setDescription(confirmation.getDescription());
this.setEvidenceIds(
Sets.immutable.ofAll(confirmation.getEvidences())
.collect(file -> new FileInfo(
file.getId(),
file.getFilename(),
file.getFilename(),
file.getId(),
"uploaded"
))
);
this.setEvidenceFiles(Sets.immutable.ofAll(confirmation.getEvidences()).collect(FileInfo::new));
}
}
}

View File

@@ -57,9 +57,13 @@ public class Confirmation extends SimpleEntity {
private Set<DataFile> evidences;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private State state = State.CHECKING;
private State state = State.DRAFT;
public enum State {
/**
* 草稿
*/
DRAFT,
/**
* 审查中
*/
@@ -69,8 +73,8 @@ public class Confirmation extends SimpleEntity {
*/
NORMAL,
/**
* 禁用
* 驳回
*/
DISABLED,
REJECT,
}
}

View File

@@ -4,7 +4,10 @@ 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 javax.transaction.Transactional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
/**
@@ -21,4 +24,11 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
@Override
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Confirmation> findById(Long id);
Boolean existsByTarget_Id(Long id);
@Transactional
@Modifying
@Query("update Confirmation confirmation set confirmation.state = ?2 where confirmation.id = ?1")
void updateStateById(Long id, Confirmation.State state);
}

View File

@@ -14,7 +14,32 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ConfirmationService extends SimpleService<Confirmation> {
public ConfirmationService(ConfirmationRepository repository, UserService userService) {
super(repository, userService);
private final ConfirmationRepository confirmationRepository;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService) {
super(confirmationRepository, userService);
this.confirmationRepository = confirmationRepository;
}
@Override
public Long save(Confirmation entity) {
if (confirmationRepository.existsByTarget_Id(entity.getTarget().getId())) {
throw new ConfirmationDuplicatedException();
}
return super.save(entity);
}
public void submit(Long id) {
confirmationRepository.updateStateById(id, Confirmation.State.CHECKING);
}
public void retract(Long id) {
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT);
}
public static final class ConfirmationDuplicatedException extends RuntimeException {
public ConfirmationDuplicatedException() {
super("数据资源已绑定确权申请,无法再次申请");
}
}
}

View File

@@ -0,0 +1,32 @@
package com.eshore.gringotts.web.domain.order.entity;
import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
* 工单
*
* @author lanyuanxiaoyao
* @date 2024-11-27
*/
@Getter
@Setter
@ToString
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@Table(name = Constants.TABLE_PREFIX + "work_order")
public class WorkOrder extends SimpleEntity {
@Column(nullable = false)
private String name;
private String description;
}

View File

@@ -3,6 +3,7 @@ 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.domain.base.controller.SimpleController;
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
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;
@@ -61,7 +62,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
dataResource.setDescription(item.getDescription());
dataResource.setType(type);
dataResource.setFormat(format);
dataResource.setExample(dataFileService.detail(item.getExampleFileId()));
if (ObjectUtil.isNotNull(item.getExampleFile())) {
dataResource.setExample(dataFileService.detail(item.getExampleFile().getValue()));
}
return dataResource;
}
@@ -73,6 +76,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
item.setDescription(dataResource.getDescription());
item.setType(dataResource.getType().getResourceType().name());
item.setFormat(dataResource.getFormat().getFormatType().name());
if (ObjectUtil.isNotNull(dataResource.getConfirmation())) {
item.setConfirmationId(dataResource.getConfirmation().getId());
}
item.setCreatedUser(dataResource.getCreatedUser().getUsername());
item.setCreatedTime(dataResource.getCreatedTime());
return item;
@@ -96,8 +102,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break;
case FILE:
FileResourceType fileType = (FileResourceType) dataResource.getType();
item.setFileId(fileType.getFile().getId());
item.setFilename(fileType.getFile().getFilename());
item.setFile(new FileInfo(fileType.getFile()));
break;
case DATABASE:
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
@@ -108,10 +113,8 @@ public class DataResourceController extends SimpleController<DataResource, DataR
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());
item.setCoreSiteFile(new FileInfo(hdfsType.getCoreSite()));
item.setHdfsSiteFile(new FileInfo(hdfsType.getHdfsSite()));
break;
case FTP:
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
@@ -144,8 +147,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break;
}
if (ObjectUtil.isNotNull(dataResource.getExample())) {
item.setExampleFileId(dataResource.getExample().getId());
item.setExampleFilename(dataResource.getExample().getFilename());
item.setExampleFile(new FileInfo(dataResource.getExample()));
}
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
item.setCreatedTime(dataResource.getCreatedTime());
@@ -161,7 +163,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword());
break;
case FILE:
DataFile dataFile = dataFileService.detail(item.getFileId());
DataFile dataFile = dataFileService.detail(item.getFile().getValue());
type = new FileResourceType(dataFile);
break;
case DATABASE:
@@ -173,7 +175,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
);
break;
case HDFS:
type = new HDFSResourceType(dataFileService.detail(item.getCoreSiteFileId()), dataFileService.detail(item.getHdfsSiteFileId()));
type = new HDFSResourceType(dataFileService.detail(item.getCoreSiteFile().getValue()), dataFileService.detail(item.getHdfsSiteFile().getValue()));
break;
case FTP:
type = new FtpResourceType(item.getFtpUrl(), item.getFtpUsername(), item.getFtpPassword(), item.getFtpPath(), item.getFtpRegexFilter());
@@ -209,34 +211,34 @@ public class DataResourceController extends SimpleController<DataResource, DataR
@Data
@EqualsAndHashCode(callSuper = true)
public static class SaveItem extends SimpleSaveItem<DataResource> {
protected String name;
protected String description;
protected Long resourceTypeId;
protected ResourceType.Type resourceType;
protected String apiUrl;
protected String apiUsername;
protected String apiPassword;
protected Long fileId;
protected String databaseType;
protected String databaseJdbc;
protected String databaseUsername;
protected String databasePassword;
protected Long coreSiteFileId;
protected Long hdfsSiteFileId;
protected String ftpUrl;
protected String ftpUsername;
protected String ftpPassword;
protected String ftpPath;
protected String ftpRegexFilter;
protected Long resourceFormatId;
protected ResourceFormat.Type formatType;
protected Map<?, ?> jsonSchema;
protected String jsonSchemaText;
protected Map<?, ?> jsonLineSchema;
protected String jsonLineSchemaText;
protected Map<?, ?> csvSchema;
protected String csvSchemaText;
protected Long exampleFileId;
private String name;
private String description;
private Long resourceTypeId;
private ResourceType.Type resourceType;
private String apiUrl;
private String apiUsername;
private String apiPassword;
private FileInfo file;
private String databaseType;
private String databaseJdbc;
private String databaseUsername;
private String databasePassword;
private FileInfo coreSiteFile;
private FileInfo hdfsSiteFile;
private String ftpUrl;
private String ftpUsername;
private String ftpPassword;
private String ftpPath;
private String ftpRegexFilter;
private Long resourceFormatId;
private ResourceFormat.Type formatType;
private Map<?, ?> jsonSchema;
private String jsonSchemaText;
private Map<?, ?> jsonLineSchema;
private String jsonLineSchemaText;
private Map<?, ?> csvSchema;
private String csvSchemaText;
private FileInfo exampleFile;
}
@Data
@@ -247,6 +249,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
private String description;
private String type;
private String format;
private Long confirmationId;
private String createdUser;
private LocalDateTime createdTime;
}
@@ -254,12 +257,6 @@ public class DataResourceController extends SimpleController<DataResource, DataR
@Data
@EqualsAndHashCode(callSuper = true)
public static final class DetailItem extends SaveItem {
private Long id;
private Long fileId;
private String filename;
private String coreSiteFilename;
private String hdfsSiteFilename;
private String exampleFilename;
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;

View File

@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.resource.entity;
import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat;
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
@@ -33,12 +34,14 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@NamedEntityGraph(name = "data_resource.list", attributeNodes = {
@NamedAttributeNode(value = "type"),
@NamedAttributeNode(value = "format"),
@NamedAttributeNode(value = "confirmation"),
@NamedAttributeNode(value = "createdUser"),
})
@NamedEntityGraph(name = "data_resource.detail", attributeNodes = {
@NamedAttributeNode(value = "type"),
@NamedAttributeNode(value = "format"),
@NamedAttributeNode(value = "example"),
@NamedAttributeNode(value = "confirmation"),
@NamedAttributeNode(value = "createdUser"),
@NamedAttributeNode(value = "modifiedUser"),
})
@@ -58,4 +61,7 @@ public class DataResource extends SimpleEntity {
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
private DataFile example;
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
@ToString.Exclude
private Confirmation confirmation;
}

View File

@@ -34,15 +34,15 @@ import org.springframework.web.multipart.MultipartFile;
*/
@RestController
@RequestMapping("/upload")
public class UploadController {
private static final Logger logger = LoggerFactory.getLogger(UploadController.class);
public class DataFileController {
private static final Logger logger = LoggerFactory.getLogger(DataFileController.class);
private final DataFileService dataFileService;
private final String uploadFolderPath;
private final String cacheFolderPath;
private final String sliceFolderPath;
public UploadController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
public DataFileController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
this.dataFileService = dataFileService;
this.uploadFolderPath = uploadConfiguration.getUploadPath();

View File

@@ -17,8 +17,13 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class DataFileService extends SimpleService<DataFile> {
public DataFileService(DataFileRepository repository, UserService userService) {
super(repository, userService);
private final DataFileRepository dataFileRepository;
private final UserService userService;
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
super(dataFileRepository, userService);
this.dataFileRepository = dataFileRepository;
this.userService = userService;
}
public DataFile detail(String id) {
@@ -34,17 +39,17 @@ public class DataFileService extends SimpleService<DataFile> {
User loginUser = userService.currentLoginUser();
dataFile.setCreatedUser(loginUser);
dataFile.setModifiedUser(loginUser);
return repository.save(dataFile).getId();
return dataFileRepository.save(dataFile).getId();
}
public void updateDataFile(Long id, String path, Long size, String md5) {
DataFile dataFile = repository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
DataFile dataFile = dataFileRepository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
dataFile.setSize(size);
dataFile.setMd5(md5);
dataFile.setPath(path);
User loginUser = userService.currentLoginUser();
dataFile.setModifiedUser(loginUser);
repository.save(dataFile);
dataFileRepository.save(dataFile);
}
public static final class DataFileNotFoundException extends RuntimeException {

View File

@@ -32,6 +32,21 @@ logging:
sdk:
eventsub:
EventSubscribeImp: error
---
spring:
config:
activate:
on-profile: macOS
gringotts:
upload:
upload-path: /Users/lanyuanxiaoyao/Project/IdeaProjects/gringotts/gringotts-web/target/upload
---
spring:
config:
activate:
on-profile: windows
gringotts:
upload:
upload-path: C:\Users\lanyuanxiaoyao\Projects\gringotts\gringotts-web\target