use of org.compiere.util.KeyNamePair 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);
}
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class RolePanel method updateWarehouseList.
private void updateWarehouseList() {
lstWarehouse.getItems().clear();
lstWarehouse.setText("");
Comboitem lstItemOrganisation = lstOrganisation.getSelectedItem();
if (lstItemOrganisation != null) {
// initial warehouse - Elaine 2009/02/06
UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
String initDefault = userPreference.getProperty(UserPreference.P_WAREHOUSE);
KeyNamePair organisationKNPair = new KeyNamePair(new Integer((String) lstItemOrganisation.getValue()), lstItemOrganisation.getLabel());
KeyNamePair[] warehouseKNPairs = login.getWarehouses(organisationKNPair);
if (warehouseKNPairs != null && warehouseKNPairs.length > 0) {
for (int i = 0; i < warehouseKNPairs.length; i++) {
ComboItem ci = new ComboItem(warehouseKNPairs[i].getName(), warehouseKNPairs[i].getID());
lstWarehouse.appendChild(ci);
if (warehouseKNPairs[i].getID().equals(initDefault))
lstWarehouse.setSelectedItem(ci);
}
if (lstWarehouse.getSelectedIndex() == -1 && lstWarehouse.getItemCount() > 0)
lstWarehouse.setSelectedIndex(0);
}
//
}
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class RolePanel method updateOrganisationList.
private void updateOrganisationList() {
lstOrganisation.getItems().clear();
lstOrganisation.setText("");
Comboitem lstItemClient = lstClient.getSelectedItem();
if (lstItemClient != null) {
// initial organisation - Elaine 2009/02/06
UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
String initDefault = userPreference.getProperty(UserPreference.P_ORG);
KeyNamePair clientKNPair = new KeyNamePair(new Integer((String) lstItemClient.getValue()), lstItemClient.getLabel());
KeyNamePair[] orgKNPairs = login.getOrgs(clientKNPair);
if (orgKNPairs != null && orgKNPairs.length > 0) {
for (int i = 0; i < orgKNPairs.length; i++) {
ComboItem ci = new ComboItem(orgKNPairs[i].getName(), orgKNPairs[i].getID());
lstOrganisation.appendChild(ci);
if (orgKNPairs[i].getID().equals(initDefault))
lstOrganisation.setSelectedItem(ci);
}
if (lstOrganisation.getSelectedIndex() == -1 && lstOrganisation.getItemCount() > 0)
lstOrganisation.setSelectedIndex(0);
}
//
}
updateWarehouseList();
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class RolePanel method updateClientList.
private void updateClientList() {
lstClient.getItems().clear();
Comboitem lstItemRole = lstRole.getSelectedItem();
if (lstItemRole != null) {
// initial client - Elaine 2009/02/06
UserPreference userPreference = SessionManager.getSessionApplication().getUserPreference();
String initDefault = userPreference.getProperty(UserPreference.P_CLIENT);
KeyNamePair roleKNPair = new KeyNamePair(new Integer((String) lstItemRole.getValue()), lstItemRole.getLabel());
KeyNamePair[] clientKNPairs = login.getClients(roleKNPair);
if (clientKNPairs != null && clientKNPairs.length > 0) {
for (int i = 0; i < clientKNPairs.length; i++) {
ComboItem ci = new ComboItem(clientKNPairs[i].getName(), clientKNPairs[i].getID());
lstClient.appendChild(ci);
if (clientKNPairs[i].getID().equals(initDefault))
lstClient.setSelectedItem(ci);
}
if (lstClient.getSelectedIndex() == -1 && lstClient.getItemCount() > 0)
lstClient.setSelectedIndex(0);
}
//
//force reload of default role
MRole.getDefault(m_ctx, true);
}
login.getRoles(m_userName, m_password);
updateOrganisationList();
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class CreateFromShipment method save.
/**
* Save - Create Invoice Lines
* @return true if saved
*/
public boolean save(IMiniTable miniTable, String trxName) {
/*
dataTable.stopEditor(true);
log.config("");
TableModel model = dataTable.getModel();
int rows = model.getRowCount();
if (rows == 0)
return false;
//
Integer defaultLoc = (Integer) locatorField.getValue();
if (defaultLoc == null || defaultLoc.intValue() == 0) {
locatorField.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
}
*/
int M_Locator_ID = defaultLocator_ID;
if (M_Locator_ID == 0) {
return false;
}
// Get Shipment
MInOut inout = new MInOut(Env.getCtx(), m_Record_ID, trxName);
log.config(inout + ", C_Locator_ID=" + M_Locator_ID);
// Lines
for (int i = 0; i < miniTable.getRowCount(); i++) {
if (((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) {
// variable values
// Qty
BigDecimal QtyEntered = (BigDecimal) miniTable.getValueAt(i, 1);
// UOM
KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2);
int C_UOM_ID = pp.getKey();
// Locator
pp = (KeyNamePair) miniTable.getValueAt(i, 3);
// If a locator is specified on the product, choose that otherwise default locator
M_Locator_ID = pp != null && pp.getKey() != 0 ? pp.getKey() : defaultLocator_ID;
// Product
pp = (KeyNamePair) miniTable.getValueAt(i, 4);
int M_Product_ID = pp.getKey();
int C_OrderLine_ID = 0;
// OrderLine
pp = (KeyNamePair) miniTable.getValueAt(i, 6);
if (pp != null)
C_OrderLine_ID = pp.getKey();
int M_RMALine_ID = 0;
// RMA
pp = (KeyNamePair) miniTable.getValueAt(i, 7);
// If we have RMA
if (pp != null)
M_RMALine_ID = pp.getKey();
int C_InvoiceLine_ID = 0;
MInvoiceLine il = null;
// InvoiceLine
pp = (KeyNamePair) miniTable.getValueAt(i, 8);
if (pp != null)
C_InvoiceLine_ID = pp.getKey();
if (C_InvoiceLine_ID != 0)
il = new MInvoiceLine(Env.getCtx(), C_InvoiceLine_ID, trxName);
//boolean isInvoiced = (C_InvoiceLine_ID != 0);
// Precision of Qty UOM
int precision = 2;
if (M_Product_ID != 0) {
MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
precision = product.getUOMPrecision();
}
QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
//
log.fine("Line QtyEntered=" + QtyEntered + ", Product=" + M_Product_ID + ", OrderLine=" + C_OrderLine_ID + ", InvoiceLine=" + C_InvoiceLine_ID);
// Credit Memo - negative Qty
if (m_invoice != null && m_invoice.isCreditMemo())
QtyEntered = QtyEntered.negate();
// Create new InOut Line
MInOutLine iol = new MInOutLine(inout);
// Line UOM
iol.setM_Product_ID(M_Product_ID, C_UOM_ID);
// Movement/Entered
iol.setQty(QtyEntered);
//
MOrderLine ol = null;
MRMALine rmal = null;
if (C_OrderLine_ID != 0) {
iol.setC_OrderLine_ID(C_OrderLine_ID);
ol = new MOrderLine(Env.getCtx(), C_OrderLine_ID, trxName);
if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0) {
iol.setMovementQty(QtyEntered.multiply(ol.getQtyOrdered()).divide(ol.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
iol.setC_UOM_ID(ol.getC_UOM_ID());
}
iol.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
iol.setDescription(ol.getDescription());
//
iol.setC_Project_ID(ol.getC_Project_ID());
iol.setC_ProjectPhase_ID(ol.getC_ProjectPhase_ID());
iol.setC_ProjectTask_ID(ol.getC_ProjectTask_ID());
iol.setC_Activity_ID(ol.getC_Activity_ID());
iol.setC_Campaign_ID(ol.getC_Campaign_ID());
iol.setAD_OrgTrx_ID(ol.getAD_OrgTrx_ID());
iol.setUser1_ID(ol.getUser1_ID());
iol.setUser2_ID(ol.getUser2_ID());
iol.setUser3_ID(ol.getUser3_ID());
iol.setUser4_ID(ol.getUser4_ID());
} else if (il != null) {
if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0) {
iol.setQtyEntered(QtyEntered.multiply(il.getQtyInvoiced()).divide(il.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
iol.setC_UOM_ID(il.getC_UOM_ID());
}
iol.setDescription(il.getDescription());
iol.setC_Project_ID(il.getC_Project_ID());
iol.setC_ProjectPhase_ID(il.getC_ProjectPhase_ID());
iol.setC_ProjectTask_ID(il.getC_ProjectTask_ID());
iol.setC_Activity_ID(il.getC_Activity_ID());
iol.setC_Campaign_ID(il.getC_Campaign_ID());
iol.setAD_OrgTrx_ID(il.getAD_OrgTrx_ID());
iol.setUser1_ID(il.getUser1_ID());
iol.setUser2_ID(il.getUser2_ID());
iol.setUser3_ID(il.getUser3_ID());
iol.setUser4_ID(il.getUser4_ID());
} else if (M_RMALine_ID != 0) {
rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, trxName);
iol.setM_RMALine_ID(M_RMALine_ID);
iol.setQtyEntered(QtyEntered);
iol.setDescription(rmal.getDescription());
iol.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
iol.setC_Project_ID(rmal.getC_Project_ID());
iol.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
iol.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
iol.setC_Activity_ID(rmal.getC_Activity_ID());
iol.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
iol.setUser1_ID(rmal.getUser1_ID());
iol.setUser2_ID(rmal.getUser2_ID());
iol.setUser3_ID(rmal.getUser3_ID());
iol.setUser4_ID(rmal.getUser4_ID());
}
// Charge
if (M_Product_ID == 0) {
if (// from order
ol != null && ol.getC_Charge_ID() != 0)
iol.setC_Charge_ID(ol.getC_Charge_ID());
else if (// from invoice
il != null && il.getC_Charge_ID() != 0)
iol.setC_Charge_ID(il.getC_Charge_ID());
else if (// from rma
rmal != null && rmal.getC_Charge_ID() != 0)
iol.setC_Charge_ID(rmal.getC_Charge_ID());
}
// Set locator
iol.setM_Locator_ID(M_Locator_ID);
if (!iol.save())
log.log(Level.SEVERE, "Line NOT created #" + i);
else // Create Invoice Line Link
if (il != null) {
il.setM_InOutLine_ID(iol.getM_InOutLine_ID());
il.saveEx();
}
}
// if selected
}
/**
* Update Header
* - if linked to another order/invoice/rma - remove link
* - if no link set it
*/
if (p_order != null && p_order.getC_Order_ID() != 0) {
inout.setC_Order_ID(p_order.getC_Order_ID());
inout.setAD_OrgTrx_ID(p_order.getAD_OrgTrx_ID());
inout.setC_Project_ID(p_order.getC_Project_ID());
inout.setC_Campaign_ID(p_order.getC_Campaign_ID());
inout.setC_Activity_ID(p_order.getC_Activity_ID());
inout.setUser1_ID(p_order.getUser1_ID());
inout.setUser2_ID(p_order.getUser2_ID());
inout.setUser3_ID(p_order.getUser3_ID());
inout.setUser4_ID(p_order.getUser4_ID());
if (p_order.isDropShip()) {
inout.setM_Warehouse_ID(p_order.getM_Warehouse_ID());
inout.setIsDropShip(p_order.isDropShip());
inout.setDropShip_BPartner_ID(p_order.getDropShip_BPartner_ID());
inout.setDropShip_Location_ID(p_order.getDropShip_Location_ID());
inout.setDropShip_User_ID(p_order.getDropShip_User_ID());
}
}
if (m_invoice != null && m_invoice.getC_Invoice_ID() != 0) {
if (inout.getC_Order_ID() == 0)
inout.setC_Order_ID(m_invoice.getC_Order_ID());
inout.setC_Invoice_ID(m_invoice.getC_Invoice_ID());
inout.setAD_OrgTrx_ID(m_invoice.getAD_OrgTrx_ID());
inout.setC_Project_ID(m_invoice.getC_Project_ID());
inout.setC_Campaign_ID(m_invoice.getC_Campaign_ID());
inout.setC_Activity_ID(m_invoice.getC_Activity_ID());
inout.setUser1_ID(m_invoice.getUser1_ID());
inout.setUser2_ID(m_invoice.getUser2_ID());
inout.setUser3_ID(m_invoice.getUser3_ID());
inout.setUser4_ID(m_invoice.getUser4_ID());
}
if (m_rma != null && m_rma.getM_RMA_ID() != 0) {
MInOut originalIO = m_rma.getShipment();
inout.setIsSOTrx(m_rma.isSOTrx());
inout.setC_Order_ID(0);
inout.setC_Invoice_ID(0);
inout.setM_RMA_ID(m_rma.getM_RMA_ID());
inout.setAD_OrgTrx_ID(originalIO.getAD_OrgTrx_ID());
inout.setC_Project_ID(originalIO.getC_Project_ID());
inout.setC_Campaign_ID(originalIO.getC_Campaign_ID());
inout.setC_Activity_ID(originalIO.getC_Activity_ID());
inout.setUser1_ID(originalIO.getUser1_ID());
inout.setUser2_ID(originalIO.getUser2_ID());
inout.setUser3_ID(originalIO.getUser3_ID());
inout.setUser4_ID(originalIO.getUser4_ID());
}
inout.saveEx();
return true;
}
Aggregations