Skip to content

Commit

Permalink
Feature/1442 move duplicate s3 logic to client libs (#1684)
Browse files Browse the repository at this point in the history
* 1442 refactor file type validation

* 1442 refactor file type validation

* 1442 fix S3FileTransferRepositoryTest

* 1442 return of extensions without dot, fix unittests

* 1442 config document-storage-url

* 1442 adjust properties for S3 client configuration

* 1442 domain specific s3 storage can be used in dms integration service

* 1442 fix task service itests

* 1442 fix s3 adapter test for ticket integration

* 1442 S3 domain specific url for dms; refactoring engine + tasklist

* 1442 refactor properties, beautifications

* remove temporary example

* 1442 fix s3 security configuration

* 1442 remove redundant import

* #1442: fix ticket integration
  • Loading branch information
markostreich authored Jun 6, 2024
1 parent bdbb10c commit a97a066
Show file tree
Hide file tree
Showing 85 changed files with 1,252 additions and 1,069 deletions.
2 changes: 0 additions & 2 deletions digiwf-apps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Vorgang {
* Art des Vortgangs.
* Default ist ELEKTRONISCH
*/
@Builder.Default
private VorgangArt art = VorgangArt.ELEKTRONISCH;

public Vorgang(final NeuerVorgang neuerVorgang, final String coo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ProcessConfig {
* Example: "[email protected],[email protected]"
*/
public static final String INCIDENT_NOTIFICATION_ADDRESSES = "app_incident_notification_addresses";
public static final String APP_FILE_S3_SYNC_CONFIG = "app_file_s3_sync_config";

/**
* key of the process config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package de.muenchen.oss.digiwf.process.definition.api.resource;

import de.muenchen.oss.digiwf.process.definition.domain.service.ServiceStartFileService;
import de.muenchen.oss.digiwf.s3.integration.client.exception.PropertyNotSetException;
import de.muenchen.oss.digiwf.shared.file.presignedUrlAdapters.PresignedUrlAction;
import de.muenchen.oss.digiwf.shared.security.AppAuthenticationProvider;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -39,12 +40,12 @@ public class ServiceStartFileRestController {
* @return file names
*/
@GetMapping("/{definitionKey}")
public ResponseEntity<List<String>> getFileNames(@PathVariable final String definitionKey, @RequestParam final String filePath) {
public ResponseEntity<List<String>> getFileNames(@PathVariable final String definitionKey, @RequestParam final String filePath)
throws PropertyNotSetException {
final List<String> fileNames = this.serviceStartFileService.getFileNames(
definitionKey,
filePath,
this.authenticationProvider.getCurrentUserId(),
this.authenticationProvider.getCurrentUserGroups());
this.authenticationProvider.getCurrentUserId());
return ResponseEntity.ok(fileNames);
}

Expand All @@ -57,14 +58,14 @@ public ResponseEntity<List<String>> getFileNames(@PathVariable final String defi
* @return presignedUrl
*/
@GetMapping("/{definitionKey}/{fileName}")
public ResponseEntity<String> getPresignedUrlForFileDownload(@PathVariable final String definitionKey, @PathVariable final String fileName, @RequestParam final String filePath) {
public ResponseEntity<String> getPresignedUrlForFileDownload(@PathVariable final String definitionKey, @PathVariable final String fileName, @RequestParam final String filePath)
throws PropertyNotSetException {
final String presignedUrl = this.serviceStartFileService.getPresignedUrl(
PresignedUrlAction.GET,
definitionKey,
filePath,
fileName,
this.authenticationProvider.getCurrentUserId(),
this.authenticationProvider.getCurrentUserGroups());
this.authenticationProvider.getCurrentUserId());
return ResponseEntity.ok(presignedUrl);
}

Expand All @@ -77,14 +78,14 @@ public ResponseEntity<String> getPresignedUrlForFileDownload(@PathVariable final
* @return presignedUrl
*/
@PostMapping("/{definitionKey}/{filename}")
public ResponseEntity<String> getPresignedUrlForFileUpload(@PathVariable final String definitionKey, @PathVariable final String filename, @RequestParam final String filePath) {
public ResponseEntity<String> getPresignedUrlForFileUpload(@PathVariable final String definitionKey, @PathVariable final String filename, @RequestParam final String filePath)
throws PropertyNotSetException {
final String presignedUrls = this.serviceStartFileService.getPresignedUrl(
PresignedUrlAction.POST,
definitionKey,
filePath,
filename,
this.authenticationProvider.getCurrentUserId(),
this.authenticationProvider.getCurrentUserGroups());
this.authenticationProvider.getCurrentUserId());
return ResponseEntity.ok(presignedUrls);
}

Expand All @@ -98,14 +99,14 @@ public ResponseEntity<String> getPresignedUrlForFileUpload(@PathVariable final S
*/
//TODO I guess this should be only one url?
@DeleteMapping("/{definitionKey}/{filename}")
public ResponseEntity<String> getPresignedUrlForFileDeletion(@PathVariable final String definitionKey, @PathVariable final String filename, @RequestParam final String filePath) {
public ResponseEntity<String> getPresignedUrlForFileDeletion(@PathVariable final String definitionKey, @PathVariable final String filename, @RequestParam final String filePath)
throws PropertyNotSetException {
final String presignedUrl = this.serviceStartFileService.getPresignedUrl(
PresignedUrlAction.DELETE,
definitionKey,
filePath,
filename,
this.authenticationProvider.getCurrentUserId(),
this.authenticationProvider.getCurrentUserGroups());
this.authenticationProvider.getCurrentUserId());
return ResponseEntity.ok(presignedUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import de.muenchen.oss.digiwf.process.config.domain.model.ProcessConfig;
import de.muenchen.oss.digiwf.process.config.domain.service.ProcessConfigService;
import de.muenchen.oss.digiwf.process.config.process.ProcessConfigFunctions;
import de.muenchen.oss.digiwf.process.definition.domain.model.StartContext;
import de.muenchen.oss.digiwf.s3.integration.client.exception.PropertyNotSetException;
import de.muenchen.oss.digiwf.s3.integration.client.repository.DocumentStorageFolderRepository;
import de.muenchen.oss.digiwf.s3.integration.client.service.S3StorageUrlProvider;
import de.muenchen.oss.digiwf.shared.exception.IllegalResourceAccessException;
import de.muenchen.oss.digiwf.shared.exception.NoFileContextException;
import de.muenchen.oss.digiwf.shared.file.AbstractFileService;
Expand All @@ -34,34 +35,38 @@ public class ServiceStartFileService extends AbstractFileService {

private final ServiceStartContextService serviceStartContextService;
private final ProcessConfigService processConfigService;
private final S3StorageUrlProvider s3StorageUrlProvider;

public ServiceStartFileService(
final DocumentStorageFolderRepository documentStorageFolderRepository,
final ServiceStartContextService serviceStartContextService,
final ProcessConfigService processConfigService,
final List<PresignedUrlAdapter> presignedUrlAdapters,
final ProcessConfigFunctions processConfigFunctions
final S3StorageUrlProvider s3StorageUrlProvider
) {
super(documentStorageFolderRepository, presignedUrlAdapters, processConfigFunctions);
super(documentStorageFolderRepository, presignedUrlAdapters);
this.serviceStartContextService = serviceStartContextService;
this.processConfigService = processConfigService;
this.s3StorageUrlProvider = s3StorageUrlProvider;
}

public List<String> getFileNames(final String definitionKey, final String filePath, final String userId, final List<String> groups) {
@Override
public List<String> getFileNames(final String definitionKey, final String filePath, final String userId) throws PropertyNotSetException {
this.checkReadAccess(definitionKey, filePath);
final String fileContext = this.getFileContext(userId, definitionKey);
return super.getFileNames(filePath, fileContext, this.getDocumentStorageUrl(definitionKey));
return super.getFileNames(filePath, fileContext, this.s3StorageUrlProvider.provideS3StorageUrl(definitionKey));
}

public String getPresignedUrl(final PresignedUrlAction action, final String definitionKey, final String filePath, final String fileName, final String userId, final List<String> groups) {
public String getPresignedUrl(final PresignedUrlAction action, final String definitionKey, final String filePath, final String fileName,
final String userId) throws PropertyNotSetException {
if (action.equals(PresignedUrlAction.GET)) {
this.checkReadAccess(definitionKey, filePath);
} else {
this.checkWriteAccess(definitionKey, filePath);
}

final String fileContext = this.getFileContext(userId, definitionKey);
return super.getPresignedUrl(action, fileContext + "/" + filePath + "/" + fileName, this.getDocumentStorageUrl(definitionKey));
return super.getPresignedUrl(action, fileContext + "/" + filePath + "/" + fileName, this.s3StorageUrlProvider.provideS3StorageUrl(definitionKey));
}

//---------------------------------------- helper methods ---------------------------------------- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package de.muenchen.oss.digiwf.process.instance.api.resource;

import de.muenchen.oss.digiwf.process.instance.domain.service.ServiceInstanceFileService;
import de.muenchen.oss.digiwf.s3.integration.client.exception.PropertyNotSetException;
import de.muenchen.oss.digiwf.shared.file.presignedUrlAdapters.PresignedUrlAction;
import de.muenchen.oss.digiwf.shared.security.AppAuthenticationProvider;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -39,7 +40,8 @@ public class ServiceInstanceFileRestController {
* @return file names
*/
@GetMapping("/{instanceId}")
public ResponseEntity<List<String>> getFileNames(@PathVariable final String instanceId, @RequestParam final String filePath) {
public ResponseEntity<List<String>> getFileNames(@PathVariable final String instanceId, @RequestParam final String filePath)
throws PropertyNotSetException {
final List<String> fileNames = this.serviceInstanceFileService.getFileNames(
instanceId,
filePath,
Expand All @@ -56,7 +58,8 @@ public ResponseEntity<List<String>> getFileNames(@PathVariable final String inst
* @return presignedUrl
*/
@GetMapping("/{instanceId}/{fileName}")
public ResponseEntity<String> getPresignedUrlForFileDownload(@PathVariable final String instanceId, @PathVariable final String fileName, @RequestParam final String filePath) {
public ResponseEntity<String> getPresignedUrlForFileDownload(@PathVariable final String instanceId, @PathVariable final String fileName, @RequestParam final String filePath)
throws PropertyNotSetException {
final String presignedUrl = this.serviceInstanceFileService.getPresignedUrl(
PresignedUrlAction.GET,
instanceId,
Expand All @@ -75,7 +78,8 @@ public ResponseEntity<String> getPresignedUrlForFileDownload(@PathVariable final
* @return presignedUrl
*/
@PostMapping("/{instanceId}/{filename}")
public ResponseEntity<String> getPresignedUrlForFileUpload(@PathVariable final String instanceId, @PathVariable final String filename, @RequestParam final String filePath) {
public ResponseEntity<String> getPresignedUrlForFileUpload(@PathVariable final String instanceId, @PathVariable final String filename, @RequestParam final String filePath)
throws PropertyNotSetException {
final String presignedUrls = this.serviceInstanceFileService.getPresignedUrl(
PresignedUrlAction.POST,
instanceId,
Expand All @@ -94,7 +98,8 @@ public ResponseEntity<String> getPresignedUrlForFileUpload(@PathVariable final S
* @return presignedUrl
*/
@DeleteMapping("/{instanceId}/{filename}")
public ResponseEntity<String> getPresignedUrlForFileDeletion(@PathVariable final String instanceId, @PathVariable final String filename, @RequestParam final String filePath) {
public ResponseEntity<String> getPresignedUrlForFileDeletion(@PathVariable final String instanceId, @PathVariable final String filename, @RequestParam final String filePath)
throws PropertyNotSetException {
final String presignedUrl = this.serviceInstanceFileService.getPresignedUrl(
PresignedUrlAction.DELETE,
instanceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import de.muenchen.oss.digiwf.process.config.domain.service.ProcessConfigService;
import de.muenchen.oss.digiwf.process.config.process.ProcessConfigFunctions;
import de.muenchen.oss.digiwf.process.instance.domain.model.ServiceInstance;
import de.muenchen.oss.digiwf.s3.integration.client.exception.PropertyNotSetException;
import de.muenchen.oss.digiwf.s3.integration.client.repository.DocumentStorageFolderRepository;
import de.muenchen.oss.digiwf.s3.integration.client.service.S3StorageUrlProvider;
import de.muenchen.oss.digiwf.shared.exception.IllegalResourceAccessException;
import de.muenchen.oss.digiwf.shared.file.AbstractFileService;
import de.muenchen.oss.digiwf.shared.file.presignedUrlAdapters.PresignedUrlAction;
Expand All @@ -34,6 +36,7 @@ public class ServiceInstanceFileService extends AbstractFileService {
private final ServiceInstanceService serviceInstanceService;
private final ServiceInstanceDataService serviceInstanceDataService;
private final ServiceInstanceAuthService serviceInstanceAuthService;
private final S3StorageUrlProvider s3StorageUrlProvider;

public ServiceInstanceFileService(
final DocumentStorageFolderRepository documentStorageFolderRepository,
Expand All @@ -42,16 +45,17 @@ public ServiceInstanceFileService(
final ServiceInstanceDataService serviceInstanceDataService,
final ServiceInstanceAuthService serviceInstanceAuthService,
final ProcessConfigService processConfigService,
final ProcessConfigFunctions processConfigFunctions
final S3StorageUrlProvider s3StorageUrlProvider
) {
super(documentStorageFolderRepository, presignedUrlAdapters, processConfigFunctions);
super(documentStorageFolderRepository, presignedUrlAdapters);
this.serviceInstanceService = serviceInstanceService;
this.processConfigService = processConfigService;
this.serviceInstanceDataService = serviceInstanceDataService;
this.serviceInstanceAuthService = serviceInstanceAuthService;
this.s3StorageUrlProvider = s3StorageUrlProvider;
}

public List<String> getFileNames(final String infoId, final String filePath, final String userId) {
public List<String> getFileNames(final String infoId, final String filePath, final String userId) throws PropertyNotSetException {
final ServiceInstance processInstance = this.getProcessInstanceId(infoId);
final String processInstanceId = processInstance.getInstanceId();
if (!this.serviceInstanceAuthService.hasAccess(processInstanceId, userId)) {
Expand All @@ -60,10 +64,11 @@ public List<String> getFileNames(final String infoId, final String filePath, fin

this.checkReadAccess(processInstanceId, filePath);
final String fileContext = this.getFileContext(processInstanceId);
return super.getFileNames(filePath, fileContext, this.getDocumentStorageUrl(processInstance.getDefinitionKey()));
return super.getFileNames(filePath, fileContext, s3StorageUrlProvider.provideS3StorageUrl(processInstance.getDefinitionKey()));
}

public String getPresignedUrl(final PresignedUrlAction action, final String infoId, final String filePath, final String fileName, final String userId) {
public String getPresignedUrl(final PresignedUrlAction action, final String infoId, final String filePath, final String fileName, final String userId)
throws PropertyNotSetException {
final ServiceInstance processInstance = this.getProcessInstanceId(infoId);
final String processInstanceId = processInstance.getInstanceId();
if (!this.serviceInstanceAuthService.hasAccess(processInstanceId, userId)) {
Expand All @@ -77,7 +82,7 @@ public String getPresignedUrl(final PresignedUrlAction action, final String info
}

final String fileContext = this.getFileContext(processInstanceId);
return super.getPresignedUrl(action, fileContext + "/" + filePath + "/" + fileName, this.getDocumentStorageUrl(processInstance.getDefinitionKey()));
return super.getPresignedUrl(action, fileContext + "/" + filePath + "/" + fileName, this.s3StorageUrlProvider.provideS3StorageUrl(processInstance.getDefinitionKey()));
}

//---------------------------------------- helper methods ---------------------------------------- //
Expand Down
Loading

0 comments on commit a97a066

Please sign in to comment.