Added Off Site Work support

This commit is contained in:
Giancarlo Panichi 2022-07-29 19:41:29 +02:00
parent 18e1e55553
commit c81a54f25b
13 changed files with 546 additions and 39 deletions

View File

@ -0,0 +1,98 @@
package it.cnr.isti.epasmed.epas.client;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import it.cnr.isti.epasmed.config.ApplicationProperties;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
@Component
public class EPASOffSiteWorksClient {
private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
@Qualifier("RestTemplateForSecondUser")
RestTemplate rt;
@Autowired
ApplicationProperties appProps;
public List<EPASPersonDays> getListByPersonId(String id, String year, String month) {
log.info("Retrieving Off Site Works List by id: {}", id);
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("id", id);
uriVariables.put("year", year);
uriVariables.put("month", month);
ResponseEntity<List<EPASPersonDays>> responseEntity = rt.exchange(appProps.getDatasourceEpasRest().getRestUrl()
+ "/v3/personDays/offSiteWorkByPersonAndMonth?id={id}&year={year}&month={month}",
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASPersonDays>>() {
}, uriVariables);
List<EPASPersonDays> listEPASPersonDays = responseEntity.getBody();
log.info("Retrieved Off Site Works List: {}", listEPASPersonDays);
return listEPASPersonDays;
}
public List<EPASPersonDays> getListByPersonFiscalCode(String fc, String year, String month) {
log.info("Retrieving Off Site Works List by fiscalcode: {}", fc);
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("fiscalCode", fc);
uriVariables.put("year", year);
uriVariables.put("month", month);
ResponseEntity<List<EPASPersonDays>> responseEntity = rt.exchange(appProps.getDatasourceEpasRest().getRestUrl()
+ "/v3/personDays/offSiteWorkByPersonAndMonth?fiscalCode={fiscalCode}&year={year}&month={month}",
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASPersonDays>>() {
}, uriVariables);
List<EPASPersonDays> listEPASPersonDays = responseEntity.getBody();
log.info("Retrieved Off Site Works List: {}", listEPASPersonDays);
return listEPASPersonDays;
}
public List<EPASPersonDays> getListByPersonEmail(String email, String year, String month) {
log.info("Retrieving Off Site Works List by email: {}", email);
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("email", email);
uriVariables.put("year", year);
uriVariables.put("month", month);
ResponseEntity<List<EPASPersonDays>> responseEntity = rt.exchange(appProps.getDatasourceEpasRest().getRestUrl()
+ "/v3/personDays/offSiteWorkByPersonAndMonth?email={email}&year={year}&month={month}",
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASPersonDays>>() {
}, uriVariables);
List<EPASPersonDays> listEPASPersonDays = responseEntity.getBody();
log.info("Retrieved Off Site Works List: {}", listEPASPersonDays);
return listEPASPersonDays;
}
public List<EPASPersonDays> getListByOfficeCodeId(String id, String year, String month) {
log.info("Retrieving Off Site Works List by office code id: {}", id);
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("sedeId", id);
uriVariables.put("year", year);
uriVariables.put("month", month);
ResponseEntity<List<EPASPersonDays>> responseEntity = rt.exchange(appProps.getDatasourceEpasRest().getRestUrl()
+ "/v3/personDays/offSiteWorkByPersonAndMonth?sedeId={sedeId}&year={year}&month={month}",
HttpMethod.GET, null, new ParameterizedTypeReference<List<EPASPersonDays>>() {
}, uriVariables);
List<EPASPersonDays> listEPASPersonDays = responseEntity.getBody();
log.info("Retrieved Off Site Works List: {}", listEPASPersonDays);
return listEPASPersonDays;
}
}

View File

@ -18,7 +18,7 @@ public class EPASWorkingTimeTypes implements Serializable {
private String externalId;
private String horizontal;
private String id;
private String office;
private EPASOffice office;
private String updatedAt;
private EPASWorkingTimeTypeDays[] workingTimeTypeDays;

View File

@ -0,0 +1,33 @@
package it.cnr.isti.epasmed.epas.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import it.cnr.isti.epasmed.epas.client.EPASOffSiteWorksClient;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
@Service
public class EPASOffSiteWorksService {
@Autowired
EPASOffSiteWorksClient epasOffSiteWorksClient;
public List<EPASPersonDays> getListByPersonId(String id, String year, String month) {
return epasOffSiteWorksClient.getListByPersonId(id, year, month);
}
public List<EPASPersonDays> getListByPersonFiscalCode(String fc, String year, String month) {
return epasOffSiteWorksClient.getListByPersonFiscalCode(fc, year, month);
}
public List<EPASPersonDays> getListByPersonEmail(String email, String year, String month) {
return epasOffSiteWorksClient.getListByPersonEmail(email, year, month);
}
public List<EPASPersonDays> getListByOfficeCodeId(String id, String year, String month) {
return epasOffSiteWorksClient.getListByOfficeCodeId(id, year, month);
}
}

View File

@ -6,9 +6,11 @@ import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
@ -31,6 +33,7 @@ import it.cnr.isti.epasmed.epas.model.EPASAffiliations;
import it.cnr.isti.epasmed.epas.model.EPASGroups;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
import it.cnr.isti.epasmed.epas.model.EPASPersons;
import it.cnr.isti.epasmed.epas.model.EPASStampings;
import it.cnr.isti.epasmed.epas.model.EPASTimeCards;
import it.cnr.isti.epasmed.epas.model.EPASValidates;
import it.cnr.isti.epasmed.epas.model.EPASWorkingTimeTypes;
@ -74,10 +77,9 @@ public class SyncService {
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
@ -113,6 +115,7 @@ public class SyncService {
@Autowired
EPASWorkingTimeTypesService epasWorkingTimeTypesService;
@Autowired
EPASTimeCardsService epasTimeCardsService;
@Autowired
EPASValidatesService epasValidatesService;
@ -162,6 +165,21 @@ public class SyncService {
}
public void executeTimeCardsWrites() throws Exception {
borario = false;
bcartellini = false;
bcartellini_rendicontazioni = false;
bpers_orario = false;
blavoro_fuori_sede = false;
baspettative = false;
List<TabsSI> tabsSI = tabsSIService.getAllTabsSI();
Long fluxId = siMasterLogService.startFluxWrites();
writeTimeCardsData(fluxId, tabsSI);
siMasterLogService.closeFluxWrites(fluxId, writeTabs());
}
private void readData(List<TabsSI> tabsSI) {
// TabsSI posizioniTab = null;
// TabsSI prorogheTab = null;
@ -440,7 +458,7 @@ public class SyncService {
EPASGroupsDTO epasGroupsDTO = epasGroupsMapper.epasGroupsToEPASGroupsDTO(groupPresent);
epasGroupsDTO.setDescription(sig.getDescrizione());
epasGroupsDTO.setName(sig.getSigla());
if(epasGroupsDTO.getOfficeId()==null || epasGroupsDTO.getOfficeId().isEmpty()) {
if (epasGroupsDTO.getOfficeId() == null || epasGroupsDTO.getOfficeId().isEmpty()) {
epasGroupsDTO.setOfficeId(ISTI_OFFICE_ID);
}
epasGroupsService.updateById(groupPresent.getId(), epasGroupsDTO);
@ -471,7 +489,7 @@ public class SyncService {
EPASGroupsMapper epasGroupsMapper = new EPASGroupsMapper();
EPASGroupsDTO epasGroupsDTO = epasGroupsMapper
.epasGroupsToEPASGroupsDTO(groupPresent);
if(epasGroupsDTO.getOfficeId()==null || epasGroupsDTO.getOfficeId().isEmpty()) {
if (epasGroupsDTO.getOfficeId() == null || epasGroupsDTO.getOfficeId().isEmpty()) {
epasGroupsDTO.setOfficeId(ISTI_OFFICE_ID);
}
epasGroupsService.updateById(groupPresent.getId(), epasGroupsDTO);
@ -798,6 +816,42 @@ public class SyncService {
}
}
private void writeTimeCardsData(Long fluxId, List<TabsSI> tabsSI) throws Exception {
for (TabsSI tab : tabsSI) {
logger.info("TabSI: {}", tab);
if (tab.getOperazioni() != null && !tab.getOperazioni().isEmpty()
&& tab.getOperazioni().compareTo("W") == 0) {
if (tab.getNome() == null || tab.getNome().isEmpty()) {
continue;
}
switch (tab.getNome()) {
// case "orario":
// syncOrario(fluxId, tab);
// break;
// case "pers_orario":
// syncPersOrario(fluxId,tab);
// break;
case "cartellini":
break;
case "cartellini_rendicontazioni":
syncCartelliniRendicontazioni(fluxId, tab);
break;
// case "lavoro_fuori_sede":
// syncLavoroFuoriSede(fluxId,tab);
// break;
// case "aspettative":
// syncAspettative(fluxId,tab);
// break;
default:
break;
}
}
}
}
private void syncOrario(Long fluxId, TabsSI tab) {
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
logger.error("Invalid Id Flusso for tab: {}", tab);
@ -840,7 +894,7 @@ public class SyncService {
}
}
private void syncCartelliniRendicontazioni(Long fluxId, TabsSI tab) {
private void syncCartelliniRendicontazioni(Long fluxId, TabsSI tab) throws Exception {
if (tab.getIdFlusso() == null || tab.getIdFlusso().longValue() == 0) {
logger.error("Invalid Id Flusso for tab: {}", tab);
return;
@ -857,13 +911,18 @@ public class SyncService {
YearMonth nextMonthToSent = YearMonth.of(year, month);
nextMonthToSent = nextMonthToSent.plusMonths(1);
EPASValidates epasValidates = epasValidatesService.getValidatesByOfficeCodeId(ISTI_OFFICE_CODEID,
String.valueOf(nextMonthToSent.getYear()), String.valueOf(nextMonthToSent.getMonthValue()));
String yearRef = String.valueOf(nextMonthToSent.getYear());
String monthRef = String.valueOf(nextMonthToSent.getMonthValue());
if (!epasValidates.getAllCertificationsValidated()) {
logger.info("No new month closed on EPAS: {}", nextMonthToSent);
return;
}
logger.info("Reference: {} - {} ", yearRef, monthRef);
EPASValidates epasValidates = epasValidatesService.getValidatesByOfficeCodeId(ISTI_OFFICE_CODEID, yearRef,
monthRef);
// if (!epasValidates.getAllCertificationsValidated()) {
// logger.info("No month closed on EPAS: {}", nextMonthToSent);
// return;
// }
logger.info("Certifications Validated: {}", nextMonthToSent);
// Set Update DateTime
@ -879,11 +938,21 @@ public class SyncService {
timeCardsReporting = timeCardsReportingService.createTimeCardsReporting(timeCardsReporting);
logger.info("Persons Validated: {}", epasValidates.getValidatedPersons().length);
checkFiscalCode(epasValidates.getValidatedPersons());
// SI
for (EPASPersons person : epasValidates.getValidatedPersons()) {
logger.info("Writing TimeCard for Person: {}", person);
if (person.getFiscalCode() == null || person.getFiscalCode().isEmpty()) {
logger.error("Invalid FiscalCode: {}", person.getFiscalCode());
continue;
} else {
logger.info("FiscalCode: {}", person.getFiscalCode());
}
EPASTimeCards epasTimeCards = epasTimeCardsService.getTimeCardByPersonFiscalCode(person.getFiscalCode(),
String.valueOf(nextMonthToSent.getYear()), String.valueOf(nextMonthToSent.getMonthValue()));
yearRef, monthRef);
EPASPersons epasPerson = epasTimeCards.getPerson();
Integer personId = Integer.valueOf(epasPerson.getId());
@ -892,20 +961,7 @@ public class SyncService {
Long id = Long.valueOf(epasPersonDay.getId());
StringBuilder motivo = new StringBuilder();
if (epasPersonDay.getIsHoliday()) {
motivo.append("[Festivo]");
}
if (epasPersonDay.getAbsences() != null && epasPersonDay.getAbsences().length > 0) {
for (EPASAbsences epasAbsences : epasPersonDay.getAbsences()) {
motivo.append("[");
motivo.append(epasAbsences.getJustifiedType());
motivo.append("-");
motivo.append(epasAbsences.getJustifiedTime());
motivo.append("-");
motivo.append(epasAbsences.getNote());
motivo.append("]");
}
}
extractMotivoInfo(epasPersonDay, motivo);
java.sql.Date date = null;
try {
@ -938,4 +994,79 @@ public class SyncService {
}
private void checkFiscalCode(EPASPersons[] validatedPersons) throws Exception {
if (validatedPersons != null && validatedPersons.length > 0) {
ArrayList<String> personsWithInvalidFiscalCode = new ArrayList<>();
for (EPASPersons epasPerson : validatedPersons) {
if (epasPerson != null) {
if (epasPerson.getFiscalCode() == null || epasPerson.getFiscalCode().isEmpty()) {
if (epasPerson.getFullname() != null && !epasPerson.getFullname().isEmpty()) {
personsWithInvalidFiscalCode.add(epasPerson.getFullname());
} else {
String error = "Dipendente non inizializzato correttamente: " + epasPerson;
logger.error(error);
throw new Exception(error);
}
}
}
}
if (!personsWithInvalidFiscalCode.isEmpty()) {
StringBuilder errore = new StringBuilder();
String invalids = personsWithInvalidFiscalCode.stream().collect(Collectors.joining(",", "[", "]"));
errore.append("Alcuni dipenenti non hanno il codice fiscale corretto ");
errore.append(invalids);
logger.error(errore.toString());
throw new Exception(errore.toString());
}
}
}
private void extractMotivoInfo(EPASPersonDays epasPersonDay, StringBuilder motivo) {
if (epasPersonDay.getIsHoliday()) {
motivo.append("[Festivo]");
}
if (epasPersonDay.getStampings() != null && epasPersonDay.getStampings().length > 0) {
boolean foundLavoroFuoriSede = false;
boolean foundMotiviDiServizio = false;
for (EPASStampings epasStamping : epasPersonDay.getStampings()) {
if (epasStamping.getStampType()!=null&&
!epasStamping.getStampType().isEmpty()) {
switch(epasStamping.getStampType()) {
case "lavoroFuoriSede":
foundLavoroFuoriSede = true;
break;
case "motiviDiServizio":
foundMotiviDiServizio = true;
break;
default:
break;
}
}
}
if (foundLavoroFuoriSede) {
motivo.append("[Lavoro Fuori Sede]");
}
if (foundMotiviDiServizio) {
motivo.append("[Servizio]");
}
}
if (epasPersonDay.getAbsences() != null && epasPersonDay.getAbsences().length > 0) {
for (EPASAbsences epasAbsences : epasPersonDay.getAbsences()) {
motivo.append("[");
// motivo.append(epasAbsences.getJustifiedType());
// motivo.append("-");
motivo.append(epasAbsences.getCode());
if (epasAbsences.getNote() != null && !epasAbsences.getNote().isEmpty()) {
motivo.append("-");
motivo.append(epasAbsences.getNote());
}
motivo.append("]");
}
}
}
}

View File

@ -0,0 +1,98 @@
package it.cnr.isti.epasmed.web.rest.epas;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
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 io.github.jhipster.web.util.ResponseUtil;
import it.cnr.isti.epasmed.epas.model.EPASPersonDays;
import it.cnr.isti.epasmed.epas.service.EPASOffSiteWorksService;
@RestController
@RequestMapping("/api/epas")
public class EPASOffSiteWorksResource {
private final Logger log = LoggerFactory.getLogger(getClass());
@Value("${jhipster.clientApp.name}")
private String applicationName;
private final EPASOffSiteWorksService epasOffSiteWorksService;
public EPASOffSiteWorksResource(EPASOffSiteWorksService epasOffSiteWorksService) {
this.epasOffSiteWorksService = epasOffSiteWorksService;
}
/**
* {@code GET /offsiteworks/byPerson} : get off site works by person, year and month
*
* @param id the id of the person.
* @param fiscalCode the fiscal code of the person.
* @param email the email of the person.
* @param year the year.
* @param month the month.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body
* the EPAS Off Site Works List, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/offsiteworks/byPerson")
public ResponseEntity<List<EPASPersonDays>> getListOffSiteWorksByPerson(@RequestParam("id") Optional<String> id,
@RequestParam("fiscalCode") Optional<String> fiscalCode,
@RequestParam("email") Optional<String> email,
@RequestParam("year") String year,@RequestParam("month") String month) {
List<EPASPersonDays> epasOffSiteWorksList = null;
if (id.isPresent()) {
log.info("REST request to get ePAS Off Site Works list by Person id: {}", id.get());
epasOffSiteWorksList = epasOffSiteWorksService.getListByPersonId(id.get(), year, month);
} else {
if (fiscalCode.isPresent()) {
log.info("REST request to get ePAS Off Site Works list by Person fiscalcode: {}", fiscalCode.get());
epasOffSiteWorksList = epasOffSiteWorksService.getListByPersonFiscalCode(fiscalCode.get(), year, month);
} else {
if (email.isPresent()) {
log.info("REST request to get ePAS Off Site Works list by Person email: {}", email.get());
epasOffSiteWorksList = epasOffSiteWorksService.getListByPersonEmail(email.get(), year, month);
} else {
return ResponseUtil.wrapOrNotFound(Optional.of(epasOffSiteWorksList), HeaderUtil.createFailureAlert(applicationName,false,
"","","Invalid parameter in call"));
}
}
}
log.info("Retrieved Off Site Works list: {}", epasOffSiteWorksList);
return ResponseUtil.wrapOrNotFound(Optional.of(epasOffSiteWorksList));
}
/**
* {@code GET /offsiteworks/byOffice} : get the time cards list.
*
* @param officeCodeId the id of the office.
* @param year the year
* @param month the month
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body
* the EPAS Off Site Works List, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/offsiteworks/byOffice")
public ResponseEntity<List<EPASPersonDays>> getOffSiteWorksByOffice(@RequestParam("codeId") String id,
@RequestParam("year") String year, @RequestParam("month") String month) {
log.info("REST request to get ePAS Off Site Works list: officeCodeId={}, year={}, month={}", id,year,month);
List<EPASPersonDays> epasOffSiteWorksList = epasOffSiteWorksService.getListByOfficeCodeId(id, year, month);
return ResponseUtil.wrapOrNotFound(Optional.of(epasOffSiteWorksList));
}
}

View File

@ -95,4 +95,34 @@ public class SyncResource {
return res;
}
/**
* {@code GET /sync/writesTimeCards} : Reports TimeCards from ePAS
* in SistemaInformativo.
*
* @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<Void> syncTimeCardsWrites() throws URISyntaxException {
logger.info("REST request syncWrites)");
ResponseEntity<Void> res;
try {
syncService.executeTimeCardsWrites();
String msg="Rendicontazione dei cartellini eseguita correttamente.";
logger.info(msg);
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();
}
return res;
}
}

View File

@ -1,11 +1,25 @@
<div class="table-responsive">
<h2 id="logs-page-heading">Sync</h2>
<jhi-alert-error></jhi-alert-error>
<jhi-alert></jhi-alert>
<p>Sync Sistema Informativo ed ePAS.</p>
<div class="d-grid gap-2 d-md-block">
<button class="btn btn-primary" type="button" (click)="sync('reads')">Reads</button>
<button class="btn btn-primary" type="button" (click)="sync('writes')">Writes</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('reads')">Reads</button>
<button class="btn btn-primary" type="button" [disabled]="isLoading"
(click)="sync('writes')">Writes</button>
</div>
<div *ngIf="isLoading" class="d-flex justify-content-center">
<div class="spinner-border text-dark" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
{{syncT}}
</div>

View File

@ -9,14 +9,28 @@ import { SyncService } from './sync.service';
})
export class SyncComponent implements OnInit {
syncT: SyncType | null = null;
isLoading = false; // hidden by default
constructor(private syncService: SyncService) {}
ngOnInit(): void {}
sync(syncType: SyncType): void {
this.isLoading = true;
this.syncT = syncType;
this.syncService.sync(syncType).subscribe(
() => this.onSuccess(),
() => this.onError()
);
}
// this.syncService.sync(syncType);
private onSuccess(): void {
this.isLoading = false;
}
private onError(): void {
this.isLoading = false;
}
//
}

View File

@ -0,0 +1,80 @@
package it.cnr.isti.epasmed.web.rest.epas;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit.jupiter.EnabledIf;
import org.springframework.test.web.servlet.MockMvc;
import it.cnr.isti.epasmed.EpasmedApp;
import it.cnr.isti.epasmed.security.AuthoritiesConstants;
/**
* Integration tests for the {@link EPASOffSiteWorksResource} REST controller.
*/
@AutoConfigureMockMvc
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
@SpringBootTest(classes = EpasmedApp.class)
@EnabledIf("false")
public class EPASOffSiteWorksResourceIT {
private final Logger log = LoggerFactory.getLogger(getClass());
//private static final String OFFICE_DEFAULT_ID = "1";
//private static final String OFFICE_DEFAULT_NAME = "ISTI - Pisa";
//private static final String OFFICE_DEFAULT_CODE = "074000";
private static final String OFFICE_DEFAULT_CODEID = "225200";
private static final String PERSON_DEFAULT_ID = "113";
//private static final String PERSON_DEFAULT_NAME = "Giuseppe";
//private static final String PERSON_DEFAULT_SURNAME = "Amato";
private static final String PERSON_DEFAULT_FISCAL_CODE = "MTAGPP68D15D976W";
private static final String PERSON_DEFAULT_EMAIL = "giuseppe.amato@cnr.it";
//private static final String PERSON_DEFAULT_QUALIFICATION = "2";
@Autowired
private MockMvc restEPASTimeCardsMockMvc;
@Autowired
private Environment environment;
@BeforeEach
public void initTest() {
for (String profileName : environment.getActiveProfiles()) {
log.info("Currently active profile - " + profileName);
}
log.info("System env - " + System.getenv("spring.profiles.active"));
}
@Test
public void getOffSiteWorksByPersonId() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/offsiteworks/byPerson?id="+PERSON_DEFAULT_ID+"&year=2022&month=6")).andExpect(status().isOk());
}
@Test
public void getOffSiteWorksByPersonFiscalCode() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/offsiteworks/byPerson?fiscalCode="+PERSON_DEFAULT_FISCAL_CODE+"&year=2022&month=6")).andExpect(status().isOk());
}
@Test
public void getOffSiteWorksByPersonEmail() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/offsiteworks/byPerson?email="+PERSON_DEFAULT_EMAIL+"&year=2022&month=6")).andExpect(status().isOk());
}
@Test
public void getOffSiteWorksByOfficeCodeId() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/offsiteworks/byOffice?codeId="+OFFICE_DEFAULT_CODEID+"&year=2022&month=6")).andExpect(status().isOk());
}
}

View File

@ -3,7 +3,6 @@ package it.cnr.isti.epasmed.web.rest.epas;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.FileWriter;
@ -114,7 +113,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/timbratureAutoCertISTI202112.csv"))) {
.lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureISTI20220701.csv"))) {
istiStampings = stream.skip(1).map(istiMapToStampingsDTO).collect(Collectors.toList());
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
@ -214,7 +213,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/timbratureAutoCertISTI202112.csv"))) {
.lines(Paths.get("src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureISTI20220701.csv"))) {
list = stream.collect(Collectors.toList());
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
@ -223,7 +222,7 @@ public class EPASStampingsResourceIT {
try {
FileWriter writer = new FileWriter(
"src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureAutoCertISTI202112_2.csv");
"src/test/resources/it/cnr/isti/epasmed/web/rest/epas/timbratureISTI20220701_2.csv");
for (String str : list) {
writer.write("\""+str+"\"" + System.lineSeparator());
}

View File

@ -37,7 +37,10 @@ public class EPASTimeCardsResourceIT {
private static final String PERSON_DEFAULT_ID = "113";
//private static final String PERSON_DEFAULT_NAME = "Giuseppe";
//private static final String PERSON_DEFAULT_SURNAME = "Amato";
private static final String PERSON_DEFAULT_FISCAL_CODE = "MTAGPP68D15D976W";
//private static final String PERSON_DEFAULT_FISCAL_CODE = "MTAGPP68D15D976W";
private static final String PERSON_DEFAULT_FISCAL_CODE = "BRTNTN60R56E974Z";
private static final String PERSON_DEFAULT_EMAIL = "giuseppe.amato@cnr.it";
//private static final String PERSON_DEFAULT_QUALIFICATION = "2";
@ -57,22 +60,22 @@ public class EPASTimeCardsResourceIT {
@Test
public void getTimeCardByPersonId() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?id="+PERSON_DEFAULT_ID+"&year=2021&month=11")).andExpect(status().isOk());
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?id="+PERSON_DEFAULT_ID+"&year=2022&month=6")).andExpect(status().isOk());
}
@Test
public void getTimeCardByPersonFiscalCode() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?fiscalCode="+PERSON_DEFAULT_FISCAL_CODE+"&year=2021&month=11")).andExpect(status().isOk());
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?fiscalCode="+PERSON_DEFAULT_FISCAL_CODE+"&year=2022&month=6")).andExpect(status().isOk());
}
@Test
public void getTimeCardByPersonEmail() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?email="+PERSON_DEFAULT_EMAIL+"&year=2021&month=11")).andExpect(status().isOk());
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byPerson?email="+PERSON_DEFAULT_EMAIL+"&year=2022&month=6")).andExpect(status().isOk());
}
@Test
public void getTimeCardByOfficeCodeId() throws Exception {
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byOffice?codeId="+OFFICE_DEFAULT_CODEID+"&year=2021&month=11")).andExpect(status().isOk());
restEPASTimeCardsMockMvc.perform(get("/api/epas/timecards/byOffice?codeId="+OFFICE_DEFAULT_CODEID+"&year=2022&month=6")).andExpect(status().isOk());
}
}

View File

@ -58,5 +58,11 @@ public class SyncResourceIT {
.andExpect(status().is2xxSuccessful());
}
@Test
public void syncTimeCardsWrites() throws Exception {
restSyncMockMvc.perform(get("/api/sync/writesTimeCards"))
.andExpect(status().is2xxSuccessful());
}
}

View File

@ -2,3 +2,4 @@
/timbratureISTI.csv
/timbratureISTIOrig.csv
/timbratureRapisardaISTI.csv
/timbratureAutoCertISTI202205.csv