RED-8339: Fixes

This commit is contained in:
Ali Oezyetimoglu 2024-05-29 17:40:06 +02:00
parent 34237ca813
commit 4487d8f586
5 changed files with 110 additions and 47 deletions

View File

@ -7,7 +7,6 @@ import java.util.Map;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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; import com.iqser.red.service.persistence.management.v1.processor.service.persistence.AuditPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.AuditCategory; import com.iqser.red.service.persistence.service.v1.api.shared.model.AuditCategory;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLog; import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLog;
@ -91,12 +90,11 @@ public class ComponentLogService {
private void replaceOverriddenComponentLogEntries(ComponentLog componentLog, List<ComponentLogEntry> componentOverrides) { private void replaceOverriddenComponentLogEntries(ComponentLog componentLog, List<ComponentLogEntry> componentOverrides) {
// remove override entries from componentLog
componentLog.getComponentLogEntries() componentLog.getComponentLogEntries()
.removeIf(entry -> componentOverrides.stream() .removeIf(entry -> componentOverrides.stream()
.anyMatch(override -> entry.getName().equals(override.getName()))); .anyMatch(override -> entry.getName().equals(override.getName())));
// insert overrides to Component log
componentLog.getComponentLogEntries().addAll(componentOverrides); componentLog.getComponentLogEntries().addAll(componentOverrides);
} }
@ -129,28 +127,14 @@ public class ComponentLogService {
componentToUpdate = optionalComponentLogEntry.get(); componentToUpdate = optionalComponentLogEntry.get();
updateComponentLogEntry(dossierId, fileId, componentOverride, componentToUpdate); updateComponentLogEntry(dossierId, fileId, componentOverride, componentToUpdate);
} else { } else {
optionalComponentLogEntry = fileManagementStorageService.getComponentLog(dossierId, fileId).getComponentLogEntries() insertOverride(dossierId, fileId, componentOverride);
.stream() auditOverride(dossierId, fileId, componentOverride);
.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) { private void updateComponentLogEntry(String dossierId, String fileId, ComponentLogEntry componentOverride, ComponentLogEntry componentToUpdate) {
componentToUpdate.setOverridden(true);
System.out.println("AAAA: " + componentToUpdate);
componentToUpdate.setComponentValues(componentOverride.getComponentValues()); componentToUpdate.setComponentValues(componentOverride.getComponentValues());
saveOverride(dossierId, fileId, componentToUpdate); saveOverride(dossierId, fileId, componentToUpdate);
auditOverride(dossierId, fileId, componentToUpdate); auditOverride(dossierId, fileId, componentToUpdate);
@ -180,10 +164,9 @@ public class ComponentLogService {
revertOverrideRequest.getComponents() revertOverrideRequest.getComponents()
.forEach(componentName -> { .forEach(componentName -> {
var componentLogEntry = componentLogMongoService.findComponentLogEntryById(dossierId, fileId, componentName) componentLogMongoService.deleteOverrides(dossierId, fileId, componentName);
.orElseThrow(() -> new NotFoundException(String.format("Component %s was not found.", componentName)));
auditOverrideRevert(dossierId, fileId, componentLogEntry); auditOverrideRevert(dossierId, fileId, componentName);
}); });
} }
@ -209,23 +192,14 @@ public class ComponentLogService {
} }
private void auditOverrideRevert(String dossierId, String fileId, ComponentLogEntry entry) { private void auditOverrideRevert(String dossierId, String fileId, String componentName) {
auditPersistenceService.audit(AuditRequest.builder() auditPersistenceService.audit(AuditRequest.builder()
.userId(KeycloakSecurity.getUserId()) .userId(KeycloakSecurity.getUserId())
.objectId(fileId) .objectId(fileId)
.category(AuditCategory.DOCUMENT.name()) .category(AuditCategory.DOCUMENT.name())
.message("The component override for was reverted") .message("The component override for was reverted")
.details(Map.of("dossierId", .details(Map.of("dossierId", dossierId, "fileId", fileId, "ComponentName", componentName, "Action", "REVERT"))
dossierId,
"fileId",
fileId,
"ComponentName",
entry.getName(),
"Action",
"REVERT",
"Values",
entry.getComponentValues()))
.build()); .build());
} }

View File

@ -7,11 +7,100 @@
<changeSet id="createComponentCollection" author="ali"> <changeSet id="createComponentCollection" author="ali">
<ext:createCollection collectionName="component-logs"/> <ext:createCollection collectionName="component-logs">
<ext:options>
{
"collMod": "component-logs",
"validator": {
"$jsonSchema": {
"bsonType": "object",
"required": ["id", "dossierId", "fileId", "analysisNumber", "componentRulesVersion", "components"],
"properties": {
"id": {
"bsonType": "string",
"description": "must be a string and is required"
},
"dossierId": {
"bsonType": "string",
"description": "must be a string and is required"
},
"fileId": {
"bsonType": "string",
"description": "must be a string and is required"
},
"analysisNumber": {
"bsonType": "int",
"description": "must be an integer and is required"
},
"componentRulesVersion": {
"bsonType": "long",
"description": "must be a long and is required"
},
"components": {
"bsonType": "array",
"items": {
"bsonType": "objectId",
"description": "must be an array of objectIds"
},
"description": "must be an array and is required"
}
}
}
},
"validationLevel": "strict",
"validationAction": "error"
}
</ext:options>
</ext:createCollection>
<ext:createCollection collectionName="components"/> <ext:createCollection collectionName="component-log-entries">
<ext:options>
{
"collMod": "component-log-entries",
"validator": {
"$jsonSchema": {
"bsonType": "object",
"required": ["id", "componentLogId", "name", "overrideValues", "values", "overridden"],
"properties": {
"id": {
"bsonType": "string",
"description": "must be a string and is required"
},
"componentLogId": {
"bsonType": "string",
"description": "must be a string and is required"
},
"name": {
"bsonType": "string",
"description": "must be a string and is required"
},
"overrideValues": {
"bsonType": "array",
"items": {
"bsonType": "object"
},
"description": "must be an array of objects and is required"
},
"values": {
"bsonType": "array",
"items": {
"bsonType": "object"
},
"description": "must be an array of objects and is required"
},
"overridden": {
"bsonType": "bool",
"description": "must be a boolean and is required"
}
}
}
},
"validationLevel": "strict",
"validationAction": "warn"
}
</ext:options>
</ext:createCollection>
</changeSet> </changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@ -17,7 +17,6 @@ import lombok.experimental.FieldDefaults;
public class ComponentLogEntryValue { public class ComponentLogEntryValue {
String value; String value;
String originalValue;
String valueDescription; String valueDescription;
String componentRuleId; String componentRuleId;

View File

@ -19,7 +19,7 @@ public interface ComponentDocumentRepository extends MongoRepository<ComponentDo
Optional<ComponentDocument> findComponentDocumentByName(String componentLogId, String componentName); Optional<ComponentDocument> findComponentDocumentByName(String componentLogId, String componentName);
@Query(value = "{ 'componentLogId': ?0 }") @Query(value = "{ 'componentLogId': ?0 }")
List<ComponentDocument> findByDossierIdAndFileId(String componentLogId); List<ComponentDocument> findByComponentLogId(String componentLogId);
@Query(value = "{ 'componentLogId': ?0 }", fields = "{ 'overrideValues': 0 }") @Query(value = "{ 'componentLogId': ?0 }", fields = "{ 'overrideValues': 0 }")
List<ComponentDocument> findWithoutOverrideValuesByDossierIdAndFileId(String componentLogId); List<ComponentDocument> findWithoutOverrideValuesByDossierIdAndFileId(String componentLogId);

View File

@ -174,19 +174,12 @@ public class ComponentLogMongoService {
String componentLogId = mapper.getComponentLogId(dossierId, fileId); String componentLogId = mapper.getComponentLogId(dossierId, fileId);
List<ComponentLogEntry> overrides = componentDocumentRepository.findByDossierIdAndFileId(componentLogId) return componentDocumentRepository.findByComponentLogId(componentLogId)
.stream() .stream()
.map(mapper::fromComponentDocument) .map(mapper::fromComponentDocument)
.peek(componentLogEntry -> componentLogEntry.setOverridden(true))
.toList(); .toList();
overrides.forEach(componentLogEntry -> {
var componentValues = componentLogEntry.getComponentValues()
.stream()
.filter(componentLogEntryValue -> !componentLogEntryValue.getValue().equals(componentLogEntryValue.getOriginalValue()))
.toList();
componentLogEntry.setComponentValues(componentValues);
});
return overrides;
} }
@ -223,4 +216,12 @@ public class ComponentLogMongoService {
.map(mapper::fromComponentLogDocument); .map(mapper::fromComponentLogDocument);
} }
public void deleteOverrides(String dossierId, String fileId, String componentName) {
String componentId = mapper.getComponentId(dossierId, fileId, componentName);
componentDocumentRepository.deleteById(componentId);
}
} }