Merge branch 'RED-6686-2' into 'master'
Resolve RED-6686 "2" Closes RED-6686 See merge request redactmanager/persistence-service!33
This commit is contained in:
commit
1157ed353e
@ -1,22 +1,40 @@
|
|||||||
package com.iqser.red.service.persistence.management.v1.processor.migration;
|
package com.iqser.red.service.persistence.management.v1.processor.migration;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.acl.custom.initializer.ACLInitializer;
|
import com.iqser.red.service.persistence.management.v1.processor.acl.custom.initializer.ACLInitializer;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.job.AutomaticAnalysisJob;
|
import com.iqser.red.service.persistence.management.v1.processor.service.job.AutomaticAnalysisJob;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.mulitenancy.DevDataProvider;
|
||||||
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
|
import com.knecon.fforesight.tenantcommons.model.UpdateDetailsRequest;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class AsyncMigrationStarterService {
|
public class AsyncMigrationStarterService {
|
||||||
|
|
||||||
private final AutomaticAnalysisJob automaticAnalysisJob;
|
private final AutomaticAnalysisJob automaticAnalysisJob;
|
||||||
private final MigrationStarterService migrationStarterService;
|
private final MigrationStarterService migrationStarterService;
|
||||||
private final ACLInitializer aclInitializer;
|
private final ACLInitializer aclInitializer;
|
||||||
|
private final TenantProvider tenantProvider;
|
||||||
|
private final DevDataProvider devDataProvider;
|
||||||
|
|
||||||
|
|
||||||
|
public AsyncMigrationStarterService(AutomaticAnalysisJob automaticAnalysisJob,
|
||||||
|
MigrationStarterService migrationStarterService,
|
||||||
|
ACLInitializer aclInitializer,
|
||||||
|
TenantProvider tenantProvider,
|
||||||
|
@Autowired(required = false) DevDataProvider devDataProvider) {
|
||||||
|
|
||||||
|
this.automaticAnalysisJob = automaticAnalysisJob;
|
||||||
|
this.migrationStarterService = migrationStarterService;
|
||||||
|
this.aclInitializer = aclInitializer;
|
||||||
|
this.tenantProvider = tenantProvider;
|
||||||
|
this.devDataProvider = devDataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@ -27,6 +45,13 @@ public class AsyncMigrationStarterService {
|
|||||||
migrationStarterService.runForTenant(tenantId);
|
migrationStarterService.runForTenant(tenantId);
|
||||||
aclInitializer.run();
|
aclInitializer.run();
|
||||||
automaticAnalysisJob.setSchedulingStopped(false);
|
automaticAnalysisJob.setSchedulingStopped(false);
|
||||||
|
|
||||||
|
tenantProvider.updateDetails(tenantId, UpdateDetailsRequest.builder().key("persistence-service-ready").value(true).build());
|
||||||
|
|
||||||
|
if (devDataProvider != null) {
|
||||||
|
devDataProvider.importDossierTemplatesToTenant(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
automaticAnalysisJob.setSchedulingStopped(false);
|
automaticAnalysisJob.setSchedulingStopped(false);
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.MigrationPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.MigrationPersistenceService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.settings.FileManagementServiceSettings;
|
import com.iqser.red.service.persistence.management.v1.processor.settings.FileManagementServiceSettings;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUtils;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
|
|
||||||
@ -29,11 +30,15 @@ public class MigrationStarterService {
|
|||||||
private final TenantProvider tenantProvider;
|
private final TenantProvider tenantProvider;
|
||||||
|
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void migrate() {
|
public void migrate() {
|
||||||
|
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
|
|
||||||
|
if (!TenantUtils.isTenantReadyForPersistence(tenant)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TenantContext.setTenantId(tenant.getTenantId());
|
TenantContext.setTenantId(tenant.getTenantId());
|
||||||
|
|
||||||
//This is always running on startup
|
//This is always running on startup
|
||||||
@ -45,6 +50,10 @@ public class MigrationStarterService {
|
|||||||
|
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
|
|
||||||
|
if (!TenantUtils.isTenantReadyForPersistence(tenant)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
runForTenant(tenant.getTenantId());
|
runForTenant(tenant.getTenantId());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import com.iqser.red.service.persistence.management.v1.processor.acl.custom.doss
|
|||||||
import com.iqser.red.service.persistence.management.v1.processor.client.tenantusermanagementservice.UsersClient;
|
import com.iqser.red.service.persistence.management.v1.processor.client.tenantusermanagementservice.UsersClient;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.users.model.User;
|
import com.iqser.red.service.persistence.management.v1.processor.service.users.model.User;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.users.UserService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.users.UserService;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUtils;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
|
|
||||||
@ -30,6 +31,10 @@ public class KeyCloakUserSyncService {
|
|||||||
public void syncUsersWithKC() {
|
public void syncUsersWithKC() {
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
|
|
||||||
|
if(!TenantUtils.isTenantReadyForPersistence(tenant)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TenantContext.setTenantId(tenant.getTenantId());
|
TenantContext.setTenantId(tenant.getTenantId());
|
||||||
|
|
||||||
var allUsers = usersClient.getAllUsers(true);
|
var allUsers = usersClient.getAllUsers(true);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration;
|
import com.iqser.red.service.persistence.management.v1.processor.configuration.MessagingConfiguration;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.settings.FileManagementServiceSettings;
|
import com.iqser.red.service.persistence.management.v1.processor.settings.FileManagementServiceSettings;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUtils;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
@ -43,7 +44,10 @@ public class AutomaticAnalysisJob implements Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
tenantProvider.updateDetails(tenant.getTenantId(), UpdateDetailsRequest.builder().key("persistence-service-ready").value(true).build());
|
|
||||||
|
if(!TenantUtils.isTenantReadyForPersistence(tenant)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TenantContext.setTenantId(tenant.getTenantId());
|
TenantContext.setTenantId(tenant.getTenantId());
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import com.iqser.red.service.persistence.management.v1.processor.service.Applica
|
|||||||
import com.iqser.red.service.persistence.management.v1.processor.service.DossierService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.DossierService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.FileService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.FileService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUtils;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
|
|
||||||
@ -35,6 +36,10 @@ public class DeletedFilesCleanupJob implements Job {
|
|||||||
|
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
|
|
||||||
|
if(!TenantUtils.isTenantReadyForPersistence(tenant)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TenantContext.setTenantId(tenant.getTenantId());
|
TenantContext.setTenantId(tenant.getTenantId());
|
||||||
|
|
||||||
var now = OffsetDateTime.now();
|
var now = OffsetDateTime.now();
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.iqser.red.service.persistence.management.v1.processor.entity.download.DownloadStatusEntity;
|
import com.iqser.red.service.persistence.management.v1.processor.entity.download.DownloadStatusEntity;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.ApplicationConfigService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.ApplicationConfigService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DownloadStatusPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DownloadStatusPersistenceService;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUtils;
|
||||||
import com.iqser.red.storage.commons.service.StorageService;
|
import com.iqser.red.storage.commons.service.StorageService;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
@ -34,6 +35,10 @@ public class DownloadCleanupJob implements Job {
|
|||||||
|
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
|
|
||||||
|
if(!TenantUtils.isTenantReadyForPersistence(tenant)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TenantContext.setTenantId(tenant.getTenantId());
|
TenantContext.setTenantId(tenant.getTenantId());
|
||||||
|
|
||||||
var now = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS);
|
var now = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationEmailService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationEmailService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationPersistenceService;
|
||||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationPreferencesPersistenceService;
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationPreferencesPersistenceService;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.utils.TenantUtils;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.notification.EmailNotificationType;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.notification.EmailNotificationType;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||||
@ -34,6 +35,10 @@ public class SendNotificationEmailJob implements Job {
|
|||||||
|
|
||||||
tenantProvider.getTenants().forEach(tenant -> {
|
tenantProvider.getTenants().forEach(tenant -> {
|
||||||
|
|
||||||
|
if(!TenantUtils.isTenantReadyForPersistence(tenant)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TenantContext.setTenantId(tenant.getTenantId());
|
TenantContext.setTenantId(tenant.getTenantId());
|
||||||
|
|
||||||
var allConfiguredPreferences = notificationPreferencesPersistenceService.findAll();
|
var allConfiguredPreferences = notificationPreferencesPersistenceService.findAll();
|
||||||
|
|||||||
@ -20,32 +20,30 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
|
|||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.importexport.ImportDossierTemplateRequest;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.importexport.ImportDossierTemplateRequest;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class DevDataProvider {
|
public class DevDataProvider {
|
||||||
|
|
||||||
@Autowired
|
private final DossierTemplateImportService dossierTemplateImportService;
|
||||||
private AsyncMigrationStarterService asyncMigrationStarterService;
|
|
||||||
|
private final DossierTemplateRepository dossierTemplateRepository;
|
||||||
|
|
||||||
|
|
||||||
public void importDossierTemplatesToTenant(String tenantId){
|
public void importDossierTemplatesToTenant(String tenantId) {
|
||||||
|
|
||||||
TenantContext.setTenantId(tenantId);
|
TenantContext.setTenantId(tenantId);
|
||||||
asyncMigrationStarterService.runForTenant(tenantId);
|
if (dossierTemplateRepository.count() == 0) {
|
||||||
if(dossierTemplateRepository.count() == 0) {
|
|
||||||
executeImport();
|
executeImport();
|
||||||
}
|
}
|
||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DossierTemplateImportService dossierTemplateImportService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DossierTemplateRepository dossierTemplateRepository;
|
|
||||||
|
|
||||||
public byte[] pack(String sourceDirPath) throws IOException {
|
public byte[] pack(String sourceDirPath) throws IOException {
|
||||||
|
|
||||||
@ -71,14 +69,14 @@ public class DevDataProvider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void executeImport() {
|
private void executeImport() {
|
||||||
|
|
||||||
var importDir = new File("/Users/timobejan/work/dossier-templates-v2/dev");
|
var importDir = new File("/Users/timobejan/work/dossier-templates-v2/dev");
|
||||||
|
|
||||||
|
|
||||||
for (var file : importDir.listFiles()) {
|
for (var file : importDir.listFiles()) {
|
||||||
if(file.isDirectory()){
|
if (file.isDirectory()) {
|
||||||
var archive = pack(file.getAbsolutePath());
|
var archive = pack(file.getAbsolutePath());
|
||||||
log.info("Importing file: " + file.getName() + " " + " with size: " + archive.length);
|
log.info("Importing file: " + file.getName() + " " + " with size: " + archive.length);
|
||||||
var request = new ImportDossierTemplateRequest();
|
var request = new ImportDossierTemplateRequest();
|
||||||
@ -89,4 +87,5 @@ public class DevDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,21 +59,18 @@ public class TenantManagementService {
|
|||||||
private final AsyncMigrationStarterService asyncMigrationStarterService;
|
private final AsyncMigrationStarterService asyncMigrationStarterService;
|
||||||
private final TenantProvider tenantProvider;
|
private final TenantProvider tenantProvider;
|
||||||
private final EncryptionDecryptionService encryptionDecryptionService;
|
private final EncryptionDecryptionService encryptionDecryptionService;
|
||||||
private final DevDataProvider devDataProvider;
|
|
||||||
|
|
||||||
public TenantManagementService(@Qualifier("tenantLiquibaseProperties") LiquibaseProperties liquibaseProperties,
|
public TenantManagementService(@Qualifier("tenantLiquibaseProperties") LiquibaseProperties liquibaseProperties,
|
||||||
ResourceLoader resourceLoader,
|
ResourceLoader resourceLoader,
|
||||||
EncryptionDecryptionService encryptionDecryptionService,
|
EncryptionDecryptionService encryptionDecryptionService,
|
||||||
AsyncMigrationStarterService asyncMigrationStarterService,
|
AsyncMigrationStarterService asyncMigrationStarterService,
|
||||||
TenantProvider tenantProvider,
|
TenantProvider tenantProvider){
|
||||||
@Autowired(required = false) DevDataProvider devDataProvider){
|
|
||||||
|
|
||||||
this.liquibaseProperties = liquibaseProperties;
|
this.liquibaseProperties = liquibaseProperties;
|
||||||
this.resourceLoader = resourceLoader;
|
this.resourceLoader = resourceLoader;
|
||||||
this.encryptionDecryptionService = encryptionDecryptionService;
|
this.encryptionDecryptionService = encryptionDecryptionService;
|
||||||
this.asyncMigrationStarterService = asyncMigrationStarterService;
|
this.asyncMigrationStarterService = asyncMigrationStarterService;
|
||||||
this.tenantProvider = tenantProvider;
|
this.tenantProvider = tenantProvider;
|
||||||
this.devDataProvider = devDataProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,13 +95,6 @@ public class TenantManagementService {
|
|||||||
|
|
||||||
asyncMigrationStarterService.runForTenant(tenantRequest.getTenantId());
|
asyncMigrationStarterService.runForTenant(tenantRequest.getTenantId());
|
||||||
|
|
||||||
tenantProvider.updateDetails(tenantRequest.getTenantId(), UpdateDetailsRequest.builder().key("persistence-service-ready").value(true).build());
|
|
||||||
|
|
||||||
if(devDataProvider!=null) {
|
|
||||||
devDataProvider.importDossierTemplatesToTenant(tenantRequest.getTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.iqser.red.service.persistence.management.v1.processor.utils;
|
||||||
|
|
||||||
|
import com.knecon.fforesight.tenantcommons.model.TenantResponse;
|
||||||
|
|
||||||
|
public class TenantUtils {
|
||||||
|
|
||||||
|
public static boolean isTenantReadyForPersistence(TenantResponse tenantResponse){
|
||||||
|
return tenantResponse.getDetails()!=null &&
|
||||||
|
tenantResponse.getDetails().getOrDefault("persistence-service-ready",false).equals(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user