322 lines
11 KiB
Java
Executable File
322 lines
11 KiB
Java
Executable File
package it.cnr.isti.epasmed.web.rest.sync;
|
|
|
|
//import java.security.SecureRandom;
|
|
//import java.util.concurrent.TimeUnit;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import io.github.jhipster.web.util.HeaderUtil;
|
|
import it.cnr.isti.epasmed.domain.TabsSI;
|
|
import it.cnr.isti.epasmed.security.AuthoritiesConstants;
|
|
import it.cnr.isti.epasmed.sync.SyncService;
|
|
|
|
/**
|
|
* REST controller for managing Table SI.
|
|
* <p>
|
|
* This class accesses the {@link TabsSI} entity.
|
|
*
|
|
*
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api")
|
|
public class SyncResource {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SyncResource.class);
|
|
|
|
@Value("${jhipster.clientApp.name}")
|
|
private String applicationName;
|
|
|
|
private final SyncService syncService;
|
|
|
|
public SyncResource(SyncService syncService) {
|
|
this.syncService = syncService;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/reads} : Retrieve new flux from Sistema Informativo and
|
|
* update ePAS.
|
|
*
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/reads")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncReads() throws Exception {
|
|
logger.info("REST request syncReads()");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeReads();
|
|
logger.info("Sincronizzazione delle Letture eseguita correttamente.");
|
|
res = ResponseEntity.noContent().headers(
|
|
HeaderUtil.createAlert(applicationName, "Sincronizzazione delle letture eseguita corretamente.", ""))
|
|
.build();
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writes} : Report from ePAS and update SistemaInformativo.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writes")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\") or hasAuthority(\"" + AuthoritiesConstants.USER
|
|
+ "\")")
|
|
public ResponseEntity<Void> syncWrites(@RequestParam("year") String year, @RequestParam("month") String month)
|
|
throws Exception {
|
|
logger.info("REST request syncWrites");
|
|
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWrites(year, month);
|
|
String msg = "Rendicontazione eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writesscheduled} : Report from ePAS and update
|
|
* SistemaInformativo scheduled info.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesscheduled")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\") or hasAuthority(\"" + AuthoritiesConstants.USER
|
|
+ "\")")
|
|
public ResponseEntity<Void> syncWritesScheduled(@RequestParam("year") String year,
|
|
@RequestParam("month") String month) throws Exception {
|
|
logger.info("REST request syncWritesScheduled");
|
|
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesScheduled(year, month);
|
|
String msg = "Sincronizzazione delle scritture schedulate eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/test} : Test api.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/test")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncTest(@RequestParam("year") String year, @RequestParam("month") String month)
|
|
throws Exception {
|
|
logger.info("REST request syncTest");
|
|
//delayTest();
|
|
ResponseEntity<Void> res;
|
|
logger.info("Selezionato {} - {} ", year, month);
|
|
String msg = "Test eseguito correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
// throw new Exception("Some errors in server!");
|
|
// } catch (Throwable e) {
|
|
// logger.error("Errore nella sincronizzazione delle letture: {}",
|
|
// e.getLocalizedMessage(), e);
|
|
// res = new ResponseEntity<Object>(e.getLocalizedMessage(), new HttpHeaders(),
|
|
// HttpStatus.INTERNAL_SERVER_ERROR);
|
|
// }
|
|
|
|
return res;
|
|
}
|
|
|
|
/* private void delayTest() {
|
|
SecureRandom rand = new SecureRandom();
|
|
int upperbound = 1000;
|
|
// Generating random values from 0 - 999
|
|
// using nextInt()
|
|
int random1 = rand.nextInt(upperbound);
|
|
logger.debug("Test: "+random1);
|
|
|
|
try {
|
|
TimeUnit.SECONDS.sleep(5);
|
|
} catch (InterruptedException e) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
*/
|
|
/**
|
|
* {@code GET /sync/writesOrario} : Report Orario from ePAS and update
|
|
* SistemaInformativo.
|
|
*
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesOrario")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncWritesOrario() throws Exception {
|
|
logger.info("REST request syncWritesOrario)");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesOrario();
|
|
String msg = "Rendicontazione dell'orario eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writesTimeCards} : Reports TimeCards from ePAS in
|
|
* SistemaInformativo.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesTimeCards")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncWritesTimeCards(@RequestParam("year") String year,
|
|
@RequestParam("month") String month) throws Exception {
|
|
logger.info("REST request syncWritesTimeCards)");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesTimeCards(year, month);
|
|
String msg = "Rendicontazione dei cartellini eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writesSingleTimeCards} : Reports SingleTimeCards from ePAS
|
|
* in SistemaInformativo.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @param fiscalCode the fiscal code
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesSingleTimeCards")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\") or hasAuthority(\"" + AuthoritiesConstants.USER
|
|
+ "\")")
|
|
public ResponseEntity<Void> syncSingleWritesTimeCards(@RequestParam("year") String year,
|
|
@RequestParam("month") String month, @RequestParam("fiscalCode") String fc) throws Exception {
|
|
logger.info("REST request syncSingleWritesTimeCards)");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesSingleTimeCards(year, month, fc);
|
|
String msg = "Rendicontazione del cartellino eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writesOffSiteWorks} : Reports Off Site Works from ePAS in
|
|
* SistemaInformativo.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesOffSiteWorks")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncWritesOffSiteWorks(@RequestParam("year") String year,
|
|
@RequestParam("month") String month) throws Exception {
|
|
logger.info("REST request syncWritesOffSiteWorks)");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesOffSiteWorks(year, month);
|
|
String msg = "Rendicontazione del lavoro fuori sede eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writesLeaves} : Reports Leaves from ePAS in
|
|
* SistemaInformativo.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesLeaves")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncWritesLeaves(@RequestParam("year") String year, @RequestParam("month") String month)
|
|
throws Exception {
|
|
logger.info("REST request syncWritesLeaves)");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesLeaves(year, month);
|
|
String msg = "Rendicontazione delle Aspettative eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* {@code GET /sync/writesPersonWorkingTime} : Reports Person Working Time from
|
|
* ePAS in SistemaInformativo.
|
|
*
|
|
* @param year the year.
|
|
* @param month the month.
|
|
* @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with
|
|
* status {@code 400 (Bad Request)} if there is a error.
|
|
* @throws Exception
|
|
*
|
|
*
|
|
*/
|
|
@GetMapping("/sync/writesPersonWorkingTime")
|
|
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
|
|
public ResponseEntity<Void> syncWritesPersonWorkingTime(@RequestParam("year") String year,
|
|
@RequestParam("month") String month) throws Exception {
|
|
logger.info("REST request syncWritesPersonWorkingTime)");
|
|
ResponseEntity<Void> res;
|
|
syncService.executeWritesPersonWorkingTime(year, month);
|
|
String msg = "Rendicontazione di Pers_Orario eseguita correttamente.";
|
|
logger.info(msg);
|
|
res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build();
|
|
|
|
return res;
|
|
}
|
|
|
|
}
|