Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(#1115): multifile-input does not show files ins subfolders #1171

Merged
merged 8 commits into from
Jan 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import de.muenchen.oss.digiwf.connector.core.domain.BpmnError;
import jakarta.validation.Valid;

public interface CreateBpmnErrorInPort {

Expand All @@ -11,5 +12,5 @@ public interface CreateBpmnErrorInPort {
*
* @param bpmnError error parameters
*/
void createBpmnError(BpmnError bpmnError);
void createBpmnError(@Valid BpmnError bpmnError);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@

public List<String> getFileNames(final String filePath, final String fileContext, final Optional<String> documentStorageUrl) {
try {
final String pathToFolder = fileContext + "/" + filePath;

Check warning on line 43 in digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java

View check run for this annotation

Codecov / codecov/patch

digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java#L43

Added line #L43 was not covered by tests
if (documentStorageUrl.isPresent()) {
return this.removeFolderFromPaths(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(fileContext + "/" + filePath, documentStorageUrl.get()).block());
return this.extractFilenamesFromFolder(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, documentStorageUrl.get()).block(), pathToFolder);

Check warning on line 45 in digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java

View check run for this annotation

Codecov / codecov/patch

digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java#L45

Added line #L45 was not covered by tests
}
return this.removeFolderFromPaths(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(fileContext + "/" + filePath).block());
return this.extractFilenamesFromFolder(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder).block(), pathToFolder);

Check warning on line 47 in digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java

View check run for this annotation

Codecov / codecov/patch

digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java#L47

Added line #L47 was not covered by tests
} catch (final Exception ex) {
log.error("Getting all files of folder {} failed: {}", filePath, ex);
throw new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Getting all files of folder %s failed", filePath));
Expand All @@ -70,10 +71,20 @@

//---------------------------------------- helper methods ---------------------------------------- //

private List<String> removeFolderFromPaths(final Set<String> fileList) {
/**
* Extract the filenames from the given file list. Make sure that only filenames for files in the given folder are returned.
* Don't return filenames for files in subfolders.
*
* @param fileList
* @param pathToFolder
* @return
*/
private List<String> extractFilenamesFromFolder(final Set<String> fileList, final String pathToFolder) {
final String basePath = (pathToFolder + "/").replace("//", "/");

Check warning on line 83 in digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java

View check run for this annotation

Codecov / codecov/patch

digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java#L83

Added line #L83 was not covered by tests
return fileList.stream()
.map(file -> file.substring(file.lastIndexOf("/") + 1))
.collect(Collectors.toList());
.map(file -> file = file.replace(basePath, ""))

Check warning on line 85 in digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java

View check run for this annotation

Codecov / codecov/patch

digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java#L85

Added line #L85 was not covered by tests
.filter(file -> !file.contains("/"))
.toList();

Check warning on line 87 in digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java

View check run for this annotation

Codecov / codecov/patch

digiwf-engine/digiwf-engine-service/src/main/java/de/muenchen/oss/digiwf/shared/file/AbstractFileService.java#L87

Added line #L87 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
{
"key": "app_instance_file_paths_readonly",
"value": "zulassungsbescheinigung_i_fahrzeugschein/assistants"
"value": "zulassungsbescheinigung_i_fahrzeugschein"
},
{
"key": "app_instance_file_paths",
"value": "zulassungsbescheinigung_i_fahrzeugschein/assistants"
"value": "zulassungsbescheinigung_i_fahrzeugschein"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@
}
},
"key": "zulassungsbescheinigung_i_fahrzeugschein",
"uuidEnabled": false,
"filePath": "zulassungsbescheinigung_i_fahrzeugschein/assistants",
"uuidEnabled": true,
"filePath": "zulassungsbescheinigung_i_fahrzeugschein",
"x-options": {
"fieldColProps": {
"cols": 12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<bpmn:userTask id="Activity_0ojk6tw" name="Check Vars" camunda:candidateGroups="group1">
<bpmn:extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="app_file_paths_readonly">zulassungsbescheinigung_i_fahrzeugschein/assistants</camunda:inputParameter>
<camunda:inputParameter name="app_file_paths">zulassungsbescheinigung_i_fahrzeugschein/assistants</camunda:inputParameter>
<camunda:inputParameter name="app_file_paths_readonly">zulassungsbescheinigung_i_fahrzeugschein</camunda:inputParameter>
<camunda:inputParameter name="app_file_paths">zulassungsbescheinigung_i_fahrzeugschein</camunda:inputParameter>
<camunda:inputParameter name="app_task_schema_key">formserver_example_parkausweis_form</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import org.springframework.web.client.HttpServerErrorException;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;


@Slf4j
@Component
Expand Down Expand Up @@ -51,9 +50,9 @@ public List<String> getFileNames(@NonNull final String taskId, @NonNull final St
String documentStorageUrl = this.fileConfig.processSyncConfig;
String pathToFolder = fileContext + "/" + filePath;
if (documentStorageUrl != null) {
return this.removeFolderFromPaths(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, documentStorageUrl).block());
return this.extractFilenamesFromFolder(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder, documentStorageUrl).block(), pathToFolder);
}
return this.removeFolderFromPaths(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder).block());
return this.extractFilenamesFromFolder(this.documentStorageFolderRepository.getAllFilesInFolderRecursively(pathToFolder).block(), pathToFolder);
} catch (final Exception ex) {
log.error("Getting all files of folder {} failed", filePath, ex);
throw new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Getting all files of folder %s failed", filePath));
Expand Down Expand Up @@ -83,10 +82,20 @@ public String getPresignedUrl(final PresignedUrlAction action, @NonNull final St
return presignedUrlPort.getPresignedUrl(pathToFile, 5, action);
}

private List<String> removeFolderFromPaths(final Set<String> fileList) {
/**
* Extract the filenames from the given file list. Make sure that only filenames for files in the given folder are returned.
* Don't return filenames for files in subfolders.
*
* @param fileList
* @param pathToFolder
* @return
*/
private List<String> extractFilenamesFromFolder(final Set<String> fileList, final String pathToFolder) {
final String basePath = (pathToFolder + "/").replace("//", "/");
return fileList.stream()
.map(file -> file.substring(file.lastIndexOf("/") + 1))
.collect(Collectors.toList());
.map(file -> file = file.replace(basePath, ""))
.filter(file -> !file.contains("/"))
.toList();
}

private void initializeFileConfig(String taskId) {
Expand Down
Loading
Loading