RED-6734 - Get merged dossier and template dictionaries #25
@ -292,9 +292,10 @@ public class DictionaryController implements DictionaryResource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dictionary> getMergedDictionaries(@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
|
||||
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME) String dossierId) {
|
||||
return dictionaryService.getMergedDictionaryForType(dossierTemplateId, dossierId);
|
||||
public Dictionary getMergedDictionaries(@PathVariable(TYPE_PARAMETER_NAME) String type,
|
||||
@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
|
||||
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME) String dossierId) {
|
||||
return dictionaryService.getMergedDictionaryForType(type, dossierTemplateId, dossierId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -173,11 +173,12 @@ public interface DictionaryResource {
|
||||
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME, required = false) String dossierId,
|
||||
@RequestParam(value = DICTIONARY_ENTRY_TYPE_PARAM, required = false, defaultValue = DEFAULT_DICTIONARY_ENTRY_TYPE) DictionaryEntryType dictionaryEntryType);
|
||||
|
||||
@GetMapping(value = DICTIONARY_REST_PATH + MERGED + DOSSIER_TEMPLATE_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "Retrieves and merge all dictionary entries for the given dossier template and dossier", description = "None")
|
||||
@GetMapping(value = DICTIONARY_REST_PATH + MERGED + TYPE_PATH_VARIABLE+ DOSSIER_TEMPLATE_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "Retrieves the merged dictionary for the given type, dossier template and dossier", description = "None")
|
||||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successfully retrieved all the dictionary entries"), @ApiResponse(responseCode = "400", description = "Request contains error."), @ApiResponse(responseCode = "404", description = "The entry type is not found.")})
|
||||
List<Dictionary> getMergedDictionaries(@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
|
||||
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME) String dossierId);
|
||||
Dictionary getMergedDictionaries(@PathVariable(TYPE_PARAMETER_NAME) String type,
|
||||
@PathVariable(DOSSIER_TEMPLATE_PARAMETER_NAME) String dossierTemplateId,
|
||||
@RequestParam(value = DOSSIER_ID_PARAMETER_NAME) String dossierId);
|
||||
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@Operation(summary = "Set system colors for redaction")
|
||||
|
||||
@ -293,23 +293,26 @@ public class DictionaryService {
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + READ_DICTIONARY_TYPES + "')")
|
||||
public List<Dictionary> getMergedDictionaryForType(String dossierTemplateId, String dossierId) {
|
||||
public Dictionary getMergedDictionaryForType(String type, String dossierTemplateId, String dossierId) {
|
||||
|
||||
try {
|
||||
if (dossierId != null) {
|
||||
accessControlService.verifyUserHasViewPermissions(dossierId);
|
||||
}
|
||||
var dossierTemplateDictionaries = dictionaryPersistenceService.getAllTypesForDossierTemplate(dossierTemplateId, false);
|
||||
var dossierDictionaries = dictionaryPersistenceService.getAllTypesForDossier(dossierId, false);
|
||||
var dossierTemplateDictionary = dictionaryPersistenceService.getType(toTypeId(type, dossierTemplateId));
|
||||
var typeId = toTypeId(type, dossierTemplateId, dossierId);
|
||||
// create dossier level type if it does not exist
|
||||
dictionaryManagementService.checkForDossierTypeExistenceAndCreate(typeId);
|
||||
var dossierDictionary = dictionaryPersistenceService.getType(typeId);
|
||||
|
||||
var mergedDictionaries = dictionaryMergeService.getMergedDictionary(convertTypes(dossierTemplateDictionaries), convertTypes(dossierDictionaries));
|
||||
var mergedDictionaries = dictionaryMergeService.getMergedDictionary(convertType(dossierTemplateDictionary), convertType(dossierDictionary));
|
||||
return convertMergedDictionaries(mergedDictionaries, dossierTemplateId, dossierId);
|
||||
} catch (AccessDeniedException e) {
|
||||
throw new NotFoundException("Object not found");
|
||||
}
|
||||
}
|
||||
|
||||
private List<Dictionary> convertMergedDictionaries (List<CommonsDictionaryModel> commonsDictionaries, String dossierTemplateId, String dossierId) {
|
||||
private Dictionary convertMergedDictionaries (List<CommonsDictionaryModel> commonsDictionaries, String dossierTemplateId, String dossierId) {
|
||||
List<Dictionary> dictionaries = new ArrayList<>();
|
||||
commonsDictionaries.forEach(cdm -> {
|
||||
var typeId = toTypeId(cdm.getType(), dossierTemplateId, dossierId);
|
||||
@ -346,22 +349,21 @@ public class DictionaryService {
|
||||
dictionaries.add(dict);
|
||||
});
|
||||
|
||||
return dictionaries;
|
||||
return dictionaries.get(0);
|
||||
}
|
||||
|
||||
private List<CommonsDictionaryModel> convertTypes(List<TypeEntity> dictionaries) {
|
||||
private List<CommonsDictionaryModel> convertType(TypeEntity typeEntity) {
|
||||
|
||||
return dictionaries.stream()
|
||||
.map(dm -> CommonsDictionaryModel.builder()
|
||||
.type(dm.getType())
|
||||
.rank(dm.getRank())
|
||||
.color(ColorUtils.convertColor(dm.getHexColor()))
|
||||
.caseInsensitive(dm.isCaseInsensitive())
|
||||
.hint(dm.isHint())
|
||||
.entries(getCommonsEntries(dm.getId(), DictionaryEntryType.ENTRY))
|
||||
.falsePositives(getCommonsEntries(dm.getId(), DictionaryEntryType.FALSE_POSITIVE))
|
||||
.falseRecommendations(getCommonsEntries(dm.getId(), DictionaryEntryType.FALSE_RECOMMENDATION))
|
||||
.build()).collect(Collectors.toList());
|
||||
return List.of(CommonsDictionaryModel.builder()
|
||||
.type(typeEntity.getType())
|
||||
.rank(typeEntity.getRank())
|
||||
.color(ColorUtils.convertColor(typeEntity.getHexColor()))
|
||||
.caseInsensitive(typeEntity.isCaseInsensitive())
|
||||
.hint(typeEntity.isHint())
|
||||
.entries(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.ENTRY))
|
||||
.falsePositives(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.FALSE_POSITIVE))
|
||||
.falseRecommendations(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.FALSE_RECOMMENDATION))
|
||||
.build());
|
||||
}
|
||||
|
||||
private Set<DictionaryEntryModel> getCommonsEntries(String typeId, DictionaryEntryType entryType) {
|
||||
|
||||
@ -403,13 +403,11 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
|
||||
dossier.getDossierId(),
|
||||
DictionaryEntryType.FALSE_RECOMMENDATION);
|
||||
|
||||
List<Dictionary> result = dictionaryClient.getMergedDictionaries(dossierTemplate.getDossierTemplateId(), dossier.getDossierId());
|
||||
assertThat(result).isNotEmpty();
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
Dictionary dict = result.get(0);
|
||||
assertThat(dict.getEntries().size()).isEqualTo(4);
|
||||
assertThat(dict.getFalsePositiveEntries().size()).isEqualTo(3);
|
||||
assertThat(dict.getEntries().size()).isEqualTo(4);
|
||||
Dictionary mergedDict = dictionaryClient.getMergedDictionaries(type.getType(), dossierTemplate.getDossierTemplateId(), dossier.getDossierId());
|
||||
assertThat(mergedDict).isNotNull();
|
||||
assertThat(mergedDict.getEntries().size()).isEqualTo(4);
|
||||
assertThat(mergedDict.getFalsePositiveEntries().size()).isEqualTo(3);
|
||||
assertThat(mergedDict.getEntries().size()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user