Skip to content

Commit

Permalink
fix: where the 'path' attribute of sub-attachments was not updated in…
Browse files Browse the repository at this point in the history
… time when attachments were moved. (#537)

* docs: update BUILD.MD

* fix: where the 'path' attribute of sub-attachments was not updated in time when attachments were moved.

* fix: checkstyle.
  • Loading branch information
li-guohao authored May 14, 2024
1 parent 3ad7eae commit 6fadb4d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
8 changes: 8 additions & 0 deletions BUILD.MD
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ commit之前,用checkstyle检查下代码,确认没有问题后再commit。
=> `Scheme` 选择 `Project`

选择右边设置,导入checkstyle文件
(如没有该项,则需要先安装checkstyle-idea插件)

最后OK保存

## 本地开发
`IkarosApplication`的运行配置里,将`Active profiles` 配置成:`dev,win,debug`

### Console编译
需要先运行任务进行Console的前端文件编译:

```text
./gradlew buildFrontend -x test
```

## IDEA格式化配置

1. 打开 `Setting` => `Editor` => `Code Style` => `Java`
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

- 启动console,找不到`@runikaros/api-client``@runikaros/shared`
[#527](https://github.com/ikaros-dev/ikaros/issues/527)
- 修复附件移动时,子附件的`path`属性没有及时更新的问题


# 0.11.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,22 @@ public class AttachmentServiceImpl implements AttachmentService {
private final R2dbcEntityTemplate template;
private final IkarosProperties ikarosProperties;
private final ApplicationEventPublisher applicationEventPublisher;
private final AttachmentRepository attachmentRepository;

/**
* Construct.
*/
public AttachmentServiceImpl(AttachmentRepository repository,
AttachmentReferenceRepository referenceRepository,
R2dbcEntityTemplate template, IkarosProperties ikarosProperties,
ApplicationEventPublisher applicationEventPublisher) {
ApplicationEventPublisher applicationEventPublisher,
AttachmentRepository attachmentRepository) {
this.repository = repository;
this.referenceRepository = referenceRepository;
this.template = template;
this.ikarosProperties = ikarosProperties;
this.applicationEventPublisher = applicationEventPublisher;
this.attachmentRepository = attachmentRepository;
}

@Override
Expand All @@ -94,16 +97,32 @@ public Mono<Attachment> save(Attachment attachment) {
Assert.notNull(attachment, "'attachment' must not be null.");
attachment.setParentId(Optional.ofNullable(attachment.getParentId())
.orElse(AttachmentConst.ROOT_DIRECTORY_ID));
final Long newParentId = attachment.getParentId();
Mono<AttachmentEntity> attachmentEntityMono =
Objects.isNull(attachment.getId())
? copyProperties(attachment, new AttachmentEntity())
: repository.findById(attachment.getId())
.flatMap(attachmentEntity -> copyProperties(attachment, attachmentEntity));
.flatMap(attachmentEntity ->
copyProperties(attachment, attachmentEntity, "parentId"));

return attachmentEntityMono
.flatMap(attachmentEntity -> updatePathWhenNewParentId(attachmentEntity, newParentId))
.flatMap(this::saveEntity)
.flatMap(attachmentEntity -> copyProperties(attachmentEntity, attachment));
}

private Mono<AttachmentEntity> updatePathWhenNewParentId(AttachmentEntity attachmentEntity,
Long newParentId) {
if (Objects.equals(newParentId, attachmentEntity.getParentId())) {
return Mono.just(attachmentEntity);
}

String name = attachmentEntity.getName();
return findPathByParentId(newParentId, name)
.map(attachmentEntity::setPath)
.map(attEntity -> attEntity.setParentId(newParentId));
}

@Override
public Mono<PagingWrap<AttachmentEntity>> listEntitiesByCondition(
AttachmentSearchCondition searchCondition) {
Expand Down Expand Up @@ -148,7 +167,13 @@ public Mono<PagingWrap<AttachmentEntity>> listEntitiesByCondition(
template.select(query, AttachmentEntity.class);
Mono<Long> countMono = template.count(query, AttachmentEntity.class);

return countMono.flatMap(total -> attachmentEntityFlux.collectList()
return countMono.flatMap(total -> attachmentEntityFlux
.flatMap(attEntity -> findPathByParentId(attEntity.getParentId(), attEntity.getName())
.filter(newPath -> !newPath.equals(attEntity.getPath()))
.map(attEntity::setPath)
.flatMap(attachmentRepository::save)
.switchIfEmpty(Mono.just(attEntity)))
.collectList()
.map(attachmentEntities -> new PagingWrap<>(page, size, total, attachmentEntities)));
}

Expand Down

0 comments on commit 6fadb4d

Please sign in to comment.