Pull request #34: test improvements for new features
Merge in RED/persistence-service from type-id-refactor to master * commit 'cd473e233672b24effc77983d2d8915ce4c37098': updated version calculations test improvements for new features
This commit is contained in:
commit
fb1c1c7056
@ -1,13 +1,14 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@ -29,4 +30,10 @@ public class Type {
|
||||
private String dossierId;
|
||||
private List<DictionaryEntry> entries = new ArrayList<>();
|
||||
|
||||
// For auto-mappers
|
||||
@JsonIgnore
|
||||
public String getTypeId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -45,7 +45,6 @@ public class ManualRedactionEntryEntity {
|
||||
@Column
|
||||
private OffsetDateTime softDeletedTime;
|
||||
|
||||
|
||||
@ElementCollection
|
||||
private List<RectangleEntity> positions = new ArrayList<>();
|
||||
|
||||
|
||||
@ -50,7 +50,6 @@ public class EntryPersistenceService {
|
||||
|
||||
|
||||
public List<DictionaryEntryEntity> getEntries(String typeId) {
|
||||
|
||||
return entryRepository.findByTypeId(typeId);
|
||||
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@ import java.util.List;
|
||||
|
||||
public interface EntryRepository extends JpaRepository<DictionaryEntryEntity, Long> {
|
||||
|
||||
@Modifying
|
||||
@Query("update DictionaryEntryEntity e set e.deleted = true , e.version = :version where e.type.id =:typeId and e.value in :values")
|
||||
void deleteAllByTypeIdAndVersionAndValueIn(String typeId, long version, List<String> values);
|
||||
|
||||
@Modifying
|
||||
|
||||
@ -58,7 +58,8 @@ public class DictionaryController implements DictionaryResource {
|
||||
|
||||
// List<String> entriesToSearch = new ArrayList<>();
|
||||
|
||||
long currentVersion = typeResult.getVersion();
|
||||
var currentVersion = getCurrentVersion(typeResult);
|
||||
|
||||
if (removeCurrent) {
|
||||
List<String> existing = entryPersistenceService.getEntries(typeId)
|
||||
.stream()
|
||||
@ -94,7 +95,7 @@ public class DictionaryController implements DictionaryResource {
|
||||
// To check whether the type exists
|
||||
Type typeResult = convert(dictionaryPersistenceService.getType(typeId), Type.class);
|
||||
|
||||
long currentVersion = typeResult.getVersion();
|
||||
var currentVersion = getCurrentVersion(typeResult);
|
||||
|
||||
if (typeResult.isCaseInsensitive()) {
|
||||
List<String> existing = entryPersistenceService.getEntries(typeId)
|
||||
@ -135,7 +136,8 @@ public class DictionaryController implements DictionaryResource {
|
||||
|
||||
if (typeResult.isHint() != typeValueRequest.isHint() || typeResult.isCaseInsensitive() != typeValueRequest.isCaseInsensitive() || typeResult
|
||||
.getRank() != typeValueRequest.getRank()) {
|
||||
long currentVersion = typeResult.getVersion();
|
||||
|
||||
var currentVersion = getCurrentVersion(typeResult);
|
||||
List<DictionaryEntry> entries = convert(entryPersistenceService.getEntries(typeId), DictionaryEntry.class);
|
||||
entryPersistenceService.setVersion(typeId, entries.stream()
|
||||
.filter(entry -> !entry.isDeleted())
|
||||
@ -180,7 +182,8 @@ public class DictionaryController implements DictionaryResource {
|
||||
|
||||
// NotFoundException would be thrown if the type not found in database.
|
||||
Type typeResult = convert(dictionaryPersistenceService.getType(typeId), Type.class);
|
||||
long currentVersion = typeResult.getVersion();
|
||||
|
||||
var currentVersion = getCurrentVersion(typeResult);
|
||||
|
||||
dictionaryPersistenceService.deleteType(typeId);
|
||||
List<String> existing = entryPersistenceService.getEntries(typeId)
|
||||
@ -296,6 +299,15 @@ public class DictionaryController implements DictionaryResource {
|
||||
}
|
||||
}
|
||||
|
||||
private long getCurrentVersion(Type typeResult) {
|
||||
long currentVersion;
|
||||
if (typeResult.getDossierId() != null) {
|
||||
currentVersion = getVersionForDossier(typeResult.getDossierId());
|
||||
} else {
|
||||
currentVersion = getVersion(typeResult.getDossierTemplateId());
|
||||
}
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
private String humanizedDictionaryType(String label) {
|
||||
|
||||
|
||||
@ -42,15 +42,22 @@ public class FileTesterAndProvider {
|
||||
@SneakyThrows
|
||||
public FileModel testAndProvideFile(Dossier dossier) {
|
||||
|
||||
return testAndProvideFile(dossier, "test.pdf");
|
||||
}
|
||||
|
||||
BinaryFileRequest upload = new BinaryFileRequest("test".getBytes(StandardCharsets.UTF_8), "test.pdf", dossier.getId(), "1");
|
||||
|
||||
@SneakyThrows
|
||||
public FileModel testAndProvideFile(Dossier dossier, String fileName) {
|
||||
|
||||
|
||||
BinaryFileRequest upload = new BinaryFileRequest("test".getBytes(StandardCharsets.UTF_8), fileName, dossier.getId(), "1");
|
||||
JSONPrimitive<String> uploadResult = uploadClient.upload(upload);
|
||||
|
||||
var file = fileClient.getFileStatus(dossier.getId(), uploadResult.getValue());
|
||||
|
||||
assertThat(file.getId()).isNotBlank();
|
||||
|
||||
assertThat(fileClient.getDossierStatus(dossier.getId()).size()).isEqualTo(1);
|
||||
assertThat(fileClient.getDossierStatus(dossier.getId()).size()).isGreaterThanOrEqualTo(1);
|
||||
|
||||
fileManagementStorageService.storeObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, objectMapper.writeValueAsBytes(new RedactionLog(1, List.of(RedactionLogEntry.builder().id("annotationId").type("manual").value("value").build()),
|
||||
null, 0, 0, 0, 0)));
|
||||
|
||||
@ -6,15 +6,12 @@ import com.iqser.red.service.peristence.v1.server.integration.service.DossierTes
|
||||
import com.iqser.red.service.peristence.v1.server.integration.service.TypeProvider;
|
||||
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.configuration.Colors;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.type.DictionaryEntry;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.type.Type;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TypeTest extends AbstractPersistenceServerServiceTest {
|
||||
@ -46,7 +43,7 @@ public class TypeTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
assertThat(loadedType.getVersion()).isGreaterThan(type.getVersion());
|
||||
|
||||
List<DictionaryEntry> dict = dictionaryClient.getEntriesForType(type.getId());
|
||||
var dict = dictionaryClient.getEntriesForType(type.getId());
|
||||
|
||||
assertThat(dict.size()).isEqualTo(3);
|
||||
|
||||
@ -56,6 +53,13 @@ public class TypeTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
assertThat(loadedType.getVersion()).isGreaterThan(type.getVersion() + 1);
|
||||
|
||||
dict = dictionaryClient.getEntriesForType(type.getId());
|
||||
|
||||
assertThat(dict.size()).isEqualTo(3);
|
||||
for (var entry : dict) {
|
||||
assertThat(entry.isDeleted()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
var request = new Type();
|
||||
BeanUtils.copyProperties(type, request);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user