/** * Get Accessible Goals * * @param ctx context * @return array of goals */ public static MGoal[] getGoals(Ctx ctx) { ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' " + "ORDER BY SeqNo"; sql = MRole.getDefault(ctx, false) .addAccessSQL(sql, "PA_Goal", false, true); // RW to restrict Access PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, (Trx) null); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeStatement(pstmt); DB.closeResultSet(rs); } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getGoals
/** Finalize. Remove Role */ @Override protected void finalize() throws Throwable { if (m_context != null) { int gwtServerID = m_context.getContextAsInt(MRole.GWTSERVERID); if (gwtServerID > 0) MRole.resetGwt(gwtServerID); } super.finalize(); } // finalize
/** * Before Save * * @param newRecord new * @return true */ @Override protected boolean beforeSave(boolean newRecord) { // if (getMultiplier(this) == null) // error // setMeasureDisplay(getMeasureScope()); // Measure required if nor Summary if (!isSummary() && getPA_Measure_ID() == 0) { log.saveError("FillMandatory", Msg.getElement(getCtx(), "PA_Measure_ID")); return false; } if (isSummary() && getPA_Measure_ID() != 0) setPA_Measure_ID(0); // User/Role Check if ((newRecord || is_ValueChanged("AD_User_ID") || is_ValueChanged("AD_Role_ID")) && getAD_User_ID() != 0) { MUser user = MUser.get(getCtx(), getAD_User_ID()); MRole[] roles = user.getRoles(getAD_Org_ID()); if (roles.length == 0) // No Role setAD_Role_ID(0); else if (roles.length == 1) // One setAD_Role_ID(roles[0].getAD_Role_ID()); else { int AD_Role_ID = getAD_Role_ID(); if (AD_Role_ID != 0) // validate { boolean found = false; for (MRole element : roles) { if (AD_Role_ID == element.getAD_Role_ID()) { found = true; break; } } if (!found) AD_Role_ID = 0; } if (AD_Role_ID == 0) // set to first one setAD_Role_ID(roles[0].getAD_Role_ID()); } // multiple roles } // user check return true; } // beforeSave
/** * Get User Goals * * @param ctx context * @param AD_User_ID user * @return array of goals */ public static MGoal[] getUserGoals(Ctx ctx) { int AD_Role_ID = ctx.getAD_Role_ID(); MRole role = MRole.get(ctx, AD_Role_ID); int AD_User_ID = ctx.getAD_User_ID(); if (AD_User_ID < 0) return getTestGoals(ctx); ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal g " + "WHERE IsActive='Y'" + " AND AD_Client_ID=?" // #1 + " AND ("; if (!role.isWebStoreRole()) sql += " (AD_User_ID IS NULL AND AD_Role_ID IS NULL) OR "; sql += " AD_User_ID=?" // #2 + " OR EXISTS (SELECT * FROM AD_User_Roles ur " + "WHERE ?=ur.AD_User_ID AND g.AD_Role_ID=ur.AD_Role_ID AND ur.IsActive='Y')) " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, (Trx) null); pstmt.setInt(1, ctx.getAD_Client_ID()); pstmt.setInt(2, AD_User_ID); pstmt.setInt(3, AD_User_ID); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getUserGoals
/** * Execute Query for Tab * * @param AD_Tab_ID tab * @param queryVO optional query * @param context record context for link columns and other variables * @param queryResultID stored query identifier provided by client * @return number of records or -1 if error */ public int executeQuery( int AD_Tab_ID, QueryVO queryVO, HashMap<String, String> context, int queryResultID) { UITab tab = getTab(AD_Tab_ID); if (tab == null) { log.config("Not found AD_Tab_ID=" + AD_Tab_ID); return -1; } ArrayList<String[]> result = tab.executeQueryString(queryVO, context, m_context); if (result == null) { log.config("Not Result for AD_Tab_ID=" + AD_Tab_ID); return -1; } MRole role = getRole(); // return -1 to indicate query exceeds if (role.isQueryMax(result.size())) { m_results.put(queryResultID, new ArrayList<String[]>()); return -1; } m_results.put(queryResultID, result); return result.size(); } // executeQuery
/** * Logout * * @param expired expire */ public void logout(boolean expired) { // End Session MSession session = MSession.get(m_context); // finish if (session != null) { if (expired) { if (session.getDescription() == null) session.setDescription("Expired"); else session.setDescription(session.getDescription() + " Expired"); } session.logout(); // saves } if (m_context != null) { int gwtServerID = m_context.getContextAsInt(MRole.GWTSERVERID); if (gwtServerID > 0) MRole.resetGwt(gwtServerID); } // Clear Cache m_tabs.clear(); m_fields.clear(); // m_windows.clear(); m_context.clear(); m_results.clear(); // } // logout