diff --git a/.github/scripts/cleanup_docker.sh b/.github/scripts/cleanup_docker.sh deleted file mode 100644 index 4d4a786b..00000000 --- a/.github/scripts/cleanup_docker.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -# Docker Cleanup Script - -echo "=====================================" -echo " Starting Docker Cleanup " -echo "=====================================" - -# Remove stopped containers -echo "Removing stopped containers..." -docker container prune -f - -# Remove unused volumes -echo "Removing unused volumes..." -docker volume ls -q | grep -v -E "qualitylab-pro-backend_mysql-volume|quality-lab-pro-react-plotly_qualitylab_node_modules|quality-lab-pro-react-plotly_qualitylab_public" | xargs -r docker volume rm - - -# Remove unused images -echo "Removing unused images..." -docker image prune -a -f - -# Remove unused networks -echo "Removing unused networks..." -docker network prune -f - -# Remove build cache -echo "Removing build cache..." -docker builder prune -a -f - -echo "=====================================" -echo " Docker Cleanup Completed " -echo "=====================================" - -# Show disk usage after cleanup -echo "Disk usage after cleanup:" -docker system df - -exit 0 \ No newline at end of file diff --git a/.github/scripts/cleanup_system.sh b/.github/scripts/cleanup_system.sh new file mode 100644 index 00000000..dce992f3 --- /dev/null +++ b/.github/scripts/cleanup_system.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Docker Cleanup Script + +echo "=====================================" +echo " Starting Docker Cleanup " +echo "=====================================" + +echo "Remove everything unused" +docker system prune -a -f + +echo "=====================================" +echo " Docker Cleanup Completed " +echo "=====================================" + +echo "Disk usage after cleanup:" +docker system df + +echo "=====================================" +echo " Starting System Cleanup " +echo "=====================================" +echo "Clearing system cache..." +sync +echo 3 > /proc/sys/vm/drop_caches + +echo "Memory usage after cleanup:" +free -h + +echo "=====================================" +echo " Starting APT Cleanup " +echo "=====================================" + +echo "Cleaning APT cache..." +apt-get clean -y + +echo "Removing unused packages..." +apt-get autoremove -y + +echo "Removing old downloaded archive files..." +apt-get autoclean -y + +echo "Current disk usage:" +df -h + +echo "=====================================" +echo " Cleanup Complete " +echo "=====================================" + +exit 0 \ No newline at end of file diff --git a/.github/scripts/bk.json b/.github/scripts/trivy.yml similarity index 80% rename from .github/scripts/bk.json rename to .github/scripts/trivy.yml index 079183cf..ae108a97 100644 --- a/.github/scripts/bk.json +++ b/.github/scripts/trivy.yml @@ -1,6 +1,6 @@ name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@master with: scan-type: 'fs' scan-ref: '.' diff --git a/.github/workflows/backend-deploy.yml b/.github/workflows/backend-deploy.yml index bac3f1f3..4d5ee11a 100644 --- a/.github/workflows/backend-deploy.yml +++ b/.github/workflows/backend-deploy.yml @@ -114,10 +114,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Cleanup Docker resources + - name: Running cleanup script run: | - chmod +x ./.github/scripts/cleanup_docker.sh - ./.github/scripts/cleanup_docker.sh + chmod +x ./.github/scripts/cleanup_system.sh + ./.github/scripts/cleanup_system.sh notify: runs-on: [ self-hosted, linux, x64, backend ] diff --git a/README.md b/README.md index f083c677..ac06c248 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # QualityLab Pro-API RESTful for internal laboratory quality control. -[![Docker Image CI/CD](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/docker-image.yml/badge.svg?branch=master)](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/docker-image.yml) +[![Docker Image CI/CD](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/backend-deploy.yml/badge.svg?branch=master)](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/backend-deploy.yml)

+ Em desenvolvimento

diff --git a/src/main/java/leonardo/labutilities/qualitylabpro/configs/rest/WebConfig.java b/src/main/java/leonardo/labutilities/qualitylabpro/configs/rest/WebConfig.java index 89bb2460..eacde2c9 100644 --- a/src/main/java/leonardo/labutilities/qualitylabpro/configs/rest/WebConfig.java +++ b/src/main/java/leonardo/labutilities/qualitylabpro/configs/rest/WebConfig.java @@ -2,8 +2,23 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.web.config.EnableSpringDataWebSupport; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import leonardo.labutilities.qualitylabpro.utils.components.StringToLocalDateTimeConverter; + @Configuration @EnableSpringDataWebSupport -public class WebConfig { -} \ No newline at end of file +public class WebConfig implements WebMvcConfigurer { + + private final StringToLocalDateTimeConverter dateTimeConverter; + + public WebConfig(StringToLocalDateTimeConverter dateTimeConverter) { + this.dateTimeConverter = dateTimeConverter; + } + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(dateTimeConverter); + } +} diff --git a/src/main/java/leonardo/labutilities/qualitylabpro/utils/components/StringToLocalDateTimeConverter.java b/src/main/java/leonardo/labutilities/qualitylabpro/utils/components/StringToLocalDateTimeConverter.java index 5216cbda..d63175cb 100644 --- a/src/main/java/leonardo/labutilities/qualitylabpro/utils/components/StringToLocalDateTimeConverter.java +++ b/src/main/java/leonardo/labutilities/qualitylabpro/utils/components/StringToLocalDateTimeConverter.java @@ -1,21 +1,58 @@ package leonardo.labutilities.qualitylabpro.utils.components; import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.Arrays; +import java.util.List; @Component public class StringToLocalDateTimeConverter implements Converter { - private static final DateTimeFormatter FORMATTER = - DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + private static final List DATE_FORMATTERS = Arrays.asList( + DateTimeFormatter.ISO_DATE_TIME, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"), + DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"), + DateTimeFormatter.ofPattern("yyyy-MM-dd"), DateTimeFormatter.ofPattern("dd/MM/yyyy")); - @Override - @NonNull - public LocalDateTime convert(@NonNull String source) { - return LocalDateTime.parse(source, FORMATTER); - } + @Override + public LocalDateTime convert(String source) { + if (source == null || source.trim().isEmpty()) { + return null; + } + + // Sanitize input + source = sanitizeDate(source); + + DateTimeParseException lastException = null; + + for (DateTimeFormatter formatter : DATE_FORMATTERS) { + try { + if (source.length() <= 10) { + LocalDate date = LocalDate.parse(source, formatter); + return LocalDateTime.of(date, LocalTime.MIDNIGHT); + } else { + return LocalDateTime.parse(source, formatter); + } + } catch (DateTimeParseException e) { + lastException = e; + } + } + + throw new IllegalArgumentException("Unable to parse date: " + source, lastException); + } + + private String sanitizeDate(String date) { + return date.trim().replaceAll("--", "-") // Fix double dashes + .replaceAll("\\s+", " ") // Fix multiple spaces + .replaceAll("T\\s", "T") // Fix space after T + .replaceAll("\\s(\\d:\\d)", "T$1") // Add T between date and time if missing + .replaceAll("(\\d)(\\s00:00:00)", "$1T00:00:00"); // Standardize midnight time + // format + } }