Skip to content

Commit

Permalink
chore: fix warnings ♻️ (#6)
Browse files Browse the repository at this point in the history
* chore: fix warnings (WIP)

* chore: fix warnings (WIP)

* chore: fix deprecated methods

* chore: fix warnings (WIP)

* chore: fix warnings (WIP)

* chore: fix warnings (WIP)

* chore: remove TODO

* ci: update Github Actions
  • Loading branch information
jy95 authored Sep 3, 2023
1 parent 85a65e6 commit ef4b804
Show file tree
Hide file tree
Showing 43 changed files with 186 additions and 129 deletions.
50 changes: 49 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,62 @@

version: 2
updates:
# Files stored in repository root
# Files stored in repository builder
- package-ecosystem: "maven"
directory: "/builder"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Files stored in repository super
- package-ecosystem: "maven"
directory: "/super"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Files stored in repository core
- package-ecosystem: "maven"
directory: "/core"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Files stored in repository ehconnector
- package-ecosystem: "maven"
directory: "/ehconnector"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Files stored in repository viewer
- package-ecosystem: "maven"
directory: "/viewer"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Files stored in repository datagenerator
- package-ecosystem: "maven"
directory: "/datagenerator"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Files stored in repository distribution
- package-ecosystem: "maven"
directory: "/distribution"
commit-message:
prefix: chore
include: "scope"
schedule:
interval: "weekly"
# Workflow files stored in the default location of `.github/workflows`
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-comment-artifact-url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
steps:
- uses: 8BitJonny/[email protected]
id: PR
with:
# Only return if PR is still open. (By default it returns PRs in any state.)
filterOutClosed: true
- name: Get Artifact URL & PR Info
if: steps.PR.outputs.pr_found == 'true'
env:
Expand Down
13 changes: 5 additions & 8 deletions core/src/main/java/org/imec/ivlab/core/RangeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.joda.time.Days;
import org.joda.time.Months;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -447,14 +448,10 @@ public LocalDate calculateEndDateForDuration(LocalDate startDate, Duration durat

}

switch (durationUnit) {

case A:
case MO:
case WK:
case D:
endDate = endDate.minusDays(1);

// Vitalink/EVS in the past substract one day for authorized units, to compute the endDate properly
List<TimeUnit> unitsToSubtractOneDay = Arrays.asList(TimeUnit.A, TimeUnit.MO, TimeUnit.WK, TimeUnit.D);
if (unitsToSubtractOneDay.contains(durationUnit)) {
endDate = endDate.minusDays(1);
}

return endDate.toLocalDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import be.fgov.ehealth.standards.kmehr.schema.v1.Kmehrmessage;
import javax.xml.bind.JAXBException;
import org.apache.commons.lang3.StringUtils;

import org.apache.commons.lang3.RegExUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.imec.ivlab.core.exceptions.TransformationException;
Expand Down Expand Up @@ -37,11 +38,11 @@ public static String resetNamespaces(String kmehrContent) {
}

private static String removeNamespaceUsage(String kmehrContent) {
return StringUtils.replacePattern(kmehrContent, "(<|<\\/)(ns\\d*:)", "$1");
return RegExUtils.replacePattern(kmehrContent, "(<|<\\/)(ns\\d*:)", "$1");
}

private static String setDefaultNamespace(String kmehrContent) {
return StringUtils.replacePattern(kmehrContent, "<kmehrmessage(?:[^>]*)>", KMEHRMESSAGE_TAG_WITH_DEFAULT_NAMESPACES);
return RegExUtils.replacePattern(kmehrContent, "<kmehrmessage(?:[^>]*)>", KMEHRMESSAGE_TAG_WITH_DEFAULT_NAMESPACES);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.imec.ivlab.core.kmehr.model.localid.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
import org.imec.ivlab.core.kmehr.model.localid.URI;
import org.imec.ivlab.core.kmehr.model.localid.URIType;

public class URIConverter {

private final static Logger log = LogManager.getLogger(URIConverter.class);
//private final static Logger log = LogManager.getLogger(URIConverter.class);


public static URI convertToUpdate(URI uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void setList(List<KmehrWithReference> list) {
}

@Override
@SuppressWarnings({"unchecked" })
public List<KmehrWithReference> getIdentifiables() {
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void setMsEntries(List<MSEntry> msEntries) {


@Override
@SuppressWarnings({"unchecked" })
public List<MSEntry> getIdentifiables() {
return msEntries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static void setReferenceDate(Kmehrmessage kmehrmessage, LocalDate referen
patient = new PersonType();
}

// TODO To fix
patient.setRecorddatetime(
new DateTime(
referenceDate.getYear(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ClassesUtil {

private final static Logger log = LogManager.getLogger(ClassesUtil.class);

@SuppressWarnings({ "unchecked"})
public static <T> List<Class<T>> getClasses(String packagePath, Class<T> clazzFilter) {

List<Class<T>> testClasses = new ArrayList<>();
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/imec/ivlab/core/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public static LocalDateTime toLocalDateTime(Calendar calendar) {
return LocalDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault());
}

// TODO issue here
public static LocalDateTime toLocalDateTime(org.joda.time.DateTime calendar) {
if (calendar == null) {
return null;
Expand Down
64 changes: 18 additions & 46 deletions core/src/main/java/org/imec/ivlab/core/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.StandardOpenOption;

public class FileUtil {

Expand All @@ -23,19 +23,10 @@ public static void copyFile(File sourceFile, File destFile) throws IOException {
destFile.createNewFile();
}

FileChannel source = null;
FileChannel destination = null;

try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
try(FileInputStream source = new FileInputStream(sourceFile)) {
try(FileOutputStream destination = new FileOutputStream(destFile)) {
FileChannel sourceChannel = source.getChannel();
destination.getChannel().transferFrom(sourceChannel, 0, sourceChannel.size());
}
}
}
Expand Down Expand Up @@ -67,42 +58,23 @@ public static void createDirectoriesRecursively(String directoryPath) {

public static boolean isLocked(File file) {

FileLock lock = null;
FileChannel channel = null;

try { // Get a file channel for the file
channel = new RandomAccessFile(file, "rw").getChannel();

// Try acquiring the lock without blocking.
// lock is null or exception if the file is already locked.
try {
lock = channel.tryLock();
} catch (OverlappingFileLockException e){
return true;
try (FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) {
FileLock lock = channel.tryLock();
if (lock != null) {
lock.release(); // Release the lock immediately
return false; // File is not locked
} else {
return true; // File is locked
}

} catch (Exception e) {
} catch (OverlappingFileLockException e) {
return true;
} catch (IOException e) {
// Handle any exceptions
log.error("Error when checking if file is locked: ", e);
} finally {
if (lock != null && lock.isValid()) {
try {
lock.release();
} catch (IOException e1) {
log.error("Error when trying to release lock", e1);
}
}
if (channel != null && channel.isOpen()) {
try {
channel.close();
} catch (IOException e) {
log.error("Error when trying to close channel", e);
}
}
}

return false;

}
return false; // Unable to determine lock status, assuming not locked
}

public static File appendTextToFilename(File file, String textToAppend) {
return new File(FilenameUtils.getFullPath(file.getAbsolutePath()) + FilenameUtils.getBaseName(file.getAbsolutePath()) + textToAppend + "." + FilenameUtils.getExtension(file.getAbsolutePath()));
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/imec/ivlab/core/util/JAXBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public static String marshal(Object o, String rootName) throws JAXBException {

QName qName = new QName(nsURI, rootName);

JAXBElement root = new JAXBElement(qName, o.getClass(), o);
@SuppressWarnings({ "rawtypes", "unchecked" })
JAXBElement<?> root = new JAXBElement(qName, o.getClass(), o);

jaxbMarshaller.marshal(root, writer);

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/imec/ivlab/core/util/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static String commonParent(String[] files) {
outerloop:
while (charPosition < shortestPathLength) {
Character charPosFirstPath = paths[0].charAt(charPosition);
innerloop:
for (int i = 0; i < paths.length; i++) {
char charAtPosition = paths[i].charAt(charPosition);
if (charAtPosition != charPosFirstPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static File getProjectDirectoryAsFile(String relativeProjectDirectory) {
// found resource inside jar
File fileAsInternalResource = getProjectDirectoryJarMode(relativeProjectDirectory);
if (fileAsInternalResource != null && fileAsInternalResource.exists()) {
log.info("Running as jar. Found resource: " + fileAsExternalResource.getAbsolutePath());
log.info("Running as jar. Found resource: " + fileAsInternalResource.getAbsolutePath());
return fileAsInternalResource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ private TemplateEngineUtils() {

public static String generate(Map<String, Object> ctx, String templateLocation) {
VelocityContext context = new VelocityContext();
Iterator template = ctx.entrySet().iterator();
Iterator<Map.Entry<String, Object>> template = ctx.entrySet().iterator();

while(template.hasNext()) {
Map.Entry writer = (Map.Entry)template.next();
context.put((String)writer.getKey(), writer.getValue());
Map.Entry<String, Object> writer = template.next();
context.put(writer.getKey(), writer.getValue());
}

if (!templateCache.containsKey(templateLocation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
//import lombok.extern.log4j.Log4j2;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
Expand All @@ -24,7 +24,7 @@
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.imec.ivlab.core.util.IOUtils;

@Log4j2
//@Log4j2
@Getter
public class VaccinationMappingReader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import be.fgov.ehealth.standards.kmehr.schema.v1.Kmehrmessage;
import be.fgov.ehealth.standards.kmehr.schema.v1.TextWithLayoutType;
import be.fgov.ehealth.standards.kmehr.schema.v1.TransactionType;
import lombok.extern.log4j.Log4j2;
//import lombok.extern.log4j.Log4j2;

@Test
@Log4j2
//@Log4j2
public class DiaryNoteEVSRefExtractorTest extends TestCase {

private EVSREF evsref = new EVSREF("TESTREF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,21 @@ public void logPatientAuditTrail(Patient patient, String actorId) throws Gateway

if (patientAuditTrail == null || patientAuditTrail.getTransactionaccesslist() == null || patientAuditTrail.getTransactionaccesslist().getTransactionaccesses() == null) {
LOG.info("No audit trail found for patient: " + patient.inReadableFormat());
}

for (Transactionaccess transactionaccess : patientAuditTrail.getTransactionaccesslist().getTransactionaccesses()) {
LOG.info("------------- Audit trail entry -------------");
LOG.info("accessed at: " + transactionaccess.getAccessdatetime());
if (transactionaccess.getHcparties() != null) {
for (HcpartyType hcpartyType : transactionaccess.getHcparties()) {
LOG.info("Accessed by: " + org.imec.ivlab.core.util.StringUtils.joinWith(" ", hcpartyType.getFirstname(), hcpartyType.getFamilyname(), hcpartyType.getName()));
} else {
for (Transactionaccess transactionaccess : patientAuditTrail.getTransactionaccesslist().getTransactionaccesses()) {
LOG.info("------------- Audit trail entry -------------");
LOG.info("accessed at: " + transactionaccess.getAccessdatetime());
if (transactionaccess.getHcparties() != null) {
for (HcpartyType hcpartyType : transactionaccess.getHcparties()) {
LOG.info("Accessed by: " + org.imec.ivlab.core.util.StringUtils.joinWith(" ", hcpartyType.getFirstname(), hcpartyType.getFamilyname(), hcpartyType.getName()));
}
}
LOG.info("break the glass info: " + transactionaccess.getBreaktheglass());
LOG.info("patient: " + transactionaccess.getPatient().getIds().get(0).getValue());
LOG.info("transaction: " + transactionaccess.getTransaction().getIds().get(0).getValue());
}
LOG.info("break the glass info: " + transactionaccess.getBreaktheglass());
LOG.info("patient: " + transactionaccess.getPatient().getIds().get(0).getValue());
LOG.info("transaction: " + transactionaccess.getTransaction().getIds().get(0).getValue());
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void run() {

boolean incurableErrorOccurred = false;
Throwable incurableError = null;
boolean breakTheGlass = false;
//boolean breakTheGlass = false;

File outputDirectory = new File(exportInstruction.getExportDir().getAbsolutePath() + File.separator + monitorInstruction.getPatient().getKey());

Expand Down
Loading

0 comments on commit ef4b804

Please sign in to comment.