Refactoring of Create Client in Posterita
This commit is contained in:
parent
9d90a6c6fa
commit
c96c9066cf
|
@ -25,25 +25,14 @@ package org.posterita.businesslogic;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.compiere.model.MBPartner;
|
||||
import org.compiere.model.MStore;
|
||||
import org.compiere.model.MUser;
|
||||
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.CustomerBean;
|
||||
import org.posterita.exceptions.DefaultStoreException;
|
||||
import org.posterita.exceptions.OperationException;
|
||||
import org.posterita.lib.UdiConstants;
|
||||
import org.posterita.user.WebUserInfo;
|
||||
|
||||
/**
|
||||
* @author Ashley
|
||||
|
@ -51,21 +40,14 @@ import org.posterita.user.WebUserInfo;
|
|||
|
||||
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_Org_ID", 0);
|
||||
MStore store = new MStore(tmkCtx, storeIds[0], null);
|
||||
MStore store = new MStore(tmkCtx, storeId, null);
|
||||
|
||||
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.ORG_ID_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.CSS, store.getWebParam5());
|
||||
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();
|
||||
if (language != null && language != "")
|
||||
|
@ -82,125 +64,7 @@ public class ApplicationManager
|
|||
}
|
||||
}
|
||||
|
||||
public static void changeApplication(HttpServletRequest request, HttpServletResponse response) throws OperationException, DefaultStoreException
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//TODO Refactor, work with store id instead of context
|
||||
public static ArrayList<ApplicationParametersBean> getAvailableApplications()
|
||||
{
|
||||
String whereClause = "IsActive='Y' order by Name";
|
||||
|
@ -218,28 +82,10 @@ public class ApplicationManager
|
|||
ApplicationParametersBean appParamBean = new ApplicationParametersBean();
|
||||
appParamBean.setApplicationName(store.getName());
|
||||
appParamBean.setApplicationWebContext(appContextPath);
|
||||
appParamBean.setApplicationType(store.getWebParam6());
|
||||
appParamBean.setStoreId(store.get_ID());
|
||||
appList.add(appParamBean);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -19,11 +19,9 @@
|
|||
**/
|
||||
|
||||
/**
|
||||
@author ashley
|
||||
@author ashley
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package org.posterita.businesslogic;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -61,273 +59,275 @@ import org.posterita.core.businesslogic.ImportManager;
|
|||
|
||||
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 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
|
||||
{
|
||||
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);
|
||||
|
||||
MSetup setup = new MSetup(ctx, 0);
|
||||
|
||||
// Step 1
|
||||
boolean ok = setup.createClient(clientName, orgName, clientName + " Client User", clientName +" Org User");
|
||||
|
||||
if (ok)
|
||||
// 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, File file) throws OperationException {
|
||||
Properties ctx = Env.getCtx();
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
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());
|
||||
throw new OperationException("Could not create accounting for client");
|
||||
}
|
||||
else
|
||||
throw new OperationException("Could not create client");
|
||||
int clientId = setup.getAD_Client_ID();
|
||||
|
||||
MClient client = MClient.get(ctx, clientId);
|
||||
|
||||
return 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");
|
||||
}
|
||||
catch(IOException ex)
|
||||
{
|
||||
throw new OperationException("Could not find accounting file", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void updateAccountingProcessor(Properties ctx, int adClientId, String trxName) throws OperationException
|
||||
{
|
||||
String updStmt = "Update C_AcctProcessor set FrequencyType='M' where AD_Client_ID=" + adClientId;
|
||||
|
||||
int updates = DB.executeUpdate(updStmt, trxName);
|
||||
|
||||
if(updates == -1)
|
||||
throw new OperationException("Accounting Processor could not be updated");
|
||||
}
|
||||
|
||||
public static void createClientDependencies(Properties ctx, MClient client, MOrg org, String address, int countryId, String city, String postalAddress, String smtpHost, String trxName) throws OperationException
|
||||
{
|
||||
//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();
|
||||
|
||||
int clientId = setup.getAD_Client_ID();
|
||||
|
||||
MClient client = MClient.get(ctx, clientId);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
protected static void updateAccountingProcessor(Properties ctx,
|
||||
int adClientId, String trxName) throws OperationException {
|
||||
String updStmt = "Update C_AcctProcessor set FrequencyType='M' where AD_Client_ID="
|
||||
+ adClientId;
|
||||
|
||||
int updates = DB.executeUpdate(updStmt, trxName);
|
||||
|
||||
if (updates == -1)
|
||||
throw new OperationException(
|
||||
"Accounting Processor could not be updated");
|
||||
}
|
||||
|
||||
public static void createClientDependencies(Properties ctx, MClient client,
|
||||
MOrg org, String address, int countryId, String city,
|
||||
String postalAddress, String smtpHost, File file, String trxName)
|
||||
throws OperationException {
|
||||
// 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();
|
||||
orgInfo.set_TrxName(trxName);
|
||||
orgInfo.setC_Location_ID(location.getC_Location_ID());
|
||||
UDIMOrgInfo udiOrgInfo = new UDIMOrgInfo(orgInfo);
|
||||
udiOrgInfo.save();
|
||||
|
||||
openPeriods(ctx, trxName);
|
||||
|
||||
File impFile = new File(ACCOUNTING_FILE_PATH);
|
||||
ImportManager.importFile(ctx, impFile, ACCOUNTS_IMPORT_FORMAT, trxName);
|
||||
ImportManager.importAccounting(ctx, Env.getAD_Client_ID(ctx), getAccoutingElementId(ctx), false, true, true, 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
|
||||
{
|
||||
MClient client;
|
||||
Properties rctx = (Properties)ctx.clone();
|
||||
if(isClientPresent(clientName))
|
||||
{
|
||||
int clientId = getClientId(clientName);
|
||||
client = new MClient(ctx, clientId, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
client = createClient(rctx, clientName, orgName, currencyId, currencyName, countryId, city);
|
||||
Env.setContext(rctx, UdiConstants.CLIENT_ID_CTX_PARAM, client.get_ID());
|
||||
MOrg org = OrganisationManager.getOrgByName(rctx, orgName, null);
|
||||
createClientDependencies(rctx, client, org, address, countryId, city, postalAddress, smtpHost, null);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Properties getCtx(Properties ctx, String clientName, String orgName) throws OperationException
|
||||
{
|
||||
int clientId = ClientManager.getClientId(clientName);
|
||||
|
||||
|
||||
openPeriods(ctx, trxName);
|
||||
|
||||
ImportManager.importFile(ctx, file, ACCOUNTS_IMPORT_FORMAT, trxName);
|
||||
ImportManager.importAccounting(ctx, Env.getAD_Client_ID(ctx),
|
||||
getAccoutingElementId(ctx), false, true, true, 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, File file)
|
||||
throws OperationException {
|
||||
MClient client;
|
||||
Properties rctx = (Properties) ctx.clone();
|
||||
if (isClientPresent(clientName)) {
|
||||
int clientId = getClientId(clientName);
|
||||
client = new MClient(ctx, clientId, null);
|
||||
} else {
|
||||
client = createClient(rctx, clientName, orgName, currencyId,
|
||||
currencyName, countryId, city, file);
|
||||
Env.setContext(rctx, UdiConstants.CLIENT_ID_CTX_PARAM, client
|
||||
.get_ID());
|
||||
MOrg org = OrganisationManager.getOrgByName(rctx, orgName, null);
|
||||
createClientDependencies(rctx, client, org, address, countryId,
|
||||
city, postalAddress, smtpHost, file, null);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Properties getCtx(Properties ctx, String clientName,
|
||||
String orgName) throws OperationException {
|
||||
int clientId = ClientManager.getClientId(clientName);
|
||||
|
||||
// Set AD_Client_ID in the context
|
||||
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId);
|
||||
|
||||
|
||||
MOrg org = OrganisationManager.getOrgByName(ctx, orgName);
|
||||
int orgId = org.get_ID();
|
||||
Env.setContext(ctx, UdiConstants.ORG_ID_CTX_PARAM, orgId);
|
||||
Env.setContext(ctx, UdiConstants.USER_ORG_CTX_PARAM, orgId);
|
||||
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public static Properties getCtx(Properties ctx, int clientId, int orgId)
|
||||
{
|
||||
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId);
|
||||
Env.setContext(ctx, UdiConstants.ORG_ID_CTX_PARAM, orgId);
|
||||
Env.setContext(ctx, UdiConstants.USER_ID_CTX_PARAM, 100);
|
||||
|
||||
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);
|
||||
|
||||
for (int i = 0; i < idPCs.length; i++)
|
||||
{
|
||||
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);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public static int getAccoutingElementId(Properties ctx) throws OperationException
|
||||
{
|
||||
}
|
||||
|
||||
public static Properties getCtx(Properties ctx, int clientId, int orgId) {
|
||||
Env.setContext(ctx, UdiConstants.CLIENT_ID_CTX_PARAM, clientId);
|
||||
Env.setContext(ctx, UdiConstants.ORG_ID_CTX_PARAM, orgId);
|
||||
Env.setContext(ctx, UdiConstants.USER_ID_CTX_PARAM, 100);
|
||||
|
||||
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);
|
||||
|
||||
for (int i = 0; i < idPCs.length; i++) {
|
||||
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);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public static int getAccoutingElementId(Properties ctx)
|
||||
throws OperationException {
|
||||
int adClientId = Env.getAD_Client_ID(ctx);
|
||||
|
||||
|
||||
String whereClause = "AD_Client_ID=" + adClientId;
|
||||
|
||||
int elementIds[] = MElement.getAllIDs(MElement.Table_Name, whereClause, null);
|
||||
|
||||
if(elementIds.length == 0)
|
||||
throw new OperationException("No accounting element found for client with id: " + adClientId);
|
||||
else if(elementIds.length > 1)
|
||||
throw new OperationException(elementIds.length + " account elements found for client with id: " + adClientId);
|
||||
|
||||
int elementIds[] = MElement.getAllIDs(MElement.Table_Name, whereClause,
|
||||
null);
|
||||
|
||||
if (elementIds.length == 0)
|
||||
throw new OperationException(
|
||||
"No accounting element found for client with id: "
|
||||
+ adClientId);
|
||||
else if (elementIds.length > 1)
|
||||
throw new OperationException(elementIds.length
|
||||
+ " account elements found for client with id: "
|
||||
+ adClientId);
|
||||
else
|
||||
return elementIds[0];
|
||||
}
|
||||
|
||||
public static void changeClientName(Properties ctx, String clientName, String trxName) throws OperationException
|
||||
{
|
||||
if(clientName == null || clientName.trim().length() == 0)
|
||||
throw new OperationException("Client Name cannot be null");
|
||||
|
||||
int adClientId = Env.getAD_Client_ID(ctx);
|
||||
|
||||
MClient client = loadClient(ctx, adClientId, trxName);
|
||||
|
||||
if(!client.getName().equals(clientName))
|
||||
{
|
||||
client.setName(clientName);
|
||||
|
||||
UDIMClient udiClient = new UDIMClient(client);
|
||||
udiClient.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanData(Properties ctx, boolean deleteAll) throws OperationException
|
||||
{
|
||||
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;
|
||||
|
||||
int clientID = 0;
|
||||
try
|
||||
{
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
clientID = rs.getInt(1);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new OperationException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
pstmt.close();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{}
|
||||
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
if (clientID == 0)
|
||||
throw new NoClientFoundException("no client found for clientName " + clientName);
|
||||
|
||||
return clientID;
|
||||
}
|
||||
|
||||
public static boolean isClientPresent(String clientName) throws OperationException
|
||||
{
|
||||
try
|
||||
{
|
||||
getClientId(clientName);
|
||||
}
|
||||
catch(NoClientFoundException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
public static void changeClientName(Properties ctx, String clientName,
|
||||
String trxName) throws OperationException {
|
||||
if (clientName == null || clientName.trim().length() == 0)
|
||||
throw new OperationException("Client Name cannot be null");
|
||||
|
||||
int adClientId = Env.getAD_Client_ID(ctx);
|
||||
|
||||
MClient client = loadClient(ctx, adClientId, trxName);
|
||||
|
||||
if (!client.getName().equals(clientName)) {
|
||||
client.setName(clientName);
|
||||
|
||||
UDIMClient udiClient = new UDIMClient(client);
|
||||
udiClient.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanData(Properties ctx, boolean deleteAll)
|
||||
throws OperationException {
|
||||
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;
|
||||
|
||||
int clientID = 0;
|
||||
try {
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
clientID = rs.getInt(1);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
throw new OperationException(e);
|
||||
} finally {
|
||||
try {
|
||||
pstmt.close();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
if (clientID == 0)
|
||||
throw new NoClientFoundException("no client found for clientName "
|
||||
+ clientName);
|
||||
|
||||
return clientID;
|
||||
}
|
||||
|
||||
public static boolean isClientPresent(String clientName)
|
||||
throws OperationException {
|
||||
try {
|
||||
getClientId(clientName);
|
||||
} catch (NoClientFoundException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.compiere.model.MOrg;
|
||||
import org.compiere.model.X_U_Menu;
|
||||
import org.compiere.model.X_U_WebMenu;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.posterita.beans.MenuItemBean;
|
||||
|
@ -41,7 +40,7 @@ import org.posterita.factory.AbstractFactory;
|
|||
import org.posterita.factory.POSMenuFactory;
|
||||
import org.posterita.keyname.MenuKeyNamePair;
|
||||
import org.posterita.model.MMenu;
|
||||
import org.posterita.model.UDIU_Menu;
|
||||
import org.posterita.model.U_WebMenu;
|
||||
|
||||
|
||||
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);
|
||||
ArrayList<UDIU_Menu> menuList = new ArrayList<UDIU_Menu>();
|
||||
ArrayList<U_WebMenu> menuList = new ArrayList<U_WebMenu>();
|
||||
int adRoleId = roleId;
|
||||
|
||||
String appName = ApplicationManager.getApplicationType(ctx).toUpperCase();
|
||||
|
||||
String sqlStatement = "";
|
||||
|
||||
sqlStatement = " select m.U_Menu_ID, " +
|
||||
sqlStatement = " select m.U_WebMenu_ID, " +
|
||||
" m.Name, m.MenuLink, " +
|
||||
" m.Module, m.ParentMenu_ID, " +
|
||||
" m.isActive, " +
|
||||
" m.ImageLink, m.Position, m.description " +
|
||||
" from U_MENU m, U_RoleMenu rm " +
|
||||
" where m.U_Menu_ID = rm.U_Menu_ID "+
|
||||
" from U_WebMENU m, U_RoleMenu rm " +
|
||||
" where m.U_WebMenu_ID = rm.U_WebMenu_ID "+
|
||||
" and M.isActive='Y'"+
|
||||
" and rm.AD_Role_ID = " + adRoleId +
|
||||
// " and m.AD_Client_ID = " + adClientId + // Menu not dependent on client
|
||||
" and m.module = '" + appName + "' " +
|
||||
" order by m.Sequence, m.U_Menu_ID";
|
||||
" order by m.Sequence, m.U_WebMenu_ID";
|
||||
|
||||
System.out.println("Query for menu manager :" + sqlStatement);
|
||||
|
||||
|
@ -129,7 +125,7 @@ public class MenuManager
|
|||
menu.setPosition(position);
|
||||
menu.setDescription(description);
|
||||
|
||||
UDIU_Menu udiMenu = new UDIU_Menu(menu);
|
||||
U_WebMenu udiMenu = new U_WebMenu(menu);
|
||||
|
||||
menuList.add(udiMenu);
|
||||
}
|
||||
|
@ -167,13 +163,13 @@ public class MenuManager
|
|||
|
||||
Iterator menuIter = menuList.iterator();
|
||||
Iterator subIterator;
|
||||
UDIU_Menu mMenu;
|
||||
UDIU_Menu sMenu;
|
||||
U_WebMenu mMenu;
|
||||
U_WebMenu sMenu;
|
||||
|
||||
|
||||
while(menuIter.hasNext())
|
||||
{
|
||||
mMenu = (UDIU_Menu)menuIter.next();
|
||||
mMenu = (U_WebMenu)menuIter.next();
|
||||
|
||||
if(mMenu.getParentMenuId() == 0) // Parent Menu
|
||||
{
|
||||
|
@ -183,7 +179,7 @@ public class MenuManager
|
|||
|
||||
while(subIterator.hasNext())
|
||||
{
|
||||
sMenu = (UDIU_Menu)subIterator.next();
|
||||
sMenu = (U_WebMenu)subIterator.next();
|
||||
if(sMenu.getParentMenuId() == mMenu.getMenuId())
|
||||
{
|
||||
MenuItem sItem = new MenuItem(sMenu);
|
||||
|
@ -209,27 +205,27 @@ public class MenuManager
|
|||
public static void saveMenu(Properties ctx, MenuItemBean bean) throws OperationException
|
||||
{
|
||||
//when creating a new menu
|
||||
X_U_Menu menu;
|
||||
UDIU_Menu selectmenu;
|
||||
X_U_WebMenu menu;
|
||||
U_WebMenu selectmenu;
|
||||
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
|
||||
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.setDescription(bean.getDescription());
|
||||
selectmenu = new UDIU_Menu(menu);
|
||||
selectmenu = new U_WebMenu(menu);
|
||||
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.setModule(moduleName);
|
||||
|
@ -237,34 +233,34 @@ public class MenuManager
|
|||
menu.setSequence(new BigDecimal(sequence));
|
||||
menu.setName(menuName);
|
||||
|
||||
UDIU_Menu udiMenu = new UDIU_Menu(menu);
|
||||
U_WebMenu udiMenu = new U_WebMenu(menu);
|
||||
|
||||
return udiMenu;
|
||||
}
|
||||
|
||||
@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.setMenuLink("GetMenuItemsAction.do?action=getMenuItems&menuId=");
|
||||
|
||||
menu.setModule(moduleName);
|
||||
menu.setPosition(AbstractFactory.MENU_POSITION_LEFT);
|
||||
|
||||
UDIU_Menu udiMenu = new UDIU_Menu(menu);
|
||||
U_WebMenu udiMenu = new U_WebMenu(menu);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(!menuLink.contains("javascript"))
|
||||
|
@ -283,14 +279,14 @@ public class MenuManager
|
|||
menu.setName(menuName);
|
||||
menu.setCategory(category);
|
||||
|
||||
UDIU_Menu udiMenu = new UDIU_Menu(menu);
|
||||
U_WebMenu udiMenu = new U_WebMenu(menu);
|
||||
return udiMenu;
|
||||
}
|
||||
|
||||
@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.setParentMenu_ID(parentId);
|
||||
|
||||
|
@ -304,11 +300,11 @@ public class MenuManager
|
|||
|
||||
menu.setPosition(AbstractFactory.MENU_POSITION_LEFT);
|
||||
|
||||
UDIU_Menu udiMenu = new UDIU_Menu(menu);
|
||||
U_WebMenu udiMenu = new U_WebMenu(menu);
|
||||
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.
|
||||
|
@ -316,10 +312,8 @@ 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 = "";
|
||||
|
||||
|
@ -329,8 +323,7 @@ public class MenuManager
|
|||
"m.isActive, " +
|
||||
"m.ImageLink, m.Position " +
|
||||
"from U_MENU m where " + //m.AD_Client_ID = " + adClientId +
|
||||
" m.module = '" + appName + "' "+
|
||||
" and m.AD_CLIENT_ID=0"+
|
||||
" m.AD_CLIENT_ID=0"+
|
||||
" and m.AD_ORG_ID=0" +
|
||||
" and m.isactive = 'Y'";
|
||||
|
||||
|
@ -373,7 +366,7 @@ public class MenuManager
|
|||
// setting the link name to be either car / bike
|
||||
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.setMenuLink(menuLink);
|
||||
menu.setModule(module);
|
||||
|
@ -382,7 +375,7 @@ public class MenuManager
|
|||
menu.setImageLink(imageLink);
|
||||
menu.setPosition(position);
|
||||
|
||||
UDIU_Menu udiMenu = new UDIU_Menu(menu);
|
||||
U_WebMenu udiMenu = new U_WebMenu(menu);
|
||||
|
||||
menuList.add(udiMenu);
|
||||
}
|
||||
|
@ -410,9 +403,7 @@ public class MenuManager
|
|||
|
||||
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 and Module='" + appName + "' ";
|
||||
String whereClause = "AD_Client_ID=0 and AD_Org_ID=0 ";
|
||||
whereClause += " and Position='TOP' and ParentMenu_ID is null";
|
||||
|
||||
int menuIds[] = MMenu.getAllIDs(MMenu.Table_Name, whereClause, null);
|
||||
|
@ -429,7 +420,7 @@ public class MenuManager
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -441,7 +432,7 @@ public class MenuManager
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -484,7 +475,7 @@ public class MenuManager
|
|||
|
||||
try
|
||||
{
|
||||
menuKeyNamePairs = MenuKeyNamePair.getData(ctx, X_U_Menu.Table_Name, sql);
|
||||
menuKeyNamePairs = MenuKeyNamePair.getData(ctx, X_U_WebMenu.Table_Name, sql);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
|
@ -496,7 +487,7 @@ public class MenuManager
|
|||
|
||||
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();
|
||||
bean.setDescription(menu.getDescription());
|
||||
|
@ -509,7 +500,7 @@ public class MenuManager
|
|||
|
||||
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.setIsActive(bean.getIsActive().booleanValue());
|
||||
menu.save();
|
||||
|
@ -524,10 +515,10 @@ public class MenuManager
|
|||
int ad_client_id = Env.getAD_Client_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'";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
|
||||
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.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
@ -43,12 +47,14 @@ import org.compiere.model.MPOS;
|
|||
import org.compiere.model.MPriceList;
|
||||
import org.compiere.model.MPriceListVersion;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.model.MRoleMenu;
|
||||
import org.compiere.model.MStore;
|
||||
import org.compiere.model.MTaxCategory;
|
||||
import org.compiere.model.MUser;
|
||||
import org.compiere.model.MWarehouse;
|
||||
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.OperationException;
|
||||
import org.posterita.factory.GenericProductAttributeFactory;
|
||||
|
@ -58,7 +64,6 @@ import org.posterita.factory.POSMenuFactory;
|
|||
import org.posterita.factory.SystemObjectsFactory;
|
||||
import org.posterita.lib.UdiConstants;
|
||||
import org.posterita.model.MBank;
|
||||
import org.posterita.model.MRoleMenu;
|
||||
import org.posterita.model.UDIMBank;
|
||||
import org.posterita.model.UDIMBankAccount;
|
||||
import org.posterita.model.UDIMLocator;
|
||||
|
@ -67,9 +72,8 @@ import org.posterita.model.UDIMPriceListVersion;
|
|||
import org.posterita.model.UDIMStore;
|
||||
import org.posterita.model.UDIMUser;
|
||||
import org.posterita.model.UDIMWarehouse;
|
||||
import org.posterita.model.UDIU_Menu;
|
||||
import org.posterita.model.UDIU_RoleMenu;
|
||||
import org.posterita.core.bean.ClientBean;
|
||||
import org.posterita.model.U_RoleMenu;
|
||||
import org.posterita.model.U_WebMenu;
|
||||
|
||||
public class POSClientManager extends ClientManager
|
||||
{
|
||||
|
@ -257,11 +261,11 @@ public class POSClientManager extends ClientManager
|
|||
while(keyIter.hasNext())
|
||||
{
|
||||
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);
|
||||
roleMenu.setAD_Role_ID(role.get_ID());
|
||||
roleMenu.setU_WebMenu_ID(udiMenu.getID());
|
||||
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu);
|
||||
U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
|
||||
udiRoleMenu.save();
|
||||
}
|
||||
|
||||
|
@ -283,15 +287,13 @@ public class POSClientManager extends ClientManager
|
|||
int storeId = StoreManager.getStoreIdByName(ctx, storeName, null);
|
||||
|
||||
MStore store = new MStore(ctx, storeId, null);
|
||||
String storeContext = store.getWebContext();
|
||||
storeContext = storeContext.replace("/", "");
|
||||
int pricelistId = store.getM_PriceList_ID();
|
||||
|
||||
Env.setContext(ctx, UdiConstants.PRICELIST_CTX_PARAM, String.valueOf(pricelistId));
|
||||
|
||||
Env.setContext(ctx, UdiConstants.POS_PURCHASE_PL_VERSION, PriceListManager.getPriceListVersionID(ctx, pricelistId, null));
|
||||
|
||||
ApplicationManager.setApplicationParametersInContext(ctx, storeContext);
|
||||
ApplicationManager.setApplicationParametersInContext(ctx, storeId);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
@ -311,8 +313,38 @@ public class POSClientManager extends ClientManager
|
|||
throw new OperationException("Could not load currency with id: " + clientBean.getCurrencyId());
|
||||
|
||||
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());
|
||||
POSClientManager.createPOSDetails(ctx, clientBean.getCurrencyId(), currency.getDescription(), hostUrl, null);
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import java.util.ArrayList;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.model.MRoleMenu;
|
||||
import org.compiere.model.MRoleOrgAccess;
|
||||
import org.compiere.model.MUser;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.KeyNamePair;
|
||||
|
@ -41,10 +41,9 @@ import org.posterita.exceptions.OperationException;
|
|||
import org.posterita.exceptions.RoleAlreadyExistsException;
|
||||
import org.posterita.exceptions.SystemException;
|
||||
import org.posterita.lib.UdiConstants;
|
||||
import org.posterita.model.MRoleMenu;
|
||||
import org.posterita.model.UDIMRole;
|
||||
import org.posterita.model.UDIU_Menu;
|
||||
import org.posterita.model.UDIU_RoleMenu;
|
||||
import org.posterita.model.U_RoleMenu;
|
||||
import org.posterita.model.U_WebMenu;
|
||||
|
||||
|
||||
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;
|
||||
for(UDIU_Menu udiMenu : menus)
|
||||
for(U_WebMenu udiMenu : menus)
|
||||
{
|
||||
if(udiMenu.getMenuId() == menuId)
|
||||
{
|
||||
|
@ -345,7 +344,7 @@ public class RoleManager
|
|||
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();
|
||||
for(MenuItem mItem : children)
|
||||
|
@ -362,9 +361,9 @@ public class RoleManager
|
|||
|
||||
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);
|
||||
|
||||
setRoleMenus(rootItem, roleMenus);
|
||||
|
@ -407,7 +406,7 @@ public class RoleManager
|
|||
MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName);
|
||||
roleMenu.setAD_Role_ID(role.get_ID());
|
||||
roleMenu.setU_WebMenu_ID(menuId[i]);
|
||||
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu);
|
||||
U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
|
||||
udiRoleMenu.save();
|
||||
}
|
||||
|
||||
|
@ -418,7 +417,7 @@ public class RoleManager
|
|||
MRoleMenu roleMenu = new MRoleMenu(ctx, 0, trxName);
|
||||
roleMenu.setAD_Role_ID(role.get_ID());
|
||||
roleMenu.setU_WebMenu_ID(defMenuIds[i]);
|
||||
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu);
|
||||
U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
|
||||
udiRoleMenu.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,10 @@ package org.posterita.businesslogic;
|
|||
|
||||
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.model.MRoleMenu;
|
||||
import org.posterita.model.UDIU_RoleMenu;
|
||||
import org.posterita.model.U_RoleMenu;
|
||||
|
||||
|
||||
public class RoleMenuManager
|
||||
|
@ -37,7 +36,7 @@ public class RoleMenuManager
|
|||
{
|
||||
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();
|
||||
|
||||
|
@ -53,7 +52,7 @@ public class RoleMenuManager
|
|||
roleMenu.setAD_Role_ID(roleId);
|
||||
roleMenu.setU_WebMenu_ID(menuId);
|
||||
|
||||
UDIU_RoleMenu udiRoleMenu = new UDIU_RoleMenu(roleMenu);
|
||||
U_RoleMenu udiRoleMenu = new U_RoleMenu(roleMenu);
|
||||
udiRoleMenu.save();
|
||||
|
||||
return roleMenu;
|
||||
|
|
Loading…
Reference in New Issue