417 lines
17 KiB
Java
417 lines
17 KiB
Java
// * --- Area Manuale = BO - Header
|
||
// * --- Fine Area Manuale
|
||
public class postin_userBO extends postin_userBL {
|
||
class SqlLoader {
|
||
double m_nColumns = 0;
|
||
CPSql m_Sql;
|
||
String m_cServer;
|
||
String m_cMainTable;
|
||
String m_cSelect;
|
||
String m_cFrom;
|
||
String m_cAlias;
|
||
String m_cWhere;
|
||
String m_cOrderBy;
|
||
public SqlLoader(CPSql sql,String server,String from,String alias,String where,String orderby) {
|
||
m_cAlias = alias;
|
||
m_Sql = sql;
|
||
m_cServer = server;
|
||
m_cMainTable = alias;
|
||
m_cSelect = m_cAlias+".*";
|
||
m_cFrom = from+" "+m_cAlias;
|
||
m_cWhere = where;
|
||
m_cOrderBy = orderby;
|
||
}
|
||
public CPResultSet Query() {
|
||
String l_cWhere = QueryFilter(m_Ctx);
|
||
if (CPLib.Empty(l_cWhere)) {
|
||
l_cWhere = m_cWhere;
|
||
} else {
|
||
if ( ! (CPLib.Empty(m_cWhere))) {
|
||
l_cWhere = "("+m_cWhere+") and ("+l_cWhere+")";
|
||
}
|
||
}
|
||
return m_Sql.Query(m_cServer,CPSql.BuildSQLPhrase(m_cSelect,m_cFrom,l_cWhere,m_cOrderBy));
|
||
}
|
||
}
|
||
// * --- Area Manuale = BO - Properties
|
||
// * --- Fine Area Manuale
|
||
public postin_userBO (CPContext p_ContextObject) {
|
||
super(p_ContextObject);
|
||
}
|
||
public boolean CheckOTPSecurity() {
|
||
boolean l_bResult;
|
||
l_bResult = true;
|
||
int accessType;
|
||
boolean requiredOTP;
|
||
boolean requiredPwd;
|
||
requiredOTP = (m_bLoaded?false:false);
|
||
requiredPwd = (m_bLoaded?false:false);
|
||
if (requiredOTP) {
|
||
accessType = 3;
|
||
} else if (requiredPwd) {
|
||
accessType = 2;
|
||
} else {
|
||
accessType = SPLib.AccessType((m_bLoaded?"edit":"insert"),"postin_user");
|
||
}
|
||
if (CPLib.eq(accessType,2)) {
|
||
// richiesta password
|
||
if ( ! (CPLib.CheckPwd(m_Ctx,m_cPassword))) {
|
||
l_bResult = false;
|
||
m_nLastError = 4;
|
||
m_cLastMsgError = (CPLib.Empty(m_cPassword)?"MSG_NEED_PWD":"MSG_WRONG_PWD");
|
||
}
|
||
} else if (CPLib.eq(accessType,3)) {
|
||
// richiesto otp
|
||
if (CPLib.Empty(m_cOTP) || ! (CPLib.CheckOTP(m_Ctx.UserCode(),m_cOTP))) {
|
||
l_bResult = false;
|
||
m_nLastError = 5;
|
||
m_cLastMsgError = (CPLib.Empty(m_cOTP)?"MSG_NEED_OTP":"MSG_WRONG_OTP");
|
||
}
|
||
}
|
||
return l_bResult;
|
||
}
|
||
public boolean CanSave() {
|
||
ResetErrorMessage();
|
||
boolean l_bResult;
|
||
l_bResult = true;
|
||
l_bResult = m_Ctx.GetAuthority().HasWarns(w_code);
|
||
if (l_bResult) {
|
||
} else {
|
||
m_cLastMsgError = "MSG_CANNOT_SAVE";
|
||
}
|
||
if (l_bResult) {
|
||
l_bResult = CanSaveMNTs(m_MNTs,true) && CanSaveMNTs(m_MNTs,false);
|
||
}
|
||
return l_bResult;
|
||
}
|
||
public static String[] m_cSaveParameterNames = {"AlreadyAccepted"};
|
||
public boolean Save() {
|
||
return Save(false);
|
||
}
|
||
public boolean Save(boolean p_bAlreadyAccepted) {
|
||
boolean l_bResult;
|
||
l_bResult = true;
|
||
// Se il record <20> stato modificato, prosegue con il salvataggio
|
||
if (IsUpdated()) {
|
||
// Verifica globale dei check delle variabili.
|
||
l_bResult = l_bResult && BRCheck();
|
||
l_bResult = l_bResult && Check();
|
||
l_bResult = l_bResult && (m_bSkipCheckOTPSecurity || CheckOTPSecurity());
|
||
l_bResult = l_bResult && (p_bAlreadyAccepted || CanSave());
|
||
if (l_bResult) {
|
||
// Il metodo "Save" richiede l'utilizzo di una transazione. Se il modulo che
|
||
// gestisce le transazioni trova che ce n'<27> gi<67> una, utilizza quella, altrimenti
|
||
// ne inizia una nuova ("begin transaction").
|
||
m_Sql.RequireTransaction();
|
||
if (m_bLoaded) {
|
||
Update();
|
||
BROnUpdated();
|
||
} else {
|
||
Insert();
|
||
BROnInserted();
|
||
}
|
||
if (CPLib.gt(m_MNTs.length,0)) {
|
||
if (m_bLoaded) {
|
||
NotifyEvent("Update children start");
|
||
} else {
|
||
NotifyEvent("Insert children start");
|
||
}
|
||
}
|
||
CPLib.SaveMNTs(m_Sql,m_MNTs,this);
|
||
l_bResult = CPLib.eq(m_Sql.GetTransactionStatus(),CPSql.OK);
|
||
if (CPLib.gt(m_MNTs.length,0)) {
|
||
if (m_bLoaded) {
|
||
NotifyEvent("Update children end");
|
||
} else {
|
||
NotifyEvent("Insert children end");
|
||
}
|
||
}
|
||
/* Se il metodo di richiesta della transazione ha cominciato una nuova transazione,
|
||
questa viene terminata ("Commit" o "Rollback"), altrimenti segna come completata
|
||
la parte di transazione corrente
|
||
*/
|
||
// * --- Area Manuale = BO - Save End
|
||
// * --- Fine Area Manuale
|
||
BROnSaved();
|
||
if (CPLib.ne(m_Sql.GetTransactionStatus(),CPSql.OK)) {
|
||
m_cLastMsgError = m_Sql.TransactionErrorMessage();
|
||
l_bResult = false;
|
||
}
|
||
m_Sql.CompleteTransaction();
|
||
}
|
||
}
|
||
return l_bResult;
|
||
}
|
||
public static String[] m_cLoadParameterNames = {"code"};
|
||
public static String[] m_cDeleteParameterNames = m_cLoadParameterNames;
|
||
public boolean Load(String p_code) {
|
||
CPResultSet l_rsLoad=null;
|
||
SqlLoader l_oSqlLoader;
|
||
l_oSqlLoader = new SqlLoader(m_Sql,m_cServer_postit,m_cPhName_postit,m_cVirtName_postit,m_cVirtName_postit+".code="+CPSql.SQLValueAdapter(CPLib.ToSQL(p_code,"C",10,0),m_cServer_postit,p_code),"");
|
||
// * --- Area Manuale = BO - Load Record Init
|
||
// * --- postin_user
|
||
l_oSqlLoader.m_cServer = m_Ctx.GetPostinServer(CPLib.Left(m_Ctx.GetAuthority().GetTableCode(p_code),CPLib.At("\\",m_Ctx.GetAuthority().GetTableCode(p_code))-1));
|
||
|
||
// * --- Fine Area Manuale
|
||
BlankStatusVariables();
|
||
// Cursore dei record caricati
|
||
l_rsLoad = l_oSqlLoader.Query();
|
||
try {
|
||
m_bLoaded = ! (l_rsLoad.Eof());
|
||
if (m_bLoaded) {
|
||
m_bCalculating = true;
|
||
/* Assegna il valore iniziale a tutte le variabili non calcolate/inizializzate.
|
||
Queste variabili non vengono inizializzate nella lettura del record,
|
||
quindi terrebbero il valore che avevano precedentemente.
|
||
*/
|
||
w_rgb = "";
|
||
w_MultiCompS = "";
|
||
/* Assegna i valori letti dal record appena caricato nelle variabili di work.
|
||
Vengono calcolate e inizializzate le variabili ed eseguiti i link, rispettando la sequenza
|
||
degli item.
|
||
*/
|
||
w_code = l_rsLoad.GetString("code");
|
||
w_postit = l_rsLoad.GetString("postit");
|
||
w_scrivi_postit = m_Ctx.Translate("MSG_POSTIT_WRITE");
|
||
w_textualpostit = (CPLib.Empty(w_postit)?w_scrivi_postit:CPLib.Strtran(CPLib.Substr(w_postit,2,CPLib.At(CPLib.Chr(13)+CPLib.Chr(10),w_postit)-3),"<EFBFBD>","\n"));
|
||
w_usercode = l_rsLoad.GetDouble("usercode");
|
||
w_createdby = l_rsLoad.GetDouble("createdby");
|
||
w_color = " 14745599";
|
||
w_status = l_rsLoad.GetString("status");
|
||
w_datestart = l_rsLoad.GetDateTime("datestart");
|
||
w_datestop = l_rsLoad.GetDateTime("datestop");
|
||
w_color_sample = "";
|
||
// Assegna i valori degli op_
|
||
SPExtenderLib.LoadExtendedFields(l_rsLoad,extendedFields);
|
||
if (CPLib.HasTableCPCCCHK(m_Ctx,"postit")) {
|
||
m_cOldCPCCCHK = l_rsLoad.GetString("CPCCCHK");
|
||
} else {
|
||
m_cOldCPCCCHK = "nocpcc";
|
||
}
|
||
m_bCalculating = false;
|
||
SaveDependsOn();
|
||
m_cPreviousState = GetCurrentState();
|
||
NotifyEvent("Load");
|
||
} else {
|
||
Blank();
|
||
}
|
||
} finally {
|
||
l_rsLoad.Close();
|
||
}
|
||
// * --- Area Manuale = BO - Load Record End
|
||
// * --- Fine Area Manuale
|
||
Calculation_WWJZTCAEIY();
|
||
return m_bLoaded;
|
||
}
|
||
public boolean Load() {
|
||
return Load(w_code);
|
||
}
|
||
void Insert() {
|
||
String l_cSql;
|
||
String l_cCPCCCHK = CPLib.NewCPCCCHK();
|
||
double l_nUpdatedRows;
|
||
// * --- Area Manuale = BO - Insert Init
|
||
// * --- postin_user
|
||
m_cServer_postit = m_Ctx.GetPostinServer(CPLib.Left(m_Ctx.GetAuthority().GetTableCode(w_code),CPLib.At("\\",m_Ctx.GetAuthority().GetTableCode(w_code))-1));
|
||
|
||
// * --- Fine Area Manuale
|
||
// * --- Area Manuale = BO - Autonum Assigned
|
||
// * --- Fine Area Manuale
|
||
NotifyEvent("Insert start");
|
||
if (CPLib.eq(m_Sql.GetTransactionStatus(),CPSql.OK)) {
|
||
m_oParameters = CPLib.GetParamsForSqlUpdate(m_cServer_postit);
|
||
l_cSql = "insert into "+m_oWrInfo_postit.GetTableWriteName()+" (";
|
||
l_cSql = l_cSql+"code,";
|
||
l_cSql = l_cSql+"postit,";
|
||
l_cSql = l_cSql+"usercode,";
|
||
l_cSql = l_cSql+"createdby,";
|
||
l_cSql = l_cSql+"status,";
|
||
l_cSql = l_cSql+"datestart,";
|
||
l_cSql = l_cSql+"datestop,";
|
||
l_cSql = l_cSql+SPExtenderLib.InsertExtendedFieldsNameToSQL(extendedFields);
|
||
l_cSql = l_cSql+m_oWrInfo_postit.InsertFields();
|
||
if (CPLib.HasTableCPCCCHK(m_Ctx,"postit")) {
|
||
l_cSql = l_cSql+"CPCCCHK";
|
||
} else {
|
||
l_cSql = CPLib.TrimTrailingComma(l_cSql);
|
||
}
|
||
l_cSql = l_cSql+") values (";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_code,"C",10,0)+", ";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_postit,"M",10,0,m_cServer_postit,m_oParameters)+", ";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_usercode,"N",4,0)+", ";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_createdby,"N",4,0)+", ";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_status,"C",3,0)+", ";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_datestart,"T",14,0)+", ";
|
||
l_cSql = l_cSql+CPLib.ToSQL(w_datestop,"T",14,0)+", ";
|
||
l_cSql = l_cSql+SPExtenderLib.InsertExtendedFieldsValueToSQL(extendedFields);
|
||
l_cSql = l_cSql+m_oWrInfo_postit.InsertValues();
|
||
if (CPLib.HasTableCPCCCHK(m_Ctx,"postit")) {
|
||
l_cSql = l_cSql+CPLib.ToSQL(l_cCPCCCHK,"C",10,0);
|
||
} else {
|
||
l_cSql = CPLib.TrimTrailingComma(l_cSql);
|
||
}
|
||
l_cSql = l_cSql+")";
|
||
l_nUpdatedRows = m_Sql.Update(m_cServer_postit,l_cSql,m_oParameters);
|
||
if (CPLib.ne(l_nUpdatedRows,1)) {
|
||
m_Sql.AbortTransaction();
|
||
}
|
||
}
|
||
NotifyEvent("Insert end");
|
||
// * --- Area Manuale = BO - Insert End
|
||
// * --- Fine Area Manuale
|
||
}
|
||
void Update() {
|
||
String l_cSql;
|
||
int l_nUpdatedRows;
|
||
String l_cCPCCCHK = CPLib.NewCPCCCHK();
|
||
// * --- Area Manuale = BO - Replace Init
|
||
// * --- postin_user
|
||
String l_cAppTableCode = m_Ctx.GetAuthority().GetTableCode(w_code),
|
||
l_cCompanyTablecode = m_Ctx.GetAuthority().CompanyTablecode(l_cAppTableCode),
|
||
l_cTablename = CPLib.Left(l_cAppTableCode,CPLib.At("\\",l_cAppTableCode)-1);
|
||
m_cServer_postit = m_Ctx.GetPostinServer(l_cTablename);
|
||
boolean l_bChange = false;
|
||
if (!l_cCompanyTablecode.equals(l_cAppTableCode)) {
|
||
CPResultSet w = m_Sql.Query(m_cServer_postit,"select 1 from "+m_Ctx.PhNameAdapter("cpwarn")+
|
||
" where tablecode = "+CPLib.ToSQL(l_cAppTableCode,"C",0,0)+
|
||
" and warncode="+CPLib.ToSQL(w_code,"C",10,0));
|
||
try {l_bChange = !w.Eof();}
|
||
finally{w.Close();}
|
||
}
|
||
String l_cLastWhere = w_MultiCompS;
|
||
if (l_bChange)
|
||
l_cLastWhere = com.zucchetti.sitepainter.Sanitizer.lastWhere(w_MultiCompS);
|
||
if (CPLib.Empty(l_cLastWhere)){
|
||
l_bChange = false;
|
||
CPStdCounter.SecurityError(new IllegalArgumentException("Ignored LastWhere:--->"+w_MultiCompS+"<---"));
|
||
}
|
||
//sixsigma 3756: correzione postin multicompany
|
||
if (l_bChange) {
|
||
m_Sql.Update(m_cServer_postit,"update "+m_Ctx.PhNameAdapter("cpwarn")+" set tablecode = "+CPLib.ToSQL(l_cCompanyTablecode,"C",0,0)+" where warncode="+CPSql.SQLValueAdapter(CPLib.ToSQL(w_code,"C",10,0),m_cServer_postit,w_code));
|
||
String l_cCompany = CPLib.RTrim(m_Ctx.GetCompany());
|
||
String l_cNotCompany = "";
|
||
postin_userBO l_BO = null;
|
||
java.util.ArrayList<String> l_OtherCompanies = new java.util.ArrayList<String>();
|
||
CPResultSet cp = m_Sql.Query(m_cServer_postit,"select codazi from "+m_Ctx.PhNameAdapter("cpazi"));
|
||
m_Ctx.BeginMutationSection();
|
||
try {
|
||
for (; !cp.Eof(); cp.Next()) if (!CPLib.RTrim(cp.GetString("codazi")).equals(l_cCompany)) {
|
||
l_OtherCompanies.add(CPLib.RTrim(cp.GetString("codazi")));
|
||
}
|
||
cp.Close();
|
||
for (int i=0;i<l_OtherCompanies.size();) {
|
||
m_Ctx.SetCompany(l_OtherCompanies.get(i),true);
|
||
cp = m_Sql.Query(m_cServer_postit, "select 1 from "+m_Ctx.GetPhName(l_cTablename)+" " + l_cTablename + " where "+l_cLastWhere);
|
||
if (cp.Eof())
|
||
l_OtherCompanies.remove(i);
|
||
else
|
||
i++;
|
||
cp.Close();
|
||
}
|
||
if (l_OtherCompanies.size() > 0 )
|
||
l_cNotCompany = GetContext();
|
||
for (String l_cACompany : l_OtherCompanies) {
|
||
m_Ctx.SetCompany(CPLib.RTrim(l_cACompany),true);
|
||
l_BO = new postin_userBO(m_Ctx);
|
||
l_BO.SetFromContext(l_cNotCompany);
|
||
l_BO.w_code = l_cAppTableCode;
|
||
postin_addwarnR.Make(m_Ctx,l_BO).Run();
|
||
l_BO.Save();
|
||
}
|
||
} finally {
|
||
m_Ctx.EndMutationSection();
|
||
cp.Close();
|
||
}
|
||
}
|
||
m_Sql.Update(m_cServer_postit,"update "+m_cPhName_postit+" set CPCCCHK = "+CPLib.ToSQL(m_cOldCPCCCHK,"C",10,0)+" where code="+CPSql.SQLValueAdapter(CPLib.ToSQL(w_code,"C",10,0),m_cServer_postit,w_code));
|
||
|
||
// * --- Fine Area Manuale
|
||
NotifyEvent("Update start");
|
||
if (CPLib.eq(m_Sql.GetTransactionStatus(),CPSql.OK)) {
|
||
m_oParameters = CPLib.GetParamsForSqlUpdate(m_cServer_postit);
|
||
l_cSql = "Update "+m_oWrInfo_postit.GetTableWriteName()+" set";
|
||
l_cSql = l_cSql+" postit = "+CPLib.ToSQL(w_postit,"M",10,0,m_cServer_postit,m_oParameters);
|
||
l_cSql = l_cSql+", usercode = "+CPLib.ToSQL(w_usercode,"N",4,0);
|
||
l_cSql = l_cSql+", createdby = "+CPLib.ToSQL(w_createdby,"N",4,0);
|
||
l_cSql = l_cSql+", status = "+CPLib.ToSQL(w_status,"C",3,0);
|
||
l_cSql = l_cSql+", datestart = "+CPLib.ToSQL(w_datestart,"T",14,0);
|
||
l_cSql = l_cSql+", datestop = "+CPLib.ToSQL(w_datestop,"T",14,0);
|
||
if (CPLib.HasTableCPCCCHK(m_Ctx,"postit")) {
|
||
l_cSql = l_cSql+", CPCCCHK ="+CPLib.ToSQL(l_cCPCCCHK,"C",10,0);
|
||
}
|
||
l_cSql = l_cSql+SPExtenderLib.UpdateExtendedFieldsNameValueToSQL(extendedFields);
|
||
l_cSql = l_cSql+" where ";
|
||
l_cSql = l_cSql+"code="+CPSql.SQLValueAdapter(CPLib.ToSQL(w_code,"C",10,0),m_cServer_postit,w_code);
|
||
l_cSql = l_cSql+m_oWrInfo_postit.WhereFilter();
|
||
if (CPLib.HasTableCPCCCHK(m_Ctx,"postit")) {
|
||
l_cSql = l_cSql+" and CPCCCHK="+CPLib.ToSQL(m_cOldCPCCCHK,"C",10,0);
|
||
}
|
||
l_nUpdatedRows = m_Sql.Update(m_cServer_postit,l_cSql,m_oParameters);
|
||
if (CPLib.ne(l_nUpdatedRows,1)) {
|
||
m_Sql.AbortTransaction();
|
||
}
|
||
}
|
||
NotifyEvent("Update end");
|
||
// * --- Area Manuale = BO - Replace End
|
||
// * --- Fine Area Manuale
|
||
}
|
||
public boolean Delete(String p_code) {
|
||
String l_cSql;
|
||
int l_nUpdatedRows = 0;
|
||
boolean l_bTrsOk = false;
|
||
Load(p_code);
|
||
// * --- Area Manuale = BO - Delete Init
|
||
// * --- postin_user
|
||
m_cServer_postit = m_Ctx.GetPostinServer(CPLib.Left(m_Ctx.GetAuthority().GetTableCode(w_code),CPLib.At("\\",m_Ctx.GetAuthority().GetTableCode(w_code))-1));
|
||
m_Sql.Update(m_cServer_postit,"update "+m_cPhName_postit+" set CPCCCHK = "+CPLib.ToSQL(m_cOldCPCCCHK,"C",10,0)+" where code="+CPSql.SQLValueAdapter(CPLib.ToSQL(w_code,"C",10,0),m_cServer_postit,w_code));
|
||
// * --- Fine Area Manuale
|
||
if (m_bLoaded) {
|
||
if (CanDelete()) {
|
||
/* Il metodo "Delete" richiede l'utilizzo di una transazione. Se il modulo che
|
||
gestisce le transazioni trova che ce n'<27> gi<67> una, utilizza quella, altrimenti
|
||
ne inizia una nuova ("begin transaction").
|
||
*/
|
||
m_Sql.RequireTransaction();
|
||
NotifyEvent("Delete start");
|
||
CPLib.DeleteMNTs(m_Sql,m_MNTs,this);
|
||
if (CPLib.eq(m_Sql.GetTransactionStatus(),CPSql.OK)) {
|
||
l_cSql = "Delete from "+m_oWrInfo_postit.GetTableWriteName()+" where ";
|
||
l_cSql = l_cSql+"code="+CPSql.SQLValueAdapter(CPLib.ToSQL(w_code,"C",10,0),m_cServer_postit,w_code);
|
||
l_cSql = l_cSql+m_oWrInfo_postit.WhereFilter();
|
||
if (CPLib.HasTableCPCCCHK(m_Ctx,"postit")) {
|
||
l_cSql = l_cSql+" and CPCCCHK="+CPLib.ToSQL(m_cOldCPCCCHK,"C",10,0);
|
||
}
|
||
l_nUpdatedRows = m_Sql.Update(m_cServer_postit,l_cSql);
|
||
if (CPLib.ne(l_nUpdatedRows,1)) {
|
||
// AbortTransaction
|
||
m_Sql.AbortTransaction();
|
||
}
|
||
}
|
||
NotifyEvent("Delete end");
|
||
BROnDeleted();
|
||
l_bTrsOk = CPLib.eq(m_Sql.GetTransactionStatus(),CPSql.OK);
|
||
// Se il metodo di richiesta della transazione ha cominciato una nuova transazione,
|
||
// questa viene terminata ("Commit" o "Rollback"), altrimenti segna come completata
|
||
// la parte di transazione corrente
|
||
m_Sql.CompleteTransaction();
|
||
} else {
|
||
m_Sql.AbortTransaction(m_cLastMsgError);
|
||
}
|
||
}
|
||
// * --- Area Manuale = BO - Delete End
|
||
// * --- Fine Area Manuale
|
||
return m_bLoaded && CPLib.eq(l_nUpdatedRows,1) && l_bTrsOk;
|
||
}
|
||
public boolean Delete() {
|
||
return Delete(w_code);
|
||
}
|
||
public static CPLib.SPLinkProperties GetLinkProperties(String p_cID) {
|
||
CPLib.SPLinkProperties result = CPLib.GetSPLinkerProperties();
|
||
return result;
|
||
}
|
||
// * --- Area Manuale = BO - Methods
|
||
// * --- Fine Area Manuale
|
||
// ENTITY_BATCHES: ,postin_deletewarn,
|
||
public static final String i_InvokedRoutines = ",postin_deletewarn,";
|
||
}
|