List configs = getAdminConfig(companyId, type);
AdminConfig config = null;
ShoppingConfig shoppingConfig = null;
if (configs.size() == 0) {
String configId = Long.toString(CounterManagerUtil.increment(
AdminConfig.class.getName()));
Company company = CompanyManagerUtil.getCompany(companyId);
shoppingConfig = new ShoppingConfig(
company.getEmailAddress(), ShoppingConfig.CC_TYPES,
ShoppingConfig.DEFAULT_CURRENCY_ID,
GetterUtil.get(
company.getState(), ShoppingConfig.DEFAULT_TAX_STATE),
ShoppingConfig.DEFAULT_TAX_RATE,
ShoppingConfig.DEFAULT_SHIPPING_FORMULA,
ShoppingConfig.DEFAULT_SHIPPING,
ShoppingConfig.DEFAULT_ALTERNATIVE_SHIPPING,
ShoppingConfig.DEFAULT_MIN_ORDER,
ShoppingConfig.DEFAULT_SHOW_SPECIAL_ITEMS,
_getShoppingConfigOrderEmail(),
_getShoppingConfigShippingEmail());
config = AdminConfigUtil.create(configId);
config.setCompanyId(companyId);
config.setType(type);
config.setName(name);
config.setConfigObj(shoppingConfig);
AdminConfigUtil.update(config);
configs.add(config);
}
else {
config = (AdminConfig)configs.iterator().next();
shoppingConfig = (ShoppingConfig)config.getConfigObj();
}
// Make sure new fields are not null
if (shoppingConfig.getCcTypes() == null) {
shoppingConfig.setCcTypes(new String[0]);
config.setConfigObj(shoppingConfig);
AdminConfigUtil.update(config);
}
if (shoppingConfig.getOrderEmail() == null) {
shoppingConfig.setOrderEmail(_getShoppingConfigOrderEmail());
config.setConfigObj(shoppingConfig);
AdminConfigUtil.update(config);
}
if (shoppingConfig.getShippingEmail() == null) {
shoppingConfig.setShippingEmail(_getShoppingConfigShippingEmail());
config.setConfigObj(shoppingConfig);
AdminConfigUtil.update(config);
}