/** * 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
/** * 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