Pull request #577: RSS-287: Added endpoint to override scm values
Merge in RED/persistence-service from RSS-287 to master * commit '505ec99b7a903795bdc952144a00291bdad42265': RSS-287: Added endpoint to override scm values
This commit is contained in:
commit
3c7c32d6a5
@ -0,0 +1,18 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ComponentsOverrides {
|
||||
|
||||
private Map<String, String> componentOverrides = new HashMap<>();
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.component;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RevertOverrideRequest {
|
||||
|
||||
private Set<String> components = new HashSet<>();
|
||||
}
|
||||
@ -15,7 +15,8 @@ public enum FileType {
|
||||
IMPORTED_REDACTIONS(".json"),
|
||||
TEXT_HIGHLIGHTS(".json"),
|
||||
FIGURE(".json"),
|
||||
TABLES(".json");
|
||||
TABLES(".json"),
|
||||
COMPONENTS(".json");
|
||||
|
||||
@Getter
|
||||
private final String extension;
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.resources;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
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.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.component.ComponentsOverrides;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.component.RevertOverrideRequest;
|
||||
|
||||
public interface ComponentOverrideResource {
|
||||
|
||||
String PATH = "/component";
|
||||
|
||||
String FILE_ID = "fileId";
|
||||
String FILE_ID_PATH_VARIABLE = "/{" + FILE_ID + "}";
|
||||
|
||||
String DOSSIER_ID_PARAM = "dossierId";
|
||||
String DOSSIER_ID_PATH_PARAM = "/{" + DOSSIER_ID_PARAM + "}";
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@PostMapping(value = PATH + DOSSIER_ID_PATH_PARAM + FILE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
void addOverrides(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody ComponentsOverrides componentsOverrides);
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@GetMapping(value = PATH + DOSSIER_ID_PATH_PARAM + FILE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
ComponentsOverrides getOverrides(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId);
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@PostMapping(value = PATH + "/revert" + DOSSIER_ID_PATH_PARAM + FILE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
void revertOverrides(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody RevertOverrideRequest revertOverrideRequest);
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package com.iqser.red.service.peristence.v1.server.controller;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileManagementStorageService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.component.ComponentsOverrides;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.component.RevertOverrideRequest;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
|
||||
import com.iqser.red.service.persistence.service.v1.api.resources.ComponentOverrideResource;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class ComponentOverrideController implements ComponentOverrideResource {
|
||||
|
||||
private final FileManagementStorageService fileManagementStorageService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public void addOverrides(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody ComponentsOverrides componentsOverrides) {
|
||||
|
||||
if (!fileManagementStorageService.objectExists(dossierId, fileId, FileType.COMPONENTS)) {
|
||||
fileManagementStorageService.storeObject(dossierId, fileId, FileType.COMPONENTS, new ByteArrayInputStream(objectMapper.writeValueAsBytes(componentsOverrides)));
|
||||
return;
|
||||
}
|
||||
|
||||
var existingComponentsBytes = fileManagementStorageService.getStoredObjectBytes(dossierId, fileId, FileType.COMPONENTS);
|
||||
var existingComponents = objectMapper.readValue(existingComponentsBytes, ComponentsOverrides.class);
|
||||
existingComponents.getComponentOverrides().putAll(componentsOverrides.getComponentOverrides());
|
||||
|
||||
fileManagementStorageService.storeObject(dossierId, fileId, FileType.COMPONENTS, new ByteArrayInputStream(objectMapper.writeValueAsBytes(existingComponents)));
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public ComponentsOverrides getOverrides(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId) {
|
||||
|
||||
var existingComponentsBytes = fileManagementStorageService.getStoredObjectBytes(dossierId, fileId, FileType.COMPONENTS);
|
||||
var existingComponents = objectMapper.readValue(existingComponentsBytes, ComponentsOverrides.class);
|
||||
return existingComponents;
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public void revertOverrides(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId, @RequestBody RevertOverrideRequest revertOverrideRequest) {
|
||||
|
||||
if (!fileManagementStorageService.objectExists(dossierId, fileId, FileType.COMPONENTS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var existingComponentsBytes = fileManagementStorageService.getStoredObjectBytes(dossierId, fileId, FileType.COMPONENTS);
|
||||
var existingComponents = objectMapper.readValue(existingComponentsBytes, ComponentsOverrides.class);
|
||||
|
||||
revertOverrideRequest.getComponents().forEach(c -> existingComponents.getComponentOverrides().remove(c));
|
||||
|
||||
fileManagementStorageService.storeObject(dossierId, fileId, FileType.COMPONENTS, new ByteArrayInputStream(objectMapper.writeValueAsBytes(existingComponents)));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user