RED-161: replace hard-coded hint-type with dictionary-service query

This commit is contained in:
cheng 2020-07-22 22:54:05 +02:00
parent 94827a417f
commit c8375a1ad9
3 changed files with 14 additions and 6 deletions

View File

@ -39,7 +39,7 @@
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>configuration-service-api-v1</artifactId>
<version>1.0.2</version>
<version>1.0.5.1</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>

View File

@ -1,6 +1,8 @@
package com.iqser.red.service.redaction.v1.server.redaction.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -32,6 +34,12 @@ public class DictionaryService {
@Getter
private Map<String, float[]> entryColors = new HashMap<>();
@Getter
private List<String> hintTypes = new ArrayList<>();
@Getter
private List<String> caseSensitiveTypes = new ArrayList<>();
public void updateDictionary() {
long version = dictionaryClient.getVersion();
@ -47,6 +55,8 @@ public class DictionaryService {
if (typeResponse != null && !CollectionUtils.isEmpty(typeResponse.getTypes())) {
entryColors = typeResponse.getTypes().stream().collect(Collectors.toMap(TypeResult::getType, TypeResult::getColor));
dictionary = entryColors.keySet().stream().collect(Collectors.toMap(type -> type, s -> dictionaryClient.getDictionaryForType(s).getEntries().stream().collect(Collectors.toSet())));
hintTypes = typeResponse.getTypes().stream().filter(TypeResult::isHint).map(TypeResult::getType).collect(Collectors.toList());
caseSensitiveTypes = typeResponse.getTypes().stream().filter(TypeResult::isCaseSensitive).map(TypeResult::getType).collect(Collectors.toList());
}
} catch (FeignException e) {
log.warn("Got some unknown feignException", e);

View File

@ -4,6 +4,7 @@ import java.awt.Color;
import java.io.IOException;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
@ -208,17 +209,14 @@ public class AnnotationHighlightService {
return dictionaryService.getEntryColors().get(entity.getType());
}
private boolean isHint(Entity entity) {
// TODO in RED-161.
if (entity.getType().equalsIgnoreCase("vertebrate") || entity.getType()
.equalsIgnoreCase("no_redaction_indicator")) {
List<String> hintTypes = dictionaryService.getHintTypes();
if (!CollectionUtils.isEmpty(hintTypes) && hintTypes.contains(entity.getType())) {
return true;
}
return false;
}
private void visualizeTextBlock(TextBlock textBlock, PDPageContentStream contentStream) throws IOException {
contentStream.setStrokingColor(Color.LIGHT_GRAY);