Search in sources :

Example 1 with WrongValueException

use of org.zkoss.zk.ui.WrongValueException in project adempiere by adempiere.

the class LoginPanel method validateLogin.

/**
     *  validates user name and password when logging in
     *
    **/
public void validateLogin() {
    Login login = new Login(ctx);
    String userId = txtUserId.getValue();
    String userPassword = txtPassword.getValue();
    //check is token
    String token = (String) txtPassword.getAttribute("user.token.hash");
    if (token != null && token.equals(userPassword)) {
        userPassword = "";
        int AD_Session_ID = (Integer) txtPassword.getAttribute("user.token.sid");
        MSession session = new MSession(Env.getCtx(), AD_Session_ID, null);
        if (session.get_ID() == AD_Session_ID) {
            MUser user = MUser.get(Env.getCtx(), session.getCreatedBy());
            if (BrowserToken.validateToken(session, user, token)) {
                userPassword = user.getPassword();
            }
        }
    }
    KeyNamePair[] rolesKNPairs = login.getRoles(userId, userPassword);
    if (rolesKNPairs == null || rolesKNPairs.length == 0)
        throw new WrongValueException("User Id or Password invalid!!!");
    else {
        String langName = null;
        if (lstLanguage.getSelectedItem() != null)
            langName = (String) lstLanguage.getSelectedItem().getLabel();
        else
            langName = Language.getBaseLanguage().getName();
        Language language = findLanguage(langName);
        wndLogin.loginOk(userId, userPassword);
        // Elaine 2009/02/06
        Env.setContext(ctx, UserPreference.LANGUAGE_NAME, language.getName());
        Locales.setThreadLocal(language.getLocale());
        String timeoutText = getUpdateTimeoutTextScript();
        if (!Strings.isEmpty(timeoutText))
            Clients.response("zkLocaleJavaScript2", new AuScript(null, timeoutText));
    }
    // This temporary validation code is added to check the reported bug
    // [ adempiere-ZK Web Client-2832968 ] User context lost?
    // https://sourceforge.net/tracker/?func=detail&atid=955896&aid=2832968&group_id=176962
    // it's harmless, if there is no bug then this must never fail
    Session currSess = Executions.getCurrent().getDesktop().getSession();
    currSess.setAttribute("Check_AD_User_ID", Env.getAD_User_ID(ctx));
    // End of temporary code for [ adempiere-ZK Web Client-2832968 ] User context lost?
    Env.setContext(ctx, BrowserToken.REMEMBER_ME, chkRememberMe.isChecked());
    /* Check DB version */
    String version = DB.getSQLValueString(null, "SELECT Version FROM AD_System");
    //  Identical DB version
    if (!Adempiere.DB_VERSION.equals(version)) {
        String AD_Message = "DatabaseVersionError";
        //  Code assumes Database version {0}, but Database has Version {1}.
        //  complete message
        String msg = Msg.getMsg(ctx, AD_Message);
        msg = MessageFormat.format(msg, new Object[] { Adempiere.DB_VERSION, version });
        throw new ApplicationException(msg);
    }
}
Also used : MSession(org.compiere.model.MSession) Login(org.compiere.util.Login) AuScript(org.zkoss.zk.au.out.AuScript) ApplicationException(org.adempiere.webui.exception.ApplicationException) Language(org.compiere.util.Language) KeyNamePair(org.compiere.util.KeyNamePair) MUser(org.compiere.model.MUser) WrongValueException(org.zkoss.zk.ui.WrongValueException) MSession(org.compiere.model.MSession) Session(org.zkoss.zk.ui.Session)

Example 2 with WrongValueException

use of org.zkoss.zk.ui.WrongValueException in project adempiere by adempiere.

the class WBPartner method actionSave.

//	loadBPartner
/**
	 *	Save.
	 *	Checks mandatory fields and saves Partner, Contact and Location
	 * 	@return true if saved
	 */
private boolean actionSave() {
    log.config("");
    //	Check Mandatory fields
    if (fName.getText().equals("")) {
        throw new WrongValueException(fName, Msg.translate(Env.getCtx(), "FillMandatory"));
    }
    if (fAddress.getC_Location_ID() == 0) {
        throw new WrongValueException(fAddress.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
    }
    if (m_partner == null) {
        int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
        m_partner = MBPartner.getTemplate(Env.getCtx(), AD_Client_ID);
        // Elaine 2009/07/03
        m_partner.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
        boolean isSOTrx = !"N".equals(Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx"));
        m_partner.setIsCustomer(isSOTrx);
        m_partner.setIsVendor(!isSOTrx);
    }
    //	Check Value
    String value = fValue.getText();
    if (value == null || value.length() == 0) {
        //	get Table Document No
        value = DB.getDocumentNo(Env.getAD_Client_ID(Env.getCtx()), "C_BPartner", null);
        fValue.setText(value);
    }
    m_partner.setValue(fValue.getText());
    m_partner.setName(fName.getText());
    m_partner.setName2(fName2.getText());
    m_partner.setTaxID(fTaxId.getText());
    ListItem listitem = fGreetingBP.getSelectedItem();
    KeyNamePair p = listitem != null ? (KeyNamePair) listitem.getValue() : null;
    if (p != null && p.getKey() > 0)
        m_partner.setC_Greeting_ID(p.getKey());
    else
        m_partner.setC_Greeting_ID(0);
    if (m_partner.save())
        log.fine("C_BPartner_ID=" + m_partner.getC_BPartner_ID());
    else
        FDialog.error(m_WindowNo, this, "BPartnerNotSaved");
    if (m_pLocation == null)
        m_pLocation = new MBPartnerLocation(m_partner);
    m_pLocation.setC_Location_ID(fAddress.getC_Location_ID());
    m_pLocation.setEMail(fEMail.getText());
    m_pLocation.setPhone(fPhone.getText());
    m_pLocation.setPhone2(fPhone2.getText());
    m_pLocation.setFax(fFax.getText());
    if (m_pLocation.save())
        log.fine("C_BPartner_Location_ID=" + m_pLocation.getC_BPartner_Location_ID());
    else
        FDialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "C_BPartner_Location_ID"));
    //	***** Business Partner - User *****
    String contact = fContact.getText();
    String email = fEMail.getText();
    if (m_user == null && (contact.length() > 0 || email.length() > 0))
        m_user = new MUser(m_partner);
    if (m_user != null) {
        if (contact.length() == 0)
            contact = fName.getText();
        m_user.setName(contact);
        m_user.setEMail(email);
        m_user.setTitle(fTitle.getText());
        listitem = fGreetingC.getSelectedItem();
        p = listitem != null ? (KeyNamePair) listitem.getValue() : null;
        if (p != null && p.getKey() > 0)
            m_user.setC_Greeting_ID(p.getKey());
        else
            m_user.setC_Greeting_ID(0);
        m_user.setPhone(fPhone.getText());
        m_user.setPhone2(fPhone2.getText());
        m_user.setFax(fFax.getText());
        if (m_user.save())
            log.fine("AD_User_ID=" + m_user.getAD_User_ID());
        else
            FDialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "AD_User_ID"));
    }
    return true;
}
Also used : ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair) MUser(org.compiere.model.MUser) WrongValueException(org.zkoss.zk.ui.WrongValueException) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 3 with WrongValueException

use of org.zkoss.zk.ui.WrongValueException in project spatial-portal by AtlasOfLivingAustralia.

the class UploadSpeciesController method afterCompose.

@Override
public void afterCompose() {
    super.afterCompose();
    setTbInstructions("3. Select file (text file, one LSID or name per line)");
    Map m = Executions.getCurrent().getArg();
    if (m != null) {
        for (Object o : m.entrySet()) {
            if (((Map.Entry) o).getKey() instanceof String && "setTbInstructions".equals(((Map.Entry) o).getKey())) {
                setTbInstructions((String) ((Map.Entry) o).getValue());
            }
            if (((Map.Entry) o).getKey() instanceof String && "addToMap".equals(((Map.Entry) o).getKey())) {
                addToMap = true;
            }
        }
    }
    tbName.setConstraint(new Constraint() {

        @Override
        public void validate(Component comp, Object value) {
            String val = (String) value;
            Map htUserSpecies = (Map) getMapComposer().getSession().getAttribute(StringConstants.USERPOINTS);
            if (htUserSpecies != null && !htUserSpecies.isEmpty()) {
                for (Object o : htUserSpecies.values()) {
                    if (((UserDataDTO) o).getName().equalsIgnoreCase(val.trim())) {
                        throw new WrongValueException(comp, "User dataset named '" + val + "' already exists. Please enter another name for your dataset.");
                    }
                }
            }
        }
    });
    fileUpload.addEventListener("onUpload", new EventListener() {

        public void onEvent(Event event) throws Exception {
            UserDataDTO ud = new UserDataDTO(tbName.getValue(), tbDesc.getValue(), "points");
            addToMap = true;
            defineArea = true;
            doFileUpload(ud, event);
            onClick$btnCancel(null);
        }
    });
}
Also used : Event(org.zkoss.zk.ui.event.Event) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) UploadEvent(org.zkoss.zk.ui.event.UploadEvent) JSONObject(org.json.simple.JSONObject) UserDataDTO(au.org.ala.spatial.dto.UserDataDTO) EventListener(org.zkoss.zk.ui.event.EventListener) Component(org.zkoss.zk.ui.Component) Map(java.util.Map) WrongValueException(org.zkoss.zk.ui.WrongValueException) WrongValueException(org.zkoss.zk.ui.WrongValueException)

Example 4 with WrongValueException

use of org.zkoss.zk.ui.WrongValueException in project adempiere by adempiere.

the class Keylistener method parseCtrlKeys.

private void parseCtrlKeys(String keys) throws UiException {
    if (keys == null || keys.length() == 0) {
        _ctrlKeys = _jsCtrlKeys = null;
        return;
    }
    final StringBuffer sbctl = new StringBuffer(), sbsft = new StringBuffer(), sbalt = new StringBuffer(), sbext = new StringBuffer();
    StringBuffer sbcur = null;
    for (int j = 0, len = keys.length(); j < len; ++j) {
        char cc = keys.charAt(j);
        switch(cc) {
            case '^':
            case '$':
            case '@':
                if (sbcur != null)
                    throw new WrongValueException("Combination of Shift, Alt and Ctrl not supported: " + keys);
                sbcur = cc == '^' ? sbctl : cc == '@' ? sbalt : sbsft;
                break;
            case '#':
                {
                    int k = j + 1;
                    for (; k < len; ++k) {
                        final char c2 = (char) keys.charAt(k);
                        if ((c2 > 'Z' || c2 < 'A') && (c2 > 'z' || c2 < 'a') && (c2 > '9' || c2 < '0'))
                            break;
                    }
                    if (k == j + 1)
                        throw new WrongValueException(MCommon.UNEXPECTED_CHARACTER, new Object[] { new Character(cc), keys });
                    final String s = keys.substring(j + 1, k).toLowerCase();
                    if ("pgup".equals(s))
                        cc = 'A';
                    else if ("pgdn".equals(s))
                        cc = 'B';
                    else if ("end".equals(s))
                        cc = 'C';
                    else if ("home".equals(s))
                        cc = 'D';
                    else if ("left".equals(s))
                        cc = 'E';
                    else if ("up".equals(s))
                        cc = 'F';
                    else if ("right".equals(s))
                        cc = 'G';
                    else if ("down".equals(s))
                        cc = 'H';
                    else if ("ins".equals(s))
                        cc = 'I';
                    else if ("del".equals(s))
                        cc = 'J';
                    else if ("enter".equals(s))
                        cc = 'K';
                    else if (s.length() > 1 && s.charAt(0) == 'f') {
                        final int v;
                        try {
                            v = Integer.parseInt(s.substring(1));
                        } catch (Throwable ex) {
                            throw new WrongValueException("Unknown #" + s + " in " + keys);
                        }
                        if (v == 0 || v > 12)
                            throw new WrongValueException("Unsupported function key: #f" + v);
                        // 'P': F1, 'Q': F2... 'Z': F12
                        cc = (char) ('O' + v);
                    } else
                        throw new WrongValueException("Unknown #" + s + " in " + keys);
                    if (sbcur == null)
                        sbext.append(cc);
                    else {
                        sbcur.append(cc);
                        sbcur = null;
                    }
                    j = k - 1;
                }
                break;
            default:
                if (sbcur == null || ((cc > 'Z' || cc < 'A') && (cc > 'z' || cc < 'a') && (cc > '9' || cc < '0')))
                    throw new WrongValueException(MCommon.UNEXPECTED_CHARACTER, new Object[] { new Character(cc), keys });
                if (sbcur == sbsft)
                    throw new WrongValueException("$" + cc + " not supported: " + keys);
                if (cc <= 'Z' && cc >= 'A')
                    // to lower case
                    cc = (char) (cc + ('a' - 'A'));
                sbcur.append(cc);
                sbcur = null;
                break;
        }
    }
    _jsCtrlKeys = new StringBuffer().append('^').append(sbctl).append(';').append('@').append(sbalt).append(';').append('$').append(sbsft).append(';').append('#').append(sbext).append(';').toString();
    _ctrlKeys = keys;
}
Also used : WrongValueException(org.zkoss.zk.ui.WrongValueException)

Example 5 with WrongValueException

use of org.zkoss.zk.ui.WrongValueException in project adempiere by adempiere.

the class RolePanel method validateRoles.

/**
     *  validate Roles
     *
    **/
public void validateRoles() {
    Comboitem lstItemRole = lstRole.getSelectedItem();
    Comboitem lstItemClient = lstClient.getSelectedItem();
    Comboitem lstItemOrg = lstOrganisation.getSelectedItem();
    Comboitem lstItemWarehouse = lstWarehouse.getSelectedItem();
    if (lstItemRole == null || lstItemRole.getValue() == null) {
        throw new WrongValueException(lstRole, Msg.getMsg(m_ctx, "FillMandatory") + lblRole.getValue());
    } else if (lstItemClient == null || lstItemClient.getValue() == null) {
        throw new WrongValueException(lstClient, Msg.getMsg(m_ctx, "FillMandatory") + lblClient.getValue());
    } else if (lstItemOrg == null || lstItemOrg.getValue() == null) {
        throw new WrongValueException(lstOrganisation, Msg.getMsg(m_ctx, "FillMandatory") + lblOrganisation.getValue());
    }
    int orgId = 0, warehouseId = 0;
    orgId = Integer.parseInt((String) lstItemOrg.getValue());
    KeyNamePair orgKNPair = new KeyNamePair(orgId, lstItemOrg.getLabel());
    KeyNamePair warehouseKNPair = null;
    if (lstItemWarehouse != null && lstItemWarehouse.getValue() != null) {
        warehouseId = Integer.parseInt((String) lstItemWarehouse.getValue());
        warehouseKNPair = new KeyNamePair(warehouseId, lstItemWarehouse.getLabel());
    }
    String msg = login.validateLogin(orgKNPair);
    if (msg != null && msg.length() > 0) {
        throw new WrongValueException(msg);
    }
    msg = login.loadPreferences(orgKNPair, warehouseKNPair, null, null);
    if (!(msg == null || msg.length() == 0)) {
        throw new WrongValueException(msg);
    }
    wndLogin.loginCompleted();
    // Elaine 2009/02/06 save preference to AD_Preference
    UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
    userPreference.setProperty(UserPreference.P_LANGUAGE, Env.getContext(m_ctx, UserPreference.LANGUAGE_NAME));
    userPreference.setProperty(UserPreference.P_ROLE, lstItemRole != null ? (String) lstItemRole.getValue() : "0");
    userPreference.setProperty(UserPreference.P_CLIENT, lstItemClient != null ? (String) lstItemClient.getValue() : "0");
    userPreference.setProperty(UserPreference.P_ORG, lstItemOrg != null ? (String) lstItemOrg.getValue() : "0");
    userPreference.setProperty(UserPreference.P_WAREHOUSE, lstItemWarehouse != null ? (String) lstItemWarehouse.getValue() : "0");
    userPreference.savePreference();
//
}
Also used : Comboitem(org.zkoss.zul.Comboitem) UserPreference(org.adempiere.webui.util.UserPreference) KeyNamePair(org.compiere.util.KeyNamePair) WrongValueException(org.zkoss.zk.ui.WrongValueException)

Aggregations

WrongValueException (org.zkoss.zk.ui.WrongValueException)5 KeyNamePair (org.compiere.util.KeyNamePair)3 MUser (org.compiere.model.MUser)2 UserDataDTO (au.org.ala.spatial.dto.UserDataDTO)1 Map (java.util.Map)1 ListItem (org.adempiere.webui.component.ListItem)1 ApplicationException (org.adempiere.webui.exception.ApplicationException)1 UserPreference (org.adempiere.webui.util.UserPreference)1 MBPartnerLocation (org.compiere.model.MBPartnerLocation)1 MSession (org.compiere.model.MSession)1 Language (org.compiere.util.Language)1 Login (org.compiere.util.Login)1 JSONObject (org.json.simple.JSONObject)1 AuScript (org.zkoss.zk.au.out.AuScript)1 Component (org.zkoss.zk.ui.Component)1 Session (org.zkoss.zk.ui.Session)1 Event (org.zkoss.zk.ui.event.Event)1 EventListener (org.zkoss.zk.ui.event.EventListener)1 ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)1 UploadEvent (org.zkoss.zk.ui.event.UploadEvent)1