use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class MWorkflow method loadTrl.
/**
* Load Translation
*/
private void loadTrl() {
if (Env.isBaseLanguage(getCtx(), "AD_Workflow") || get_ID() == 0)
return;
String sql = "SELECT Name, Description, Help FROM AD_Workflow_Trl WHERE AD_Workflow_ID=? AND AD_Language=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, get_ID());
pstmt.setString(2, Env.getAD_Language(getCtx()));
rs = pstmt.executeQuery();
if (rs.next()) {
m_name_trl = rs.getString(1);
m_description_trl = rs.getString(2);
m_help_trl = rs.getString(3);
m_translated = true;
}
} catch (SQLException e) {
//log.log(Level.SEVERE, sql, e);
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("Translated=" + m_translated);
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class ReportStarter method addProcessParameters.
/**
* Load Process Parameters into given params map
* @param AD_PInstance_ID
* @param params
* @param trxName
*/
private static void addProcessParameters(int AD_PInstance_ID, Map<String, Object> params, String trxName) {
final String sql = "SELECT " + " " + X_AD_PInstance_Para.COLUMNNAME_ParameterName + "," + X_AD_PInstance_Para.COLUMNNAME_P_String + "," + X_AD_PInstance_Para.COLUMNNAME_P_String_To + "," + X_AD_PInstance_Para.COLUMNNAME_P_Number + "," + X_AD_PInstance_Para.COLUMNNAME_P_Number_To + "," + X_AD_PInstance_Para.COLUMNNAME_P_Date + "," + X_AD_PInstance_Para.COLUMNNAME_P_Date_To + "," + X_AD_PInstance_Para.COLUMNNAME_Info + "," + X_AD_PInstance_Para.COLUMNNAME_Info_To + " FROM " + X_AD_PInstance_Para.Table_Name + " WHERE " + X_AD_PInstance_Para.COLUMNNAME_AD_PInstance_ID + "=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName);
pstmt.setInt(1, AD_PInstance_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
String pStr = rs.getString(2);
String pStrTo = rs.getString(3);
BigDecimal pNum = rs.getBigDecimal(4);
BigDecimal pNumTo = rs.getBigDecimal(5);
Timestamp pDate = rs.getTimestamp(6);
Timestamp pDateTo = rs.getTimestamp(7);
if (pStr != null) {
if (pStrTo != null) {
params.put(name + "1", pStr);
params.put(name + "2", pStrTo);
} else {
params.put(name, pStr);
}
} else if (pDate != null) {
if (pDateTo != null) {
params.put(name + "1", pDate);
params.put(name + "2", pDateTo);
} else {
params.put(name, pDate);
}
} else if (pNum != null) {
if (pNumTo != null) {
params.put(name + "1", pNum);
params.put(name + "2", pNumTo);
} else {
params.put(name, pNum);
}
}
//
// Add parameter info - teo_sarca FR [ 2581145 ]
String info = rs.getString(8);
String infoTo = rs.getString(9);
params.put(name + "_Info1", (info != null ? info : ""));
params.put(name + "_Info2", (infoTo != null ? infoTo : ""));
}
} catch (SQLException e) {
// log.severe("Execption; sql = "+sql+"; e.getMessage() = " +e.getMessage());
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class Doc method fillDocumentsTableArrays.
private static void fillDocumentsTableArrays() {
if (documentsTableID == null) {
String sql = "SELECT t.AD_Table_ID, t.TableName " + "FROM AD_Table t, AD_Column c " + "WHERE t.AD_Table_ID=c.AD_Table_ID AND " + "c.ColumnName='Posted' AND " + "IsView='N' " + "ORDER BY t.AD_Table_ID";
ArrayList<Integer> tableIDs = new ArrayList<Integer>();
ArrayList<String> tableNames = new ArrayList<String>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
tableIDs.add(rs.getInt(1));
tableNames.add(rs.getString(2));
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Convert to array
documentsTableID = new int[tableIDs.size()];
documentsTableName = new String[tableIDs.size()];
for (int i = 0; i < documentsTableID.length; i++) {
documentsTableID[i] = tableIDs.get(i);
documentsTableName[i] = tableNames.get(i);
}
}
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class MReportCube method update.
public String update(boolean reset, boolean force) {
String result = getName() + ": ";
Timestamp ts = null;
long start;
long elapsed;
String where = " WHERE PA_ReportCube_ID = " + getPA_ReportCube_ID();
String periods = " (-1) ";
if (getLastRecalculated() != null && !reset) {
StringBuilder periodList = new StringBuilder();
StringBuilder periodNames = new StringBuilder();
String sql = "SELECT DISTINCT p.C_Period_ID, p.Name FROM C_Period p " + "INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID) " + "INNER JOIN PA_ReportCube c ON (c.C_Calendar_ID = y.C_Calendar_ID) " + "INNER JOIN Fact_Acct fact ON (fact.dateacct between p.startdate and p.enddate " + " and fact.ad_client_id = c.ad_client_id) " + "WHERE c.PA_ReportCube_ID = ? " + "AND fact.updated > c.LastRecalculated " + "AND p.periodtype='S' ";
log.log(Level.FINE, sql);
start = System.currentTimeMillis();
KeyNamePair[] changedPeriods = DB.getKeyNamePairs(sql, false, getPA_ReportCube_ID());
elapsed = (System.currentTimeMillis() - start) / 1000;
log.log(Level.FINE, "Selecting changed periods took:" + elapsed + "s");
if (changedPeriods != null && changedPeriods.length > 0) {
periodList.append(" (");
for (KeyNamePair p : changedPeriods) {
periodList.append(p.getID() + ", ");
periodNames.append(p.getName() + ", ");
}
periodList.delete(periodList.length() - 2, periodList.length());
periodList.append(" )");
log.log(Level.FINE, "Periods requiring update: " + periodNames.toString());
} else
return "Nothing to update in " + getName();
periods = periodList.toString();
where += (" AND C_Period_ID IN " + periods);
}
if (!force) {
String lockSQL = "UPDATE PA_ReportCube SET Processing = 'Y' " + "WHERE Processing = 'N' AND PA_ReportCube_ID = " + getPA_ReportCube_ID();
int locked = DB.executeUpdateEx(lockSQL, get_TrxName());
if (locked != 1) {
throw new AdempiereException("Unable to lock cube for update:" + getName());
}
}
try {
// delete
String delSQL = "DELETE FROM Fact_Acct_Summary fas " + where;
log.log(Level.FINE, "Delete sql: " + delSQL);
start = System.currentTimeMillis();
int deleted = DB.executeUpdateEx(delSQL, get_TrxName());
elapsed = (System.currentTimeMillis() - start) / 1000;
result += "Deleted " + deleted + " in " + elapsed + " s;";
log.log(Level.FINE, result);
// insert
StringBuilder insert = new StringBuilder("INSERT " + "INTO FACT_ACCT_SUMMARY (PA_ReportCube_ID , AD_Client_ID, " + "AD_Org_ID, Created, CreatedBy, Updated, UpdatedBy, IsActive, " + "C_AcctSchema_ID, Account_ID, PostingType, " + "GL_Budget_ID, C_Period_ID, DateAcct, AmtAcctDr, AmtAcctCr, Qty");
StringBuilder select = new StringBuilder(" ) SELECT " + "?, f.AD_CLIENT_ID, f.AD_ORG_ID, " + "max(f.Created), max(f.CreatedBy), max(f.Updated), max(f.UpdatedBy), 'Y', " + "f.C_ACCTSCHEMA_ID, f.ACCOUNT_ID, f.POSTINGTYPE, GL_Budget_ID, " + "p.c_period_id, p.StartDate, COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), " + "COALESCE(SUM(Qty),0)");
String from = " FROM fact_acct f " + " INNER JOIN C_Period p ON ( f.DateAcct BETWEEN p.StartDate AND p.EndDate ) " + " INNER JOIN C_Year y ON ( p.C_Year_ID = y.C_Year_ID ) " + " WHERE p.PeriodType = 'S' " + " AND y.C_Calendar_ID = ? ";
if (getLastRecalculated() != null && !reset)
from += "AND p.C_Period_ID IN " + periods;
StringBuilder groups = new StringBuilder(" GROUP BY " + "f.AD_CLIENT_ID, f.AD_ORG_ID, f.C_ACCTSCHEMA_ID, f.ACCOUNT_ID, " + "f.POSTINGTYPE, GL_Budget_ID, p.c_period_id, p.StartDate ");
ArrayList<String> values = new ArrayList<String>();
if (isProductDim())
values.add("M_Product_ID");
if (isBPartnerDim())
values.add("C_BPartner_ID");
if (isProjectDim())
values.add("C_Project_ID");
if (isOrgTrxDim())
values.add("AD_OrgTrx_ID");
if (isSalesRegionDim())
values.add("C_SalesRegion_ID");
if (isActivityDim())
values.add("C_Activity_ID");
if (isCampaignDim())
values.add("C_Campaign_ID");
if (isLocToDim())
values.add("C_LocTo_ID");
if (isLocFromDim())
values.add("C_LocFrom_ID");
if (isUser1Dim())
values.add("User1_ID");
if (isUser2Dim())
values.add("User2_ID");
if (isUser3Dim())
values.add("User3_ID");
if (isUser4Dim())
values.add("User4_ID");
if (isUserElement1Dim())
values.add("UserElement1_ID");
if (isUserElement2Dim())
values.add("UserElement2_ID");
if (isSubAcctDim())
values.add("C_SubAcct_ID");
if (isProjectPhaseDim())
values.add("C_ProjectPhase_ID");
if (isProjectTaskDim())
values.add("C_ProjectTask_ID");
// --(CASE v.IsGL_Category_ID WHEN 'Y' THEN f."GL_Category_ID END) GL_Category_ID
Iterator<String> iter = values.iterator();
while (iter.hasNext()) {
String dim = iter.next();
insert.append(", " + dim);
select.append(", f." + dim);
groups.append(", f." + dim);
}
String sql = insert.append(select.toString()).append(from).append(groups.toString()).toString();
log.log(Level.FINE, sql);
Object[] params = new Object[] { getPA_ReportCube_ID(), getC_Calendar_ID() };
start = System.currentTimeMillis();
int rows = DB.executeUpdateEx(sql, params, get_TrxName());
long seconds = (System.currentTimeMillis() - start) / 1000;
String insertResult = "Inserted " + rows + " in " + seconds + " s.";
log.log(Level.FINE, insertResult);
result += insertResult;
// set timestamp
String tsSQL = "SELECT max(fas.Updated)" + " FROM Fact_Acct_Summary fas" + " WHERE fas.PA_ReportCube_ID = " + getPA_ReportCube_ID();
ts = DB.getSQLValueTS(get_TrxName(), tsSQL);
log.log(Level.FINE, "Last updated: " + ts);
} catch (DBException e) {
// failure results in null timestamp => rebuild on next run
// nothing else to do
log.log(Level.FINE, getName() + " update failed:" + e.getMessage());
} finally {
// unlock
String unlockSQL = "UPDATE PA_ReportCube SET Processing = 'N', " + "LastRecalculated = " + (ts == null ? "null" : "?") + " WHERE PA_ReportCube_ID = " + getPA_ReportCube_ID();
Object[] parameters = ts == null ? new Object[] {} : new Object[] { ts };
DB.executeUpdateEx(unlockSQL, parameters, get_TrxName());
}
return result;
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class MRequest method sendNotices.
// afterSave
/**
* Send transfer Message
*/
/*TODO - red1 Never used locally - check later
* private void sendTransferMessage ()
{
// Sender
int AD_User_ID = Env.getContextAsInt(p_ctx, "#AD_User_ID");
if (AD_User_ID == 0)
AD_User_ID = getUpdatedBy();
// Old
Object oo = get_ValueOld("SalesRep_ID");
int oldSalesRep_ID = 0;
if (oo instanceof Integer)
oldSalesRep_ID = ((Integer)oo).intValue();
// RequestActionTransfer - Request {0} was transfered by {1} from {2} to {3}
Object[] args = new Object[] {getDocumentNo(),
MUser.getNameOfUser(AD_User_ID),
MUser.getNameOfUser(oldSalesRep_ID),
MUser.getNameOfUser(getSalesRep_ID())
};
String subject = Msg.getMsg(getCtx(), "RequestActionTransfer", args);
String message = subject + "\n" + getSummary();
MClient client = MClient.get(getCtx());
MUser from = MUser.get (getCtx(), AD_User_ID);
MUser to = MUser.get (getCtx(), getSalesRep_ID());
//
client.sendEMail(from, to, subject, message, createPDF());
} // afterSaveTransfer
*/
/**
* Send Update EMail/Notices
* @param list list of changes
*/
public void sendNotices(ArrayList<String> list) {
// Subject
String subject = Msg.translate(getCtx(), "R_Request_ID") + " " + Msg.getMsg(getCtx(), "Updated") + ": " + getDocumentNo();
// Message
StringBuffer message = new StringBuffer();
// UpdatedBy: Joe
int UpdatedBy = Env.getAD_User_ID(getCtx());
MUser from = MUser.get(getCtx(), UpdatedBy);
if (from != null)
message.append(Msg.translate(getCtx(), "UpdatedBy")).append(": ").append(from.getName());
// LastAction/Created: ...
if (getDateLastAction() != null)
message.append("\n").append(Msg.translate(getCtx(), "DateLastAction")).append(": ").append(getDateLastAction());
else
message.append("\n").append(Msg.translate(getCtx(), "Created")).append(": ").append(getCreated());
// Changes
for (int i = 0; i < list.size(); i++) {
String columnName = (String) list.get(i);
message.append("\n").append(Msg.getElement(getCtx(), columnName)).append(": ").append(get_DisplayValue(columnName, false)).append(" -> ").append(get_DisplayValue(columnName, true));
}
// NextAction
if (getDateNextAction() != null)
message.append("\n").append(Msg.translate(getCtx(), "DateNextAction")).append(": ").append(getDateNextAction());
message.append(SEPARATOR).append(getSummary());
if (getResult() != null)
message.append("\n----------\n").append(getResult());
message.append(getMailTrailer(null));
File pdf = createPDF();
log.finer(message.toString());
// Prepare sending Notice/Mail
MClient client = MClient.get(getCtx());
// Reset from if external
if (from.getEMailUser() == null || from.getEMailUserPW() == null)
from = null;
int success = 0;
int failure = 0;
int notices = 0;
//
ArrayList<Integer> userList = new ArrayList<Integer>();
final String sql = "SELECT u.AD_User_ID, u.NotificationType, u.EMail, u.Name, MAX(r.AD_Role_ID) " + "FROM RV_RequestUpdates_Only ru" + " INNER JOIN AD_User u ON (ru.AD_User_ID=u.AD_User_ID OR u.AD_User_ID=?)" + " LEFT OUTER JOIN AD_User_Roles r ON (u.AD_User_ID=r.AD_User_ID) " + "WHERE ru.R_Request_ID=? " + "GROUP BY u.AD_User_ID, u.NotificationType, u.EMail, u.Name";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getSalesRep_ID());
pstmt.setInt(2, getR_Request_ID());
rs = pstmt.executeQuery();
while (rs.next()) {
int AD_User_ID = rs.getInt(1);
String NotificationType = rs.getString(2);
if (NotificationType == null)
NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
String email = rs.getString(3);
String Name = rs.getString(4);
// Role
int AD_Role_ID = rs.getInt(5);
if (rs.wasNull())
AD_Role_ID = -1;
// No confidential to externals
if (AD_Role_ID == -1 && (getConfidentialTypeEntry().equals(CONFIDENTIALTYPE_Internal) || getConfidentialTypeEntry().equals(CONFIDENTIALTYPE_PrivateInformation)))
continue;
if (X_AD_User.NOTIFICATIONTYPE_None.equals(NotificationType)) {
log.config("Opt out: " + Name);
continue;
}
if ((X_AD_User.NOTIFICATIONTYPE_EMail.equals(NotificationType) || X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(NotificationType)) && (email == null || email.length() == 0)) {
if (AD_Role_ID >= 0)
NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
else {
log.config("No EMail: " + Name);
continue;
}
}
if (X_AD_User.NOTIFICATIONTYPE_Notice.equals(NotificationType) && AD_Role_ID >= 0) {
log.config("No internal User: " + Name);
continue;
}
// Check duplicate receivers
Integer ii = new Integer(AD_User_ID);
if (userList.contains(ii))
continue;
userList.add(ii);
//
MUser to = MUser.get(getCtx(), AD_User_ID);
// Send Mail
if (X_AD_User.NOTIFICATIONTYPE_EMail.equals(NotificationType) || X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(NotificationType)) {
if (client.sendEMail(from, to, subject, message.toString(), pdf)) {
success++;
if (m_emailTo.length() > 0)
m_emailTo.append(", ");
m_emailTo.append(to.getEMail());
} else {
log.warning("Failed: " + Name);
failure++;
NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
}
}
// Send Note
if (X_AD_User.NOTIFICATIONTYPE_Notice.equals(NotificationType) || X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(NotificationType)) {
int AD_Message_ID = 834;
MNote note = new MNote(getCtx(), AD_Message_ID, AD_User_ID, X_R_Request.Table_ID, getR_Request_ID(), subject, message.toString(), get_TrxName());
if (note.save())
notices++;
}
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.info("EMail Success=" + success + ", Failure=" + failure + " - Notices=" + notices);
}
Aggregations