diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java index 0277898..9fee9f0 100755 --- a/src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/sync/SyncResource.java @@ -5,6 +5,8 @@ import java.net.URISyntaxException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; @@ -43,157 +45,185 @@ public class SyncResource { * {@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. - * - + * @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with + * status {@code 400 (Bad Request)} if there is a error. + * + * */ @GetMapping("/sync/reads") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") - public ResponseEntity syncReads() throws URISyntaxException { + public ResponseEntity syncReads() throws URISyntaxException { logger.info("REST request syncReads()"); - ResponseEntity res; + ResponseEntity res; try { syncService.executeReads(); logger.info("Sincronizzazione delle Letture eseguita correttamente."); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - "Sincronizzazione delle letture eseguita corretamente.","")).build(); + res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, + "Sincronizzazione delle letture eseguita corretamente.", "")).build(); } catch (Throwable e) { logger.error("Errore nella sincronizzazione delle letture: {}", e.getLocalizedMessage(), e); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - "Errore nella sincronizzazione delle letture: {}", e.getLocalizedMessage())).build(); + res=new ResponseEntity( + e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); } - return res; + return res; } - - - + /** - * {@code GET /sync/writes} : Report from ePAS and - * update SistemaInformativo. + * {@code GET /sync/writes} : Report from ePAS and update SistemaInformativo. * - * @param year the year. + * @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. - * - + * @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with + * status {@code 400 (Bad Request)} if there is a error. + * + * */ @GetMapping("/sync/writes") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") - public ResponseEntity syncWrites(@RequestParam("year") String year, - @RequestParam("month") String month) throws URISyntaxException { + public ResponseEntity syncWrites(@RequestParam("year") String year, @RequestParam("month") String month) + throws URISyntaxException { logger.info("REST request syncWrites"); - ResponseEntity res; + ResponseEntity res; try { - syncService.executeWrites(year,month); - String msg="Rendicontazione eseguita correttamente."; + syncService.executeWrites(year, month); + String msg = "Rendicontazione eseguita correttamente."; logger.info(msg); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - msg,"")).build(); + res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build(); } catch (Throwable e) { logger.error("Errore nella rendicontazione: {}", e.getLocalizedMessage(), e); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - "Errore nella rendicontazione: {}", e.getLocalizedMessage())).build(); + res=new ResponseEntity( + e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); } - return res; + return res; } - + /** - * {@code GET /sync/writesOrario} : Report Orario from ePAS and - * update SistemaInformativo. + * {@code GET /sync/test} : Test api. * - * @return the {@link ResponseEntity} with status {@code 201 (Executed)} - * or with status {@code 400 (Bad Request)} if there is a error. - * - + * @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. + * + * + */ + @GetMapping("/sync/test") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity syncTest(@RequestParam("year") String year, @RequestParam("month") String month) + throws URISyntaxException { + logger.info("REST request syncTest"); + + ResponseEntity res; + try { + 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 nel test: {}", e.getLocalizedMessage(), e); + //res = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR). + // headers(HeaderUtil.createFailureAlert(applicationName, false, "Test", "Test", errore)).body(errore); + //res = ResponseEntity.noContent() + //.headers(HeaderUtil.createFailureAlert(applicationName, false, null, null, errore)).build(); + res=new ResponseEntity( + e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); + } + return res; + } + + /** + * {@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. + * + * */ @GetMapping("/sync/writesOrario") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") - public ResponseEntity syncWritesOrario() throws URISyntaxException { + public ResponseEntity syncWritesOrario() throws URISyntaxException { logger.info("REST request syncWritesOrario)"); - ResponseEntity res; + ResponseEntity res; try { syncService.executeWritesOrario(); - String msg="Rendicontazione dell'orario eseguita correttamente."; + String msg = "Rendicontazione dell'orario eseguita correttamente."; logger.info(msg); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - msg,"")).build(); + res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build(); } catch (Throwable e) { logger.error("Errore nella rendicontazione dell'orario: {}", e.getLocalizedMessage(), e); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - "Errore nella rendicontazione dell'orario: {}", e.getLocalizedMessage())).build(); + res=new ResponseEntity( + e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); } - return res; + return res; } - - + /** - * {@code GET /sync/writesTimeCards} : Reports TimeCards from ePAS - * in SistemaInformativo. + * {@code GET /sync/writesTimeCards} : Reports TimeCards from ePAS in + * SistemaInformativo. * - * @param year the year. + * @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. - * - + * @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with + * status {@code 400 (Bad Request)} if there is a error. + * + * */ @GetMapping("/sync/writesTimeCards") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") - public ResponseEntity syncWritesTimeCards(@RequestParam("year") String year, + public ResponseEntity syncWritesTimeCards(@RequestParam("year") String year, @RequestParam("month") String month) throws URISyntaxException { logger.info("REST request syncWritesTimeCards)"); - ResponseEntity res; + ResponseEntity res; try { - syncService.executeWritesTimeCards(year,month); - String msg="Rendicontazione dei cartellini eseguita correttamente."; + syncService.executeWritesTimeCards(year, month); + String msg = "Rendicontazione dei cartellini eseguita correttamente."; logger.info(msg); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - msg,"")).build(); + res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build(); } catch (Throwable e) { logger.error("Errore nella rendicontazione dei cartellini: {}", e.getLocalizedMessage(), e); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - "Errore nella rendicontazione dei cartellini: {}", e.getLocalizedMessage())).build(); + res=new ResponseEntity( + e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); } - return res; + return res; } - + /** - * {@code GET /sync/writesOffSiteWorks} : Reports Off Site Works from ePAS - * in SistemaInformativo. + * {@code GET /sync/writesOffSiteWorks} : Reports Off Site Works from ePAS in + * SistemaInformativo. * - * @param year the year. + * @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. - * - + * @return the {@link ResponseEntity} with status {@code 201 (Executed)} or with + * status {@code 400 (Bad Request)} if there is a error. + * + * */ @GetMapping("/sync/writesOffSiteWorks") @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") - public ResponseEntity syncWritesOffSiteWorks(@RequestParam("year") String year, + public ResponseEntity syncWritesOffSiteWorks(@RequestParam("year") String year, @RequestParam("month") String month) throws URISyntaxException { logger.info("REST request syncWritesOffSiteWorks)"); - ResponseEntity res; + ResponseEntity res; try { - syncService.executeWriteOffSiteWorks(year,month); - String msg="Rendicontazione del lavoro fuori sede eseguita correttamente."; + syncService.executeWriteOffSiteWorks(year, month); + String msg = "Rendicontazione del lavoro fuori sede eseguita correttamente."; logger.info(msg); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - msg,"")).build(); + res = ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, msg, "")).build(); } catch (Throwable e) { logger.error("Errore nella rendicontazione del lavoro fuori sede: {}", e.getLocalizedMessage(), e); - res=ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, - "Errore nella rendicontazione del lavoro fuori sede: {}", e.getLocalizedMessage())).build(); + res=new ResponseEntity( + e.getLocalizedMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); } - return res; + return res; } - + } diff --git a/src/main/webapp/app/layouts/navbar/navbar.component.html b/src/main/webapp/app/layouts/navbar/navbar.component.html index 158b954..a7bfb3d 100755 --- a/src/main/webapp/app/layouts/navbar/navbar.component.html +++ b/src/main/webapp/app/layouts/navbar/navbar.component.html @@ -49,6 +49,12 @@