updated version calculations
This commit is contained in:
parent
daadcf09c7
commit
cd473e2336
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
|
||||
@ -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