Merge branch 'RED-8339-7' into 'master'

RED-8339: fixed misbehaving when adding an override in old endpoint

Closes RED-8339

See merge request redactmanager/persistence-service!530
This commit is contained in:
Ali Oezyetimoglu 2024-06-07 09:59:50 +02:00
commit a6c6a4111c
2 changed files with 35 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package com.iqser.red.persistence.service.v1.external.api.impl.controller;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.GET_RSS;
import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_REDACTION_LOG;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -14,7 +15,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
@ -54,9 +54,7 @@ public class ComponentLogController implements ComponentLogResource {
@Deprecated(forRemoval = true)
@PostMapping(value = COMPONENT_LOG_PATH + OVERRIDE_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('" + GET_RSS + "')")
public void addOverride(@PathVariable(DOSSIER_ID) String dossierId,
@PathVariable(FILE_ID) String fileId,
@RequestBody ComponentsOverrides componentsOverrides) {
public void addOverride(@PathVariable(DOSSIER_ID) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody ComponentsOverrides componentsOverrides) {
accessControlService.checkDossierExistenceAndAccessPermissionsToDossier(dossierId);
accessControlService.validateFileResourceExistence(fileId);
@ -65,10 +63,29 @@ public class ComponentLogController implements ComponentLogResource {
throw new BadRequestException("Request body cannot be empty!");
}
var componentLog = componentLogService.getComponentLog(dossierId, fileId);
componentsOverrides.getComponentOverrides()
.forEach((k, v) -> {
ComponentLogEntryValue overrideValue = ComponentLogEntryValue.builder().value(v).build();
ComponentLogEntry override = ComponentLogEntry.builder().name(k).componentValues(List.of(overrideValue)).build();
ComponentLogEntry override;
var entryOptional = componentLog.getComponentLogEntries()
.stream()
.filter(componentLogEntry -> componentLogEntry.getName().equals(k))
.findFirst();
if (entryOptional.isPresent()) {
override = entryOptional.get();
override.getComponentValues()
.forEach(componentLogEntryValue -> componentLogEntryValue.setValue(v));
} else {
ComponentLogEntryValue overrideValue = ComponentLogEntryValue.builder()
.value(v)
.originalValue(v)
.valueDescription("")
.componentRuleId("")
.componentLogEntityReferences(new ArrayList<>())
.build();
override = ComponentLogEntry.builder().name(k).componentValues(List.of(overrideValue)).build();
}
componentLogService.addOverride(dossierId, fileId, override);
});
@ -78,8 +95,7 @@ public class ComponentLogController implements ComponentLogResource {
@Deprecated(forRemoval = true)
@GetMapping(value = COMPONENT_LOG_PATH + OVERRIDE_PATH + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('" + GET_RSS + "')")
public ComponentsOverrides getOverrides(@PathVariable(DOSSIER_ID) String dossierId,
@PathVariable(FILE_ID) String fileId) {
public ComponentsOverrides getOverrides(@PathVariable(DOSSIER_ID) String dossierId, @PathVariable(FILE_ID) String fileId) {
accessControlService.checkDossierExistenceAndViewPermissionsToDossier(dossierId);
accessControlService.validateFileResourceExistence(fileId);
@ -100,9 +116,7 @@ public class ComponentLogController implements ComponentLogResource {
@Deprecated(forRemoval = true)
@PostMapping(value = COMPONENT_LOG_PATH + OVERRIDE_PATH + "/revert" + DOSSIER_ID_PATH_VARIABLE + FILE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('" + GET_RSS + "')")
public void revertOverrides(@PathVariable(DOSSIER_ID) String dossierId,
@PathVariable(FILE_ID) String fileId,
@RequestBody RevertOverrideRequest revertOverrideRequest) {
public void revertOverrides(@PathVariable(DOSSIER_ID) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody RevertOverrideRequest revertOverrideRequest) {
accessControlService.checkDossierExistenceAndAccessPermissionsToDossier(dossierId);
accessControlService.validateFileResourceExistence(fileId);

View File

@ -21,6 +21,7 @@ import com.iqser.red.service.peristence.v1.server.integration.client.DossierTemp
import com.iqser.red.service.peristence.v1.server.integration.service.DossierTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.service.FileTesterAndProvider;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLogEntry;
import com.iqser.red.service.persistence.service.v1.api.shared.model.component.ComponentsOverrides;
import com.iqser.red.service.persistence.service.v1.api.shared.model.component.RevertOverrideRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
@ -186,16 +187,19 @@ public class ComponentOverrideTest extends AbstractPersistenceServerServiceTest
.get().isOverridden());
Map<String, String> componentOverrides = new HashMap<>();
componentOverrides.put("Study_Title", "BBBB Strange Chemical Name And the rest of a title With a dash and some more text");
String value = "BBBB Strange Chemical Name And the rest of a title With a dash and some more text";
componentOverrides.put("Study_Title", value);
ComponentsOverrides componentOverrideModel4 = ComponentsOverrides.builder().componentOverrides(componentOverrides).build();
componentLogClient.addOverride(dossier.getId(), file.getId(), componentOverrideModel4);
overridesFromOldEndpoint = componentLogClient.getComponentLog(dossier.getId(), file.getId(), true);
assertTrue(overridesFromOldEndpoint.getComponentLogEntries()
.stream()
.filter(component -> component.getName().equals("Study_Title"))
.findAny()
.get().isOverridden());
ComponentLogEntry studyTitle = overridesFromOldEndpoint.getComponentLogEntries()
.stream()
.filter(component -> component.getName().equals("Study_Title"))
.findAny()
.get();
assertTrue(studyTitle.isOverridden());
assertTrue(studyTitle.getComponentValues().stream().anyMatch(componentLogEntryValue -> componentLogEntryValue.getValue().equals(value)));
}