Refactoring of Create Client in Posterita

This commit is contained in:
shameem_z 2007-10-29 12:38:34 +00:00
parent 9d90a6c6fa
commit c96c9066cf
6 changed files with 358 additions and 499 deletions

View File

@ -25,25 +25,14 @@ package org.posterita.businesslogic;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.compiere.model.MBPartner;
import org.compiere.model.MStore; import org.compiere.model.MStore;
import org.compiere.model.MUser;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.WebSessionCtx;
import org.compiere.util.WebUser;
import org.compiere.wstore.JSPEnv;
import org.posterita.Constants;
import org.posterita.beans.ApplicationParametersBean; import org.posterita.beans.ApplicationParametersBean;
import org.posterita.beans.CustomerBean;
import org.posterita.exceptions.DefaultStoreException; import org.posterita.exceptions.DefaultStoreException;
import org.posterita.exceptions.OperationException;
import org.posterita.lib.UdiConstants; import org.posterita.lib.UdiConstants;
import org.posterita.user.WebUserInfo;
/** /**
* @author Ashley * @author Ashley
@ -51,21 +40,14 @@ import org.posterita.user.WebUserInfo;
public class ApplicationManager public class ApplicationManager
{ {
public static void setApplicationParametersInContext(Properties tmkCtx, String applicationName) public static void setApplicationParametersInContext(Properties tmkCtx, int storeId)
{ {
String sql = "WebContext='/" + applicationName + "'";
int storeIds[] = MStore.getAllIDs(MStore.Table_Name, sql, null);
if(storeIds == null || storeIds.length == 0)
throw new RuntimeException("No store found for application with name/context: " + applicationName);
else if(storeIds.length > 1)
throw new RuntimeException(storeIds.length + " stores found with same context, " + applicationName);
Env.setContext(tmkCtx, "#AD_Client_ID", 0); Env.setContext(tmkCtx, "#AD_Client_ID", 0);
Env.setContext(tmkCtx, "#AD_Org_ID", 0); Env.setContext(tmkCtx, "#AD_Org_ID", 0);
MStore store = new MStore(tmkCtx, storeIds[0], null); MStore store = new MStore(tmkCtx, storeId, null);
if(store.get_ID() == 0) if(store.get_ID() == 0)
throw new RuntimeException("No store found for application with name/context: " + applicationName); throw new RuntimeException("No store found for application with ID: " + storeId);
Env.setContext(tmkCtx, UdiConstants.CLIENT_ID_CTX_PARAM, store.getAD_Client_ID()); Env.setContext(tmkCtx, UdiConstants.CLIENT_ID_CTX_PARAM, store.getAD_Client_ID());
Env.setContext(tmkCtx, UdiConstants.ORG_ID_CTX_PARAM, store.getAD_Org_ID()); Env.setContext(tmkCtx, UdiConstants.ORG_ID_CTX_PARAM, store.getAD_Org_ID());
Env.setContext(tmkCtx, UdiConstants.USER_ORG_CTX_PARAM, store.getAD_Org_ID()); Env.setContext(tmkCtx, UdiConstants.USER_ORG_CTX_PARAM, store.getAD_Org_ID());
@ -73,7 +55,7 @@ public class ApplicationManager
Env.setContext(tmkCtx, UdiConstants.WAREHOUSE_CTX_PARAM, store.getM_Warehouse_ID()); Env.setContext(tmkCtx, UdiConstants.WAREHOUSE_CTX_PARAM, store.getM_Warehouse_ID());
Env.setContext(tmkCtx, UdiConstants.CSS, store.getWebParam5()); Env.setContext(tmkCtx, UdiConstants.CSS, store.getWebParam5());
Env.setContext(tmkCtx, UdiConstants.FORWARD, store.getWebParam6()); Env.setContext(tmkCtx, UdiConstants.FORWARD, store.getWebParam6());
Env.setContext(tmkCtx, "#W_Store_ID", store.get_ID()); Env.setContext(tmkCtx, UdiConstants.WSTORE_CTX_PARAM, store.get_ID());
String language = store.getWebParam4(); String language = store.getWebParam4();
if (language != null && language != "") if (language != null && language != "")
@ -82,125 +64,7 @@ public class ApplicationManager
} }
} }
public static void changeApplication(HttpServletRequest request, HttpServletResponse response) throws OperationException, DefaultStoreException //TODO Refactor, work with store id instead of context
{
String appName = ApplicationManager.getApplicationNameFromCookie(request);
changeApplication(request, response, appName);
}
public static void changeApplication(HttpServletRequest request, HttpServletResponse response, String applicationType) throws DefaultStoreException
{
if(applicationType == null)
applicationType = getDefaultApplicationType();
if(!isApplicationPresent(applicationType))
applicationType = getDefaultApplicationType();
HttpSession session = request.getSession();
WebUserInfo wuInfo = (WebUserInfo)session.getAttribute(WebUserInfo.NAME);
if (wuInfo != null)
{
WebUser wu = wuInfo.getUser();
if (wu != null)
wu.logout();
}
session.removeAttribute(WebSessionCtx.NAME);
session.removeAttribute(WebUserInfo.NAME);
session.setMaxInactiveInterval(0);
Properties ctx = JSPEnv.getCtx(request);
setApplicationParametersInContext(ctx, applicationType);
setApplicationNameInCookie(response, applicationType);
}
public static String getApplicationType(Properties ctx) throws OperationException
{
String appType = Env.getContext(ctx, UdiConstants.WEBPARAM6);
if(appType != null && appType.length() != 0)
return appType;
else
throw new OperationException("Session has timed out! Please reload the home page.");
}
public static void setApplicationNameInCookie(HttpServletResponse response,String appName)
{
Cookie cookie = new Cookie(Constants.APP_NAME, appName);
cookie.setMaxAge(365*24*60*60);
response.addCookie(cookie);
}
public static String getApplicationNameFromCookie(HttpServletRequest request)
{
Cookie[] cookies = request.getCookies();
String appName = null;
if(cookies != null)
{
for(int i = 0; i < cookies.length; i++)
{
if(cookies[i].getName().equalsIgnoreCase(Constants.APP_NAME))
{
appName = cookies[i].getValue();
}
}
}
return appName;
}
public static String getDefaultApplicationType() throws DefaultStoreException
{
Properties ctx = Env.getCtx();
MStore store = StoreManager.getDefaultStore(ctx);
String retVal = store.getWebContext();
retVal = retVal.replaceAll("/", "");
return retVal;
}
public static boolean isApplicationPresent(String applicationType)
{
return StoreManager.isStorePresent("/" + applicationType);
}
//This method is used to find out the email sender depending on the application
public static CustomerBean getSalesRepMStore(Properties ctx, String trxName) throws OperationException
{
CustomerBean bean = new CustomerBean();
String storeIdStr = Env.getContext(ctx, "#W_Store_ID");
if (storeIdStr == null || storeIdStr.equals(""))
throw new OperationException("WStore not found in session!!");
MStore store = new MStore(ctx, Integer.parseInt(storeIdStr), trxName);
if(store == null)
throw new OperationException("No store found!!");
if (store.getSalesRep_ID() == 0)
{
//Default sender
bean.setEmail("crm@posterita.com");
bean.setUsername("Tamak Webmaster");
}
MUser user = UserManager.loadUser(ctx, store.getSalesRep_ID(), null);
MBPartner partner = BPartnerManager.loadBPartner(ctx, user.getC_BPartner_ID(), null);
bean.setSalesRepId(store.getSalesRep_ID());
bean.setEmail(user.getEMail());
bean.setUsername(partner.getName() + " " + partner.getName2());
return bean;
}
public static ArrayList<ApplicationParametersBean> getAvailableApplications() public static ArrayList<ApplicationParametersBean> getAvailableApplications()
{ {
String whereClause = "IsActive='Y' order by Name"; String whereClause = "IsActive='Y' order by Name";
@ -218,28 +82,10 @@ public class ApplicationManager
ApplicationParametersBean appParamBean = new ApplicationParametersBean(); ApplicationParametersBean appParamBean = new ApplicationParametersBean();
appParamBean.setApplicationName(store.getName()); appParamBean.setApplicationName(store.getName());
appParamBean.setApplicationWebContext(appContextPath); appParamBean.setApplicationWebContext(appContextPath);
appParamBean.setApplicationType(store.getWebParam6()); appParamBean.setStoreId(store.get_ID());
appList.add(appParamBean); appList.add(appParamBean);
} }
return appList; return appList;
} }
public static String getApplicationName(String appContextPath)
{
String whereClause = "IsActive='Y' and WEBCONTEXT='/"+ appContextPath + "'";
int storeIds[] = MStore.getAllIDs(MStore.Table_Name, whereClause, null);
Properties ctx = Env.getCtx();
if (storeIds.length == 0)
return null;
MStore store = new MStore(ctx, storeIds[0], null);
return store.getName();
}
} }

View File

@ -19,11 +19,9 @@
**/ **/
/** /**
@author ashley @author ashley
*/ */
package org.posterita.businesslogic; package org.posterita.businesslogic;
import java.io.File; import java.io.File;
@ -61,87 +59,95 @@ import org.posterita.core.businesslogic.ImportManager;
public class ClientManager public class ClientManager
{ {
public static final String ACCOUNTING_FILE_PATH = PathInfo.PROJECT_HOME + "/config/accounting/AccountingUS.csv"; public static final String ACCOUNTING_FILE_PATH = PathInfo.PROJECT_HOME
+ "/config/accounting/AccountingUS.csv";
public static final String ACCOUNTS_IMPORT_FORMAT = "Accounting - Accounts"; public static final String ACCOUNTS_IMPORT_FORMAT = "Accounting - Accounts";
//public static String ACCOUNTS_IMPORT_TABLE = "I_ElementValue";
private static MClient createClient(Properties nCtx, String clientName, String orgName, int currencyId, String currencyName, int countryId, String city) throws OperationException // public static String ACCOUNTS_IMPORT_TABLE = "I_ElementValue";
{
Properties ctx = Env.getCtx();
try
{
Env.setContext(ctx, "#AD_User_ID", 100); // set user as SuperUser
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, "11"); // Garden World
MCountry.get(ctx, countryId); private static MClient createClient(Properties nCtx, String clientName,
String orgName, int currencyId, String currencyName, int countryId,
String city, File file) throws OperationException {
Properties ctx = Env.getCtx();
MSetup setup = new MSetup(ctx, 0); Env.setContext(ctx, "#AD_User_ID", 100); // set user as SuperUser
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, "11"); // Garden
// World
// Step 1 MCountry.get(ctx, countryId);
boolean ok = setup.createClient(clientName, orgName, clientName + " Client User", clientName +" Org User");
if (ok) MSetup setup = new MSetup(ctx, 0);
// Step 1
boolean ok = setup.createClient(clientName, orgName, clientName
+ " Client User", clientName + " Org User");
if (ok)
{
// Generate Accounting
KeyNamePair currency = new KeyNamePair(currencyId, currencyName);
if (!setup.createAccounting(currency, true, true, false, false,
false, file))
{ {
// Generate Accounting throw new OperationException("Could not create accounting for client");
KeyNamePair currency = new KeyNamePair(currencyId, currencyName);
String udiHome = PathInfo.PROJECT_HOME;
String accountingfile = UdiConstants.ACCOUNTING_FILE;
String accountingFileName = udiHome + accountingfile;
URL url = new URL("file://" + accountingFileName);
File m_file=new File(url.getFile());
if (!setup.createAccounting(currency, true, true, false, false, false, m_file))
throw new OperationException("Could not create accounting for client");
// Generate Entities
if(!setup.createEntities(countryId, city, 0, currency.getKey()))
throw new OperationException("Could not create setup entities");
// Create Print Documents
PrintUtil.setupPrintForm(setup.getAD_Client_ID());
} }
else
throw new OperationException("Could not create client");
int clientId = setup.getAD_Client_ID();
MClient client = MClient.get(ctx, clientId); // Generate Entities
if (!setup.createEntities(countryId, city, 0, currency.getKey()))
{
throw new OperationException(
"Could not create setup entities");
}
return client; // Create Print Documents
PrintUtil.setupPrintForm(setup.getAD_Client_ID());
} }
catch(IOException ex) else
{ {
throw new OperationException("Could not find accounting file", ex); throw new OperationException("Could not create client");
} }
} int clientId = setup.getAD_Client_ID();
protected static void updateAccountingProcessor(Properties ctx, int adClientId, String trxName) throws OperationException MClient client = MClient.get(ctx, clientId);
{
String updStmt = "Update C_AcctProcessor set FrequencyType='M' where AD_Client_ID=" + adClientId;
int updates = DB.executeUpdate(updStmt, trxName); return client;
}
if(updates == -1) protected static void updateAccountingProcessor(Properties ctx,
throw new OperationException("Accounting Processor could not be updated"); int adClientId, String trxName) throws OperationException {
} String updStmt = "Update C_AcctProcessor set FrequencyType='M' where AD_Client_ID="
+ adClientId;
public static void createClientDependencies(Properties ctx, MClient client, MOrg org, String address, int countryId, String city, String postalAddress, String smtpHost, String trxName) throws OperationException int updates = DB.executeUpdate(updStmt, trxName);
{
//Set client smtp host for sending emails
client.setSMTPHost(smtpHost);
// client.setIsPostImmediate(true);
// client.setIsCostImmediate(true);
UDIMClient udiClient = new UDIMClient(client);
udiClient.save();
// Create Organisation location if (updates == -1)
MLocation location = LocationManager.createLocation(ctx, address, postalAddress, city, countryId, trxName); throw new OperationException(
"Accounting Processor could not be updated");
}
// Create Linked Business Partner public static void createClientDependencies(Properties ctx, MClient client,
MBPartner bpartner = BPartnerManager.createLinkedBPartner(ctx, 0, org.getName(), " ", false, false, false, false, address, postalAddress, city, " ", countryId, trxName); MOrg org, String address, int countryId, String city,
bpartner.setAD_OrgBP_ID(org.get_ID()); String postalAddress, String smtpHost, File file, String trxName)
UDIMBPartner udiBPartner = new UDIMBPartner(bpartner); throws OperationException {
udiBPartner.save(); // Set client smtp host for sending emails
client.setSMTPHost(smtpHost);
// client.setIsPostImmediate(true);
// client.setIsCostImmediate(true);
UDIMClient udiClient = new UDIMClient(client);
udiClient.save();
// Create Organisation location
MLocation location = LocationManager.createLocation(ctx, address,
postalAddress, city, countryId, trxName);
// Create Linked Business Partner
MBPartner bpartner = BPartnerManager.createLinkedBPartner(ctx, 0, org
.getName(), " ", false, false, false, false, address,
postalAddress, city, " ", countryId, trxName);
bpartner.setAD_OrgBP_ID(org.get_ID());
UDIMBPartner udiBPartner = new UDIMBPartner(bpartner);
udiBPartner.save();
MOrgInfo orgInfo = org.getInfo(); MOrgInfo orgInfo = org.getInfo();
orgInfo.set_TrxName(trxName); orgInfo.set_TrxName(trxName);
@ -149,36 +155,38 @@ public class ClientManager
UDIMOrgInfo udiOrgInfo = new UDIMOrgInfo(orgInfo); UDIMOrgInfo udiOrgInfo = new UDIMOrgInfo(orgInfo);
udiOrgInfo.save(); udiOrgInfo.save();
openPeriods(ctx, trxName); openPeriods(ctx, trxName);
File impFile = new File(ACCOUNTING_FILE_PATH); ImportManager.importFile(ctx, file, ACCOUNTS_IMPORT_FORMAT, trxName);
ImportManager.importFile(ctx, impFile, ACCOUNTS_IMPORT_FORMAT, trxName); ImportManager.importAccounting(ctx, Env.getAD_Client_ID(ctx),
ImportManager.importAccounting(ctx, Env.getAD_Client_ID(ctx), getAccoutingElementId(ctx), false, true, true, trxName); getAccoutingElementId(ctx), false, true, true, trxName);
updateAccountingProcessor(ctx, Env.getAD_Client_ID(ctx), trxName); updateAccountingProcessor(ctx, Env.getAD_Client_ID(ctx), trxName);
} }
public static MClient getCreateClient(Properties ctx, String clientName, String orgName, int currencyId, String currencyName, int countryId, String city, String address, String postalAddress, String smtpHost) throws OperationException public static MClient getCreateClient(Properties ctx, String clientName,
{ String orgName, int currencyId, String currencyName, int countryId,
MClient client; String city, String address, String postalAddress, String smtpHost, File file)
Properties rctx = (Properties)ctx.clone(); throws OperationException {
if(isClientPresent(clientName)) MClient client;
{ Properties rctx = (Properties) ctx.clone();
int clientId = getClientId(clientName); if (isClientPresent(clientName)) {
client = new MClient(ctx, clientId, null); int clientId = getClientId(clientName);
} client = new MClient(ctx, clientId, null);
else } else {
{ client = createClient(rctx, clientName, orgName, currencyId,
client = createClient(rctx, clientName, orgName, currencyId, currencyName, countryId, city); currencyName, countryId, city, file);
Env.setContext(rctx, UdiConstants.CLIENT_ID_CTX_PARAM, client.get_ID()); Env.setContext(rctx, UdiConstants.CLIENT_ID_CTX_PARAM, client
MOrg org = OrganisationManager.getOrgByName(rctx, orgName, null); .get_ID());
createClientDependencies(rctx, client, org, address, countryId, city, postalAddress, smtpHost, null); MOrg org = OrganisationManager.getOrgByName(rctx, orgName, null);
} createClientDependencies(rctx, client, org, address, countryId,
return client; city, postalAddress, smtpHost, file, null);
} }
return client;
}
public static Properties getCtx(Properties ctx, String clientName, String orgName) throws OperationException public static Properties getCtx(Properties ctx, String clientName,
{ String orgName) throws OperationException {
int clientId = ClientManager.getClientId(clientName); int clientId = ClientManager.getClientId(clientName);
// Set AD_Client_ID in the context // Set AD_Client_ID in the context
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId); Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId);
@ -189,145 +197,137 @@ public class ClientManager
Env.setContext(ctx, UdiConstants.USER_ORG_CTX_PARAM, orgId); Env.setContext(ctx, UdiConstants.USER_ORG_CTX_PARAM, orgId);
return ctx; return ctx;
} }
public static Properties getCtx(Properties ctx, int clientId, int orgId) public static Properties getCtx(Properties ctx, int clientId, int orgId) {
{ Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId);
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId); Env.setContext(ctx, UdiConstants.ORG_ID_CTX_PARAM, orgId);
Env.setContext(ctx, UdiConstants.ORG_ID_CTX_PARAM, orgId); Env.setContext(ctx, UdiConstants.USER_ID_CTX_PARAM, 100);
Env.setContext(ctx, UdiConstants.USER_ID_CTX_PARAM, 100);
return ctx; return ctx;
} }
public static void openPeriods(Properties ctx, String trxName)
throws OperationException {
UDIMPeriodControl udiPeriodControl;
int idPCs[] = PO.getAllIDs(MPeriodControl.Table_Name, " AD_CLIENT_ID ="
+ Env.getAD_Client_ID(ctx), trxName);
public static void openPeriods(Properties ctx, String trxName) throws OperationException for (int i = 0; i < idPCs.length; i++) {
{ MPeriodControl period = new MPeriodControl(ctx, idPCs[i], trxName);
UDIMPeriodControl udiPeriodControl; period.setPeriodStatus(MPeriodControl.PERIODSTATUS_Open);
int idPCs[] = PO.getAllIDs(MPeriodControl.Table_Name," AD_CLIENT_ID =" + Env.getAD_Client_ID(ctx), trxName); udiPeriodControl = new UDIMPeriodControl(period);
for (int i = 0; i < idPCs.length; i++) udiPeriodControl.save();
{ }
MPeriodControl period = new MPeriodControl(ctx,idPCs[i], trxName); }
period.setPeriodStatus(MPeriodControl.PERIODSTATUS_Open);
udiPeriodControl = new UDIMPeriodControl(period);
udiPeriodControl.save(); public static MClient loadClient(Properties ctx, int clientId,
} String trxName) throws OperationException {
} MClient client = new MClient(ctx, clientId, trxName);
if (client.get_ID() == 0)
throw new OperationException("Could not load client with id: "
+ clientId);
public static MClient loadClient(Properties ctx, int clientId, String trxName) throws OperationException return client;
{ }
MClient client = new MClient(ctx, clientId, trxName);
if(client.get_ID() == 0)
throw new OperationException("Could not load client with id: " + clientId);
return client; public static int getAccoutingElementId(Properties ctx)
} throws OperationException {
public static int getAccoutingElementId(Properties ctx) throws OperationException
{
int adClientId = Env.getAD_Client_ID(ctx); int adClientId = Env.getAD_Client_ID(ctx);
String whereClause = "AD_Client_ID=" + adClientId; String whereClause = "AD_Client_ID=" + adClientId;
int elementIds[] = MElement.getAllIDs(MElement.Table_Name, whereClause, null); int elementIds[] = MElement.getAllIDs(MElement.Table_Name, whereClause,
null);
if(elementIds.length == 0) if (elementIds.length == 0)
throw new OperationException("No accounting element found for client with id: " + adClientId); throw new OperationException(
else if(elementIds.length > 1) "No accounting element found for client with id: "
throw new OperationException(elementIds.length + " account elements found for client with id: " + adClientId); + adClientId);
else if (elementIds.length > 1)
throw new OperationException(elementIds.length
+ " account elements found for client with id: "
+ adClientId);
else else
return elementIds[0]; return elementIds[0];
} }
public static void changeClientName(Properties ctx, String clientName, String trxName) throws OperationException public static void changeClientName(Properties ctx, String clientName,
{ String trxName) throws OperationException {
if(clientName == null || clientName.trim().length() == 0) if (clientName == null || clientName.trim().length() == 0)
throw new OperationException("Client Name cannot be null"); throw new OperationException("Client Name cannot be null");
int adClientId = Env.getAD_Client_ID(ctx); int adClientId = Env.getAD_Client_ID(ctx);
MClient client = loadClient(ctx, adClientId, trxName); MClient client = loadClient(ctx, adClientId, trxName);
if(!client.getName().equals(clientName)) if (!client.getName().equals(clientName)) {
{ client.setName(clientName);
client.setName(clientName);
UDIMClient udiClient = new UDIMClient(client); UDIMClient udiClient = new UDIMClient(client);
udiClient.save(); udiClient.save();
} }
} }
public static void cleanData(Properties ctx, boolean deleteAll) throws OperationException public static void cleanData(Properties ctx, boolean deleteAll)
{ throws OperationException {
throw new RuntimeException("This operation is no more supported"); throw new RuntimeException("This operation is no more supported");
} }
public static int getClientId(String clientName) throws OperationException {
String sql = "select ad_client_id from ad_client where upper(name)=upper('"
+ clientName + "')";
PreparedStatement pstmt = DB.prepareStatement(sql, null);
ResultSet rs = null;
public static int getClientId(String clientName) throws OperationException int clientID = 0;
{ try {
String sql = "select ad_client_id from ad_client where upper(name)=upper('" + clientName + "')"; rs = pstmt.executeQuery();
while (rs.next()) {
clientID = rs.getInt(1);
}
PreparedStatement pstmt = DB.prepareStatement(sql,null); rs.close();
ResultSet rs = null; } catch (SQLException e) {
throw new OperationException(e);
} finally {
try {
pstmt.close();
} catch (Exception ex) {
}
int clientID = 0; pstmt = null;
try }
{
rs = pstmt.executeQuery();
while (rs.next())
{
clientID = rs.getInt(1);
}
rs.close(); if (clientID == 0)
} throw new NoClientFoundException("no client found for clientName "
catch (SQLException e) + clientName);
{
throw new OperationException(e);
}
finally
{
try
{
pstmt.close();
}
catch(Exception ex)
{}
pstmt = null; return clientID;
} }
if (clientID == 0) public static boolean isClientPresent(String clientName)
throw new NoClientFoundException("no client found for clientName " + clientName); throws OperationException {
try {
getClientId(clientName);
} catch (NoClientFoundException e) {
return false;
}
return clientID; return true;
} }
public static boolean isClientPresent(String clientName) throws OperationException /*
{ * Retrieve all clients in the system for which POS/Webstore transactions
try * are valid
{ */
getClientId(clientName); public static int[] getAvailableClientIds() {
} int clientIds[] = MClient.getAllIDs(MClient.Table_Name,
catch(NoClientFoundException e) "IsActive='Y' and AD_Client_ID not in (0)", null);
{
return false;
}
return true; return clientIds;
} }
/*
* Retrieve all clients in the system for which POS/Webstore transactions are valid
*/
public static int[] getAvailableClientIds()
{
int clientIds[] = MClient.getAllIDs(MClient.Table_Name, "IsActive='Y' and AD_Client_ID not in (0)", null);
return clientIds;
}
} }

View File

@ -28,8 +28,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import org.compiere.model.MOrg; import org.compiere.model.X_U_WebMenu;
import org.compiere.model.X_U_Menu;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.posterita.beans.MenuItemBean; import org.posterita.beans.MenuItemBean;
@ -41,7 +40,7 @@ import org.posterita.factory.AbstractFactory;
import org.posterita.factory.POSMenuFactory; import org.posterita.factory.POSMenuFactory;
import org.posterita.keyname.MenuKeyNamePair; import org.posterita.keyname.MenuKeyNamePair;
import org.posterita.model.MMenu; import org.posterita.model.MMenu;
import org.posterita.model.UDIU_Menu; import org.posterita.model.U_WebMenu;
public class MenuManager public class MenuManager
@ -55,28 +54,25 @@ public class MenuManager
} }
public static ArrayList<UDIU_Menu> getMenus(Properties ctx, int roleId) throws SystemException, OperationException public static ArrayList<U_WebMenu> getMenus(Properties ctx, int roleId) throws SystemException, OperationException
{ {
POSMenuFactory.getFactoryInstance(ctx); POSMenuFactory.getFactoryInstance(ctx);
ArrayList<UDIU_Menu> menuList = new ArrayList<UDIU_Menu>(); ArrayList<U_WebMenu> menuList = new ArrayList<U_WebMenu>();
int adRoleId = roleId; int adRoleId = roleId;
String appName = ApplicationManager.getApplicationType(ctx).toUpperCase();
String sqlStatement = ""; String sqlStatement = "";
sqlStatement = " select m.U_Menu_ID, " + sqlStatement = " select m.U_WebMenu_ID, " +
" m.Name, m.MenuLink, " + " m.Name, m.MenuLink, " +
" m.Module, m.ParentMenu_ID, " + " m.Module, m.ParentMenu_ID, " +
" m.isActive, " + " m.isActive, " +
" m.ImageLink, m.Position, m.description " + " m.ImageLink, m.Position, m.description " +
" from U_MENU m, U_RoleMenu rm " + " from U_WebMENU m, U_RoleMenu rm " +
" where m.U_Menu_ID = rm.U_Menu_ID "+ " where m.U_WebMenu_ID = rm.U_WebMenu_ID "+
" and M.isActive='Y'"+ " and M.isActive='Y'"+
" and rm.AD_Role_ID = " + adRoleId + " and rm.AD_Role_ID = " + adRoleId +
// " and m.AD_Client_ID = " + adClientId + // Menu not dependent on client // " and m.AD_Client_ID = " + adClientId + // Menu not dependent on client
" and m.module = '" + appName + "' " + " order by m.Sequence, m.U_WebMenu_ID";
" order by m.Sequence, m.U_Menu_ID";
System.out.println("Query for menu manager :" + sqlStatement); System.out.println("Query for menu manager :" + sqlStatement);
@ -129,7 +125,7 @@ public class MenuManager
menu.setPosition(position); menu.setPosition(position);
menu.setDescription(description); menu.setDescription(description);
UDIU_Menu udiMenu = new UDIU_Menu(menu); U_WebMenu udiMenu = new U_WebMenu(menu);
menuList.add(udiMenu); menuList.add(udiMenu);
} }
@ -167,13 +163,13 @@ public class MenuManager
Iterator menuIter = menuList.iterator(); Iterator menuIter = menuList.iterator();
Iterator subIterator; Iterator subIterator;
UDIU_Menu mMenu; U_WebMenu mMenu;
UDIU_Menu sMenu; U_WebMenu sMenu;
while(menuIter.hasNext()) while(menuIter.hasNext())
{ {
mMenu = (UDIU_Menu)menuIter.next(); mMenu = (U_WebMenu)menuIter.next();
if(mMenu.getParentMenuId() == 0) // Parent Menu if(mMenu.getParentMenuId() == 0) // Parent Menu
{ {
@ -183,7 +179,7 @@ public class MenuManager
while(subIterator.hasNext()) while(subIterator.hasNext())
{ {
sMenu = (UDIU_Menu)subIterator.next(); sMenu = (U_WebMenu)subIterator.next();
if(sMenu.getParentMenuId() == mMenu.getMenuId()) if(sMenu.getParentMenuId() == mMenu.getMenuId())
{ {
MenuItem sItem = new MenuItem(sMenu); MenuItem sItem = new MenuItem(sMenu);
@ -209,27 +205,27 @@ public class MenuManager
public static void saveMenu(Properties ctx, MenuItemBean bean) throws OperationException public static void saveMenu(Properties ctx, MenuItemBean bean) throws OperationException
{ {
//when creating a new menu //when creating a new menu
X_U_Menu menu; X_U_WebMenu menu;
UDIU_Menu selectmenu; U_WebMenu selectmenu;
if (bean.getMenuId().equals(Integer.valueOf(0))) if (bean.getMenuId().equals(Integer.valueOf(0)))
{ {
menu = new X_U_Menu(ctx,0,null); menu = new X_U_WebMenu(ctx,0,null);
} }
// when editing a menu // when editing a menu
else else
{ {
menu = new X_U_Menu(ctx,bean.getMenuId().intValue(),null); menu = new X_U_WebMenu(ctx,bean.getMenuId().intValue(),null);
} }
menu.setIsActive(bean.getIsActive().booleanValue()); menu.setIsActive(bean.getIsActive().booleanValue());
menu.setDescription(bean.getDescription()); menu.setDescription(bean.getDescription());
selectmenu = new UDIU_Menu(menu); selectmenu = new U_WebMenu(menu);
selectmenu.save(); selectmenu.save();
} }
public static UDIU_Menu createParentMenu(Properties ctx, String menuName, String moduleName, int sequence) throws OperationException public static U_WebMenu createParentMenu(Properties ctx, String menuName, String moduleName, int sequence) throws OperationException
{ {
X_U_Menu menu = new X_U_Menu(ctx, 0, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, 0, null);
menu.setMenuLink("GetMenuItemsAction.do?action=getMenuItems&menuId="); menu.setMenuLink("GetMenuItemsAction.do?action=getMenuItems&menuId=");
menu.setModule(moduleName); menu.setModule(moduleName);
@ -237,34 +233,34 @@ public class MenuManager
menu.setSequence(new BigDecimal(sequence)); menu.setSequence(new BigDecimal(sequence));
menu.setName(menuName); menu.setName(menuName);
UDIU_Menu udiMenu = new UDIU_Menu(menu); U_WebMenu udiMenu = new U_WebMenu(menu);
return udiMenu; return udiMenu;
} }
@Deprecated @Deprecated
public static UDIU_Menu createParentMenu(Properties ctx, String menuName, String moduleName, boolean forRetailer, boolean forWholesaler, boolean forShipper) throws OperationException public static U_WebMenu createParentMenu(Properties ctx, String menuName, String moduleName, boolean forRetailer, boolean forWholesaler, boolean forShipper) throws OperationException
{ {
X_U_Menu menu = new X_U_Menu(ctx, 0, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, 0, null);
menu.setName(menuName); menu.setName(menuName);
menu.setMenuLink("GetMenuItemsAction.do?action=getMenuItems&menuId="); menu.setMenuLink("GetMenuItemsAction.do?action=getMenuItems&menuId=");
menu.setModule(moduleName); menu.setModule(moduleName);
menu.setPosition(AbstractFactory.MENU_POSITION_LEFT); menu.setPosition(AbstractFactory.MENU_POSITION_LEFT);
UDIU_Menu udiMenu = new UDIU_Menu(menu); U_WebMenu udiMenu = new U_WebMenu(menu);
return udiMenu; return udiMenu;
} }
public static UDIU_Menu createSubMenu(Properties ctx,String menuName, String menuLink, String moduleName, int parentId, int sequence) throws OperationException public static U_WebMenu createSubMenu(Properties ctx,String menuName, String menuLink, String moduleName, int parentId, int sequence) throws OperationException
{ {
return createSubMenu(ctx, menuName, menuLink, moduleName, parentId, sequence, null); return createSubMenu(ctx, menuName, menuLink, moduleName, parentId, sequence, null);
} }
public static UDIU_Menu createSubMenu(Properties ctx,String menuName, String menuLink, String moduleName, int parentId, int sequence, String category) throws OperationException public static U_WebMenu createSubMenu(Properties ctx,String menuName, String menuLink, String moduleName, int parentId, int sequence, String category) throws OperationException
{ {
X_U_Menu menu = new X_U_Menu(ctx, 0, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, 0, null);
menu.setParentMenu_ID(parentId); menu.setParentMenu_ID(parentId);
if(!menuLink.contains("javascript")) if(!menuLink.contains("javascript"))
@ -283,14 +279,14 @@ public class MenuManager
menu.setName(menuName); menu.setName(menuName);
menu.setCategory(category); menu.setCategory(category);
UDIU_Menu udiMenu = new UDIU_Menu(menu); U_WebMenu udiMenu = new U_WebMenu(menu);
return udiMenu; return udiMenu;
} }
@Deprecated @Deprecated
public static UDIU_Menu createSubMenu(Properties ctx,String menuName, String menuLink, String moduleName, int parentId, boolean closable, boolean forRetailer, boolean forWholesaler, boolean forShipper) throws OperationException public static U_WebMenu createSubMenu(Properties ctx,String menuName, String menuLink, String moduleName, int parentId, boolean closable, boolean forRetailer, boolean forWholesaler, boolean forShipper) throws OperationException
{ {
X_U_Menu menu = new X_U_Menu(ctx, 0, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, 0, null);
menu.setName(menuName); menu.setName(menuName);
menu.setParentMenu_ID(parentId); menu.setParentMenu_ID(parentId);
@ -304,11 +300,11 @@ public class MenuManager
menu.setPosition(AbstractFactory.MENU_POSITION_LEFT); menu.setPosition(AbstractFactory.MENU_POSITION_LEFT);
UDIU_Menu udiMenu = new UDIU_Menu(menu); U_WebMenu udiMenu = new U_WebMenu(menu);
return udiMenu; return udiMenu;
} }
public static ArrayList<UDIU_Menu> getMenusForOrganisationType(Properties ctx) throws OperationException public static ArrayList<U_WebMenu> getMenusForOrganisationType(Properties ctx) throws OperationException
{ {
// Creating the menus first. // Creating the menus first.
@ -316,11 +312,9 @@ public class MenuManager
ArrayList<UDIU_Menu> menuList = new ArrayList<UDIU_Menu>(); ArrayList<U_WebMenu> menuList = new ArrayList<U_WebMenu>();
String appName = ApplicationManager.getApplicationType(ctx).toUpperCase();
String sqlStatement = ""; String sqlStatement = "";
sqlStatement = "select m.U_Menu_ID, " + sqlStatement = "select m.U_Menu_ID, " +
@ -329,8 +323,7 @@ public class MenuManager
"m.isActive, " + "m.isActive, " +
"m.ImageLink, m.Position " + "m.ImageLink, m.Position " +
"from U_MENU m where " + //m.AD_Client_ID = " + adClientId + "from U_MENU m where " + //m.AD_Client_ID = " + adClientId +
" m.module = '" + appName + "' "+ " m.AD_CLIENT_ID=0"+
" and m.AD_CLIENT_ID=0"+
" and m.AD_ORG_ID=0" + " and m.AD_ORG_ID=0" +
" and m.isactive = 'Y'"; " and m.isactive = 'Y'";
@ -373,7 +366,7 @@ public class MenuManager
// setting the link name to be either car / bike // setting the link name to be either car / bike
name = formatMenuName(ctx, name); name = formatMenuName(ctx, name);
X_U_Menu menu = new X_U_Menu(ctx, menuId, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, menuId, null);
menu.setName(name); menu.setName(name);
menu.setMenuLink(menuLink); menu.setMenuLink(menuLink);
menu.setModule(module); menu.setModule(module);
@ -382,7 +375,7 @@ public class MenuManager
menu.setImageLink(imageLink); menu.setImageLink(imageLink);
menu.setPosition(position); menu.setPosition(position);
UDIU_Menu udiMenu = new UDIU_Menu(menu); U_WebMenu udiMenu = new U_WebMenu(menu);
menuList.add(udiMenu); menuList.add(udiMenu);
} }
@ -410,9 +403,7 @@ public class MenuManager
public static int[] getDefaultMenus(Properties ctx) throws OperationException public static int[] getDefaultMenus(Properties ctx) throws OperationException
{ {
String appName = ApplicationManager.getApplicationType(ctx).toUpperCase(); String whereClause = "AD_Client_ID=0 and AD_Org_ID=0 ";
String whereClause = "AD_Client_ID=0 and AD_Org_ID=0 and Module='" + appName + "' ";
whereClause += " and Position='TOP' and ParentMenu_ID is null"; whereClause += " and Position='TOP' and ParentMenu_ID is null";
int menuIds[] = MMenu.getAllIDs(MMenu.Table_Name, whereClause, null); int menuIds[] = MMenu.getAllIDs(MMenu.Table_Name, whereClause, null);
@ -429,7 +420,7 @@ public class MenuManager
String whereClause = "AD_CLIENT_ID=" + adClientId; String whereClause = "AD_CLIENT_ID=" + adClientId;
int menuIds[] = X_U_Menu.getAllIDs(X_U_Menu.Table_Name, whereClause, null); int menuIds[] = X_U_WebMenu.getAllIDs(X_U_WebMenu.Table_Name, whereClause, null);
return menuIds; return menuIds;
} }
@ -441,7 +432,7 @@ public class MenuManager
String whereClause = "AD_CLIENT_ID =" + adClientId + " and AD_ORG_ID = " + adOrgId + " and ISSUPERUSER = 'Y'"; String whereClause = "AD_CLIENT_ID =" + adClientId + " and AD_ORG_ID = " + adOrgId + " and ISSUPERUSER = 'Y'";
int menuIds[] = X_U_Menu.getAllIDs(X_U_Menu.Table_Name, whereClause, null); int menuIds[] = X_U_WebMenu.getAllIDs(X_U_WebMenu.Table_Name, whereClause, null);
return menuIds; return menuIds;
} }
@ -484,7 +475,7 @@ public class MenuManager
try try
{ {
menuKeyNamePairs = MenuKeyNamePair.getData(ctx, X_U_Menu.Table_Name, sql); menuKeyNamePairs = MenuKeyNamePair.getData(ctx, X_U_WebMenu.Table_Name, sql);
} }
catch (SQLException e) catch (SQLException e)
{ {
@ -496,7 +487,7 @@ public class MenuManager
public static MenuItemBean getMenu(Properties ctx, int menuId) public static MenuItemBean getMenu(Properties ctx, int menuId)
{ {
X_U_Menu menu = new X_U_Menu(ctx, menuId, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, menuId, null);
MenuItemBean bean = new MenuItemBean(); MenuItemBean bean = new MenuItemBean();
bean.setDescription(menu.getDescription()); bean.setDescription(menu.getDescription());
@ -509,7 +500,7 @@ public class MenuManager
public static MenuItemBean editMenu(Properties ctx, MenuItemBean bean) public static MenuItemBean editMenu(Properties ctx, MenuItemBean bean)
{ {
X_U_Menu menu = new X_U_Menu(ctx, bean.getMenuId().intValue(), null); X_U_WebMenu menu = new X_U_WebMenu(ctx, bean.getMenuId().intValue(), null);
menu.setDescription(bean.getDescription()); menu.setDescription(bean.getDescription());
menu.setIsActive(bean.getIsActive().booleanValue()); menu.setIsActive(bean.getIsActive().booleanValue());
menu.save(); menu.save();
@ -524,10 +515,10 @@ public class MenuManager
int ad_client_id = Env.getAD_Client_ID(ctx); int ad_client_id = Env.getAD_Client_ID(ctx);
int ad_org_id = Env.getAD_Org_ID(ctx); int ad_org_id = Env.getAD_Org_ID(ctx);
String whereClause = " module = '"+ module +"' and ad_client_id = "+ ad_client_id + String whereClause = " and ad_client_id = "+ ad_client_id +
" and ad_org_id = "+ ad_org_id +" and isactive = 'Y'"; " and ad_org_id = "+ ad_org_id +" and isactive = 'Y'";
return X_U_Menu.getAllIDs(X_U_Menu.Table_Name,whereClause,null); return X_U_WebMenu.getAllIDs(X_U_WebMenu.Table_Name,whereClause,null);
} }
@ -572,14 +563,6 @@ public class MenuManager
} }
} }
return access; return access;
} }

View File

@ -24,6 +24,10 @@
package org.posterita.businesslogic; package org.posterita.businesslogic;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
@ -43,12 +47,14 @@ import org.compiere.model.MPOS;
import org.compiere.model.MPriceList; import org.compiere.model.MPriceList;
import org.compiere.model.MPriceListVersion; import org.compiere.model.MPriceListVersion;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MRoleMenu;
import org.compiere.model.MStore; import org.compiere.model.MStore;
import org.compiere.model.MTaxCategory; import org.compiere.model.MTaxCategory;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.model.MWarehouse; import org.compiere.model.MWarehouse;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.posterita.core.FileManager;
import org.posterita.core.bean.ClientBean;
import org.posterita.exceptions.ClientAlreadyExistException; import org.posterita.exceptions.ClientAlreadyExistException;
import org.posterita.exceptions.OperationException; import org.posterita.exceptions.OperationException;
import org.posterita.factory.GenericProductAttributeFactory; import org.posterita.factory.GenericProductAttributeFactory;
@ -58,7 +64,6 @@ import org.posterita.factory.POSMenuFactory;
import org.posterita.factory.SystemObjectsFactory; import org.posterita.factory.SystemObjectsFactory;
import org.posterita.lib.UdiConstants; import org.posterita.lib.UdiConstants;
import org.posterita.model.MBank; import org.posterita.model.MBank;
import org.posterita.model.MRoleMenu;
import org.posterita.model.UDIMBank; import org.posterita.model.UDIMBank;
import org.posterita.model.UDIMBankAccount; import org.posterita.model.UDIMBankAccount;
import org.posterita.model.UDIMLocator; import org.posterita.model.UDIMLocator;
@ -67,9 +72,8 @@ import org.posterita.model.UDIMPriceListVersion;
import org.posterita.model.UDIMStore; import org.posterita.model.UDIMStore;
import org.posterita.model.UDIMUser; import org.posterita.model.UDIMUser;
import org.posterita.model.UDIMWarehouse; import org.posterita.model.UDIMWarehouse;
import org.posterita.model.UDIU_Menu; import org.posterita.model.U_RoleMenu;
import org.posterita.model.UDIU_RoleMenu; import org.posterita.model.U_WebMenu;
import org.posterita.core.bean.ClientBean;
public class POSClientManager extends ClientManager public class POSClientManager extends ClientManager
{ {
@ -257,11 +261,11 @@ public class POSClientManager extends ClientManager
while(keyIter.hasNext()) while(keyIter.hasNext())
{ {
String key = (String)keyIter.next(); String key = (String)keyIter.next();
UDIU_Menu udiMenu = (UDIU_Menu)posMFactory.get(nCtx, key); U_WebMenu udiMenu = (U_WebMenu)posMFactory.get(nCtx, key);
MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName); MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName);
roleMenu.setAD_Role_ID(role.get_ID()); roleMenu.setAD_Role_ID(role.get_ID());
roleMenu.setU_WebMenu_ID(udiMenu.getID()); roleMenu.setU_WebMenu_ID(udiMenu.getID());
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu); U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
udiRoleMenu.save(); udiRoleMenu.save();
} }
@ -283,15 +287,13 @@ public class POSClientManager extends ClientManager
int storeId = StoreManager.getStoreIdByName(ctx, storeName, null); int storeId = StoreManager.getStoreIdByName(ctx, storeName, null);
MStore store = new MStore(ctx, storeId, null); MStore store = new MStore(ctx, storeId, null);
String storeContext = store.getWebContext();
storeContext = storeContext.replace("/", "");
int pricelistId = store.getM_PriceList_ID(); int pricelistId = store.getM_PriceList_ID();
Env.setContext(ctx, UdiConstants.PRICELIST_CTX_PARAM, String.valueOf(pricelistId)); Env.setContext(ctx, UdiConstants.PRICELIST_CTX_PARAM, String.valueOf(pricelistId));
Env.setContext(ctx, UdiConstants.POS_PURCHASE_PL_VERSION, PriceListManager.getPriceListVersionID(ctx, pricelistId, null)); Env.setContext(ctx, UdiConstants.POS_PURCHASE_PL_VERSION, PriceListManager.getPriceListVersionID(ctx, pricelistId, null));
ApplicationManager.setApplicationParametersInContext(ctx, storeContext); ApplicationManager.setApplicationParametersInContext(ctx, storeId);
return ctx; return ctx;
} }
@ -311,8 +313,38 @@ public class POSClientManager extends ClientManager
throw new OperationException("Could not load currency with id: " + clientBean.getCurrencyId()); throw new OperationException("Could not load currency with id: " + clientBean.getCurrencyId());
String hostUrl = "http://www." + clientBean.getClientName() + ".com/"; String hostUrl = "http://www." + clientBean.getClientName() + ".com/";
File file = null;
FileOutputStream fos = null;
ClientManager.getCreateClient(ctx, clientBean.getClientName(), clientBean.getOrgName(), clientBean.getCurrencyId(), currency.getDescription(), clientBean.getCountryId(), clientBean.getCity(), clientBean.getAddress1(), clientBean.getPostalAddress(), ""); try
{
file = File.createTempFile("accounting_" + System.currentTimeMillis(), ".csv");
FileManager.write(clientBean.getFile().getInputStream(), file.getAbsolutePath());
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (fos != null)
{
try
{
fos.close();
}
catch(Exception ex)
{}
}
}
ClientManager.getCreateClient(ctx, clientBean.getClientName(), clientBean.getOrgName(), clientBean.getCurrencyId(), currency.getDescription(), clientBean.getCountryId(), clientBean.getCity(), clientBean.getAddress1(), clientBean.getPostalAddress(), "", file);
ctx = ClientManager.getCtx(ctx, clientBean.getClientName(), clientBean.getOrgName()); ctx = ClientManager.getCtx(ctx, clientBean.getClientName(), clientBean.getOrgName());
POSClientManager.createPOSDetails(ctx, clientBean.getCurrencyId(), currency.getDescription(), hostUrl, null); POSClientManager.createPOSDetails(ctx, clientBean.getCurrencyId(), currency.getDescription(), hostUrl, null);

View File

@ -29,8 +29,8 @@ import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MRoleMenu;
import org.compiere.model.MRoleOrgAccess; import org.compiere.model.MRoleOrgAccess;
import org.compiere.model.MUser;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
@ -41,10 +41,9 @@ import org.posterita.exceptions.OperationException;
import org.posterita.exceptions.RoleAlreadyExistsException; import org.posterita.exceptions.RoleAlreadyExistsException;
import org.posterita.exceptions.SystemException; import org.posterita.exceptions.SystemException;
import org.posterita.lib.UdiConstants; import org.posterita.lib.UdiConstants;
import org.posterita.model.MRoleMenu;
import org.posterita.model.UDIMRole; import org.posterita.model.UDIMRole;
import org.posterita.model.UDIU_Menu; import org.posterita.model.U_RoleMenu;
import org.posterita.model.UDIU_RoleMenu; import org.posterita.model.U_WebMenu;
public class RoleManager public class RoleManager
@ -331,10 +330,10 @@ public class RoleManager
} }
private static boolean hasMenu(int menuId, ArrayList<UDIU_Menu> menus) private static boolean hasMenu(int menuId, ArrayList<U_WebMenu> menus)
{ {
boolean menuAvailable = false; boolean menuAvailable = false;
for(UDIU_Menu udiMenu : menus) for(U_WebMenu udiMenu : menus)
{ {
if(udiMenu.getMenuId() == menuId) if(udiMenu.getMenuId() == menuId)
{ {
@ -345,7 +344,7 @@ public class RoleManager
return menuAvailable; return menuAvailable;
} }
private static void setRoleMenus(MenuItem menuItem, ArrayList<UDIU_Menu> menus) private static void setRoleMenus(MenuItem menuItem, ArrayList<U_WebMenu> menus)
{ {
ArrayList<MenuItem> children = menuItem.getAllChildren(); ArrayList<MenuItem> children = menuItem.getAllChildren();
for(MenuItem mItem : children) for(MenuItem mItem : children)
@ -362,9 +361,9 @@ public class RoleManager
public static MenuItem getAvailableMenus(Properties ctx, int roleId) throws SystemException, OperationException public static MenuItem getAvailableMenus(Properties ctx, int roleId) throws SystemException, OperationException
{ {
ArrayList<UDIU_Menu> roleMenus = MenuManager.getMenus(ctx, roleId); ArrayList<U_WebMenu> roleMenus = MenuManager.getMenus(ctx, roleId);
ArrayList<UDIU_Menu> appMenus = MenuManager.getMenusForOrganisationType(ctx); ArrayList<U_WebMenu> appMenus = MenuManager.getMenusForOrganisationType(ctx);
MenuItem rootItem = MenuManager.buildMenuTree(ctx, appMenus); MenuItem rootItem = MenuManager.buildMenuTree(ctx, appMenus);
setRoleMenus(rootItem, roleMenus); setRoleMenus(rootItem, roleMenus);
@ -407,7 +406,7 @@ public class RoleManager
MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName); MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName);
roleMenu.setAD_Role_ID(role.get_ID()); roleMenu.setAD_Role_ID(role.get_ID());
roleMenu.setU_WebMenu_ID(menuId[i]); roleMenu.setU_WebMenu_ID(menuId[i]);
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu); U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
udiRoleMenu.save(); udiRoleMenu.save();
} }
@ -418,7 +417,7 @@ public class RoleManager
MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName); MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName);
roleMenu.setAD_Role_ID(role.get_ID()); roleMenu.setAD_Role_ID(role.get_ID());
roleMenu.setU_WebMenu_ID(defMenuIds[i]); roleMenu.setU_WebMenu_ID(defMenuIds[i]);
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu); U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
udiRoleMenu.save(); udiRoleMenu.save();
} }
} }

View File

@ -23,11 +23,10 @@ package org.posterita.businesslogic;
import java.util.Properties; import java.util.Properties;
import org.compiere.model.X_U_Menu; import org.compiere.model.MRoleMenu;
import org.compiere.model.X_U_WebMenu;
import org.posterita.exceptions.OperationException; import org.posterita.exceptions.OperationException;
import org.posterita.model.MRoleMenu; import org.posterita.model.U_RoleMenu;
import org.posterita.model.UDIU_RoleMenu;
public class RoleMenuManager public class RoleMenuManager
@ -37,7 +36,7 @@ public class RoleMenuManager
{ {
MRoleMenu roleMenu; MRoleMenu roleMenu;
X_U_Menu menu = new X_U_Menu(ctx, menuId, null); X_U_WebMenu menu = new X_U_WebMenu(ctx, menuId, null);
int parentMenuId = menu.getParentMenu_ID(); int parentMenuId = menu.getParentMenu_ID();
@ -53,7 +52,7 @@ public class RoleMenuManager
roleMenu.setAD_Role_ID(roleId); roleMenu.setAD_Role_ID(roleId);
roleMenu.setU_WebMenu_ID(menuId); roleMenu.setU_WebMenu_ID(menuId);
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu); U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
udiRoleMenu.save(); udiRoleMenu.save();
return roleMenu; return roleMenu;