use of org.compiere.model.MPreference in project adempiere by adempiere.
the class UserPreference method loadPreference.
/**
* load user preference
* @param AD_User_ID
*/
public void loadPreference(int AD_User_ID) {
if (AD_User_ID > 0) {
m_AD_User_ID = AD_User_ID;
props = new Properties();
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "AD_User_ID = ? AND Attribute = ? AND AD_Window_ID Is NULL", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = VALUES[i];
MPreference preference = query.setParameters(new Object[] { m_AD_User_ID, attribute }).firstOnly();
if (preference != null) {
value = preference.getValue();
}
props.setProperty(attribute, value);
}
}
}
use of org.compiere.model.MPreference in project adempiere by adempiere.
the class UserPreference method savePreference.
/**
* save user preference
*/
public void savePreference() {
if (m_AD_User_ID > 0) {
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "AD_User_ID = ? AND Attribute = ? AND AD_Window_ID Is NULL", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
String value = props.getProperty(attribute);
MPreference preference = query.setParameters(new Object[] { m_AD_User_ID, attribute }).firstOnly();
if (preference == null) {
preference = new MUserPreference(Env.getCtx(), 0, null);
preference.setAD_User_ID(m_AD_User_ID);
preference.setAttribute(attribute);
} else {
if (preference.getAD_Client_ID() > 0 || preference.getAD_Org_ID() > 0) {
preference = new MUserPreference(Env.getCtx(), preference.getAD_Preference_ID(), null);
}
}
preference.setValue(value);
preference.saveEx();
}
}
}
use of org.compiere.model.MPreference in project adempiere by adempiere.
the class PreferenceElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
// TODO Add User_ID
Attributes atts = element.attributes;
int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
if (windowid <= 0) {
element.defer = true;
return;
}
StringBuffer sqlB = new StringBuffer("select AD_Preference_ID from AD_Preference where ").append(" Attribute = '" + atts.getValue("Attribute") + "'").append(" and AD_Window_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), windowid);
MPreference m_Preference = new MPreference(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Preference_ID") != null && Integer.parseInt(atts.getValue("AD_Preference_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Preference.setAD_Preference_ID(Integer.parseInt(atts.getValue("AD_Preference_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Preference", m_Preference);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
sqlB = null;
m_Preference.setAD_Window_ID(windowid);
m_Preference.setAttribute(atts.getValue("Attribute"));
m_Preference.setValue(atts.getValue("Value"));
if (m_Preference.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Preference.getAttribute(), "Preference", m_Preference.get_ID(), AD_Backup_ID, Object_Status, "AD_Preference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Preference"));
} else {
record_log(ctx, 0, m_Preference.getAttribute(), "Preference", m_Preference.get_ID(), AD_Backup_ID, Object_Status, "AD_Preference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Preference"));
throw new POSaveFailedException("Failed to save Preference");
}
}
use of org.compiere.model.MPreference in project adempiere by adempiere.
the class UserPreference method deletePreference.
/**
* delete all user preference
*/
public void deletePreference() {
if (m_AD_User_ID > 0) {
props = new Properties();
Query query = new Query(Env.getCtx(), I_AD_Preference.Table_Name, "AD_User_ID = ? AND Attribute = ? AND AD_Window_ID Is NULL", null);
for (int i = 0; i < PROPERTIES.length; i++) {
String attribute = PROPERTIES[i];
MPreference preference = query.setParameters(new Object[] { m_AD_User_ID, attribute }).firstOnly();
if (preference != null) {
preference.deleteEx(true);
}
}
}
}
use of org.compiere.model.MPreference in project lar_361 by comitsrl.
the class Wsfe method getPath.
/**
* @author Horacio Alvarez
* @return: Devuelve el path donde se encuentra alojado el proceso wsfe.py en el
* sistema de archvos local. Este path se guarda en la tabla AD_Preference (Valores Predeterminados)
*/
protected String getPath() {
/**
* El nombre de AD_Preference a consultar se forma concatenando el valor
* WSFE_PV y el Nro de Punto de Venta
*/
if (path != "")
return path;
else {
MPOS pos = new MPOS(m_ctx, invoice.get_ValueAsInt("C_Pos_ID"), trxName);
String atributo = "WSFE_PV" + pos.get_ValueAsInt("PosNumber");
// @fchiappano Si el SO es Windows, busco la preferencia del mismo.
String osName = System.getProperty("os.name");
if (!osName.equals("Linux"))
atributo = atributo + "_WIN";
MPreference preference = MPreference.getOrgPreference(Env.getAD_Client_ID(getM_ctx()), Env.getAD_Org_ID(getM_ctx()), atributo, getM_ctx(), getTrxName());
// por defecto que es: WSFE
if (preference == null) {
atributo = "WSFE";
preference = MPreference.getOrgPreference(Env.getAD_Client_ID(getM_ctx()), Env.getAD_Org_ID(getM_ctx()), atributo, getM_ctx(), getTrxName());
}
path = preference.getValue();
return path;
}
}
Aggregations