|
|
|
|
@@ -40,6 +40,7 @@ import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.function.ToDoubleBiFunction;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@@ -97,6 +98,7 @@ public class SynchronisationServiceImpl implements SynchronisationService {
|
|
|
|
|
private final MobileDataPersonneRepository mobileDataPersonneRepository;
|
|
|
|
|
private final MobileDataMembreGroupeRepository mobileDataMembreGroupeRepository;
|
|
|
|
|
private final MobileDataPieceRepository mobileDataPieceRepository;
|
|
|
|
|
private final MobileDataBatimentRepository mobileDataBatimentRepository;
|
|
|
|
|
private final MobileDataUploadRepository mobileDataUploadRepository;
|
|
|
|
|
private final MobileDataEnqueteRepository mobileDataEnqueteRepository;
|
|
|
|
|
private final MobileDataCaracteristiqueParcelleRepository mobileDataCaracteristiqueParcelleRepository;
|
|
|
|
|
@@ -263,7 +265,6 @@ public class SynchronisationServiceImpl implements SynchronisationService {
|
|
|
|
|
Optional<Personne> optionalPersonne = personneRepository.findById(personnePayLoad.getIdBackend());
|
|
|
|
|
if (optionalPersonne.isPresent()) {
|
|
|
|
|
personne = optionalPersonne.get();
|
|
|
|
|
System.out.println("SUPRESSION FROM PERSONNE "+personne.getId());
|
|
|
|
|
deleteFromPersonne(personne.getId());
|
|
|
|
|
}else{
|
|
|
|
|
personnePayLoad.setIdBackend(null);
|
|
|
|
|
@@ -291,7 +292,6 @@ public class SynchronisationServiceImpl implements SynchronisationService {
|
|
|
|
|
syncResponse.setExternalKey(personnePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(personnePayLoad.isSynchronise());
|
|
|
|
|
syncResponse.setIdBackend(personnePayLoad.getIdBackend());
|
|
|
|
|
System.out.println(syncResponse);
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
@@ -304,63 +304,532 @@ public class SynchronisationServiceImpl implements SynchronisationService {
|
|
|
|
|
return syncResponses;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T> void saveMobileData(List<T> payloads, TypeObjet typeObjet) {
|
|
|
|
|
private <T> List<SyncResponse> saveMobileData(List<T> payloads, TypeObjet typeObjet) {
|
|
|
|
|
List<SyncResponse> syncResponses = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
switch (typeObjet){
|
|
|
|
|
case PERSONNE -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
PersonnePayLoad p= (PersonnePayLoad) payLoad ;
|
|
|
|
|
PersonnePayLoad personnePayLoad = (PersonnePayLoad) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataPersonne mobileDataPersonne = new MobileDataPersonne();
|
|
|
|
|
mobileDataPersonne.setPersonnePayLoad(p);
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataPersonne> optionalMobileDataPersonne=
|
|
|
|
|
mobileDataPersonneRepository.findByPersonnePayLoad_TerminalIdAndPersonnePayLoad_ExternalKey(p.getTerminalId(),p.getExternalKey());
|
|
|
|
|
Optional<MobileDataPersonne> optionalMobileDataPersonne = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (personnePayLoad.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataPersonne = mobileDataPersonneRepository.findById(personnePayLoad.getIdBackend());
|
|
|
|
|
if (optionalMobileDataPersonne.isPresent()) {
|
|
|
|
|
mobileDataPersonne = optionalMobileDataPersonne.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataPersonne = mobileDataPersonneRepository.findByPersonnePayLoad_TerminalIdAndPersonnePayLoad_ExternalKey(personnePayLoad.getTerminalId(), personnePayLoad.getExternalKey());
|
|
|
|
|
if (optionalMobileDataPersonne.isPresent()) {
|
|
|
|
|
mobileDataPersonne = optionalMobileDataPersonne.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mobileDataPersonne.setTraiter(false);
|
|
|
|
|
mobileDataPersonne.setPersonnePayLoad(personnePayLoad);
|
|
|
|
|
mobileDataPersonne = mobileDataPersonneRepository.save(mobileDataPersonne);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.PERSONNE.toString());
|
|
|
|
|
syncResponse.setExternalKey(personnePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataPersonne.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.PERSONNE.toString());
|
|
|
|
|
syncResponse.setExternalKey(personnePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(personnePayLoad.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case MEMBREGROUPE -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
MembreGroupePayLoad membreGroupePayLoad = (MembreGroupePayLoad) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataMembreGroupe mobileDataMembreGroupe = new MobileDataMembreGroupe();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataMembreGroupe> optionalMobileDataMembreGroupe = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (membreGroupePayLoad.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataMembreGroupe = mobileDataMembreGroupeRepository.findById(membreGroupePayLoad.getIdBackend());
|
|
|
|
|
if (optionalMobileDataMembreGroupe.isPresent()) {
|
|
|
|
|
mobileDataMembreGroupe = optionalMobileDataMembreGroupe.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataMembreGroupe = mobileDataMembreGroupeRepository.findByMembreGroupePayLoad_TerminalIdAndMembreGroupePayLoad_ExternalKey(membreGroupePayLoad.getTerminalId(), membreGroupePayLoad.getExternalKey());
|
|
|
|
|
if (optionalMobileDataMembreGroupe.isPresent()) {
|
|
|
|
|
mobileDataMembreGroupe = optionalMobileDataMembreGroupe.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mobileDataMembreGroupe.setTraiter(false);
|
|
|
|
|
mobileDataMembreGroupe.setMembreGroupePayLoad(membreGroupePayLoad);
|
|
|
|
|
mobileDataMembreGroupe = mobileDataMembreGroupeRepository.save(mobileDataMembreGroupe);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.MEMBREGROUPE.toString());
|
|
|
|
|
syncResponse.setExternalKey(membreGroupePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataMembreGroupe.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.MEMBREGROUPE.toString());
|
|
|
|
|
syncResponse.setExternalKey(membreGroupePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(membreGroupePayLoad.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case ACTEURCONCERNER -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
ActeurConcernePayLoad acteurConcernePayLoad = (ActeurConcernePayLoad) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataActeurConcerne mobileDataActeurConcerne = new MobileDataActeurConcerne();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataActeurConcerne> optionalMobileDataActeurConcerne = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (acteurConcernePayLoad.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataActeurConcerne = mobileDataActeurConcerneRepository.findById(acteurConcernePayLoad.getIdBackend());
|
|
|
|
|
if (optionalMobileDataActeurConcerne.isPresent()) {
|
|
|
|
|
mobileDataActeurConcerne = optionalMobileDataActeurConcerne.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataActeurConcerne = mobileDataActeurConcerneRepository.findByActeurConcernePayLoad_TerminalIdAndActeurConcernePayLoad_ExternalKey(acteurConcernePayLoad.getTerminalId(), acteurConcernePayLoad.getExternalKey());
|
|
|
|
|
if (optionalMobileDataActeurConcerne.isPresent()) {
|
|
|
|
|
mobileDataActeurConcerne = optionalMobileDataActeurConcerne.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mobileDataActeurConcerne.setTraiter(false);
|
|
|
|
|
mobileDataActeurConcerne.setActeurConcernePayLoad(acteurConcernePayLoad);
|
|
|
|
|
mobileDataActeurConcerne = mobileDataActeurConcerneRepository.save(mobileDataActeurConcerne);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.ACTEURCONCERNER.toString());
|
|
|
|
|
syncResponse.setExternalKey(acteurConcernePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataActeurConcerne.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.ACTEURCONCERNER.toString());
|
|
|
|
|
syncResponse.setExternalKey(acteurConcernePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(acteurConcernePayLoad.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case PIECE -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
PiecePayLoad piecePayLoad = (PiecePayLoad) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataPiece mobileDataPiece = new MobileDataPiece();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataPiece> optionalMobileDataPiece = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (piecePayLoad.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataPiece = mobileDataPieceRepository.findById(piecePayLoad.getIdBackend());
|
|
|
|
|
if (optionalMobileDataPiece.isPresent()) {
|
|
|
|
|
mobileDataPiece = optionalMobileDataPiece.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataPiece = mobileDataPieceRepository.findByPiecePayLoad_TerminalIdAndPiecePayLoad_ExternalKey(piecePayLoad.getTerminalId(), piecePayLoad.getExternalKey());
|
|
|
|
|
if (optionalMobileDataPiece.isPresent()) {
|
|
|
|
|
mobileDataPiece = optionalMobileDataPiece.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataPiece.setTraiter(false);
|
|
|
|
|
mobileDataPiece.setPiecePayLoad(piecePayLoad);
|
|
|
|
|
mobileDataPiece = mobileDataPieceRepository.save(mobileDataPiece);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.PIECE.toString());
|
|
|
|
|
syncResponse.setExternalKey(piecePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataPiece.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.PIECE.toString());
|
|
|
|
|
syncResponse.setExternalKey(piecePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(piecePayLoad.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case UPLOAD -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
UploadPayLoad uploadPayLoad = (UploadPayLoad) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataUpload mobileDataUpload = new MobileDataUpload();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataUpload> optionalMobileDataUpload = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (uploadPayLoad.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataUpload = mobileDataUploadRepository.findById(uploadPayLoad.getIdBackend());
|
|
|
|
|
if (optionalMobileDataUpload.isPresent()) {
|
|
|
|
|
mobileDataUpload = optionalMobileDataUpload.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataUpload = mobileDataUploadRepository.findByUploadPayLoad_TerminalIdAndUploadPayLoad_ExternalKey(uploadPayLoad.getTerminalId(), uploadPayLoad.getExternalKey());
|
|
|
|
|
if (optionalMobileDataUpload.isPresent()) {
|
|
|
|
|
mobileDataUpload = optionalMobileDataUpload.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataUpload.setTraiter(false);
|
|
|
|
|
mobileDataUpload.setUploadPayLoad(uploadPayLoad);
|
|
|
|
|
String fileName = fileStorageService.storeFile(uploadPayLoad.getFile());
|
|
|
|
|
mobileDataUpload.setFileName(fileName);
|
|
|
|
|
mobileDataUpload.setMimeType(uploadPayLoad.getFile().getContentType());
|
|
|
|
|
mobileDataUpload.setSize(uploadPayLoad.getFile().getSize());
|
|
|
|
|
mobileDataUpload.setOriginalFileName(uploadPayLoad.getFile().getOriginalFilename());
|
|
|
|
|
mobileDataUpload.setName(uploadPayLoad.getName());
|
|
|
|
|
mobileDataUpload.setFilePath(uploadPayLoad.getFilePath());
|
|
|
|
|
|
|
|
|
|
mobileDataUpload = mobileDataUploadRepository.save(mobileDataUpload);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.UPLOAD.toString());
|
|
|
|
|
syncResponse.setExternalKey(uploadPayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataUpload.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.UPLOAD.toString());
|
|
|
|
|
syncResponse.setExternalKey(uploadPayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(uploadPayLoad.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case BATIMENT -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
BatimentPaylaod batimentPaylaod = (BatimentPaylaod) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataBatiment mobileDataBatiment = new MobileDataBatiment();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataBatiment> optionalMobileDataBatiment = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (batimentPaylaod.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataBatiment = mobileDataBatimentRepository.findById(batimentPaylaod.getIdBackend());
|
|
|
|
|
if (optionalMobileDataBatiment.isPresent()) {
|
|
|
|
|
mobileDataBatiment = optionalMobileDataBatiment.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataBatiment = mobileDataBatimentRepository.findMobileDataBatimentByBatimentPaylaod_TerminalIdAndBatimentPaylaod_ExternalKey(batimentPaylaod.getTerminalId(), batimentPaylaod.getExternalKey());
|
|
|
|
|
if (optionalMobileDataBatiment.isPresent()) {
|
|
|
|
|
mobileDataBatiment = optionalMobileDataBatiment.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataBatiment.setTraiter(false);
|
|
|
|
|
mobileDataBatiment.setBatimentPaylaod(batimentPaylaod);
|
|
|
|
|
mobileDataBatiment = mobileDataBatimentRepository.save(mobileDataBatiment);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.BATIMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(batimentPaylaod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataBatiment.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.PIECE.toString());
|
|
|
|
|
syncResponse.setExternalKey(batimentPaylaod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(batimentPaylaod.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case UNITELOGEMENT -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
UniteLogementPaylaod uniteLogementPaylaod = (UniteLogementPaylaod) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataUniteLogement mobileDataUniteLogement = new MobileDataUniteLogement();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataUniteLogement> optionalMobileDataUniteLogement = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (uniteLogementPaylaod.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataUniteLogement = mobileDataUniteLogementRepository.findById(uniteLogementPaylaod.getIdBackend());
|
|
|
|
|
if (optionalMobileDataUniteLogement.isPresent()) {
|
|
|
|
|
mobileDataUniteLogement = optionalMobileDataUniteLogement.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataUniteLogement = mobileDataUniteLogementRepository.findByUniteLogementPaylaod_TerminalIdAndUniteLogementPaylaod_ExternalKey(uniteLogementPaylaod.getTerminalId(), uniteLogementPaylaod.getExternalKey());
|
|
|
|
|
if (optionalMobileDataUniteLogement.isPresent()) {
|
|
|
|
|
mobileDataUniteLogement = optionalMobileDataUniteLogement.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataUniteLogement.setTraiter(false);
|
|
|
|
|
mobileDataUniteLogement.setUniteLogementPaylaod(uniteLogementPaylaod);
|
|
|
|
|
mobileDataUniteLogement = mobileDataUniteLogementRepository.save(mobileDataUniteLogement);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.UNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(uniteLogementPaylaod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataUniteLogement.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.PIECE.toString());
|
|
|
|
|
syncResponse.setExternalKey(uniteLogementPaylaod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(uniteLogementPaylaod.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case ENQUETEBATIMENT -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
EnqueteBatimentPayload enqueteBatimentPayload = (EnqueteBatimentPayload) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataEnqueteBatiment mobileDataEnqueteBatiment = new MobileDataEnqueteBatiment();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataEnqueteBatiment> optionalMobileDataEnqueteBatiment = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (enqueteBatimentPayload.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataEnqueteBatiment = mobileDataEnqueteBatimentRepository.findById(enqueteBatimentPayload.getIdBackend());
|
|
|
|
|
if (optionalMobileDataEnqueteBatiment.isPresent()) {
|
|
|
|
|
mobileDataEnqueteBatiment = optionalMobileDataEnqueteBatiment.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataEnqueteBatiment = mobileDataEnqueteBatimentRepository.findByEnqueteBatimentPayload_TerminalIdAndEnqueteBatimentPayload_ExternalKey(enqueteBatimentPayload.getTerminalId(), enqueteBatimentPayload.getExternalKey());
|
|
|
|
|
if (optionalMobileDataEnqueteBatiment.isPresent()) {
|
|
|
|
|
mobileDataEnqueteBatiment = optionalMobileDataEnqueteBatiment.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataEnqueteBatiment.setTraiter(false);
|
|
|
|
|
mobileDataEnqueteBatiment.setEnqueteBatimentPayload(enqueteBatimentPayload);
|
|
|
|
|
mobileDataEnqueteBatiment = mobileDataEnqueteBatimentRepository.save(mobileDataEnqueteBatiment);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.UNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(enqueteBatimentPayload.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataEnqueteBatiment.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.ENQUETEBATIMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(enqueteBatimentPayload.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(enqueteBatimentPayload.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case ENQUETEUNITELOGEMENT -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
EnqueteUniteLogementPayload enqueteUniteLogementPayload = (EnqueteUniteLogementPayload) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataEnqueteUniteLogement mobileDataEnqueteUniteLogement = new MobileDataEnqueteUniteLogement();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataEnqueteUniteLogement> optionalMobileDataEnqueteUniteLogement = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (enqueteUniteLogementPayload.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataEnqueteUniteLogement = mobileDataEnqueteUniteLogementRepository.findById(enqueteUniteLogementPayload.getIdBackend());
|
|
|
|
|
if (optionalMobileDataEnqueteUniteLogement.isPresent()) {
|
|
|
|
|
mobileDataEnqueteUniteLogement = optionalMobileDataEnqueteUniteLogement.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataEnqueteUniteLogement = mobileDataEnqueteUniteLogementRepository.findByEnqueteUniteLogementPayload_TerminalIdAndEnqueteUniteLogementPayload_ExternalKey(enqueteUniteLogementPayload.getTerminalId(), enqueteUniteLogementPayload.getExternalKey());
|
|
|
|
|
if (optionalMobileDataEnqueteUniteLogement.isPresent()) {
|
|
|
|
|
mobileDataEnqueteUniteLogement = optionalMobileDataEnqueteUniteLogement.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataEnqueteUniteLogement.setTraiter(false);
|
|
|
|
|
mobileDataEnqueteUniteLogement.setEnqueteUniteLogementPayload(enqueteUniteLogementPayload);
|
|
|
|
|
mobileDataEnqueteUniteLogement = mobileDataEnqueteUniteLogementRepository.save(mobileDataEnqueteUniteLogement);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.ENQUETEUNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(enqueteUniteLogementPayload.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataEnqueteUniteLogement.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.ENQUETEUNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(enqueteUniteLogementPayload.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(enqueteUniteLogementPayload.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case CARACTERISTIQUEPARCELLE -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
CaracteristiqueParcellePaylod caracteristiqueParcellePaylod = (CaracteristiqueParcellePaylod) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataCaracteristiqueParcelle mobileDataCaracteristiqueParcelle = new MobileDataCaracteristiqueParcelle();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataCaracteristiqueParcelle> optionalMobileDataCaracteristiqueParcelle = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (caracteristiqueParcellePaylod.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataCaracteristiqueParcelle = mobileDataCaracteristiqueParcelleRepository.findById(caracteristiqueParcellePaylod.getIdBackend());
|
|
|
|
|
if (optionalMobileDataCaracteristiqueParcelle.isPresent()) {
|
|
|
|
|
mobileDataCaracteristiqueParcelle = optionalMobileDataCaracteristiqueParcelle.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataCaracteristiqueParcelle = mobileDataCaracteristiqueParcelleRepository.findByCaracteristiqueParcellePaylod_TerminalIdAndCaracteristiqueParcellePaylod_ExternalKey(caracteristiqueParcellePaylod.getTerminalId(), caracteristiqueParcellePaylod.getExternalKey());
|
|
|
|
|
if (optionalMobileDataCaracteristiqueParcelle.isPresent()) {
|
|
|
|
|
mobileDataCaracteristiqueParcelle = optionalMobileDataCaracteristiqueParcelle.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataCaracteristiqueParcelle.setTraiter(false);
|
|
|
|
|
mobileDataCaracteristiqueParcelle.setCaracteristiqueParcellePaylod(caracteristiqueParcellePaylod);
|
|
|
|
|
mobileDataCaracteristiqueParcelle = mobileDataCaracteristiqueParcelleRepository.save(mobileDataCaracteristiqueParcelle);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.CARACTERISTIQUEPARCELLE.toString());
|
|
|
|
|
syncResponse.setExternalKey(caracteristiqueParcellePaylod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataCaracteristiqueParcelle.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.CARACTERISTIQUEPARCELLE.toString());
|
|
|
|
|
syncResponse.setExternalKey(caracteristiqueParcellePaylod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(caracteristiqueParcellePaylod.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CARACTERISTIQUEBATIMENT -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
CaracteristiqueBatimentPaylod caracteristiqueBatimentPaylod = (CaracteristiqueBatimentPaylod) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataCaracteristiqueBatiment mobileDataCaracteristiqueBatiment = new MobileDataCaracteristiqueBatiment();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataCaracteristiqueBatiment> optionalMobileDataCaracteristiqueBatiment = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (caracteristiqueBatimentPaylod.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataCaracteristiqueBatiment = mobileDataCaracteristiqueBatimentRepository.findById(caracteristiqueBatimentPaylod.getIdBackend());
|
|
|
|
|
if (optionalMobileDataCaracteristiqueBatiment.isPresent()) {
|
|
|
|
|
mobileDataCaracteristiqueBatiment = optionalMobileDataCaracteristiqueBatiment.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataCaracteristiqueBatiment = mobileDataCaracteristiqueBatimentRepository.findByCaracteristiqueBatimentPaylod_TerminalIdAndCaracteristiqueBatimentPaylod_ExternalKey(caracteristiqueBatimentPaylod.getTerminalId(), caracteristiqueBatimentPaylod.getExternalKey());
|
|
|
|
|
if (optionalMobileDataCaracteristiqueBatiment.isPresent()) {
|
|
|
|
|
mobileDataCaracteristiqueBatiment = optionalMobileDataCaracteristiqueBatiment.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataCaracteristiqueBatiment.setTraiter(false);
|
|
|
|
|
mobileDataCaracteristiqueBatiment.setCaracteristiqueBatimentPaylod(caracteristiqueBatimentPaylod);
|
|
|
|
|
mobileDataCaracteristiqueBatiment = mobileDataCaracteristiqueBatimentRepository.save(mobileDataCaracteristiqueBatiment);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.CARACTERISTIQUEBATIMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(caracteristiqueBatimentPaylod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataCaracteristiqueBatiment.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.CARACTERISTIQUEBATIMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(caracteristiqueBatimentPaylod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(caracteristiqueBatimentPaylod.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case CARACTERISTIQUEUNITELOGEMENT -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
CaracteristiqueUniteLogementPaylod caracteristiqueUniteLogementPaylod = (CaracteristiqueUniteLogementPaylod) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataCaracteristiqueUniteLogement mobileDataCaracteristiqueUniteLogement = new MobileDataCaracteristiqueUniteLogement();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataCaracteristiqueUniteLogement> optionalMobileDataCaracteristiqueUniteLogement = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (caracteristiqueUniteLogementPaylod.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataCaracteristiqueUniteLogement = mobileDataCaracteristiqueUniteLogementRepository.findById(caracteristiqueUniteLogementPaylod.getIdBackend());
|
|
|
|
|
if (optionalMobileDataCaracteristiqueUniteLogement.isPresent()) {
|
|
|
|
|
mobileDataCaracteristiqueUniteLogement = optionalMobileDataCaracteristiqueUniteLogement.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataCaracteristiqueUniteLogement = mobileDataCaracteristiqueUniteLogementRepository.findByCaracteristiqueUniteLogementPaylod_TerminalIdAndCaracteristiqueUniteLogementPaylod_ExternalKey(caracteristiqueUniteLogementPaylod.getTerminalId(), caracteristiqueUniteLogementPaylod.getExternalKey());
|
|
|
|
|
if (optionalMobileDataCaracteristiqueUniteLogement.isPresent()) {
|
|
|
|
|
mobileDataCaracteristiqueUniteLogement = optionalMobileDataCaracteristiqueUniteLogement.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mobileDataCaracteristiqueUniteLogement.setTraiter(false);
|
|
|
|
|
mobileDataCaracteristiqueUniteLogement.setCaracteristiqueUniteLogementPaylod(caracteristiqueUniteLogementPaylod);
|
|
|
|
|
mobileDataCaracteristiqueUniteLogement = mobileDataCaracteristiqueUniteLogementRepository.save(mobileDataCaracteristiqueUniteLogement);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.CARACTERISTIQUEUNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(caracteristiqueUniteLogementPaylod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataCaracteristiqueUniteLogement.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.CARACTERISTIQUEUNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(caracteristiqueUniteLogementPaylod.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(caracteristiqueUniteLogementPaylod.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
case PARCELLE -> {
|
|
|
|
|
payloads.forEach(payLoad -> {
|
|
|
|
|
ParcellePayLoad parcellePayLoad = (ParcellePayLoad) payLoad;
|
|
|
|
|
try {
|
|
|
|
|
MobileDataParcelle mobileDataParcelle = new MobileDataParcelle();
|
|
|
|
|
|
|
|
|
|
Optional<MobileDataParcelle> optionalMobileDataParcelle = Optional.empty();
|
|
|
|
|
|
|
|
|
|
if (parcellePayLoad.getIdBackend() != null) {
|
|
|
|
|
optionalMobileDataParcelle = mobileDataParcelleRepository.findById(parcellePayLoad.getIdBackend());
|
|
|
|
|
if (optionalMobileDataParcelle.isPresent()) {
|
|
|
|
|
mobileDataParcelle = optionalMobileDataParcelle.get();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
optionalMobileDataParcelle = mobileDataParcelleRepository.findByParcellePayLoad_TerminalIdAndParcellePayLoad_ExternalKey(parcellePayLoad.getTerminalId(), parcellePayLoad.getExternalKey());
|
|
|
|
|
if (optionalMobileDataParcelle.isPresent()) {
|
|
|
|
|
mobileDataParcelle = optionalMobileDataParcelle.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mobileDataParcelle.setTraiter(false);
|
|
|
|
|
mobileDataParcelle.setParcellePayLoad(parcellePayLoad);
|
|
|
|
|
mobileDataParcelle = mobileDataParcelleRepository.save(mobileDataParcelle);
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation effectuée avec succès pour " + TypeObjet.CARACTERISTIQUEUNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(parcellePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(true);
|
|
|
|
|
syncResponse.setIdBackend(mobileDataParcelle.getId());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
syncResponse.setObservation("Synchronisation échouée pour " + TypeObjet.CARACTERISTIQUEUNITELOGEMENT.toString());
|
|
|
|
|
syncResponse.setExternalKey(parcellePayLoad.getExternalKey());
|
|
|
|
|
syncResponse.setSynchronise(false);
|
|
|
|
|
syncResponse.setIdBackend(parcellePayLoad.getIdBackend());
|
|
|
|
|
syncResponses.add(syncResponse);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return syncResponses;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteFromPersonne(Long idBackend) {
|
|
|
|
|
uploadRepository.deleteUploadByMembreGroupe_PersonneRepresantee_Id(idBackend);
|
|
|
|
|
@@ -1410,8 +1879,7 @@ public class SynchronisationServiceImpl implements SynchronisationService {
|
|
|
|
|
uploadPayLoad.setEnqueteBatimentId(enqueteBatimentId);
|
|
|
|
|
uploadPayLoad.setEnqueteUniteLogementId(enqueteUniteLogementId);
|
|
|
|
|
uploadPayLoad.setPersonneId(personneId);
|
|
|
|
|
System.out.println("ZZZ");
|
|
|
|
|
System.out.println(uploadPayLoad);
|
|
|
|
|
//System.out.println(uploadPayLoad);
|
|
|
|
|
try {
|
|
|
|
|
Upload upload = new Upload();
|
|
|
|
|
SyncResponse syncResponse = new SyncResponse();
|
|
|
|
|
@@ -1541,7 +2009,7 @@ public class SynchronisationServiceImpl implements SynchronisationService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Upload getUploadFromUplaodPayLoad(Upload upload, UploadPayLoad uploadPayLoad) {
|
|
|
|
|
System.out.println("YYY");
|
|
|
|
|
|
|
|
|
|
if (uploadPayLoad.getTerminalId() != null) {
|
|
|
|
|
Optional<Tpe> optionalTpe = tpeRepository.findById(uploadPayLoad.getTerminalId());
|
|
|
|
|
upload.setTerminal(optionalTpe.orElse(null));
|
|
|
|
|
|