diff --git a/app/controllers/UploadSituation.java b/app/controllers/UploadSituation.java index fb57267cf..5d8cb0de2 100755 --- a/app/controllers/UploadSituation.java +++ b/app/controllers/UploadSituation.java @@ -59,12 +59,14 @@ public class UploadSituation extends Controller { public static final String LOGIN_RESPONSE_CACHED = "loginResponse"; public static final String LISTA_DIPENTENTI_CNR_CACHED = "listaDipendentiCnr"; - + public static final String FILE_PREFIX = "situazioneMensile"; public static final String FILE_SUFFIX = ".txt"; - + public static final String URL_TO_PRESENCE = "url_to_presence"; - + + public static final String DEFAULT_URL_TO_PRESENCE = "https://attestati.rm.cnr.it/attestati/"; + @Inject private static SecurityRules rules; @Inject @@ -79,7 +81,8 @@ public class UploadSituation extends Controller { private static UploadSituationManager updloadSituationManager; /** - * Tab carica data. + * Tab carica data. + * * @param officeId sede */ public static void uploadData(Long officeId) { @@ -87,20 +90,20 @@ public static void uploadData(Long officeId) { Office office = officeDao.getOfficeById(officeId); notFoundIfNull(office); rules.checkIfPermitted(office); - + IWrapperOffice wrOffice = factory.create(office); Optional monthToUpload = wrOffice.nextYearMonthToUpload(); - + //caricare eventuale sessione già presente SessionAttestati sessionAttestati = loadAttestatiLoginCached(); if (sessionAttestati != null && monthToUpload.isPresent()) { - + int year = sessionAttestati.getYear(); int month = sessionAttestati.getMonth(); - + monthToUpload = Optional.fromNullable(new YearMonth(year, month)); - + DipendenteComparedRecap dipendenteComparedRecap = attestatiClient .buildComparedLists(office, sessionAttestati); @@ -110,26 +113,26 @@ public static void uploadData(Long officeId) { render(wrOffice, monthToUpload, sessionAttestati); } - + /** * Modale Cambia il mese e la sede. - * + * * @param officeId sede */ public static void updateSession(Long officeId) { - + Office office = officeDao.getOfficeById(officeId); notFoundIfNull(office); rules.checkIfPermitted(office); - + IWrapperOffice wrOffice = factory.create(office); SessionAttestati sessionAttestati = loadAttestatiLoginCached(); if (sessionAttestati != null) { - YearMonth monthToUpload = new YearMonth(sessionAttestati.getYear(), + YearMonth monthToUpload = new YearMonth(sessionAttestati.getYear(), sessionAttestati.getMonth()); render(wrOffice, sessionAttestati, monthToUpload); - + } else { //sessione scaduta. render(wrOffice); @@ -138,33 +141,35 @@ public static void updateSession(Long officeId) { /** * Tab creazione file. + * * @param officeId sede - * @param year anno - * @param month mese + * @param year anno + * @param month mese */ public static void createFile(Long officeId, Integer year, Integer month) { - + Office office = officeDao.getOfficeById(officeId); notFoundIfNull(office); rules.checkIfPermitted(office); //TODO: costruire la lista degli anni sulla base di tutti gli uffici permessi //e usarla nel template. - + IWrapperOffice wrOffice = factory.create(office); Optional monthToUpload = wrOffice.nextYearMonthToUpload(); render(wrOffice, monthToUpload); } - + /** * Tab creazione file. + * * @param office sede - * @param year anno - * @param month mese + * @param year anno + * @param month mese */ - public static void computeCreateFile(@Valid Office office, - @Required Integer year, @Required Integer month) { - + public static void computeCreateFile(@Valid Office office, + @Required Integer year, @Required Integer month) { + notFoundIfNull(office); rules.checkIfPermitted(office); @@ -184,28 +189,28 @@ public static void computeCreateFile(@Valid Office office, Optional monthToUpload = Optional.of(new YearMonth(year, month)); render("@createFile", wrOffice, monthToUpload); } - + String body = updloadSituationManager.createFile(office, year, month); - String fileName = FILE_PREFIX + office.codeId + " - " + year + month + FILE_SUFFIX; + String fileName = FILE_PREFIX + office.codeId + " - " + year + month + FILE_SUFFIX; renderBinary(IOUtils.toInputStream(body), fileName); } - + /** - * Carica i dati sul personale (sia lato CNR sia lato ePAS confrontando le due liste). - * Se necessario effettua login (in caso di username e password null si cerca la login in cache). - * - * @param office sede - * @param year anno - * @param month mese - * @param attestatiLogin username + * Carica i dati sul personale (sia lato CNR sia lato ePAS confrontando le due liste). Se + * necessario effettua login (in caso di username e password null si cerca la login in cache). + * + * @param office sede + * @param year anno + * @param month mese + * @param attestatiLogin username * @param attestatiPassword pass */ - public static void fetchData(@Valid Office office, Integer year, Integer month, - final String attestatiLogin, final String attestatiPassword, boolean updateSession) { - + public static void fetchData(@Valid Office office, Integer year, Integer month, + final String attestatiLogin, final String attestatiPassword, boolean updateSession) { + rules.checkIfPermitted(office); IWrapperOffice wrOffice = factory.create(office); - + // Sessione in cache SessionAttestati sessionAttestati = loadAttestatiLoginCached(); @@ -225,20 +230,21 @@ public static void fetchData(@Valid Office office, Integer year, Integer month, Optional monthToUpload = Optional.of(new YearMonth(year, month)); render("@changeMonth", wrOffice, monthToUpload, sessionAttestati); } - + //ripulire lo stato della sessione - sessionAttestati = new SessionAttestati(sessionAttestati.getUsernameCnr(), true, + sessionAttestati = new SessionAttestati(sessionAttestati.getUsernameCnr(), true, sessionAttestati.getCookies(), office, year, month); - - sessionAttestati = attestatiClient.login(Play.configuration.getProperty(URL_TO_PRESENCE), + + sessionAttestati = attestatiClient.login(Play.configuration + .getProperty(URL_TO_PRESENCE, DEFAULT_URL_TO_PRESENCE), null, null, sessionAttestati, office, year, month); - + if (sessionAttestati != null) { flash.success("Sessione aggiornata."); } memAttestatiIntoCache(sessionAttestati, null); } - + // Nuovo login e scarico lista dei dipendenti in attestati if (attestatiLogin != null && attestatiPassword != null) { try { @@ -251,7 +257,8 @@ public static void fetchData(@Valid Office office, Integer year, Integer month, month = next.get().getMonthOfYear(); } - sessionAttestati = attestatiClient.login(Play.configuration.getProperty(URL_TO_PRESENCE), + sessionAttestati = attestatiClient.login(Play.configuration + .getProperty(URL_TO_PRESENCE, DEFAULT_URL_TO_PRESENCE), attestatiLogin, attestatiPassword, null, office, year, month); if (!sessionAttestati.isLoggedIn()) { @@ -260,48 +267,48 @@ public static void fetchData(@Valid Office office, Integer year, Integer month, } memAttestatiIntoCache(sessionAttestati, null); - + } catch (AttestatiException e) { flash.error(String.format("Errore durante il login e/o prelevamento della lista " + "dei dipendenti dal sistema degli attestati. Eccezione: {}", e)); UploadSituation.uploadData(office.id); } } else { - + if (sessionAttestati == null || !sessionAttestati.isLoggedIn()) { flash.error("La sessione attestati non è attiva o è scaduta, effettuare nuovamente login."); UploadSituation.uploadData(office.id); } } - + uploadData(office.id); } - + /** * Logout attestati. + * * @param officeId sede */ public static void logoutAttestati(Long officeId) { - + memAttestatiIntoCache(null, null); flash.success("Logout attestati eseguito."); UploadSituation.uploadData(officeId); } - + /** * Elabora i dati di tutte le persone della sede per quel mese. + * * @param office sede - * @param year anno - * @param month mese - * @throws MalformedURLException - * @throws URISyntaxException + * @param year anno + * @param month mese */ public static void processAllPersons(Office office, int year, int month) throws MalformedURLException, URISyntaxException { - + rules.checkIfPermitted(office); - + SessionAttestati sessionAttestati = loadAttestatiLoginCached(); if (sessionAttestati == null || !sessionAttestati.isLoggedIn()) { @@ -319,10 +326,10 @@ public static void processAllPersons(Office office, int year, int month) + "utilizzare l'apposita funzione di cambio mese."); uploadData(office.id); } - + DipendenteComparedRecap dipendenteComparedRecap = attestatiClient .buildComparedLists(office, sessionAttestati); - + List checks = attestatiClient.elaboraDatiDipendenti( Optional.fromNullable(sessionAttestati), dipendenteComparedRecap.getValidDipendenti(), year, month); @@ -344,7 +351,7 @@ public boolean apply(RispostaElaboraDati risposta) { + "1 dipendente. Controllare l'esito."); } else { flash.error("Elaborazione dipendenti effettuata. Sono stati riscontrati problemi per %s" - + " dipendenti. Controllare l'esito.", + + " dipendenti. Controllare l'esito.", risposteNotOk.size()); } @@ -355,16 +362,15 @@ public boolean apply(RispostaElaboraDati risposta) { /** * Elabora i dati della matricola. - * @param officeId sede - * @param matricola matricola - * @param year anno - * @param month mese - * @throws MalformedURLException - * @throws URISyntaxException + * + * @param officeId sede + * @param matricola matricola + * @param year anno + * @param month mese */ public static void processSinglePerson(Long officeId, String matricola, int year, int month) throws MalformedURLException, URISyntaxException { - + Office office = officeDao.getOfficeById(officeId); notFoundIfNull(office); notFoundIfNull(matricola); @@ -386,10 +392,10 @@ public static void processSinglePerson(Long officeId, String matricola, int year + "utilizzare l'apposita funzione di cambio mese."); uploadData(office.id); } - + DipendenteComparedRecap dipendenteComparedRecap = attestatiClient .buildComparedLists(office, sessionAttestati); - + Optional dipendente = Optional.absent(); for (Dipendente dipCached : dipendenteComparedRecap.getValidDipendenti()) { if (dipCached.getMatricola().equals(matricola)) { @@ -405,7 +411,7 @@ public static void processSinglePerson(Long officeId, String matricola, int year } List checks = attestatiClient - .elaboraDatiDipendenti(Optional.fromNullable(sessionAttestati), + .elaboraDatiDipendenti(Optional.fromNullable(sessionAttestati), Lists.newArrayList(dipendente.get()), year, month); Predicate rispostaOk = new Predicate() { @@ -431,7 +437,7 @@ public boolean apply(RispostaElaboraDati risposta) { /** * Modale visualizzazione problemi. - * + * * @param certificatedDataId dati certificati */ public static void showProblems(Long certificatedDataId) { @@ -445,6 +451,7 @@ public static void showProblems(Long certificatedDataId) { /** * Modale visualizzazione dati inviati. + * * @param certificatedDataId dati certificati */ public static void showCertificatedData(Long certificatedDataId) { @@ -457,50 +464,49 @@ public static void showCertificatedData(Long certificatedDataId) { } /** - * Verifica i dati che ePAS invierebbe ad Attestati. Visualizza anche gli eventuali dati mandati - * e gli errori riportati. - * + * Verifica i dati che ePAS invierebbe ad Attestati. Visualizza anche gli eventuali dati mandati e + * gli errori riportati. + * * @param officeId sede */ - public static void checkData(Long officeId, Integer year, Integer month) { - + public static void checkData(Long officeId, Integer year, Integer month) { + Office office = officeDao.getOfficeById(officeId); notFoundIfNull(office); rules.checkIfPermitted(office); - + IWrapperOffice wrOffice = factory.create(office); render(wrOffice, year, month); - + } - + /** * Visualizza i dati certificati per la sede in quel mese. + * * @param office sede - * @param year anno - * @param month mese - * @throws MalformedURLException - * @throws URISyntaxException + * @param year anno + * @param month mese */ public static void performCheckData(Office office, Integer year, Integer month) - throws MalformedURLException, URISyntaxException { + throws MalformedURLException, URISyntaxException { notFoundIfNull(office); rules.checkIfPermitted(office); - + IWrapperOffice wrOffice = factory.create(office); Set people = attestatiClient.officeActivePeopleAsDipendente(office, year, month); List results = attestatiClient.elaboraDatiDipendenti( Optional.absent(), Lists.newArrayList(people), year, month); - + IWrapperFactory wrapper = factory; render("@checkData", results, wrOffice, year, month, wrapper); - + } private static void memAttestatiIntoCache( SessionAttestati sessionAttestati, List listaDipendenti) { - + Cache.set(LOGIN_RESPONSE_CACHED + Security.getUser().get().username, sessionAttestati); Cache.set(LISTA_DIPENTENTI_CNR_CACHED + Security.getUser().get().username, listaDipendenti); } @@ -513,10 +519,4 @@ private static SessionAttestati loadAttestatiLoginCached() { } - - - - - - } diff --git a/docker-compose.yml b/docker-compose.yml index fd1255ec3..e61509237 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,10 @@ postgres: image: postgres:9.4.0 volumes: - - /opt/epas/db/data:/var/lib/postgresql/data - - /etc/localtime:/etc/localtime:ro - - /opt/epas/backups/:/tmp:ro + - /opt/epas/db/data:/var/lib/postgresql/data + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + - /opt/epas/backups/:/tmp:ro # restart: always @@ -16,12 +17,13 @@ nginx: image: jwilder/nginx-proxy:latest ports: - - "80:80" + - "80:80" # - "443:443" volumes: - - /etc/localtime:/etc/localtime:ro - - /var/run/docker.sock:/tmp/docker.sock + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + - /var/run/docker.sock:/tmp/docker.sock # - /opt/epas/certs/:/etc/nginx/certs # restart: always @@ -31,14 +33,16 @@ epas: image: docker-registry.services.iit.cnr.it/epas:latest volumes: - - /opt/epas/logs/:/home/epas/epas/logs - - /opt/epas/attachments:/home/epas/epas/data/attachments - - /opt/epas/backups/:/home/epas/epas/backups - - /etc/localtime:/etc/localtime:ro + - /opt/epas/logs/:/home/epas/epas/logs + - /opt/epas/attachments:/home/epas/epas/data/attachments + - /opt/epas/backups/:/home/epas/epas/backups + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro environment: - VIRTUAL_HOST=localhost # - HTTPS=true # default: false -- Attiva l'utilizzodel protocollo HTTPS +# - URL_ATTESTATI= # default: https://attestati.rm.cnr.it/attestati/ # - CERT_NAME=epas # default: valore specificato in VIRTUAL_HOST -- Specifica un nome diverso per i file del certificato SSL # - DB_HOST= # default: indirizzo assegnato al container postgres linkato # - DB_PORT= # default: 5432 @@ -59,6 +63,6 @@ epas: # - MARK_BACKUP_AFTER=1 # Imposta i server come backup sul proxy links: - - postgres + - postgres # restart: always diff --git a/docker_conf/init b/docker_conf/init index 3709a17bc..97dd6275d 100755 --- a/docker_conf/init +++ b/docker_conf/init @@ -115,6 +115,13 @@ else sudo -u epas -H sed 's/{{SMTP_PROTOCOL}}/'"${SMTP_PROTOCOL}"'/' -i /home/epas/epas/conf/prod.conf fi +if [ -z "${URL_ATTESTATI}" ]; then + sed -n '/URL_ATTESTATI/!p' -i /home/epas/epas/conf/prod.conf +else + sudo -u epas -H sed 's/{{URL_ATTESTATI}}/'"${URL_ATTESTATI}"'/' -i /home/epas/epas/conf/prod.conf +fi + + sudo -u epas -H sed 's/{{SKIP_IP_CHECK}}/'"${SKIP_IP_CHECK}"'/' -i /home/epas/epas/conf/prod.conf sudo -u epas -H sed 's/{{EPAS_SHIB_LOGIN}}/'"${EPAS_SHIB_LOGIN}"'/' -i /home/epas/epas/conf/prod.conf diff --git a/docker_conf/prod.conf b/docker_conf/prod.conf index 1277c6067..68417c3c4 100755 --- a/docker_conf/prod.conf +++ b/docker_conf/prod.conf @@ -24,3 +24,5 @@ %prod.mail.smtp.port={{SMTP_PORT}} %prod.mail.smtp.channel={{SMTP_CHANNEL}} %prod.mail.smtp.protocol={{SMTP_PROTOCOL}} + +%prod.url_to_presence={{URL_ATTESTATI}}