Search in sources :

Example 36 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Scheduler method doWork.

/**
	 * 	Work
	 */
protected void doWork() {
    m_summary = new StringBuffer(m_model.toString()).append(" - ");
    // Prepare a ctx for the report/process - BF [1966880]
    m_schedulerctx.clear();
    MClient schedclient = MClient.get(getCtx(), m_model.getAD_Client_ID());
    Env.setContext(m_schedulerctx, "#AD_Client_ID", schedclient.getAD_Client_ID());
    Env.setContext(m_schedulerctx, "#AD_Language", schedclient.getAD_Language());
    Env.setContext(m_schedulerctx, "#AD_Org_ID", m_model.getAD_Org_ID());
    if (m_model.getAD_Org_ID() != 0) {
        MOrgInfo schedorg = MOrgInfo.get(getCtx(), m_model.getAD_Org_ID(), null);
        if (schedorg.getM_Warehouse_ID() > 0)
            Env.setContext(m_schedulerctx, "#M_Warehouse_ID", schedorg.getM_Warehouse_ID());
    }
    Env.setContext(m_schedulerctx, "#AD_User_ID", getAD_User_ID());
    Env.setContext(m_schedulerctx, "#SalesRep_ID", getAD_User_ID());
    // TODO: It can be convenient to add  AD_Scheduler.AD_Role_ID
    MUser scheduser = MUser.get(getCtx(), getAD_User_ID());
    MRole[] schedroles = scheduser.getRoles(m_model.getAD_Org_ID());
    if (schedroles != null && schedroles.length > 0)
        // first role, ordered by AD_Role_ID
        Env.setContext(m_schedulerctx, "#AD_Role_ID", schedroles[0].getAD_Role_ID());
    Timestamp ts = new Timestamp(System.currentTimeMillis());
    SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat("yyyy-MM-dd");
    //  JDBC format
    Env.setContext(m_schedulerctx, "#Date", dateFormat4Timestamp.format(ts) + " 00:00:00");
    Properties currentctx = Env.getCtx();
    Env.setCtx(m_schedulerctx);
    MProcess process = new MProcess(m_schedulerctx, m_model.getAD_Process_ID(), null);
    try {
        m_trx = Trx.get(Trx.createTrxName("Scheduler"), true);
        m_summary.append(runProcess(process));
        m_trx.commit(true);
    } catch (Exception e) {
        if (m_trx != null)
            m_trx.rollback();
        log.log(Level.WARNING, process.toString(), e);
        m_summary.append(e.toString());
    } finally {
        if (m_trx != null)
            m_trx.close();
    }
    // Restore system context
    Env.setCtx(currentctx);
    //
    int no = m_model.deleteLog();
    m_summary.append(" Logs deleted=").append(no);
    //
    MSchedulerLog pLog = new MSchedulerLog(m_model, m_summary.toString());
    pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork)));
    pLog.saveEx();
}
Also used : MProcess(org.compiere.model.MProcess) MRole(org.compiere.model.MRole) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MClient(org.compiere.model.MClient) MSchedulerLog(org.compiere.model.MSchedulerLog) MOrgInfo(org.compiere.model.MOrgInfo) MUser(org.compiere.model.MUser) SimpleDateFormat(java.text.SimpleDateFormat)

Example 37 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class WWFActivity method getActivitiesCount.

/**
	 * Get active activities count
	 * @return int
	 */
public int getActivitiesCount() {
    int count = 0;
    String sql = "SELECT count(*) FROM AD_WF_Activity a " + "WHERE a.Processed='N' AND a.WFState='OS' AND (" + //	Owner of Activity
    " a.AD_User_ID=?" + //	Invoker (if no invoker = all)
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + //	#2
    " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" + // Responsible User
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + //	#3
    " AND r.AD_User_ID=?)" + //	Responsible Role
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)" + //	#4
    " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?))";
    //
    //+ ") ORDER BY a.Priority DESC, Created";
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
    sql = role.addAccessSQL(sql, "a", true, false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_User_ID);
        pstmt.setInt(2, AD_User_ID);
        pstmt.setInt(3, AD_User_ID);
        pstmt.setInt(4, AD_User_ID);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            count = rs.getInt(1);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return count;
}
Also used : MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 38 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class AbstractADWindowPanel method actionButton.

//
/**************************************************************************
	 *	Start Button Process
	 *  @param wButton button
	 */
private void actionButton(WButtonEditor wButton) {
    GridTab currentTab = toolbar.getCurrentPanel().getGridTab();
    if (currentTab.hasChangedCurrentTabAndParents()) {
        String msg = CLogger.retrieveErrorString("Please ReQuery Window");
        FDialog.error(curWindowNo, parent, null, msg);
        return;
    }
    logger.info(wButton.toString());
    boolean startWOasking = false;
    String col = wButton.getColumnName();
    //  Zoom
    if (col.equals("Record_ID")) {
        int AD_Table_ID = Env.getContextAsInt(ctx, curWindowNo, "AD_Table_ID");
        int Record_ID = Env.getContextAsInt(ctx, curWindowNo, "Record_ID");
        AEnv.zoom(AD_Table_ID, Record_ID);
        return;
    }
    if (currentTab.needSave(true, false)) {
        if (!onSave(false))
            return;
    }
    int table_ID = currentTab.getAD_Table_ID();
    //	Record_ID
    int record_ID = currentTab.getRecord_ID();
    if (record_ID == -1 && currentTab.getKeyColumnName().equals("AD_Language"))
        record_ID = Env.getContextAsInt(ctx, curWindowNo, "AD_Language_ID");
    if (record_ID == -1 && (wButton.getProcess_ID() == 306 || wButton.getProcess_ID() == 307)) {
        Integer id = (Integer) currentTab.getValue("AD_ChangeLog_ID");
        record_ID = id.intValue();
    }
    if (record_ID == -1 && currentTab.getKeyColumnName().endsWith("_ID")) {
        FDialog.error(curWindowNo, parent, "SaveErrorRowNotFound");
        return;
    }
    boolean isProcessMandatory = false;
    if (col.equals("PaymentRule")) {
        WPayment vp = new WPayment(curWindowNo, currentTab, wButton);
        if (//	may not be allowed
        vp.isInitOK()) {
            vp.setVisible(true);
            AEnv.showWindow(vp);
        }
        if (vp.needSave()) {
            onSave(false);
            onRefresh(false);
        }
    } else if (col.equals("DocAction")) {
        isProcessMandatory = true;
        WDocActionPanel win = new WDocActionPanel(currentTab);
        if (win.getNumberOfOptions() == 0) {
            logger.info("DocAction - No Options");
            return;
        } else {
            AEnv.showWindow(win);
            if (!win.isStartProcess())
                return;
            //batch = win.isBatch();
            startWOasking = true;
        //vda.dispose();
        }
    } else if (col.equals("CreateFrom")) {
        ICreateFrom cf = WCreateFromFactory.create(currentTab);
        if (cf != null) {
            if (cf.isInitOK()) {
                cf.showWindow();
                currentTab.dataRefresh();
            }
            return;
        }
    // else may start process
    } else if (col.equals("Posted") && MRole.getDefault().isShowAcct()) {
        //  Check Doc Status
        String processed = Env.getContext(ctx, curWindowNo, "Processed");
        if (!processed.equals("Y")) {
            String docStatus = Env.getContext(ctx, curWindowNo, "DocStatus");
            if (DocAction.STATUS_Completed.equals(docStatus) || DocAction.STATUS_Closed.equals(docStatus) || DocAction.STATUS_Reversed.equals(docStatus) || DocAction.STATUS_Voided.equals(docStatus))
                ;
            else {
                FDialog.error(curWindowNo, parent, "PostDocNotComplete");
                return;
            }
        }
        // try to get table and record id from context data (eg for unposted view)
        // otherwise use current table/record
        int tableId = Env.getContextAsInt(ctx, curWindowNo, "AD_Table_ID", true);
        int recordId = Env.getContextAsInt(ctx, curWindowNo, "Record_ID", true);
        if (tableId == 0 || recordId == 0) {
            tableId = currentTab.getAD_Table_ID();
            recordId = currentTab.getRecord_ID();
        }
        //  Check Post Status
        Object ps = currentTab.getValue("Posted");
        if (ps != null && ps.equals("Y")) {
            new org.adempiere.webui.acct.WAcctViewer(Env.getContextAsInt(ctx, curWindowNo, "AD_Client_ID"), tableId, recordId);
        } else {
            if (FDialog.ask(curWindowNo, null, "PostImmediate?")) {
                //	force when problems
                boolean force = ps != null && !ps.equals("N");
                String error = AEnv.postImmediate(curWindowNo, Env.getAD_Client_ID(ctx), tableId, recordId, force);
                if (error != null)
                    FDialog.error(curWindowNo, null, "PostingError-N", error);
                onRefresh(false);
            }
        }
        return;
    }
    //  Posted
    /**
		 *  Start Process ----
		 */
    logger.config("Process_ID=" + wButton.getProcess_ID() + ", Record_ID=" + record_ID);
    if (wButton.getProcess_ID() == 0) {
        if (isProcessMandatory) {
            FDialog.error(curWindowNo, null, null, Msg.parseTranslation(ctx, "@NotFound@ @AD_Process_ID@"));
        }
        return;
    }
    if (currentTab.needSave(true, false)) {
        if (!onSave(false))
            return;
    }
    // call form
    MProcess pr = new MProcess(ctx, wButton.getProcess_ID(), null);
    //	Validate Access
    //	BR [ 147 ]
    MRole role = MRole.getDefault(ctx, false);
    Boolean accessRW = role.checkProcessAccess(pr.getAD_Process_ID());
    if (accessRW == null || !accessRW.booleanValue()) {
        FDialog.error(curWindowNo, parent, "AccessCannotProcess");
        return;
    }
    int adFormID = pr.getAD_Form_ID();
    //	Yamel Senih BR[ 127 ], 2015-11-25
    //	Bug with launch form
    int adBrowseID = pr.getAD_Browse_ID();
    if (adFormID != 0) {
        String title = wButton.getDescription();
        if (title == null || title.length() == 0)
            title = wButton.getDisplay();
        ProcessInfo pi = new ProcessInfo(title, wButton.getProcess_ID(), table_ID, record_ID);
        pi.setWindowNo(curWindowNo);
        pi.setAD_User_ID(Env.getAD_User_ID(ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
        ADForm form = ADForm.openForm(adFormID);
        form.setProcessInfo(pi);
        //	Yamel Senih FR [ 114 ], 2015-11-25
        form.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
        form.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT);
        form.setClosable(true);
        form.setMaximizable(true);
        form.setSizable(true);
        form.setContentStyle("overflow: auto");
        AEnv.showWindow(form);
        //	End Yamel Senih
        currentTab.dataRefreshAll();
    } else if (adBrowseID != 0) {
        String title = wButton.getDescription();
        if (title == null || title.length() == 0)
            title = wButton.getDisplay();
        ProcessInfo pi = new ProcessInfo(title, wButton.getProcess_ID(), table_ID, record_ID);
        pi.setAD_User_ID(Env.getAD_User_ID(ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(ctx));
        MBrowse browse = new MBrowse(Env.getCtx(), adBrowseID, null);
        WBrowser browser = new WBrowser(true, curWindowNo, "", browse, "", true, "", "Y".equals(Env.isSOTrx(Env.getCtx(), curWindowNo)));
        browser.setProcessInfo(pi);
        CustomForm ff = browser.getForm();
        ff.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
        ff.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT);
        ff.setTitle(title);
        SessionManager.getAppDesktop().showWindow(ff);
        onRefresh(false);
    } else {
        ProcessModalDialog dialog = new ProcessModalDialog(this, curWindowNo, wButton.getProcess_ID(), table_ID, record_ID, startWOasking);
        if (dialog.isValid()) {
            dialog.setWidth("500px");
            dialog.setVisible(true);
            dialog.setPosition("center");
            AEnv.showWindow(dialog);
        }
    //onRefresh(true); // Need to fire events to activate subordinate tabs.
    }
}
Also used : MProcess(org.compiere.model.MProcess) MRole(org.compiere.model.MRole) ProcessInfo(org.compiere.process.ProcessInfo) ProcessModalDialog(org.adempiere.webui.apps.ProcessModalDialog) MBrowse(org.adempiere.model.MBrowse) WBrowser(org.eevolution.form.WBrowser) ICreateFrom(org.compiere.grid.ICreateFrom) WPayment(org.adempiere.webui.apps.form.WPayment) GridTab(org.compiere.model.GridTab)

Example 39 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class DB method afterMigration.

/**************************************************************************
	 * 	Check need for post Upgrade
	 * 	@param ctx context
	 *	@return true if post upgrade ran - false if there was no need
	 */
public static boolean afterMigration(Properties ctx) {
    //	UPDATE AD_System SET IsJustMigrated='Y'
    MSystem system = MSystem.get(ctx);
    if (!system.isJustMigrated())
        return false;
    //	Role update
    log.info("Role");
    String sql = "SELECT * FROM AD_Role";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MRole role = new MRole(ctx, rs, null);
            role.updateAccessRecords();
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "(1)", e);
    } finally {
        close(rs);
        close(pstmt);
        rs = null;
        pstmt = null;
    }
    //	Release Specif stuff & Print Format
    try {
        Class<?> clazz = Class.forName("org.compiere.MigrateData");
        clazz.newInstance();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Data", e);
    }
    //	Language check
    log.info("Language");
    MLanguage.maintain(ctx);
    //	Sequence check
    log.info("Sequence");
    SequenceCheck.validate(ctx);
    //	Costing Setup
    log.info("Costing");
    MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, 0);
    for (int i = 0; i < ass.length; i++) {
        ass[i].checkCosting();
        ass[i].saveEx();
    }
    //	Reset Flag
    system.setIsJustMigrated(false);
    return system.save();
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet) POResultSet(org.compiere.model.POResultSet) PreparedStatement(java.sql.PreparedStatement) MSystem(org.compiere.model.MSystem) SQLException(java.sql.SQLException) DBException(org.adempiere.exceptions.DBException)

Example 40 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class GridSynchronizer method propertyChange.

/**
	 * @param evt
	 */
public void propertyChange(PropertyChangeEvent evt) {
    MRole role = MRole.getDefault();
    child.query(false, 0, role.getMaxQueryRecords());
}
Also used : MRole(org.compiere.model.MRole)

Aggregations

MRole (org.compiere.model.MRole)42 PreparedStatement (java.sql.PreparedStatement)14 ResultSet (java.sql.ResultSet)14 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)7 Point (java.awt.Point)4 Properties (java.util.Properties)4 BigDecimal (java.math.BigDecimal)3 Statement (java.sql.Statement)3 GridField (org.compiere.model.GridField)3 GridTab (org.compiere.model.GridTab)3 QName (javax.xml.namespace.QName)2 MBrowse (org.adempiere.model.MBrowse)2 XFireFault (org.codehaus.xfire.fault.XFireFault)2 ICreateFrom (org.compiere.grid.ICreateFrom)2 MOrgInfo (org.compiere.model.MOrgInfo)2 MProcess (org.compiere.model.MProcess)2 MTable (org.compiere.model.MTable)2 MWFActivity (org.compiere.wf.MWFActivity)2 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)2