RED-9056: Change flag name and decline requests except dossierDictionaryOnly is true
This commit is contained in:
parent
08671583fe
commit
8a5e97b9ce
@ -357,9 +357,9 @@ public class DictionaryController implements DictionaryResource {
|
||||
public void changeFlags(@PathVariable(TYPE_PARAMETER_NAME) String type,
|
||||
@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
|
||||
@PathVariable(value = DOSSIER_ID_PARAMETER_NAME) String dossierId,
|
||||
@RequestParam(value = "addToDictionary") boolean addToDictionary) {
|
||||
@RequestParam(value = "addToDictionaryAction") boolean addToDictionaryAction) {
|
||||
|
||||
dictionaryService.changeAddToDictionary(type, dossierTemplateId, dossierId, addToDictionary);
|
||||
dictionaryService.changeAddToDictionary(type, dossierTemplateId, dossierId, addToDictionaryAction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -223,7 +223,7 @@ public interface DictionaryResource {
|
||||
void changeFlags(@PathVariable(TYPE_PARAMETER_NAME) String type,
|
||||
@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
|
||||
@PathVariable(DOSSIER_ID_PARAMETER_NAME) String dossierId,
|
||||
@RequestParam(value = "addToDictionary") boolean addToDictionary);
|
||||
@RequestParam(value = "addToDictionaryAction") boolean addToDictionaryAction);
|
||||
|
||||
|
||||
@PostMapping(value = DICTIONARY_REST_PATH + DIFFERENCE + DOSSIER_TEMPLATE_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
|
||||
@ -494,9 +494,9 @@ public class DictionaryService {
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + ADD_UPDATE_DICTIONARY_TYPE + "')")
|
||||
public void changeAddToDictionary(String type, String dossierTemplateId, String dossierId, boolean addToDictionary) {
|
||||
public void changeAddToDictionary(String type, String dossierTemplateId, String dossierId, boolean addToDictionaryAction) {
|
||||
|
||||
dictionaryPersistenceService.updateAddToDictionary(toTypeId(type, dossierTemplateId, dossierId), addToDictionary);
|
||||
dictionaryPersistenceService.updateAddToDictionary(toTypeId(type, dossierTemplateId, dossierId), addToDictionaryAction);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.TypeEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DossierRepository;
|
||||
@ -357,12 +358,14 @@ public class DictionaryPersistenceService {
|
||||
|
||||
|
||||
@Transactional
|
||||
public void updateAddToDictionary(String typeId, boolean addToDictionary) {
|
||||
public void updateAddToDictionary(String typeId, boolean addToDictionaryAction) {
|
||||
|
||||
var typeEntity = getType(typeId);
|
||||
if (typeEntity.isDossierDictionaryOnly()) {
|
||||
typeEntity.setAddToDictionaryAction(addToDictionary);
|
||||
typeEntity.setAddToDictionaryAction(addToDictionaryAction);
|
||||
typeRepository.saveAndFlush(typeEntity);
|
||||
} else {
|
||||
throw new BadRequestException("The addToDictionaryAction flag can only be adjusted for dossierDictionaryOnly-types.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1183,7 +1183,7 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
var type = dictionaryClient.addType(createTypeValue);
|
||||
|
||||
List<TypeValue> customTypes = dictionaryClient.getAllTypes(dossierTemplate.getId(), dossier.getId(), false).getTypes()
|
||||
List<TypeValue> customTypes = dictionaryClient.getAllTypes(dossierTemplate.getId(), dossier.getId(), false).getTypes()
|
||||
.stream()
|
||||
.filter(t -> !t.isSystemManaged())
|
||||
.toList();
|
||||
@ -1213,7 +1213,7 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
|
||||
@Test
|
||||
void testRecreateTypeAndCheckMergedDictionary() {
|
||||
void testRecreateTypeAndCheckMergedDictionary() {
|
||||
|
||||
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
|
||||
var dossier = dossierTesterAndProvider.provideTestDossier(dossierTemplate, "TestDossier");
|
||||
@ -1240,7 +1240,10 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
UpdateEntries updateEntries = new UpdateEntries(newDossierEntries, allEntries);
|
||||
dictionaryClient.updateEntries(type.getType(), type.getDossierTemplateId(), updateEntries, dossier.getId(), DictionaryEntryType.ENTRY);
|
||||
|
||||
List<DictionaryEntryEntity> deleted = entryRepository.findAll().stream().filter(DictionaryEntryEntity::isDeleted).toList();
|
||||
List<DictionaryEntryEntity> deleted = entryRepository.findAll()
|
||||
.stream()
|
||||
.filter(DictionaryEntryEntity::isDeleted)
|
||||
.toList();
|
||||
assertEquals(3, deleted.size());
|
||||
|
||||
var updatedDossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), dossierTemplate.getId(), dossier.getId());
|
||||
@ -1257,7 +1260,10 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
assertEquals(2, deletedType1Entities.size());
|
||||
|
||||
deleted = entryRepository.findAll().stream().filter(DictionaryEntryEntity::isDeleted).toList();
|
||||
deleted = entryRepository.findAll()
|
||||
.stream()
|
||||
.filter(DictionaryEntryEntity::isDeleted)
|
||||
.toList();
|
||||
assertEquals(2, deleted.size());
|
||||
|
||||
// recreation
|
||||
@ -1265,7 +1271,10 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
dictionaryClient.addEntry(type2.getType(), type2.getDossierTemplateId(), templateEntries, false, null, DictionaryEntryType.ENTRY);
|
||||
|
||||
deleted = entryRepository.findAll().stream().filter(DictionaryEntryEntity::isDeleted).toList();
|
||||
deleted = entryRepository.findAll()
|
||||
.stream()
|
||||
.filter(DictionaryEntryEntity::isDeleted)
|
||||
.toList();
|
||||
assertEquals(0, deleted.size());
|
||||
|
||||
deletedType1Entities = typeRepository.findAllTypesByDossierTemplateIdOrDossierId(dossierTemplate.getId(), dossier.getId())
|
||||
@ -1292,6 +1301,72 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChangeFlagsSuccessful() {
|
||||
|
||||
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
|
||||
var dossier1 = dossierTesterAndProvider.provideTestDossier(dossierTemplate, "Dossier1");
|
||||
|
||||
var type1 = dictionaryClient.addType(CreateTypeValue.builder()
|
||||
.type("test_change_flags_true")
|
||||
.label("Test Change Flags True")
|
||||
.hexColor("#123456")
|
||||
.rank(100)
|
||||
.hint(false)
|
||||
.hasDictionary(true)
|
||||
.caseInsensitive(false)
|
||||
.recommendation(false)
|
||||
.addToDictionaryAction(false)
|
||||
.dossierTemplateId(dossierTemplate.getId())
|
||||
.dossierDictionaryOnly(true)
|
||||
.build());
|
||||
dictionaryClient.getAllTypes(dossierTemplate.getId(), dossier1.getId(), false);
|
||||
|
||||
|
||||
dictionaryClient.changeFlags(type1.getType(), dossierTemplate.getId(), dossier1.getId(), true);
|
||||
|
||||
String compositeTypeId1 = type1.getType() + ":" + dossierTemplate.getId() + ":" + dossier1.getId();
|
||||
var updatedTypeEntity1 = typeRepository.findById(compositeTypeId1)
|
||||
.orElseThrow(() -> new AssertionError("Type entity not found in repository"));
|
||||
|
||||
assertThat(updatedTypeEntity1.isAddToDictionaryAction()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChangeFlagsUnsuccessful() {
|
||||
|
||||
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
|
||||
var dossier2 = dossierTesterAndProvider.provideTestDossier(dossierTemplate, "Dossier2");
|
||||
|
||||
var type2 = dictionaryClient.addType(CreateTypeValue.builder()
|
||||
.type("test_change_flags_false")
|
||||
.label("Test Change Flags False")
|
||||
.hexColor("#654321")
|
||||
.rank(101)
|
||||
.hint(false)
|
||||
.hasDictionary(true)
|
||||
.caseInsensitive(false)
|
||||
.recommendation(false)
|
||||
.addToDictionaryAction(false)
|
||||
.dossierTemplateId(dossierTemplate.getId())
|
||||
.dossierDictionaryOnly(false)
|
||||
.build());
|
||||
dictionaryClient.getAllTypes(dossierTemplate.getId(), dossier2.getId(), false);
|
||||
|
||||
|
||||
assertThatThrownBy(() -> dictionaryClient.changeFlags(type2.getType(), dossierTemplate.getId(), dossier2.getId(), true))
|
||||
.isInstanceOf(FeignException.BadRequest.class)
|
||||
.hasMessageContaining("The addToDictionaryAction flag can only be adjusted for dossierDictionaryOnly-types.");
|
||||
|
||||
String compositeTypeId2 = type2.getType() + ":" + dossierTemplate.getId() + ":" + dossier2.getId();
|
||||
var typeEntity2 = typeRepository.findById(compositeTypeId2)
|
||||
.orElseThrow(() -> new AssertionError("Type entity not found in repository"));
|
||||
|
||||
assertThat(typeEntity2.isAddToDictionaryAction()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
private static final class ListContentWithoutOrderAndWithoutDuplicatesComparator<T> implements Comparator<List<? extends T>> {
|
||||
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user