use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class Find method parseUserQuery.
/**
* Parse delimited string into user query
* Old field sequence: column, operator, value, value to
* New field sequence: column, operator, value, value to, and/or, left brackets, right brackets
* @param userQuery
*/
private void parseUserQuery(MUserQuery userQuery) {
String code = userQuery.getCode();
log.fine("Parse user query: " + code);
String[] segments = code.split(Pattern.quote(SEGMENT_SEPARATOR), -1);
advancedTable.stopEditor(true);
DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
int cnt = model.getRowCount();
for (int i = cnt - 1; i >= 0; i--) model.removeRow(i);
for (int i = 0; i < segments.length; i++) {
String[] fields = segments[i].split(Pattern.quote(FIELD_SEPARATOR));
model.addRow(new Object[] { "", "", null, MQuery.OPERATORS[MQuery.EQUAL_INDEX], null, null, "" });
String columnName = null;
for (int j = 0; j < fields.length; j++) {
// column
if (j == 0) {
for (ValueNamePair vnp : columnValueNamePairs) {
if (vnp.getValue().equals(fields[j])) {
model.setValueAt(vnp, i, INDEX_COLUMNNAME);
columnName = fields[j];
break;
}
}
} else // operator
if (j == 1) {
for (ValueNamePair vnp : MQuery.OPERATORS) {
if (vnp.getValue().equals(fields[j])) {
model.setValueAt(vnp, i, INDEX_OPERATOR);
break;
}
}
} else // value
if (j == 2 && fields[j].length() > 0) {
GridField field = getTargetMField(columnName);
Object value = parseString(field, fields[j]);
model.setValueAt(value, i, INDEX_VALUE);
} else // value 2
if (j == 3 && fields[j].length() > 0) {
GridField field = getTargetMField(columnName);
Object value = parseString(field, fields[j]);
model.setValueAt(value, i, INDEX_VALUE2);
} else // and/or
if (j == 4 && fields[j].length() > 0) {
if (i != 0)
model.setValueAt(fields[j], i, INDEX_ANDOR);
} else if (j == 5 && fields[j].length() > 0) {
model.setValueAt(fields[j], i, INDEX_LEFTBRACKET);
} else if (j == 6 && fields[j].length() > 0) {
model.setValueAt(fields[j], i, INDEX_RIGHTBRACKET);
}
}
}
advancedTable.invalidate();
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class WLogin method doPost.
// doGet
/**
* Process the HTTP Post request.
* <pre>
* - Optionally create Session
* - Check database connection
* - LoginInfo from request?
* - Yes: DoLogin success ?
* - Yes: return (second) preferences page
* - No: return (first) user/password page
* - No: User Principal ?
* - Yes: DoLogin success ?
* - Yes: return (second) preferences page
* - No: return (first) user/password page
* - No: return (first) user/password page
* </pre>
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("");
// Create New Session
HttpSession sess = request.getSession(true);
sess.setMaxInactiveInterval(MobileEnv.TIMEOUT);
// Get Cookie Properties
Properties cProp = MobileUtil.getCookieProprties(request);
// Create Context
MobileSessionCtx wsc = MobileSessionCtx.get(request);
// Page
MobileDoc doc = null;
// Check DB connection
if (!DB.isConnected()) {
String msg = Msg.getMsg(wsc.ctx, "WLoginNoDB");
if (msg.equals("WLoginNoDB"))
msg = "No Database Connection";
doc = MobileDoc.createWindow(msg);
}
// Get Parameters: Role, Client, Org, Warehouse, Date
String role = MobileUtil.getParameter(request, WLogin.P_ROLE);
String client = MobileUtil.getParameter(request, WLogin.P_CLIENT);
String org = MobileUtil.getParameter(request, WLogin.P_ORG);
String language = MobileUtil.getParameter(request, Env.LANGUAGE);
if (role != null && client != null && org != null) {
// Get Info from Context - User, Role, Client
int AD_User_ID = Env.getAD_User_ID(wsc.ctx);
int AD_Role_ID = Env.getAD_Role_ID(wsc.ctx);
int AD_Client_ID = Env.getAD_Client_ID(wsc.ctx);
// Not available in context yet - Org, Warehouse
int AD_Org_ID = -1;
int M_Warehouse_ID = -1;
// Get latest info from context
try {
int req_role = Integer.parseInt(role);
if (req_role != AD_Role_ID) {
log.fine("AD_Role_ID - changed from " + AD_Role_ID);
AD_Role_ID = req_role;
Env.setContext(wsc.ctx, "#AD_Role_ID", AD_Role_ID);
}
log.fine("AD_Role_ID = " + AD_Role_ID);
//
int req_client = Integer.parseInt(client);
if (req_client != AD_Client_ID) {
log.fine("AD_Client_ID - changed from " + AD_Client_ID);
AD_Client_ID = req_client;
Env.setContext(wsc.ctx, "#AD_Client_ID", AD_Client_ID);
}
log.fine("AD_Client_ID = " + AD_Client_ID);
//
AD_Org_ID = Integer.parseInt(org);
log.fine("AD_Org_ID = " + AD_Org_ID);
//
} catch (Exception e) {
log.log(Level.SEVERE, "Parameter", e);
MobileUtil.createTimeoutPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
return;
}
// Check Login info and set environment
wsc.loginInfo = checkLogin(wsc.ctx, AD_User_ID, AD_Role_ID, AD_Client_ID, AD_Org_ID, M_Warehouse_ID);
if (wsc.loginInfo == null) {
MobileUtil.createErrorPage(request, response, this, Msg.getMsg(wsc.ctx, "RoleInconsistent"));
return;
}
// Set Date
Timestamp ts = MobileUtil.getParameterAsDate(request, WLogin.P_DATE);
if (ts == null)
ts = new Timestamp(System.currentTimeMillis());
// JDBC format
Env.setContext(wsc.ctx, "#Date", ts);
cProp.setProperty(P_ROLE, Integer.toString(AD_Role_ID));
cProp.setProperty(P_ORG, Integer.toString(AD_Org_ID));
// Update Cookie - overwrite
if (cProp != null) {
Cookie cookie = new Cookie(MobileEnv.COOKIE_INFO, MobileUtil.propertiesEncode(cProp));
cookie.setComment("(c) adempiere, Inc - Jorg Janke");
cookie.setSecure(false);
cookie.setPath("/");
if (cProp.size() == 0)
// delete cookie
cookie.setMaxAge(0);
else
// 30 days in seconds 60*60*24*30
cookie.setMaxAge(2592000);
response.addCookie(cookie);
}
response.sendRedirect(MobileEnv.getBaseDirectory("/WMenu"));
return;
} else // Login Info from request?
{
// Get Parameters: UserName/Password
String usr = MobileUtil.getParameter(request, P_USERNAME);
String pwd = MobileUtil.getParameter(request, P_PASSWORD);
// Get Principle
Principal userPrincipal = request.getUserPrincipal();
log.info("Principal=" + userPrincipal + "; User=" + usr);
// Login info not from request and not pre-authorized
if (userPrincipal == null && (usr == null || pwd == null))
doc = createFirstPage(cProp, request, "");
else // Login info from request or authorized
{
KeyNamePair[] roles = null;
Login login = new Login(wsc.ctx);
// Pre-authorized
if (userPrincipal != null) {
roles = login.getRoles(userPrincipal);
usr = userPrincipal.getName();
} else
roles = login.getRoles(usr, pwd);
//
if (roles == null)
doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
else {
String sql = "SELECT AD_Role_ID, Name FROM AD_Role WHERE IsMobileAccessible='Y'";
ArrayList<KeyNamePair> validRoles = new ArrayList();
try {
ValueNamePair[] mobileRoles = DB.getValueNamePairs(sql, false, null);
for (KeyNamePair role1 : roles) {
for (ValueNamePair mobileRole : mobileRoles) {
if (role1.getKey() == Integer.parseInt(mobileRole.getValue())) {
validRoles.add(role1);
break;
}
}
}
roles = new KeyNamePair[validRoles.size()];
roles = validRoles.toArray(roles);
} catch (Exception e) {
// IsMobileAccessible not supported, allow any role
}
cProp.setProperty(P_USERNAME, usr);
cProp.setProperty(Env.LANGUAGE, language);
if (roles.length == 0)
doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
else {
String roleData = (cProp.getProperty(P_ROLE, null));
doc = createSecondPage(cProp, request, MobileUtil.convertToOption(roles, roleData), "");
// Create adempiere Session - user id in ctx
MSession.get(wsc.ctx, request.getRemoteAddr(), request.getRemoteHost(), sess.getId());
MobileUtil.createResponseFragment(request, response, this, cProp, doc);
return;
}
}
}
}
MobileUtil.createResponse(request, response, this, cProp, doc, false);
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class PreviewPanel method setLFSelection.
/**
* Update the look list and theme list to show the current selection
*/
private void setLFSelection() {
m_setting = true;
// Search for PLAF
ValueNamePair plaf = null;
LookAndFeel lookFeel = UIManager.getLookAndFeel();
String look = lookFeel.getClass().getName();
for (int i = 0; i < AdempierePLAF.getPLAFs().length; i++) {
ValueNamePair vp = AdempierePLAF.getPLAFs()[i];
if (vp.getValue().equals(look)) {
plaf = vp;
break;
}
}
if (plaf != null)
lookList.setSelectedValue(plaf, true);
// Search for Theme
MetalTheme metalTheme = null;
ValueNamePair theme = null;
boolean metal = UIManager.getLookAndFeel() instanceof MetalLookAndFeel;
themeList.setModel(new DefaultComboBoxModel(AdempierePLAF.getThemes()));
if (metal) {
theme = null;
AppContext context = AppContext.getAppContext();
metalTheme = (MetalTheme) context.get("currentMetalTheme");
if (metalTheme != null) {
String lookTheme = metalTheme.getName();
for (int i = 0; i < AdempierePLAF.getThemes().length; i++) {
ValueNamePair vp = AdempierePLAF.getThemes()[i];
if (vp.getName().equals(lookTheme)) {
theme = vp;
break;
}
}
}
if (theme != null)
themeList.setSelectedValue(theme, true);
}
m_setting = false;
log.info(lookFeel + " - " + metalTheme);
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class MClickCount method getCount.
// getMClicks
/**
* Get Count for date format
* @param DateFormat valid TRUNC date format
* @return count
*/
protected ValueNamePair[] getCount(String DateFormat) {
ArrayList<ValueNamePair> list = new ArrayList<ValueNamePair>();
String sql = "SELECT TRUNC(Created, '" + DateFormat + "'), Count(*) " + "FROM W_Click " + "WHERE W_ClickCount_ID=? " + "GROUP BY TRUNC(Created, '" + DateFormat + "')";
//
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getW_ClickCount_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String value = m_dateFormat.format(rs.getTimestamp(1));
String name = m_intFormat.format(rs.getInt(2));
ValueNamePair pp = new ValueNamePair(value, name);
list.add(pp);
}
rs.close();
pstmt.close();
pstmt = null;
} catch (SQLException ex) {
log.log(Level.SEVERE, sql, ex);
}
try {
if (pstmt != null)
pstmt.close();
} catch (SQLException ex1) {
}
pstmt = null;
//
ValueNamePair[] retValue = new ValueNamePair[list.size()];
list.toArray(retValue);
return retValue;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class PayPrint method loadPaymentRule.
// loadPaySelectInfo
/**
* Bank changed - load PaymentRule
*/
public ArrayList<ValueNamePair> loadPaymentRule(int paySelectionId) {
ArrayList<ValueNamePair> data = new ArrayList<ValueNamePair>();
// load PaymentRule for Bank
// MLookupInfo.getAD_Reference_ID("All_Payment Rule");
int AD_Reference_ID = 195;
Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx()));
MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID);
String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) + " AND " + info.KeyColumn + " IN (SELECT PaymentRule FROM C_PaySelectionCheck WHERE C_PaySelection_ID=?) " + info.Query.substring(info.Query.indexOf(" ORDER BY"));
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, paySelectionId);
ResultSet rs = pstmt.executeQuery();
//
while (rs.next()) {
ValueNamePair pp = new ValueNamePair(rs.getString(2), rs.getString(3));
data.add(pp);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
if (data.size() == 0)
log.config("PaySel=" + paySelectionId + ", BAcct=" + bankAccountId + " - " + sql);
return data;
}
Aggregations