Je t’envoi le code du dossiers.
Il y a un truc mais je ne vois pas quoi. En essayant de debuger je vois bien que les valeurs sont perdu et recherger par quelques choses…
Ok pour faire en live si tu peux.
package com.simplicite.objects.ladnext;
import java.util.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import static com.simplicite.commons.ladnext.Constantes.*;
import com.simplicite.commons.ladnext.EmailRequestToCreateDto;
import com.simplicite.util.*;
import com.simplicite.util.exceptions.GetException;
import com.simplicite.util.exceptions.SaveException;
import com.simplicite.util.exceptions.UpdateException;
import com.simplicite.util.exceptions.ValidateException;
import com.simplicite.util.tools.BusinessObjectTool;
import java.time.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
/** Business object LadDossiers */
public class LadDossiers extends ObjectDB {
private static final long serialVersionUID = 1L;
private static final String INCOMPLET_001 = "LDM_INCOMPLET_001";
private static final String INCOMPLET_002 = "LDM_INCOMPLET_002";
private static final String INCOMPLET_003 = "LDM_INCOMPLET_003";
private static final String INCOMPLET_004 = "LDM_INCOMPLET_004";
public static class TemplateId {
@JsonProperty("templateCode")
String templateCode;
@JsonProperty("templateValue")
Integer templateValue;
}
@Override
public void initCreate() {
setUpFunctionalId();
}
@Override
public void initUpdate() {
Grant g = getGrant();
AppLog.info(
LadDossiers.class,
"initUpdate",
g.getLogin() + "," + g.hasResponsibility("LADOM_GROUP_API"),
null);
AppLog.info(
LadDossiers.class,
"initUpdate",
" ladSouhFormationSouhaite " + getFieldValue("ladSouhFormationSouhaite"),
null);
if (g.hasResponsibility("LADOM_GROUP_API")) {
setFieldValue("ladDosCreepar", replaceApiByNomPrenom(getFieldValue("ladDossiersFunctionalId"), g));
} else {
setFieldValue("ladDosCreepar", g.getLogin());
}
}
@Override
public String postCreate() {
Grant g = getGrant();
AppLog.info(
LadDossiers.class,
"postCreate",
g.getLogin() + "," + g.hasResponsibility("LADOM_GROUP_API") + "," + getFieldValue("ladDossiersFunctionalId"),
null);
updateCreeByDossier(g,getFieldValue("ladDossiersFunctionalId"),g.hasResponsibility("LADOM_GROUP_API"));
return null;
}
/*
@Override
public String[] getTargetObject(String rowId, String[] row) {
AppLog.debug(LadDossiers.class, "getTargetObject", "rowId " + rowId , null);
//
if (rowId.equals(ObjectField.DEFAULT_ROW_ID)) {
return null;
}
if (row==null && (rowId.equals(getRowId()) || select(rowId))) {
row = getValues();
}
String target = null;
if (row!=null) {
String type = row[getFieldIndex("ladDossiersTypedeparcours")];
AppLog.debug(LadDossiers.class, "getTargetObject", "type " + type , null);
//10 PMFP, 20 ACT, 30 PME OBS : FUNERAIRE
if (type.equals("ACT")) {
target = "LadDossierAct";
} else {
if (type.equals("PMFP")) {
target = "LadDossierPmfp";
} else {
if (type.equals("PME")) {
target = "LadDossierPme";
} else {
target = "LadDossierFuneraire";
}
}
}
}
AppLog.debug(LadDossiers.class, "getTargetObject", "target " + target , null);
if (target==null) {
return null; // no redirection
}
String t[] = new String[3];
t[0] = target; // target object
t[1] = "the_ajax_"+target; // main target instance
t[2] = rowId; // target id
return t;
}
*/
/** private */
private void setUpFunctionalId() {
try {
UUID uuid = UUID.randomUUID();
int countThatUuid;
int cpt = 0;
do {
String countThatUuidQuery =
String.format(
"select count(*) from lad_dossiers where lad_dos_func_id = '%s' ",
uuid);
countThatUuid = Integer.parseInt(getGrant().simpleQuery(countThatUuidQuery));
cpt++;
} while (countThatUuid == 0 && cpt < 10);
setFieldValue("ladDossiersFunctionalId", uuid.toString());
} catch (Exception e) {
AppLog.error("Error init uuid", e, getGrant());
}
}
private void updateCreeByDossier(Grant g, String uuidDos, boolean isApi){
ObjectDB o = g.getTmpObject("LadDossiers");
o.resetFilters();
o.getField("ladDossiersFunctionalId").setFilter(uuidDos);
final List<String[]> rows = o.search(false);
for (String[] row : rows) {
o.setValues(row, true);
if (isApi) {
o.setFieldValue("ladDosCreepar", replaceApiByNomPrenom(uuidDos, g));
}else {
o.setFieldValue("ladDosCreepar", g.getLogin());
}
o.save();
}
}
private String replaceApiByNomPrenom(String uuid, Grant g) {
String resultNom = "ladomAPI";
try {
String nomPrenom =
String.format(
"select lad_demandeur_nom,"
+ "lad_demandeur_prenom, "
+ "lad_dossiers_numerodossier "
+ "from lad_dossiers dos "
+ "join lad_demandeur dem on (dos.lad_dosact_dem_id = dem.row_id or "
+ "dos.lad_dospme_dem_id = dem.row_id \n"
+ "or dos.lad_dospmfp_dem_id = dem.row_id or dos.lad_obs_dem_id = dem.row_id)\n"
+ " where lad_dos_func_id = '%s' ",
uuid);
List<String[]> listNomPrenom = getGrant().query(nomPrenom);
AppLog.debug(
LadDossiers.class,
"replaceApiByNomPrenom",
"query " + nomPrenom + " nom,prenom,numdossier " + listNomPrenom,
null);
for (String[] nomprenom : listNomPrenom) {
resultNom = nomprenom[0] + " " + nomprenom[1];
}
return resultNom;
} catch (Exception e) {
AppLog.error("Error replaceApiByNomPrenom", e, getGrant());
return "";
}
}
/** Méthode planifié via cron */
public void relanceDocAllDos() {
Grant g = getGrant();
LocalDate currentDate = LocalDate.parse(Tool.getCurrentDate());
AppLog.info(getClass(), "Begin relanceDocAllDos", ":" + currentDate, g);
controleEtRelance(g, INCOMPLET_001, 1);
controleEtRelance(g, INCOMPLET_002, 7);
controleEtRelance(g, INCOMPLET_003, 14);
controleEtRelance(g, INCOMPLET_004, 21);
AppLog.info(getClass(), "End relanceDocAllDos", ":" + currentDate, g);
}
/** private */
private void controleEtRelance(Grant g, String templateCode, int delay) {
// init conf sendinblue
AppLog.info(
getClass(),
"Begin controleEtRelance",
" templateCode, delay " + templateCode + "," + delay,
g);
int templateId = 0;
final String service = "/smtp/email";
final String sendIndBlueEndPoint = g.getSystemParam("LAD_SENDINBLUE_ENDPOINT");
final JSONObject configMailService =
new JSONObject(g.getSystemParam("LADOM_SENDINDBLUE_SERVICE"));
final String apiKey = configMailService.get("mail.apikey").toString();
final boolean isActive = configMailService.get("mail.actif").toString().equals("true");
final String url = sendIndBlueEndPoint + service;
final JSONArray template = configMailService.getJSONArray("mail.templateId");
// Surchage template Id pour mail
try {
ObjectMapper mapper = new ObjectMapper();
LadDossiers.TemplateId[] listTmpId =
mapper.readValue(template.toString(), LadDossiers.TemplateId[].class);
for (LadDossiers.TemplateId tmpId : listTmpId) {
if (templateCode.equals(tmpId.templateCode)) {
templateId = tmpId.templateValue;
}
}
AppLog.info(
getClass(), "controleEtRelance", "Surchage de templateId:" + templateId, g);
} catch (Exception e) {
AppLog.error(getClass(), "controleEtRelance", "------------", e, g);
}
try {
// Recherche des dossiers Incomplet
String query =
" select dos.row_id, lad_dossiers_numerodossier ,lad_demandeur_nom,lad_demandeur_prenom,lad_demandeur_mail "
+ " from lad_dossiers dos "
+ " join lad_demandeur dem on (dos.lad_dosact_dem_id = dem.row_id or "
+ " dos.lad_dospme_dem_id = dem.row_id or "
+ " dos.lad_dospmfp_dem_id = dem.row_id or "
+ " dos.lad_obs_dem_id= dem.row_id) "
+ " where (lad_dossier_act_statut = 'INCOMPLET' or "
+ " lad_dossier_pme_statut = 'INCOMPLET' or "
+ " lad_dossier_pmfp_statut = 'INCOMPLET' or "
+ " lad_dossier_obs_statut = 'INCOMPLET') "
+ " AND to_char(dos.updated_dt,'YYYYMMDD') = to_char(now() + '" + delay + " DAY','YYYYMMDD');";
// Cas MySQL
//+ " AND STR_TO_DATE(dos.updated_dt, '%Y-%m-%d') = DATE_SUB(CURDATE(), INTERVAL "
// Cas HSQL
//" AND CAST(dos.updated_dt AS DATE) = DATE_SUB(current_date, INTERVAL "
//+ delay
//+ " DAY);";
AppLog.debug(getClass(), "controleEtRelance", "query:" + query, g);
List<String[]> listDossier = g.query(query);
for (String[] cur : listDossier) {
// select data
String rowId = cur[0];
String type = cur[1] != null ? cur[1].replaceAll("[0-9]", "") : "";
// Init content POST
EmailRequestToCreateDto.ToMail toMail = new EmailRequestToCreateDto.ToMail();
toMail.setName(cur[2] != null ? cur[2] : "");
toMail.setEmail(cur[4] != null ? cur[4] : "");
List<EmailRequestToCreateDto.ToMail> to = new ArrayList<>();
to.add(toMail);
EmailRequestToCreateDto.ParamsTemplate paramsTemplate =
new EmailRequestToCreateDto.ParamsTemplate();
paramsTemplate.setLadDemandeurMail(cur[4] != null ? cur[4] : "");
// paramsTemplate.setFIDENT("NumeroSiam");
// paramsTemplate.setNDOSDEM("123456789");
paramsTemplate.setLadDossiersNumerodossier(cur[1] != null ? cur[1] : "");
String subject = "Relance";
EmailRequestToCreateDto body = new EmailRequestToCreateDto();
body.setParams(paramsTemplate);
body.setTemplateId(templateId);
body.setTo(to);
body.setSubject(subject);
AppLog.debug(getClass(), "controleEtRelance", " rowId " + rowId, g);
if (isActive) {
// envoi mail
com.simplicite.commons.ladnext.LadomProxyService.sendMail(
url, apiKey, body.toJson(body));
// mise à jour statut dossier si 21 relance
if (templateCode.equals(INCOMPLET_004)) {
// mise à ABANDON etat dossier
updateDossier(rowId, "ABANDON", type);
}
}
}
AppLog.info(getClass(), "End controleEtRelance", " delay " + delay, g);
} catch (Exception e) {
AppLog.error(getClass(), "controleEtRelance", "------------", e, g);
}
}
/**
* @param rowId
* @param statutDossier
* @param type
*/
private void updateDossier(String rowId, String statutDossier, String type) {
String target = "";
String statut = "";
switch (type) {
case "ACT":
target = "LadDossierAct";
statut = "ladDossierActStatut";
break;
case "PMFP":
target = "LadDossierPmfp";
statut = "ladDossierPmfpStatut";
break;
case "PME":
target = "LadDossierPme";
statut = "ladDossierPmeStatut";
break;
case "OBS":
target = "LadDossierFuneraire";
statut = "ladObsStatut";
break;
}
ObjectDB messageObj;
BusinessObjectTool messageTool;
messageObj = getGrant().getProcessObject(target);
messageTool = messageObj.getTool();
try {
messageTool.getForUpsert(new JSONObject().put("row_id", rowId));
messageObj.setFieldValue(statut, statutDossier);
} catch (GetException e) {
AppLog.error(getClass(), "GetException", e.getMessage(), null, getGrant());
}
try {
messageTool.validateAndUpdate();
} catch (ValidateException ev) {
AppLog.error(getClass(), "ValidateException", ev.getMessage(), null, getGrant());
} catch (UpdateException ex) {
AppLog.error(getClass(), "UpdateException", ex.getMessage(), null, getGrant());
} catch (SaveException es) {
AppLog.error(getClass(), "SaveException", es.getMessage(), null, getGrant());
}
}
public void updateDossierActPerime() {
Grant g = getGrant();
LocalDate currentDate = LocalDate.parse(Tool.getCurrentDate());
AppLog.info(getClass(), "Begin updateDossierActPerime", ":" + currentDate, g);
// Requete pour recuperer les dossiers ACT dont le bon est arrive a expiration
try {
// Recherche des dossiers Incomplet
String query = "select dos.row_id, dos.lad_dossier_act_statut "
+ "from lad_dossiers dos "
+ "join lad_bon_act bon on (bon.ladbonact_laddossieract_id = dos.row_id) "
+ "where to_char(bon.lad_bon_act_date_fin_validite, 'YYYYMMDD') < to_char(now(), 'YYYYMMDD');";
AppLog.info(getClass(), "updateDossierActPerime", "query:" + query, g);
List<String[]> listeDossiers = g.query(query);
for (String[] cur : listeDossiers) {
// select data
String rowId = cur[0];
String statut = cur[1];
// Pour eviter de mettre a jour les dossiers deja a "perime", on ne prend que ceux qui sont au statut "favorable" et "bon emis"
AppLog.info(getClass(), "updateDossierActPerime", "dossiers a mettre a jour : row_id = " + rowId + " - statut : " + statut, g);
if (StringUtils.equals(LISTCODE_ETATDOSSIER_BON_EMIS, statut) || StringUtils.equals(LISTCODE_ETATDOSSIER_FAVORABLE, statut)) {
// mise à ABANDON etat dossier
updateDossier(rowId, LISTCODE_ETATDOSSIER_PERIME, "ACT");
}
}
LocalDate currentDateFin = LocalDate.parse(Tool.getCurrentDate());
AppLog.info(getClass(), "End updateDossierActPerime", ":" + currentDateFin, g);
} catch (Exception e) {
AppLog.error(getClass(), "updateDossierActPerime", "------------", e, g);
}
}
}