RED-9888 && RED-9891

This commit is contained in:
Maverick Studer 2024-08-19 16:46:14 +02:00
parent ef98112871
commit 4beb6e0647
12 changed files with 89 additions and 29 deletions

View File

@ -145,7 +145,7 @@ public class StorageToMongoCopyService {
});
if (file.softDeleted != null) {
componentLogService.softDeleteAllOverrides(file.dossierId(), file.fileId());
componentLogService.softDeleteAllOverrides(file.dossierId(), file.fileId(), file.softDeleted);
}
fileManagementStorageService.deleteObject(file.dossierId(), file.fileId(), FileType.COMPONENTS);

View File

@ -49,12 +49,17 @@ public class ComponentDefinitionService {
List<ComponentDefinitionEntity> componentEntities = new ArrayList<>();
componentDefinitionAddRequests.forEach(componentDefinitionAddRequest -> {
Optional<String> optionalIdOfSoftDeleted = componentDefinitionPersistenceService.findIdByTechnicalNameAndSoftDeleted(componentDefinitionAddRequest.getTechnicalName());
Optional<String> optionalIdOfSoftDeleted = componentDefinitionPersistenceService.findIdByDossierTemplateIdAndTechnicalNameAndIsSoftDeleted(dossierTemplateId,
componentDefinitionAddRequest.getTechnicalName());
ComponentDefinitionEntity entity;
if (optionalIdOfSoftDeleted.isEmpty()) {
entity = componentDefinitionPersistenceService.insert(componentDefinitionAddRequest, dossierTemplateId);
} else {
int rank = componentDefinitionPersistenceService.maxRankByDossierTemplateId(dossierTemplateId) + 1;
entity = componentDefinitionPersistenceService.restoreComponent(dossierTemplateId, optionalIdOfSoftDeleted.get());
entity.setDescription(componentDefinitionAddRequest.getDescription());
entity.setRank(rank);
entity = componentDefinitionPersistenceService.update(entity);
}
componentEntities.add(entity);
});
@ -149,7 +154,7 @@ public class ComponentDefinitionService {
validateDossierTemplateExists(dossierTemplateId);
List<ComponentDefinitionEntity> componentDefinitionEntities = componentDefinitionPersistenceService.restoreComponents(dossierTemplateId, componentIds);
int rank = componentDefinitionPersistenceService.countByDossierTemplateId(dossierTemplateId);
int rank = componentDefinitionPersistenceService.maxRankByDossierTemplateId(dossierTemplateId);
for (ComponentDefinitionEntity componentDefinitionEntity : componentDefinitionEntities) {
componentDefinitionEntity.setRank(++rank);
componentDefinitionPersistenceService.update(componentDefinitionEntity);

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.persistence.management.v1.processor.service;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
@ -187,9 +188,9 @@ public class ComponentLogService {
}
public void softDeleteAllOverrides(String dossierId, String fileId) {
public void softDeleteAllOverrides(String dossierId, String fileId, OffsetDateTime softDeletedTime) {
componentLogMongoService.softDeleteComponentLogEntries(dossierId, fileId);
componentLogMongoService.softDeleteComponentLogEntries(dossierId, fileId, softDeletedTime);
}

View File

@ -57,7 +57,7 @@ public class FileDeletionService {
resizeRedactionPersistenceService.undeleteByFileId(fileId, softDeletedTime);
//revert override deletion
componentLogMongoService.undeleteComponentLogEntries(dossierId, fileId);
componentLogMongoService.undeleteComponentLogEntries(dossierId, fileId, softDeletedTime);
fileStatusPersistenceService.undelete(fileId);
}
@ -81,7 +81,7 @@ public class FileDeletionService {
viewedPagesPersistenceService.deleteForFiles(fileIds);
//delete all overrides
fileIds.forEach(fileId -> componentLogMongoService.softDeleteComponentLogEntries(dossierId, fileId));
fileIds.forEach(fileId -> componentLogMongoService.softDeleteComponentLogEntries(dossierId, fileId, softDeleteTime));
fileStatusPersistenceService.softDeleteFiles(fileIds, softDeleteTime);

View File

@ -3,6 +3,8 @@ package com.iqser.red.service.persistence.management.v1.processor.service;
import static com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException.DOSSIER_NOT_FOUND_MESSAGE;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Set;
@ -124,7 +126,9 @@ public class FileService {
for (String fileId : fileIds) {
FileModel fileStatus = fileStatusService.getStatus(fileId);
OffsetDateTime softDeletedTime = fileStatus.getDeleted();
fileDeletionService.undeleteFile(dossierId, fileId, softDeletedTime);
ZonedDateTime zonedDeletedTime = softDeletedTime.atZoneSameInstant(ZoneId.systemDefault());
OffsetDateTime adjustedSoftDeletedTime = zonedDeletedTime.toOffsetDateTime();
fileDeletionService.undeleteFile(dossierId, fileId, adjustedSoftDeletedTime);
}
fileDeletionService.reindexUndeletedFiles(dossier.getDossierTemplateId(), dossierId, fileIds);
fileIds.forEach(fileId -> {

View File

@ -59,6 +59,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemp
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.ProcessingStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.WorkflowStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.service.ComponentLogMongoService;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.service.EntityLogMongoService;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
import com.knecon.fforesight.service.ocr.v1.api.model.DocumentRequest;
@ -102,6 +103,7 @@ public class FileStatusService {
LayoutParsingRequestFactory layoutParsingRequestFactory;
ComponentMappingService componentMappingService;
EntityLogMongoService entityLogMongoService;
ComponentLogMongoService componentLogMongoService;
WebsocketService websocketService;
@ -825,6 +827,9 @@ public class FileStatusService {
commentPersistenceService.softDeleteCommentsForFiles(List.of(fileId), now);
fileStatusPersistenceService.updateHasComments(fileId, false);
//delete all overrides
componentLogMongoService.softDeleteComponentLogEntries(dossierId, fileId, now);
}

View File

@ -28,7 +28,7 @@ public class ComponentDefinitionPersistenceService {
public ComponentDefinitionEntity insert(ComponentDefinitionAddRequest component, String dossierTemplateId) {
return insert(component, countByDossierTemplateId(dossierTemplateId) + 1, dossierTemplateId);
return insert(component, maxRankByDossierTemplateId(dossierTemplateId) + 1, dossierTemplateId);
}
@ -57,9 +57,9 @@ public class ComponentDefinitionPersistenceService {
}
public int countByDossierTemplateId(String dossierTemplateId) {
public int maxRankByDossierTemplateId(String dossierTemplateId) {
return componentDefinitionRepository.countByDossierTemplateId(dossierTemplateId);
return componentDefinitionRepository.maxRankByDossierTemplateId(dossierTemplateId);
}
@ -120,9 +120,9 @@ public class ComponentDefinitionPersistenceService {
}
public Optional<String> findIdByTechnicalNameAndSoftDeleted(String technicalName) {
public Optional<String> findIdByDossierTemplateIdAndTechnicalNameAndIsSoftDeleted(String dossierTemplateId, String technicalName) {
return componentDefinitionRepository.findIdByTechnicalNameAndIsSoftDeleted(technicalName);
return componentDefinitionRepository.findIdByDossierTemplateIdAndTechnicalNameAndIsSoftDeleted(dossierTemplateId, technicalName);
}
}

View File

@ -34,11 +34,11 @@ public interface ComponentDefinitionRepository extends JpaRepository<ComponentDe
List<ComponentDefinitionEntity> findByIdsAndDossierTemplateId(@Param("ids") List<String> ids, @Param("dossierTemplateId") String dossierTemplateId);
@Query("SELECT COUNT(c) from ComponentDefinitionEntity c WHERE c.dossierTemplateId = :dossierTemplateId AND c.softDeleteTime IS NULL")
int countByDossierTemplateId(@Param("dossierTemplateId") String dossierTemplateId);
@Query("SELECT COALESCE(MAX(c.rank), 0) from ComponentDefinitionEntity c WHERE c.dossierTemplateId = :dossierTemplateId AND c.softDeleteTime IS NULL")
int maxRankByDossierTemplateId(@Param("dossierTemplateId") String dossierTemplateId);
@Query("SELECT c.id FROM ComponentDefinitionEntity c WHERE c.technicalName = :technicalName AND c.softDeleteTime IS NOT NULL")
Optional<String> findIdByTechnicalNameAndIsSoftDeleted(@Param("technicalName") String technicalName);
@Query("SELECT c.id FROM ComponentDefinitionEntity c WHERE c.dossierTemplateId = :dossierTemplateId AND c.technicalName = :technicalName AND c.softDeleteTime IS NOT NULL")
Optional<String> findIdByDossierTemplateIdAndTechnicalNameAndIsSoftDeleted(@Param("dossierTemplateId") String dossierTemplateId, @Param("technicalName") String technicalName);
}

View File

@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.iqser.red.service.peristence.v1.server.integration.client.DossierTemplateExternalClient;
import com.iqser.red.service.peristence.v1.server.integration.service.DossierTemplateTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.ComponentDefinitionPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.DossierTemplateModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.component.ComponentDefinition;
import com.iqser.red.service.persistence.service.v1.api.shared.model.component.ComponentDefinitionAddRequest;
@ -29,6 +30,9 @@ public class ComponentDefinitionTests extends AbstractPersistenceServerServiceTe
@Autowired
private DossierTemplateExternalClient dossierTemplateExternalClient;
@Autowired
private ComponentDefinitionPersistenceService componentDefinitionPersistenceService;
@Test
public void testCreateComponentDefinition() {
@ -163,8 +167,13 @@ public class ComponentDefinitionTests extends AbstractPersistenceServerServiceTe
List<ComponentDefinition> componentsExcludingSoftDeleted = dossierTemplateExternalClient.getComponents(dossierTemplate.getId(), false);
assertEquals(componentsIncludingSoftDeleted.size(), componentsExcludingSoftDeleted.size() + 1);
String changedDescription = "changed description";
componentDefinitionAddRequest.setDescription(changedDescription);
int count = componentDefinitionPersistenceService.maxRankByDossierTemplateId(dossierTemplate.getId());
response = dossierTemplateExternalClient.createComponents(dossierTemplate.getId(), List.of(componentDefinitionAddRequest));
assertEquals(response.size(), 1);
assertEquals(response.get(0).getDescription(), changedDescription);
assertEquals(response.get(0).getRank(), count + 1);
}

View File

@ -31,6 +31,8 @@ import com.iqser.red.service.persistence.service.v2.api.external.model.Component
import com.iqser.red.service.persistence.service.v2.api.external.model.ComponentValue;
import com.iqser.red.service.persistence.service.v2.api.external.model.EntityReference;
import lombok.SneakyThrows;
public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest {
@Autowired
@ -212,6 +214,7 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
@Test
@SneakyThrows
public void testDeletedFileOverrides() throws IOException {
var dossier = dossierTesterAndProvider.provideTestDossier();
@ -240,17 +243,36 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
.build()))
.build();
Component componentOverrideModel2 = Component.builder()
.name("Performing_Laboratory")
.componentValues(List.of(ComponentValue.builder()
.value("Test Labor Deutschland AG, Switzerland")
.originalValue("Test Labor Deutschland AG, Switzerland BBBB")
.valueDescription("Laboratory name and country found!")
.componentRuleId("PerformingLaboratory.1.0")
.entityReferences(List.of(EntityReference.builder()
.id("cdfa1386cc0b1c665c7dfb1b8bd2a134")
.type("laboratory_name")
.entityRuleId("DOC.7.0")
.page(1)
.build()))
.build()))
.build();
var componentLogJson = new ClassPathResource("files/componentlog/exampleComponentLog.json");
fileManagementStorageService.storeObject(dossier.getId(), file.getId(), FileType.COMPONENT_LOG, componentLogJson.getInputStream());
componentClient.addOverride(dossierTemplate.getId(), dossier.getId(), file.getId(), componentOverrideModel);
componentClient.addOverride(dossierTemplate.getId(), dossier.getId(), file.getId(), componentOverrideModel2);
var overrides = componentClient.getOverrides(dossierTemplate.getId(), dossier.getId(), file.getId());
assertFalse(overrides.getComponentOverrides().isEmpty());
assertTrue(overrides.getComponentOverrides()
.get(0).isOverridden());
assertTrue(overrides.getComponentOverrides()
.get(1).isOverridden());
// case 1: delete file, overrides should not be returned anymore
fileService.deleteFile(dossier.getId(), file.getFileId());
@ -266,9 +288,18 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
assertTrue(overrides.getComponentOverrides().isEmpty());
componentClient.addOverride(dossierTemplate.getId(), dossier.getId(), file.getId(), componentOverrideModel);
componentClient.addOverride(dossierTemplate.getId(), dossier.getId(), file.getId(), componentOverrideModel2);
overrides = componentClient.getOverrides(dossierTemplate.getId(), dossier.getId(), file.getId());
assertFalse(overrides.getComponentOverrides().isEmpty());
// delete file again
fileService.deleteFile(dossier.getId(), file.getFileId());
Thread.sleep(1000);
// case 3: when undeleting, the overrides should be there again (restored)
fileService.undeleteFiles(dossier.getId(), Set.of(file.getFileId()));
@ -277,6 +308,8 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
assertFalse(overrides.getComponentOverrides().isEmpty());
assertTrue(overrides.getComponentOverrides()
.get(0).isOverridden());
assertTrue(overrides.getComponentOverrides()
.get(1).isOverridden());
// case 4: on hard delete overrides should also be gone of course
fileService.hardDeleteFiles(dossier.getId(), List.of(file.getFileId()));

View File

@ -19,23 +19,25 @@ public class ComponentDocumentUpdateService {
public ComponentDocumentUpdateService(MongoTemplate mongoTemplate) {this.mongoTemplate = mongoTemplate;}
public void setSoftDeletedTime(String componentLogId) {
public void setSoftDeletedTime(String componentLogId, OffsetDateTime softDeletedTime) {
Query query = new Query(Criteria.where("componentLogId").is(componentLogId));
Query query = new Query(Criteria.where("componentLogId").is(componentLogId)
.and("softDeletedTime").is(null));
Update update = new Update().set("softDeletedTime", OffsetDateTime.now());
mongoTemplate.updateFirst(query, update, ComponentDocument.class);
Update update = new Update().set("softDeletedTime", softDeletedTime);
mongoTemplate.updateMulti(query, update, ComponentDocument.class);
}
public void unsetSoftDeletedTimeWhereGreaterThanEquals(String componentLogId, OffsetDateTime softDeletedTime) {
public void unsetSoftDeletedTime(String componentLogId) {
Query query = new Query(Criteria.where("componentLogId").is(componentLogId));
Query query = new Query(Criteria.where("componentLogId").is(componentLogId)
.and("softDeletedTime").gte(softDeletedTime));
Update update = new Update().unset("softDeletedTime");
mongoTemplate.updateFirst(query, update, ComponentDocument.class);
mongoTemplate.updateMulti(query, update, ComponentDocument.class);
}
}

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.persistence.service.v1.api.shared.mongo.service;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -113,19 +114,19 @@ public class ComponentLogMongoService {
}
public void softDeleteComponentLogEntries(String dossierId, String fileId) {
public void softDeleteComponentLogEntries(String dossierId, String fileId, OffsetDateTime softDeletedTime) {
String componentLogId = mapper.getComponentLogId(dossierId, fileId);
componentDocumentUpdateService.setSoftDeletedTime(componentLogId);
componentDocumentUpdateService.setSoftDeletedTime(componentLogId, softDeletedTime);
}
public void undeleteComponentLogEntries(String dossierId, String fileId) {
public void undeleteComponentLogEntries(String dossierId, String fileId, OffsetDateTime softDeletedTime) {
String componentLogId = mapper.getComponentLogId(dossierId, fileId);
componentDocumentUpdateService.unsetSoftDeletedTime(componentLogId);
componentDocumentUpdateService.unsetSoftDeletedTimeWhereGreaterThanEquals(componentLogId, softDeletedTime);
}