Skip to content

Commit

Permalink
Fix issue when folderId of getElements is null
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonpoo authored and ludomikula committed Dec 10, 2024
1 parent 0838e42 commit ebdc031
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Mono<ResponseView<FolderInfoView>> create(@RequestBody Folder folder) {
@Override
public Mono<ResponseView<Void>> delete(@PathVariable("id") String folderId) {
return gidService.convertFolderIdToObjectId(folderId).flatMap(objectId ->
folderApiService.delete(objectId)
folderApiService.delete(objectId.orElse(null))
.delayUntil(f -> businessEventPublisher.publishFolderCommonEvent(f.getId(), f.getName(), EventType.FOLDER_DELETE))
.then(Mono.fromSupplier(() -> ResponseView.success(null))));
}
Expand Down Expand Up @@ -73,8 +73,9 @@ public Mono<PageResponseView<?>> getElements(@RequestParam(value = "id", require
@RequestParam(required = false) String category,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
return gidService.convertFolderIdToObjectId(folderId).flatMap(objectId -> {
var flux = folderApiService.getElements(objectId, applicationType, name, category).cache();
return gidService.convertFolderIdToObjectId(folderId).flatMap(optionalObjectId -> {
String objectId = optionalObjectId.orElse(null);
var flux = folderApiService.getElements(optionalObjectId.orElse(null), applicationType, name, category).cache();
var countMono = flux.count();
var flux1 = flux.skip((long) (pageNum - 1) * pageSize);
if (pageSize > 0) flux1 = flux1.take(pageSize);
Expand All @@ -89,8 +90,8 @@ public Mono<PageResponseView<?>> getElements(@RequestParam(value = "id", require
public Mono<ResponseView<Void>> move(@PathVariable("id") String applicationLikeId,
@RequestParam(value = "targetFolderId", required = false) String targetFolderId) {
return gidService.convertFolderIdToObjectId(targetFolderId).flatMap(objectId ->
folderApiService.move(applicationLikeId, objectId)
.then(businessEventPublisher.publishApplicationCommonEvent(applicationLikeId, objectId, APPLICATION_MOVE))
folderApiService.move(applicationLikeId, objectId.orElse(null))
.then(businessEventPublisher.publishApplicationCommonEvent(applicationLikeId, objectId.orElse(null), APPLICATION_MOVE))
.then(Mono.fromSupplier(() -> ResponseView.success(null))));
}

Expand All @@ -104,7 +105,7 @@ public Mono<ResponseView<Void>> updatePermission(@PathVariable String folderId,
}

return gidService.convertFolderIdToObjectId(folderId).flatMap(objectId ->
folderApiService.updatePermission(objectId, permissionId, role)
folderApiService.updatePermission(objectId.orElse(null), permissionId, role)
.then(Mono.fromSupplier(() -> ResponseView.success(null))));
}

Expand All @@ -113,7 +114,7 @@ public Mono<ResponseView<Void>> removePermission(
@PathVariable String folderId,
@PathVariable String permissionId) {
return gidService.convertFolderIdToObjectId(folderId).flatMap(objectId ->
folderApiService.removePermission(objectId, permissionId)
folderApiService.removePermission(objectId.orElse(null), permissionId)
.then(Mono.fromSupplier(() -> ResponseView.success(null))));
}

Expand All @@ -126,14 +127,14 @@ public Mono<ResponseView<Void>> grantPermission(
return ofError(INVALID_PARAMETER, "INVALID_PARAMETER", request.role());
}
return gidService.convertFolderIdToObjectId(folderId).flatMap(objectId ->
folderApiService.grantPermission(objectId, request.userIds(), request.groupIds(), role)
folderApiService.grantPermission(objectId.orElse(null), request.userIds(), request.groupIds(), role)
.then(Mono.fromSupplier(() -> ResponseView.success(null))));
}

@Override
public Mono<ResponseView<ApplicationPermissionView>> getApplicationPermissions(@PathVariable String folderId) {
return gidService.convertFolderIdToObjectId(folderId).flatMap(objectId ->
folderApiService.getPermissions(objectId)
folderApiService.getPermissions(objectId.orElse(null))
.map(ResponseView::success));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.Optional;

@Component
public class GidService {
@Autowired
Expand Down Expand Up @@ -72,11 +74,11 @@ public Mono<String> convertLibraryQueryIdToObjectId(String id) {
return Mono.just(id);
}

public Mono<String> convertFolderIdToObjectId(String id) {
public Mono<Optional<String>> convertFolderIdToObjectId(String id) {
if(FieldName.isGID(id)) {
return folderRepository.findByGid(id).next().mapNotNull(HasIdAndAuditing::getId);
return folderRepository.findByGid(id).next().mapNotNull(HasIdAndAuditing::getId).map(Optional::ofNullable).switchIfEmpty(Mono.just(Optional.empty()));
}
return Mono.just(id);
return Mono.just(Optional.ofNullable(id));
}

public Mono<String> convertBundleIdToObjectId(String id) {
Expand Down

0 comments on commit ebdc031

Please sign in to comment.