Pull request #228: RED-2276: Fixed sonar bug findings
Merge in RED/redaction-service from RED-2276 to master * commit '34daa4c22c3b5c8692f2f5f3056a633f9ec09649': RED-2276: Fixed sonar bug findings
This commit is contained in:
commit
bee124f394
@ -1,5 +1,7 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.redaction.model;
|
package com.iqser.red.service.redaction.v1.server.redaction.model;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -8,6 +10,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.DictionaryEntry;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Dictionary {
|
public class Dictionary {
|
||||||
|
|
||||||
@ -61,11 +65,11 @@ public class Dictionary {
|
|||||||
public boolean containsValue(String type, String value) {
|
public boolean containsValue(String type, String value) {
|
||||||
|
|
||||||
return localAccessMap.containsKey(type) && localAccessMap.get(type)
|
return localAccessMap.containsKey(type) && localAccessMap.get(type)
|
||||||
.getEntries()
|
.getEntries().stream().map(DictionaryEntry::getValue).collect(toSet())
|
||||||
.contains(value) || localAccessMap.containsKey(type) && localAccessMap.get(type)
|
.contains(value) || localAccessMap.containsKey(type) && localAccessMap.get(type)
|
||||||
.getLocalEntries()
|
.getLocalEntries()
|
||||||
.contains(value) || localAccessMap.containsKey(RECOMMENDATION_PREFIX + type) && localAccessMap.get(RECOMMENDATION_PREFIX + type)
|
.contains(value) || localAccessMap.containsKey(RECOMMENDATION_PREFIX + type) && localAccessMap.get(RECOMMENDATION_PREFIX + type)
|
||||||
.getEntries()
|
.getEntries().stream().map(DictionaryEntry::getValue).collect(toSet())
|
||||||
.contains(value) || localAccessMap.containsKey(RECOMMENDATION_PREFIX + type) && localAccessMap.get(RECOMMENDATION_PREFIX + type)
|
.contains(value) || localAccessMap.containsKey(RECOMMENDATION_PREFIX + type) && localAccessMap.get(RECOMMENDATION_PREFIX + type)
|
||||||
.getLocalEntries()
|
.getLocalEntries()
|
||||||
.contains(value);
|
.contains(value);
|
||||||
|
|||||||
@ -89,7 +89,7 @@ public class EntityRedactionService {
|
|||||||
String imageId = IdBuilder.buildId(image.getPosition(), image.getPage());
|
String imageId = IdBuilder.buildId(image.getPosition(), image.getPage());
|
||||||
for (ManualImageRecategorization imageRecategorization : analyzeRequest.getManualRedactions()
|
for (ManualImageRecategorization imageRecategorization : analyzeRequest.getManualRedactions()
|
||||||
.getImageRecategorization()) {
|
.getImageRecategorization()) {
|
||||||
if (imageRecategorization.getStatus().equals(AnnotationStatus.APPROVED) && imageRecategorization.getId()
|
if (imageRecategorization.getStatus().equals(AnnotationStatus.APPROVED) && imageRecategorization.getId().getId()
|
||||||
.equals(imageId)) {
|
.equals(imageId)) {
|
||||||
image.setType(imageRecategorization.getType());
|
image.setType(imageRecategorization.getType());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -240,7 +240,7 @@ public class RedactionLogMergeService {
|
|||||||
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, manualRedactionEntry
|
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, manualRedactionEntry
|
||||||
.getId().getId(), dossierTemplateId);
|
.getId().getId(), dossierTemplateId);
|
||||||
redactionLogEntry.setPositions(convertPositions(manualRedactionEntry.getPositions()));
|
redactionLogEntry.setPositions(convertPositions(manualRedactionEntry.getPositions()));
|
||||||
redactionLogEntry.setComments(comments.get(manualRedactionEntry.getId()));
|
redactionLogEntry.setComments(comments.get(manualRedactionEntry.getId().getId()));
|
||||||
redactionLogEntries.add(redactionLogEntry);
|
redactionLogEntries.add(redactionLogEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,7 +140,12 @@ public class EntitySearchUtils {
|
|||||||
public void addEntitiesWithHigherRank(Set<Entity> entities, Entity found, Dictionary dictionary) {
|
public void addEntitiesWithHigherRank(Set<Entity> entities, Entity found, Dictionary dictionary) {
|
||||||
|
|
||||||
if (entities.contains(found)) {
|
if (entities.contains(found)) {
|
||||||
Entity existing = entities.stream().filter(entity -> entity.equals(found)).findFirst().get();
|
Optional<Entity> existingOptional = entities.stream().filter(entity -> entity.equals(found)).findFirst();
|
||||||
|
if(!existingOptional.isPresent()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var existing = existingOptional.get();
|
||||||
|
|
||||||
if (dictionary.getDictionaryRank(existing.getType()) <= dictionary.getDictionaryRank(found.getType())) {
|
if (dictionary.getDictionaryRank(existing.getType()) <= dictionary.getDictionaryRank(found.getType())) {
|
||||||
entities.remove(found);
|
entities.remove(found);
|
||||||
entities.add(found);
|
entities.add(found);
|
||||||
@ -164,7 +169,11 @@ public class EntitySearchUtils {
|
|||||||
|
|
||||||
for(Entity toAdd: toBeAdded){
|
for(Entity toAdd: toBeAdded){
|
||||||
if (existing.contains(toAdd)) {
|
if (existing.contains(toAdd)) {
|
||||||
Entity existingEntity = existing.stream().filter(entity -> entity.equals(toAdd)).findFirst().get();
|
Optional<Entity> existingOptional = existing.stream().filter(entity -> entity.equals(toAdd)).findFirst();
|
||||||
|
if(!existingOptional.isPresent()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var existingEntity = existingOptional.get();
|
||||||
existingEntity.getEngines().addAll(toAdd.getEngines());
|
existingEntity.getEngines().addAll(toAdd.getEngines());
|
||||||
} else {
|
} else {
|
||||||
existing.add(toAdd);
|
existing.add(toAdd);
|
||||||
|
|||||||
@ -60,7 +60,8 @@ public class PdfSegmentationService {
|
|||||||
try {
|
try {
|
||||||
//create tempFile
|
//create tempFile
|
||||||
File tempFile = File.createTempFile("document", ".pdf");
|
File tempFile = File.createTempFile("document", ".pdf");
|
||||||
IOUtils.copy(documentInputStream, new FileOutputStream(tempFile));
|
try (var fos = new FileOutputStream(tempFile)) {
|
||||||
|
IOUtils.copy(documentInputStream, fos);
|
||||||
|
|
||||||
// initialize required variables
|
// initialize required variables
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
@ -127,9 +128,12 @@ public class PdfSegmentationService {
|
|||||||
|
|
||||||
IOUtils.close(pdDocument);
|
IOUtils.close(pdDocument);
|
||||||
|
|
||||||
tempFile.delete();
|
if(!tempFile.delete()){
|
||||||
|
log.warn("Could not delete tmp file");
|
||||||
|
}
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (pdDocument != null) {
|
if (pdDocument != null) {
|
||||||
pdDocument.close();
|
pdDocument.close();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user