findbugs and pmd cleanup
This commit is contained in:
parent
d3a2919b27
commit
874569cf76
@ -24,12 +24,8 @@ public class ControllerAdvice {
|
||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(value = NullPointerException.class)
|
||||
public ErrorMessage handleContentNotFoundException(NullPointerException e) {
|
||||
if (e != null) {
|
||||
log.error(e.getMessage(), e);
|
||||
return new ErrorMessage(OffsetDateTime.now(), e.getMessage());
|
||||
}
|
||||
log.error("Nullpointer exception at ", e);
|
||||
return new ErrorMessage(OffsetDateTime.now(), "Nullpointer exception");
|
||||
log.error(e.getMessage(), e);
|
||||
return new ErrorMessage(OffsetDateTime.now(), e.getMessage());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
|
||||
@ -51,7 +51,7 @@ public class DictionaryController implements DictionaryResource {
|
||||
// To check whether the type exists, type should not be added into database implicitly by addEntry.
|
||||
Type typeResult = dictionaryPersistenceService.getType(typeId);
|
||||
|
||||
List<String> entriesToSearch = new ArrayList<>();
|
||||
// List<String> entriesToSearch = new ArrayList<>();
|
||||
|
||||
long currentVersion = typeResult.getVersion();
|
||||
if (removeCurrent) {
|
||||
@ -70,11 +70,11 @@ public class DictionaryController implements DictionaryResource {
|
||||
entryPersistenceService.deleteEntries(typeId, removed, currentVersion + 1);
|
||||
entryPersistenceService.addEntry(typeId, added, currentVersion + 1);
|
||||
|
||||
entriesToSearch.addAll(added);
|
||||
entriesToSearch.addAll(removed);
|
||||
// entriesToSearch.addAll(added);
|
||||
// entriesToSearch.addAll(removed);
|
||||
} else {
|
||||
entryPersistenceService.addEntry(typeId, cleanEntries, currentVersion + 1);
|
||||
entriesToSearch.addAll(cleanEntries);
|
||||
// entriesToSearch.addAll(cleanEntries);
|
||||
}
|
||||
|
||||
dictionaryPersistenceService.incrementVersion(typeId);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.iqser.red.service.file.management.v1.server.controller;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.iqser.red.service.file.management.v1.server.service.DossierService;
|
||||
import com.iqser.red.service.file.management.v1.server.service.FileStatusService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
@ -10,12 +11,14 @@ import com.iqser.red.service.persistence.service.v1.api.model.ImportCsvResponse;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.FileAttributesGeneralConfiguration;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.data.dossier.*;
|
||||
import com.iqser.red.service.persistence.service.v1.api.resources.FileAttributesResource;
|
||||
import com.iqser.red.service.persistence.service.v1.api.utils.SuppressFBWarnings;
|
||||
import com.opencsv.CSVParser;
|
||||
import com.opencsv.CSVParserBuilder;
|
||||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.CSVReaderBuilder;
|
||||
import com.opencsv.exceptions.CsvValidationException;
|
||||
import com.opencsv.exceptions.CsvException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -24,10 +27,12 @@ import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class FileAttributesController implements FileAttributesResource {
|
||||
@ -130,20 +135,19 @@ public class FileAttributesController implements FileAttributesResource {
|
||||
}
|
||||
|
||||
|
||||
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
|
||||
private List<List<String>> getCsvRecords(byte[] csv, String delimiter) {
|
||||
|
||||
CSVParser parser = new CSVParserBuilder().withSeparator(delimiter.charAt(0)).build();
|
||||
|
||||
List<List<String>> records = new ArrayList<>();
|
||||
try (CSVReader csvReader = new CSVReaderBuilder(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(csv))))
|
||||
|
||||
try (CSVReader csvReader = new CSVReaderBuilder(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(csv), StandardCharsets.UTF_8)))
|
||||
.withCSVParser(parser)
|
||||
.build()) {
|
||||
String[] values = null;
|
||||
while ((values = csvReader.readNext()) != null) {
|
||||
records.add(Arrays.asList(values));
|
||||
}
|
||||
} catch (IOException | CsvValidationException e) {
|
||||
e.printStackTrace();
|
||||
records.addAll(csvReader.readAll().stream().map(Lists::newArrayList).collect(Collectors.toList()));
|
||||
} catch (IOException | CsvException e) {
|
||||
log.error("Failed to process CSV", e);
|
||||
}
|
||||
|
||||
return records;
|
||||
|
||||
@ -17,6 +17,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -223,7 +225,7 @@ public class FileService {
|
||||
}
|
||||
|
||||
private String generateFileId(BinaryFileRequest file) {
|
||||
return hashFunction.hashBytes((file.getFilename() + file.getDossierId()).getBytes()).toString();
|
||||
return hashFunction.hashBytes((file.getFilename() + file.getDossierId()).getBytes(StandardCharsets.UTF_8)).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,10 +5,12 @@ import static java.util.stream.Collectors.toList;
|
||||
import java.time.Instant;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.InternalServerErrorException;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.data.dossier.Dossier;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -43,10 +45,14 @@ public class LicenseReportService {
|
||||
licenseReportRequest.setRequestId(UUID.randomUUID().toString());
|
||||
}
|
||||
CachedReportData cachedReportData = cachedReports.get(licenseReportRequest);
|
||||
if(cachedReportData == null){
|
||||
throw new InternalServerErrorException("Report not loaded");
|
||||
}
|
||||
|
||||
LicenseReport licenseReport = new LicenseReport();
|
||||
licenseReport.setNumberOfAnalyzedPages(cachedReportData.getTotalPagesAnalyzed());
|
||||
licenseReport.setNumberOfAnalyzedFiles(cachedReportData.getData().size());
|
||||
licenseReport.setNumberOfOcrFiles(cachedReportData.getData().stream().filter(reportData -> reportData.getNumberOfOcrPages() > 0).collect(toList()).size());
|
||||
licenseReport.setNumberOfOcrFiles((int) cachedReportData.getData().stream().filter(reportData -> reportData.getNumberOfOcrPages() > 0).count());
|
||||
licenseReport.setNumberOfOcrPages(cachedReportData.getTotalOcrPages());
|
||||
licenseReport.setNumberOfDossiers(cachedReportData.getNumberOfDossiers());
|
||||
licenseReport.setNumberOfAnalyses(cachedReportData.getTotalNumberOfAnalyses());
|
||||
|
||||
@ -336,7 +336,7 @@ public class ManualRedactionService {
|
||||
@SuppressWarnings("PMD")
|
||||
public void updateRemoveRedactionStatus(String dossierId, String fileId, String annotationId, AnnotationStatus annotationStatus) {
|
||||
|
||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
|
||||
IdRemoval idRemoval = removeRedactionPersistenceService.findRemoveRedaction(fileId, annotationId);
|
||||
if (idRemoval.isRemoveFromDictionary()) {
|
||||
@ -344,7 +344,7 @@ public class ManualRedactionService {
|
||||
RedactionLog redactionLog = fileManagementStorageService.getRedactionLog(dossierId, fileId);
|
||||
RedactionLogEntry redactionLogEntry = redactionLog.getRedactionLogEntry()
|
||||
.stream()
|
||||
.filter(entry -> entry.getId().equals(idRemoval.getId()))
|
||||
.filter(entry -> entry.getId().equals(idRemoval.getId().getId()))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
@ -409,7 +409,7 @@ public class ManualRedactionService {
|
||||
@SuppressWarnings("PMD")
|
||||
public void updateAddRedactionStatus(String dossierId, String fileId, String annotationId, AnnotationStatus annotationStatus) {
|
||||
|
||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
|
||||
ManualRedactionEntry manualRedactionEntry = addRedactionPersistenceService.findAddRedaction(fileId, annotationId);
|
||||
if (manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()) {
|
||||
|
||||
@ -72,7 +72,10 @@ public class FileSystemBackedArchiver implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
tempFile.delete();
|
||||
boolean res = tempFile.delete();
|
||||
if(!res){
|
||||
log.warn("Failed to delete temp file");
|
||||
}
|
||||
zipOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
log.debug("Failed to close FileSystemBackedArchiver");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user