Skip to content

Commit

Permalink
Merge pull request #51 from consiglionazionaledellericerche/50-invoca…
Browse files Browse the repository at this point in the history
…re-le-stored-procedure-oracle-senza-passare-da-jpa

Chiamate le stored procedure Oracle sanza utilizzare JPA.
criluc authored May 28, 2024
2 parents ba2976c + 163b4d5 commit a65c5c2
Showing 8 changed files with 79 additions and 50 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<version>3.2.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>it.cnr.iit.epas.timesheet</groupId>
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
@Configuration
@OpenAPIDefinition(
info = @Info(title = "ePAS UGov PJ Timesheet",
version = "0.1.0",
version = "0.2.0",
description = "ePAS UGov PJ Timesheet è il servizio per l'integrazione dei dati delle presenze/assenze presenti"
+ "in ePAS con le tabelle di frontiera Oracle di UGov PJ UWeb Timesheet Intime di Cineca"),
servers = {
Original file line number Diff line number Diff line change
@@ -16,18 +16,15 @@
*/
package it.cnr.iit.epas.timesheet.ugovpj.repo;

import io.hypersistence.utils.spring.repository.BaseJpaRepository;
import it.cnr.iit.epas.timesheet.ugovpj.model.PersonTimeDetail;
import jakarta.transaction.Transactional;
import java.util.Optional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;

import io.hypersistence.utils.spring.repository.BaseJpaRepository;
import it.cnr.iit.epas.timesheet.ugovpj.model.PersonTimeDetail;
import jakarta.transaction.Transactional;

/**
* Repository per l'accesso e la gestione dei dati del PersonTimeDetail.
@@ -44,22 +41,6 @@ public interface PersonTimeDetailRepo
@Query(value = "DELETE FROM PersonTimeDetail ptd")
void truncateTable();

@Procedure(name = PersonTimeDetail.LOAD_DETAILS_PROCEDURE_NAME)
void loadDetails();

@Procedure(name = PersonTimeDetail.LOAD_DETAILS_JOB_PROCEDURE_NAME)
void loadDetailsJob();

@Transactional
@Modifying
@Query(value = "call IE_PJ.TS_P_CARICA_MARCATURE()", nativeQuery = true)
void loadDetailsNative();

@Transactional
@Modifying
@Query(value = "call IE_PJ.TS_P_CARICA_MARCATURE_JOB()", nativeQuery = true)
void loadDetailsJobNative();

@Query(value = "SELECT MAX(ptd.id) FROM PersonTimeDetail ptd")
Optional<Long> findMaxid();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2024 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package it.cnr.iit.epas.timesheet.ugovpj.service;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
* Servizio per invocare le stored procedure Oracle.
*
* @author Cristian Lucchesi
*/
@Slf4j
@Service
public class PersonTimeDetailLoadService {

private final String LOAD_DETAILS_PROCEDURE_NAME = "IE_PJ.TS_P_CARICA_MARCATURE";
private final String LOAD_DETAILS_JOB_PROCEDURE_NAME = "IE_PJ.TS_P_CARICA_MARCATURE_JOB";

@PersistenceContext
private EntityManager entityManager;

@Value("${spring.jpa.properties.hibernate.default_schema}")
private String dbSchema;

public void loadDetails() {
log.info("Sto per effetuare la chiamata alla stored procedure {}", LOAD_DETAILS_PROCEDURE_NAME);
entityManager.createStoredProcedureQuery(
String.format("%s.%s", dbSchema, LOAD_DETAILS_PROCEDURE_NAME))
.execute();
log.info("Terminata la chiamata alla stored procedure {}", LOAD_DETAILS_PROCEDURE_NAME);
}

public void loadDetailsJob() {
log.info("Sto per effetuare la chiamata alla stored procedure {}", LOAD_DETAILS_JOB_PROCEDURE_NAME);
entityManager.createStoredProcedureQuery(
String.format("%s.%s", dbSchema, LOAD_DETAILS_JOB_PROCEDURE_NAME))
.execute();
log.info("Terminata la chiamata alla stored procedure {}", LOAD_DETAILS_JOB_PROCEDURE_NAME);
}

}
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@ public class SyncService {

private final PersonTimeDetailRepo repo;
private final TimeDetailTypeService typeService;
private final PersonTimeDetailLoadService detailLoadService;

private final EpasClient epasClient;
private final TimesheetConfig timesheetConfig;
@@ -299,17 +300,8 @@ public void deleteAllPersonTimeDetails() {
* nella tabella definitiva.
*/
public void loadDetails() {
repo.loadDetails();
repo.loadDetailsJob();
}

/**
* Invoca le stored procedure per il caricamento dei dati delle marcature
* nella tabella definitiva utilizzando native query.
*/
public void loadDetailsNative() {
repo.loadDetailsNative();
repo.loadDetailsJobNative();
detailLoadService.loadDetails();
detailLoadService.loadDetailsJob();
}

}
Original file line number Diff line number Diff line change
@@ -107,20 +107,6 @@ public ResponseEntity<Void> loadDetails() {
return ResponseEntity.ok().build();
}

@Operation(
summary = "Effettua il caricamento definitivo dei dati delle presenze/assenza, invocando le apposite "
+ "stored procedures (in modo SQL nativo, senza utilizzare Spring Data).")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "Stored procedure di caricamento definitivo dei dati invocate correttamente")
})
@PostMapping("/loadDetailsNative")
public ResponseEntity<Void> loadDetailsNative() {
log.debug("Richiesta caricamento definitivo dati tramite stored procedure (native)");
syncService.loadDetailsNative();
return ResponseEntity.ok().build();
}

@Operation(
summary = "Effettua la sincronizzazione dei dati di presenza/assenza di un singolo ufficio "
+ "in un singolo mese.")
11 changes: 11 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa

spring.jpa.properties.hibernate.default_schema=

# Informazioni per l'accesso di questo servizio ai servizi REST di ePAS
epas.server-url=http://localhost:9000
epas.username=epas.timesheet
@@ -12,4 +14,13 @@ epas.password=timesheet
security.username=epas.timesheet
security.password=timesheet

# Informazioni interne al servizio per la gestione dei dati delle presenze/assenze
timesheet.stampings-type=N
timesheet.days-in-the-past=90
timesheet.all-day-presence-codes[0]=assign_all_day
timesheet.all-day-presence-codes[1]=complete_day_and_add_overtime
timesheet.delete-before-sync-all=true

timesheet.number.length.max=6

caching.spring.timeDetailTypes=60000

0 comments on commit a65c5c2

Please sign in to comment.