Updated SyncService
This commit is contained in:
parent
7e1643a450
commit
bc97474bd0
|
@ -8,18 +8,33 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import it.cnr.isti.epasmed.sync.SyncService;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class SyncConfiguration {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SyncConfiguration.class);
|
||||
|
||||
@Scheduled(cron = "0 0 7 * * ?")
|
||||
private final SyncService syncService;
|
||||
|
||||
public SyncConfiguration(SyncService syncService) {
|
||||
this.syncService = syncService;
|
||||
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 24 18 * * ?")
|
||||
public void cronJobSch() {
|
||||
|
||||
LocalDateTime start = LocalDateTime.now();
|
||||
logger.info("Scheduled Sync Start : {}", start);
|
||||
|
||||
try {
|
||||
syncService.executeReads();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
LocalDateTime end = LocalDateTime.now();
|
||||
logger.info("Scheduled Sync End : {}", end);
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -69,9 +72,12 @@ public class SyncService {
|
|||
@SuppressWarnings("unused")
|
||||
private static final String SI_TIPO_EMAIL_ISTITUZIONALE = "Istituzionale";
|
||||
private static final String SI_TIPO_EMAIL_CNR = "C.N.R.";
|
||||
private static final String PERSON_DEFAULT_QUALIFICATION = "3";
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SyncService.class);
|
||||
private final SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
@Autowired
|
||||
TabsSIService tabsSIService;
|
||||
@Autowired
|
||||
|
@ -214,13 +220,23 @@ public class SyncService {
|
|||
if (sia.getCodicefiscale() != null && !sia.getCodicefiscale().isEmpty()) {
|
||||
if (sia.getFlag_del() != null && !sia.getFlag_del().isEmpty()) {
|
||||
if (sia.getFlag_del().compareTo(SI_FLAG_DEL_TRUE) != 0) {
|
||||
EPASPersons epasPerson = epasPersonsService.getByFiscalCode(sia.getCodicefiscale());
|
||||
EPASPersons epasPerson = null;
|
||||
try {
|
||||
epasPerson = epasPersonsService.getByFiscalCode(sia.getCodicefiscale());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving person by fiscal code: {}", sia.getCodicefiscale());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
if (epasPerson == null) {
|
||||
EPASPersonsDTO epasPersonsDTO = new EPASPersonsDTO();
|
||||
epasPersonsDTO.setFiscalCode(sia.getCodicefiscale());
|
||||
epasPersonsDTO.setName(sia.getNome());
|
||||
epasPersonsDTO.setSurname(sia.getCognome());
|
||||
epasPersonsDTO.setOfficeId(ISTI_OFFICE_ID);
|
||||
String email = createCNREmail(sia);
|
||||
epasPersonsDTO.setEmail(email);
|
||||
epasPersonsDTO.setQualification(PERSON_DEFAULT_QUALIFICATION);
|
||||
epasPerson = epasPersonsService.create(epasPersonsDTO);
|
||||
logger.info("EPAS Created Person: {}", epasPerson);
|
||||
} else {
|
||||
|
@ -245,6 +261,34 @@ public class SyncService {
|
|||
|
||||
}
|
||||
|
||||
private String createCNREmail(SIAnagrafico sia) {
|
||||
StringBuilder cnrEmail = new StringBuilder();
|
||||
if (sia.getNome() != null && !sia.getNome().isEmpty()) {
|
||||
cnrEmail.append(sia.getNome().toLowerCase());
|
||||
if (sia.getCognome() != null && !sia.getCognome().isEmpty()) {
|
||||
cnrEmail.append(".");
|
||||
cnrEmail.append(sia.getCognome().toLowerCase().trim());
|
||||
}
|
||||
} else {
|
||||
if (sia.getCognome() != null && !sia.getCognome().isEmpty()) {
|
||||
cnrEmail.append(sia.getCognome().toLowerCase().trim());
|
||||
} else {
|
||||
cnrEmail.append("empty");
|
||||
}
|
||||
}
|
||||
cnrEmail.append("@cnr.it");
|
||||
|
||||
try {
|
||||
InternetAddress emailAddr = new InternetAddress(cnrEmail.toString());
|
||||
emailAddr.validate();
|
||||
} catch (AddressException ex) {
|
||||
cnrEmail = new StringBuilder();
|
||||
cnrEmail.append("empty@cnr.it");
|
||||
}
|
||||
|
||||
return cnrEmail.toString();
|
||||
}
|
||||
|
||||
private void syncMail(TabsSI tab) {
|
||||
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
|
||||
logger.error("Invalid Id Flusso for tab: {}", tab);
|
||||
|
@ -263,7 +307,13 @@ public class SyncService {
|
|||
if (se.getTipo() != null && !se.getTipo().isEmpty()) {
|
||||
String emailTipo = se.getTipo().trim();
|
||||
if (!emailTipo.isEmpty()) {
|
||||
EPASPersons epasPerson = epasPersonsService.getByFiscalCode(se.getCf());
|
||||
EPASPersons epasPerson = null;
|
||||
try {
|
||||
epasPerson = epasPersonsService.getByFiscalCode(se.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving person by fiscal code: {}", se.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
if (epasPerson != null) {
|
||||
EPASPersonsDTO epasPersonsDTO = epasPersonsMapper
|
||||
.epasPersonsToEPASPersonsDTO(epasPerson);
|
||||
|
@ -322,7 +372,13 @@ public class SyncService {
|
|||
String tipoRecapitoTelefonico = sit.getTiporecapitotelefonico().trim();
|
||||
if (!tipoRecapitoTelefonico.isEmpty()) {
|
||||
if (tipoRecapitoTelefonico.compareTo(SI_RECAPITO_TELEFONICO_UFFICIO) == 0) {
|
||||
EPASPersons epasPerson = epasPersonsService.getByFiscalCode(sit.getCf());
|
||||
EPASPersons epasPerson = null;
|
||||
try {
|
||||
epasPerson = epasPersonsService.getByFiscalCode(sit.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving person by fiscal code: {}", sit.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
if (epasPerson != null) {
|
||||
EPASPersonsDTO epasPersonsDTO = epasPersonsMapper
|
||||
.epasPersonsToEPASPersonsDTO(epasPerson);
|
||||
|
@ -384,6 +440,9 @@ public class SyncService {
|
|||
EPASGroupsDTO epasGroupsDTO = epasGroupsMapper.epasGroupsToEPASGroupsDTO(groupPresent);
|
||||
epasGroupsDTO.setDescription(sig.getDescrizione());
|
||||
epasGroupsDTO.setName(sig.getSigla());
|
||||
if(epasGroupsDTO.getOfficeId()==null || epasGroupsDTO.getOfficeId().isEmpty()) {
|
||||
epasGroupsDTO.setOfficeId(ISTI_OFFICE_ID);
|
||||
}
|
||||
epasGroupsService.updateById(groupPresent.getId(), epasGroupsDTO);
|
||||
logger.info("EPAS Updated Group: {}", epasGroupsDTO);
|
||||
}
|
||||
|
@ -412,6 +471,9 @@ public class SyncService {
|
|||
EPASGroupsMapper epasGroupsMapper = new EPASGroupsMapper();
|
||||
EPASGroupsDTO epasGroupsDTO = epasGroupsMapper
|
||||
.epasGroupsToEPASGroupsDTO(groupPresent);
|
||||
if(epasGroupsDTO.getOfficeId()==null || epasGroupsDTO.getOfficeId().isEmpty()) {
|
||||
epasGroupsDTO.setOfficeId(ISTI_OFFICE_ID);
|
||||
}
|
||||
epasGroupsService.updateById(groupPresent.getId(), epasGroupsDTO);
|
||||
logger.info("EPAS Delete Group: {}", epasGroupsDTO);
|
||||
}
|
||||
|
@ -447,8 +509,14 @@ public class SyncService {
|
|||
if (sigp.getId() != null && sigp.getId() != 0) {
|
||||
if (sigp.getFlag_del() != null && !sigp.getFlag_del().isEmpty()) {
|
||||
if (sigp.getFlag_del().compareTo(SI_FLAG_DEL_TRUE) != 0) {
|
||||
List<EPASAffiliations> epasAffiliations = epasAffiliationsService
|
||||
.getByPersonFiscalcode(sigp.getCf());
|
||||
List<EPASAffiliations> epasAffiliations = null;
|
||||
try {
|
||||
epasAffiliations = epasAffiliationsService.getByPersonFiscalcode(sigp.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving Affiliations for fiscalcode: {}", sigp.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
if (epasAffiliations != null) {
|
||||
EPASAffiliations affPresent = null;
|
||||
for (EPASAffiliations aff : epasAffiliations) {
|
||||
|
@ -468,7 +536,14 @@ public class SyncService {
|
|||
}
|
||||
}
|
||||
if (groupPresent != null) {
|
||||
EPASPersons epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
|
||||
EPASPersons epasPerson = null;
|
||||
try {
|
||||
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
if (epasPerson != null) {
|
||||
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(
|
||||
sdfDate.format(sigp.getDal()), sdfDate.format(sigp.getAl()),
|
||||
|
@ -492,7 +567,14 @@ public class SyncService {
|
|||
}
|
||||
}
|
||||
if (groupPresent != null) {
|
||||
EPASPersons epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
|
||||
EPASPersons epasPerson = null;
|
||||
try {
|
||||
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
if (epasPerson != null) {
|
||||
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(
|
||||
sdfDate.format(sigp.getDal()), sdfDate.format(sigp.getAl()),
|
||||
|
@ -518,7 +600,14 @@ public class SyncService {
|
|||
}
|
||||
}
|
||||
if (groupPresent != null) {
|
||||
EPASPersons epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
|
||||
EPASPersons epasPerson = null;
|
||||
try {
|
||||
epasPerson = epasPersonsService.getByFiscalCode(sigp.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving person by fiscal code: {}", sigp.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
if (epasPerson != null) {
|
||||
EPASAffiliationsDTO epasAffiliationsDTO = new EPASAffiliationsDTO(
|
||||
sdfDate.format(sigp.getDal()), sdfDate.format(sigp.getAl()),
|
||||
|
@ -529,13 +618,19 @@ public class SyncService {
|
|||
logger.info("EPAS Created Affilation: {}", epasAffiliationNew);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<EPASAffiliations> epasAffiliations = epasAffiliationsService
|
||||
.getByPersonFiscalcode(sigp.getCf());
|
||||
|
||||
List<EPASAffiliations> epasAffiliations = null;
|
||||
try {
|
||||
epasAffiliations = epasAffiliationsService.getByPersonFiscalcode(sigp.getCf());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving Affiliations for fiscal code: {}", sigp.getCf());
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
if (epasAffiliations != null) {
|
||||
EPASAffiliations affPresent = null;
|
||||
for (EPASAffiliations aff : epasAffiliations) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
id,nome,operazioni,id_flusso,last_update
|
||||
1,anagrafico,R,116002,2020-12-07 06:33:01
|
||||
2,mail,R,116214,2020-12-14 06:33:01
|
||||
3,telefoni,R,115866,2020-12-02 06:33:01
|
||||
4,recapiti,R,116214,2020-12-14 06:33:01
|
||||
5,titoli_studio,R,116214,2020-12-14 06:33:01
|
||||
6,gruppi,R,114623,2020-11-15 06:33:03
|
||||
7,gruppo_pers,R,116214,2020-12-14 06:33:01
|
||||
8,posizioni,R,115866,2020-12-02 06:33:01
|
||||
9,proroghe,R,115692,2020-11-28 06:33:02
|
||||
1,anagrafico,R,3758479,2022-01-20 17:00:06
|
||||
2,mail,R,3758613,2022-01-20 17:00:07
|
||||
3,telefoni,R,3757605,2022-01-20 17:00:07
|
||||
4,recapiti,R,3665710,2021-11-26 10:33:00
|
||||
5,titoli_studio,R,2949197,2021-10-29 16:17:37
|
||||
6,gruppi,R,3755892,2022-01-20 18:24:00
|
||||
7,gruppo_pers,R,3759182,2022-01-20 18:24:00
|
||||
8,posizioni,R,3755634,2021-11-30 12:02:16
|
||||
9,proroghe,R,3562140,2021-11-22 15:48:30
|
||||
10,cartellini,W,116175,2020-12-12 04:58:52
|
||||
11,cartellini_rendicontazioni,W,116174,2020-12-12 04:58:52
|
||||
12,pers_orario,W,115869,2020-12-02 04:33:02
|
||||
|
|
|
|
@ -114,7 +114,7 @@ public class EPASStampingsResourceIT {
|
|||
logger.info(userDirectory);
|
||||
List<EPASStampingsDTO> istiStampings = null;
|
||||
try (Stream<String> stream = Files
|
||||
.lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureRapisardaISTI.csv"))) {
|
||||
.lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureAutoCertISTI202112.csv"))) {
|
||||
istiStampings = stream.skip(1).map(istiMapToStampingsDTO).collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
|
@ -214,7 +214,7 @@ public class EPASStampingsResourceIT {
|
|||
logger.info(userDirectory);
|
||||
List<String> list = new ArrayList<>();
|
||||
try (Stream<String> stream = Files
|
||||
.lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureRapisardaISTI.csv"))) {
|
||||
.lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureAutoCertISTI202112.csv"))) {
|
||||
list = stream.collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
|
@ -223,7 +223,7 @@ public class EPASStampingsResourceIT {
|
|||
|
||||
try {
|
||||
FileWriter writer = new FileWriter(
|
||||
"src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureRapisardaISTI2.csv");
|
||||
"src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureAutoCertISTI202112_2.csv");
|
||||
for (String str : list) {
|
||||
writer.write("\""+str+"\"" + System.lineSeparator());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue