RED-8339: Fixes
This commit is contained in:
parent
9c93cd32c1
commit
fcc87a078b
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.AuditPersistenceService;
|
||||
@ -118,27 +119,44 @@ public class ComponentLogService {
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void addOverride(String dossierId, String fileId, ComponentLogEntry componentOverride) {
|
||||
|
||||
var optionalComponentLogEntry = componentLogMongoService.findComponentLogEntryById(dossierId, fileId, componentOverride.getName());
|
||||
|
||||
ComponentLogEntry componentToUpdate;
|
||||
if (optionalComponentLogEntry.isPresent()) {
|
||||
ComponentLogEntry componentToUpdate = optionalComponentLogEntry.get();
|
||||
componentToUpdate.setOverridden(true);
|
||||
System.out.println("AAAA1: " + componentToUpdate);
|
||||
componentToUpdate.getComponentValues().addAll(componentOverride.getComponentValues());
|
||||
saveOverride(dossierId, fileId, componentToUpdate);
|
||||
auditOverride(dossierId, fileId, componentToUpdate);
|
||||
componentToUpdate = optionalComponentLogEntry.get();
|
||||
updateComponentLogEntry(dossierId, fileId, componentOverride, componentToUpdate);
|
||||
} else {
|
||||
componentOverride.setOverridden(true);
|
||||
System.out.println("AAAA2: " + componentOverride);
|
||||
insertOverride(dossierId, fileId, componentOverride);
|
||||
auditOverride(dossierId, fileId, componentOverride);
|
||||
optionalComponentLogEntry = fileManagementStorageService.getComponentLog(dossierId, fileId).getComponentLogEntries()
|
||||
.stream()
|
||||
.filter(componentLogEntry -> componentOverride.getName().equals(componentLogEntry.getName()))
|
||||
.findFirst();
|
||||
if (optionalComponentLogEntry.isPresent()) {
|
||||
componentToUpdate = optionalComponentLogEntry.get();
|
||||
updateComponentLogEntry(dossierId, fileId, componentOverride, componentToUpdate);
|
||||
} else {
|
||||
componentOverride.setOverridden(true);
|
||||
System.out.println("AAAA2: " + componentOverride);
|
||||
insertOverride(dossierId, fileId, componentOverride);
|
||||
auditOverride(dossierId, fileId, componentOverride);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void updateComponentLogEntry(String dossierId, String fileId, ComponentLogEntry componentOverride, ComponentLogEntry componentToUpdate) {
|
||||
|
||||
componentToUpdate.setOverridden(true);
|
||||
System.out.println("AAAA: " + componentToUpdate);
|
||||
componentToUpdate.setComponentValues(componentOverride.getComponentValues());
|
||||
saveOverride(dossierId, fileId, componentToUpdate);
|
||||
auditOverride(dossierId, fileId, componentToUpdate);
|
||||
}
|
||||
|
||||
|
||||
private void saveOverride(String dossierId, String fileId, ComponentLogEntry componentToUpdate) {
|
||||
|
||||
componentLogMongoService.saveComponentLogEntries(dossierId, fileId, List.of(componentToUpdate));
|
||||
|
||||
@ -2,6 +2,7 @@ package com.iqser.red.service.peristence.v1.server.integration.tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -62,7 +63,6 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
|
||||
.page(1)
|
||||
.build()))
|
||||
.build()))
|
||||
.overridden(true)
|
||||
.build();
|
||||
|
||||
var componentLogJson = new ClassPathResource("files/componentlog/exampleComponentLog.json");
|
||||
@ -78,7 +78,35 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
|
||||
assertEquals(file.getId(), overrides.getFileId());
|
||||
|
||||
assertFalse(overrides.getComponentOverrideModels().isEmpty());
|
||||
assertTrue(overrides.getComponentOverrideModels().get(0).isOverridden());
|
||||
|
||||
// override same entry a second time
|
||||
Component componentOverrideModel2 = Component.builder()
|
||||
.name("Study_Title")
|
||||
.componentValues(List.of(ComponentValue.builder()
|
||||
.value("BBBB Strange Chemical Name And the rest of a title – With a dash and some more text")
|
||||
.originalValue("Strange Chemical Name And the rest of a title – With a dash and some more text")
|
||||
.valueDescription("First found value of type title or else ''")
|
||||
.componentRuleId("StudyTitle.0.0")
|
||||
.entityReferences(List.of(EntityReference.builder()
|
||||
.id("cf7f0d0c4c07918ce7d67b204f5fdb7d")
|
||||
.type("title")
|
||||
.entityRuleId("DOC.6.1")
|
||||
.page(1)
|
||||
.build()))
|
||||
.build()))
|
||||
.build();
|
||||
componentClient.addOverride(dossierTemplate.getId(), dossier.getId(), file.getId(), componentOverrideModel2);
|
||||
|
||||
// when(fileManagementStorageService.getComponentLog(any(), any())).thenReturn();
|
||||
overrides = componentClient.getOverrides(dossierTemplate.getId(), dossier.getId(), file.getId());
|
||||
|
||||
assertEquals(dossierTemplate.getId(), overrides.getDossierTemplateId());
|
||||
assertEquals(dossier.getId(), overrides.getDossierId());
|
||||
assertEquals(file.getId(), overrides.getFileId());
|
||||
|
||||
assertFalse(overrides.getComponentOverrideModels().isEmpty());
|
||||
assertTrue(overrides.getComponentOverrideModels().get(0).isOverridden());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ import lombok.experimental.FieldDefaults;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE)
|
||||
@Document(collection = "components")
|
||||
@Document(collection = "component-log-entries")
|
||||
public class ComponentDocument {
|
||||
|
||||
@Id
|
||||
@ -33,7 +33,8 @@ public class ComponentDocument {
|
||||
|
||||
List<ComponentLogEntryValue> overrideValues = new ArrayList<>();
|
||||
|
||||
// these parameters will be needed later
|
||||
// List<ComponentLogEntryValue> values = new ArrayList<>();
|
||||
// boolean overridden;
|
||||
List<ComponentLogEntryValue> values = new ArrayList<>();
|
||||
|
||||
boolean overridden;
|
||||
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@ public interface ComponentDocumentRepository extends MongoRepository<ComponentDo
|
||||
@Query(value = "{ 'componentLogId' : ?0}", delete = true)
|
||||
void deleteByComponentLogId(String componentLogId);
|
||||
|
||||
|
||||
@Query(value = "{ 'componentLogId': ?0, 'componentName': ?1 }")
|
||||
Optional<ComponentDocument> findComponentDocumentByName(String componentLogId, String componentName);
|
||||
|
||||
|
||||
@ -105,7 +105,6 @@ public class ComponentLogMongoService {
|
||||
.map(componentLogEntry -> mapper.toComponentDocument(componentLogId, componentLogEntry))
|
||||
.toList();
|
||||
|
||||
System.out.println("BBBB: " + componentDocuments);
|
||||
componentDocumentRepository.insert(componentDocuments);
|
||||
}
|
||||
|
||||
@ -126,16 +125,11 @@ public class ComponentLogMongoService {
|
||||
|
||||
String componentLogId = mapper.getComponentLogId(dossierId, fileId);
|
||||
|
||||
ComponentLogDocument componentLogDocument = getComponentLogDocument(componentLogId);
|
||||
|
||||
List<ComponentDocument> componentDocuments = componentLogEntries.stream()
|
||||
.map(componentLogEntry -> mapper.toComponentDocument(componentLogId, componentLogEntry))
|
||||
.toList();
|
||||
|
||||
componentLogDocument.getComponents().addAll(componentDocuments);
|
||||
|
||||
componentDocumentRepository.saveAll(componentDocuments);
|
||||
componentLogDocumentRepository.save(componentLogDocument);
|
||||
}
|
||||
|
||||
|
||||
@ -149,7 +143,7 @@ public class ComponentLogMongoService {
|
||||
}
|
||||
|
||||
|
||||
public void deleteComponentLogEntries(String dossierId, String fileId, List<ComponentLogEntry> componentLogEntries) {
|
||||
public void deleteComponentLogEntriesFromComponentLog(String dossierId, String fileId, List<ComponentLogEntry> componentLogEntries) {
|
||||
|
||||
String componentLogId = mapper.getComponentLogId(dossierId, fileId);
|
||||
|
||||
@ -175,7 +169,7 @@ public class ComponentLogMongoService {
|
||||
|
||||
public Optional<ComponentLogEntry> findComponentLogEntryById(String dossierId, String fileId, String componentName) {
|
||||
|
||||
return componentDocumentRepository.findComponentDocumentByName(mapper.getComponentLogId(dossierId, fileId), componentName)
|
||||
return componentDocumentRepository.findById(mapper.getComponentId(mapper.getComponentLogId(dossierId, fileId), componentName))
|
||||
.map(mapper::fromComponentDocument);
|
||||
}
|
||||
|
||||
@ -197,11 +191,6 @@ public class ComponentLogMongoService {
|
||||
});
|
||||
|
||||
return overrides;
|
||||
|
||||
// return componentLogDocumentRepository.findOverrides(dossierId, fileId)
|
||||
// .stream()
|
||||
// .map(mapper::fromComponentDocument)
|
||||
// .toList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user