Commit c615bc62 authored by Gabriel Monnerat's avatar Gabriel Monnerat

[ERP5 Configurator] Rename _build to _checkConsistency to follow Constraint API

The logic of all Configuration Items was not changed, but now the
changes are applied only if fixit is True and the constraints are
filtered by constraint type equal configuration.

Cosmetic: Trailing whitespaces were removed in the same commit
parent 91ef6772
......@@ -56,17 +56,22 @@ class AccountConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore
, PropertySheet.Account )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
account_module = self.getPortalObject().account_module
account = None
account_id = getattr(self, 'account_id', None)
error_list = []
error_list_append = lambda msg: error_list.append(
self._createConstraintMessage(msg))
extra_kw = {}
if account_id:
extra_kw['id'] = account_id
account = getattr(account_module, account_id, None)
if account is None:
error_list_append("Account %s should be created" % self.getTitle())
if fixit:
account = account_module.newContent(
portal_type='Account',
title=self.getTitle(),
......@@ -77,6 +82,8 @@ class AccountConfiguratorItem(ConfiguratorItemMixin, XMLObject):
description=self.getDescription(),
**extra_kw)
else:
error_list_append("Account %s should be updated" % account.getRelativeUrl())
if fixit:
# Update existing account
if (self.getAccountType() != account.getAccountType()) and \
(self.getFinancialSection() != account.getFinancialSection()):
......@@ -90,8 +97,12 @@ class AccountConfiguratorItem(ConfiguratorItemMixin, XMLObject):
account.setGapList(gap_list)
account.setCreditAccount(self.isCreditAccount())
if account and fixit:
if self.portal_workflow.isTransitionPossible(account, 'validate'):
account.validate(comment=translateString("Validated by Configurator"))
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(account, business_configuration)
return error_list
......@@ -55,11 +55,13 @@ class AccountingPeriodConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore
, PropertySheet.Task )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal = self.getPortalObject()
business_configuration = self.getBusinessConfigurationValue()
organisation_id = business_configuration.\
getGlobalConfigurationAttr('organisation_id')
organisation = portal.organisation_module._getOb(organisation_id)
if fixit:
period = organisation.newContent(
portal_type='Accounting Period',
start_date=self.getStartDate(),
......@@ -72,3 +74,4 @@ class AccountingPeriodConfiguratorItem(ConfiguratorItemMixin, XMLObject):
# no need to 'install' in the business template, because it's contain as
# subobject of an organisation we already added.
return ['Accounting Period %s should be created' % self.getTitle()]
......@@ -58,8 +58,9 @@ class AlarmConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.Periodicity
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal_alarms = self.getPortalObject().portal_alarms
error_list = []
property_dict = {
"active_sense_method_id" : self.getActiveSenseMethodId(),
"periodicity_hour_list" : self.getPeriodicityHourList(),
......@@ -72,14 +73,22 @@ class AlarmConfiguratorItem(ConfiguratorItemMixin, XMLObject):
"periodicity_week_list": self.getPeriodicityWeekList(),
}
alarm = getattr(portal_alarms, self.getId(), None)
alarm_id = self.getId()
alarm = getattr(portal_alarms, alarm_id, None)
if alarm is None:
alarm = portal_alarms.newContent(id=self.getId(),
error_list.append(self._createConstraintMessage(
"Alarm %s should be created" % alarm_id))
if fixit:
alarm = portal_alarms.newContent(id=alarm_id,
title=self.getTitle())
alarm.edit(**property_dict)
# Always enabled
alarm.setEnabled(True)
if alarm and fixit:
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(alarm, business_configuration)
return error_list
......@@ -346,13 +346,14 @@ class BusinessConfiguration(Item):
configuration_item_list = configuration_save.contentValues()
configuration_item_list.sort(lambda x, y: cmp(x.getIntId(), y.getIntId()))
for configurator_item in configuration_item_list:
configurator_item.activate(**kw).build(self.getRelativeUrl())
configurator_item.activate(**kw).fixConsistency(
filter={"constraint_type":"configuration"})
kw["after_tag"] = kw["tag"]
kw["tag"] = "configurator_item_%s_%s" % (configurator_item.getId(),
configurator_item.getUid())
kw["tag"] = "final_configuration_step_%s" % self.getId()
kw["after_method_id"] = ["build", 'immediateReindexObject', \
kw["after_method_id"] = ["fixConsistency", 'immediateReindexObject', \
"recursiveImmediateReindexObject"]
self.activate(**kw).ERP5Site_afterConfigurationSetup()
......
......@@ -58,13 +58,15 @@ class BusinessProcessConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.Reference
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
error_list = ["Business Process %s should be created" % self.getReference(),]
if fixit:
portal = self.getPortalObject()
business_process = portal.business_process_module.newContent(
portal_type="Business Process",
reference=self.getReference(),
title=self.getTitle())
business_configuration = self.getBusinessConfigurationValue()
business_configuration.setGlobalConfigurationAttr(\
business_process_id=business_process.getId())
......@@ -110,6 +112,8 @@ class BusinessProcessConfiguratorItem(ConfiguratorItemMixin, XMLObject):
business_process.validate(comment=translateString('Validated by configurator'))
self.install(business_process, business_configuration)
return error_list
def _getBusinessProcessDict(self):
""" Read the spreadsheet and return the configuration for
Trade Model Paths and Business Links.
......
......@@ -55,15 +55,21 @@ class CatalogKeywordKeyConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
error_list = []
portal = self.getPortalObject()
catalog = portal.portal_catalog.getSQLCatalog()
key_list = list(catalog.getProperty('sql_catalog_keyword_search_keys', ()))
for k in self.key_list:
if k not in key_list:
error_list.append(self._createConstraintMessage(
"%s should be in sql_catalog_keyword_search_keys" % k))
key_list.append(k)
key_list = tuple(key_list)
if fixit:
catalog._setPropValue('sql_catalog_keyword_search_keys', key_list)
business_configuration = self.getBusinessConfigurationValue()
bt = business_configuration.getSpecialiseValue()
bt.edit(template_catalog_keyword_key_list=key_list)
return error_list
......@@ -64,20 +64,26 @@ class CategoriesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.ConfiguratorItem
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal = self.getPortalObject()
ctool = portal.portal_categories
self._readSpreadSheet()
cache = self._category_cache
object_id_list = ctool.objectIds()
error_list = []
for bc_id, category_list in cache.items():
if bc_id in ctool.objectIds():
if bc_id in object_id_list:
bc = ctool._getOb(bc_id)
else:
# TODO: test bc creation
# the bc should be added as base category in bt5 ?
error_list.append(self._createConstraintMessage(
"Base Category %s should be created" % bc_id))
if fixit:
bc = ctool.newContent(id=bc_id)
if fixit:
for category_info in category_list:
path = bc
for cat in category_info['path'].split("/")[1:]:
......@@ -94,7 +100,13 @@ class CategoriesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObject):
path.edit(**edit_dict)
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(path, business_configuration)
else:
error_list.extend(["%s should be created" % category['path'] \
for category in category_list])
return error_list
def _readSpreadSheet(self):
"""Read the spreadsheet and prepare internal category cache.
......
......@@ -54,7 +54,8 @@ class CategoryConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
if fixit:
portal = self.getPortalObject()
category_root = portal.portal_categories[self.category_root]
object_id = self.object_id
......@@ -64,4 +65,6 @@ class CategoryConfiguratorItem(ConfiguratorItemMixin, XMLObject):
id = object_id,
title = self.getTitle())
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(category, business_configuration)
return ['Category %s should be created' % self.getTitle(),]
......@@ -58,22 +58,29 @@ class CurrencyConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.Resource
, PropertySheet.Reference )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
currency_module = self.getPortalObject().currency_module
error_list = []
title = self.getTitle()
reference = self.getReference()
base_unit_quantity = self.getBaseUnitQuantity()
# XXX FIXME This is not exactly desired behaviour
currency = self.portal_catalog.getResultValue(id=reference,
portal_type="Currency")
if currency is None:
error_list.append(self._createConstraintMessage(
"Currency %s should be created" % reference))
if fixit:
currency = currency_module.newContent(portal_type = "Currency",
id = reference,
title = title,
reference = reference,
base_unit_quantity = base_unit_quantity)
base_unit_quantity=self.getBaseUnitQuantity())
currency.validate(comment=translateString("Validated by Configurator"))
if currency:
business_configuration = self.getBusinessConfigurationValue()
business_configuration.setGlobalConfigurationAttr(currency_id=currency.getId())
## add to customer template
self.install(currency, business_configuration)
return error_list
......@@ -57,9 +57,17 @@ class CustomerBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
bt5 = self.getPortalObject().portal_templates.newContent(
portal_type="Business Template", title=self.bt5_title)
def _checkConsistency(self, fixit=False, filter=None, **kw):
template_tool = self.getPortalObject().portal_templates
error_list = []
if self.bt5_title not in template_tool.getBuiltBusinessTemplateList():
error_list.append(self._createConstraintMessage(
'%s should be created' % self.bt5_title))
## ..and set it as current
if fixit:
bt5 = template_tool.newContent(portal_type="Business Template",
title=self.bt5_title)
business_configuration = self.getBusinessConfigurationValue()
business_configuration.setSpecialise(bt5.getRelativeUrl())
return error_list
......@@ -56,8 +56,9 @@ class OrganisationConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore
, PropertySheet.Organisation )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
""" Setup organisation. """
if fixit:
portal = self.getPortalObject()
organisation = portal.organisation_module.newContent(portal_type="Organisation")
......@@ -75,6 +76,7 @@ class OrganisationConfiguratorItem(ConfiguratorItemMixin, XMLObject):
}
organisation.edit(**org_dict)
business_configuration = self.getBusinessConfigurationValue()
# store globally organization_id
business_configuration.setGlobalConfigurationAttr(organisation_id=organisation.getId())
......@@ -83,3 +85,4 @@ class OrganisationConfiguratorItem(ConfiguratorItemMixin, XMLObject):
## add to customer template
self.install(organisation, business_configuration)
return ['Organisation should be created',]
......@@ -54,9 +54,11 @@ class PermissionConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
template_module_id_list = []
error_list = []
module_permissions_map = {}
business_configuration = self.getBusinessConfigurationValue()
sheets_dict = business_configuration.ConfigurationTemplate_readOOCalcFile(\
self.filename)
for module_id, permissions in sheets_dict.items():
......@@ -79,9 +81,14 @@ class PermissionConfiguratorItem(ConfiguratorItemMixin, XMLObject):
for permission_name, roles in permissions_map.items():
# we must alway include additionally 'Manager' and 'Owner'
roles.extend(['Manager', 'Owner'])
if fixit:
module.manage_permission(permission_name, tuple(roles), 0)
error_list.append(self._createConstraintMessage(
'%s should be set to %s' % (','.join(roles), module.getId())))
# add customized module to customer's bt5
if len(template_module_id_list):
if len(template_module_id_list) and fixit:
bt5_obj = business_configuration.getSpecialiseValue()
bt5_obj.setTemplateModuleIdList(template_module_id_list)
return error_list
......@@ -60,9 +60,11 @@ class PersonConfiguratorItem(XMLObject, ConfiguratorItemMixin):
, PropertySheet.Person
, PropertySheet.Login)
def _build(self, business_configuration):
portal = self.getPortalObject()
person = portal.person_module.newContent(portal_type="Person")
def _checkConsistency(self, fixit=False, filter=None, **kw):
error_list = ["Person %s should be created" % self.getReference(),]
if fixit:
person_module = self.getPortalObject().person_module
person = person_module.newContent(portal_type="Person")
group_id = getattr(aq_base(self), 'group_id', None)
site_id = getattr(aq_base(self), 'site_id', None)
......@@ -97,4 +99,7 @@ class PersonConfiguratorItem(XMLObject, ConfiguratorItemMixin):
assignment.open(comment=translateString("Open by Configuration"))
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(person, business_configuration)
return error_list
......@@ -54,7 +54,7 @@ class PortalTypeConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal = self.getPortalObject()
# Support adding new property sheet to portal type information.
......@@ -67,6 +67,8 @@ class PortalTypeConfiguratorItem(ConfiguratorItemMixin, XMLObject):
new_property_sheet_list = list(type_information.property_sheet_list)
new_property_sheet_list.append(name)
type_information.property_sheet_list = tuple(new_property_sheet_list)
business_configuration = self.getBusinessConfigurationValue()
bt5_obj = business_configuration.getSpecialiseValue()
old_property_sheet_list = bt5_obj.getTemplatePortalTypePropertySheetList()
......@@ -74,10 +76,12 @@ class PortalTypeConfiguratorItem(ConfiguratorItemMixin, XMLObject):
['%s | %s' % (self.target_portal_type, name)
for name in self.add_propertysheet_list]
)
if fixit:
bt5_obj.edit(
template_portal_type_property_sheet_list=new_property_sheet_list)
#
# TODO:This class must support many other features we can use in ZMI.
#
return ['Property Sheets configuration should be added in %s' % \
bt5_obj.getTitle(),]
......@@ -59,10 +59,10 @@ class PortalTypeRolesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObjec
, PropertySheet.DublinCore
, PropertySheet.ConfiguratorItem
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal = self.getPortalObject()
portal_type_role_dict = self._getPortalTypeRoleDict()
error_list = []
for type_name, role_list in portal_type_role_dict.items():
portal_type = portal.portal_types.getTypeInfo(type_name)
if portal_type is None:
......@@ -76,10 +76,14 @@ class PortalTypeRolesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObjec
if role.get(bc):
category_list.append(role[bc])
#category = '\n'.join(category_list)
role_name_list = [x.strip() for x in role.get('Role', '').split(';')]
error_list.append(self._createConstraintMessage(
"Add roles(%s) to %s are required" % (role_name_list, portal_type)))
if fixit:
role_dict = {
'title': role.get('Name', 'Default'),
'description': role.get('Description', 'Configured by ERP5 Configurator'),
'role_name_list': [x.strip() for x in role.get('Role', '').split(';')],
'role_name_list': role_name_list,
'role_category_list': category_list,
'role_base_category_list': role.get('Base_Category', ''),
'role_base_category_script_id': role.get('Base_Category_Script',
......@@ -87,11 +91,15 @@ class PortalTypeRolesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObjec
portal_type.newContent(portal_type='Role Information', \
**role_dict)
if fixit:
## Update BT5
business_configuration = self.getBusinessConfigurationValue()
bt5_obj = business_configuration.getSpecialiseValue()
if bt5_obj is not None:
bt5_obj.edit(template_portal_type_role_list=portal_type_role_dict.keys())
return error_list
def checkSpreadSheetConsistency(self):
"""Check that the spread sheet is consistent with categories spreadsheet.
......
......@@ -71,16 +71,22 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
property_id_list.append('%s%s' % (prop.getReference(), list_prefix))
return property_id_list
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
error_list = []
portal = self.getPortalObject()
preference = portal.portal_preferences._getOb(self.object_id, None)
if preference is None:
error_list.append(self._createConstraintMessage(
"Preference %s should be created" % self.object_id))
if fixit:
preference = portal.portal_preferences.newContent(
portal_type = 'Preference',
id = self.object_id,
title = self.title,
description = self.description,
priority = 1)
else:
return error_list
preference_dict = {}
......@@ -94,6 +100,7 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
if self.portal_workflow.isTransitionPossible(preference, 'enable'):
preference.enable()
business_configuration = self.getBusinessConfigurationValue()
organisation_id = business_configuration.\
getGlobalConfigurationAttr('organisation_id')
organisation_path = 'organisation_module/%s' % organisation_id
......@@ -107,3 +114,4 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
current_template_preference_list.append(preference.getId())
bt5_obj.edit(template_preference_list=current_template_preference_list,)
return error_list
......@@ -58,8 +58,10 @@ class PurchaseTradeConditionConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.Reference
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
if fixit:
portal = self.getPortalObject()
business_configuration = self.getBusinessConfigurationValue()
business_process_id = \
business_configuration.getGlobalConfigurationAttr('business_process_id')
......@@ -84,3 +86,6 @@ class PurchaseTradeConditionConfiguratorItem(ConfiguratorItemMixin, XMLObject):
trade_condition.validate(comment=translateString("Validated by Configurator"))
self.install(trade_condition, business_configuration)
return ['Purchase Trade Condition with reference %s should be created' % \
self.getReference(),]
......@@ -56,7 +56,10 @@ class RoleConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
error_list = ['Roles should imported and created',]
if fixit:
business_configuration = self.getBusinessConfigurationValue()
object_list = business_configuration.ConfigurationTemplate_readOOCalcFile(self.filename)
portal = self.getPortalObject()
......@@ -97,8 +100,11 @@ class RoleConfiguratorItem(ConfiguratorItemMixin, XMLObject):
LOG("CONFIGURATOR", INFO, "Fail to define Roles for %s" % portal_type)
## Update BT5
bt5_obj = business_configuration.getSpecialiseValue()
# keep existing roles definition (from previous configuration saves)
for existing_type in bt5_obj.getTemplatePortalTypeRoleList():
portal_type_dict[existing_type] = 1
bt5_obj.edit(template_portal_type_role_list=[i for i in portal_type_dict.keys() if i not in ignore_list])
return error_list
......@@ -56,7 +56,8 @@ class RuleConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore
, PropertySheet.Reference )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
if fixit:
portal = self.getPortalObject()
template_id = self.getId()
......@@ -73,4 +74,6 @@ class RuleConfiguratorItem(ConfiguratorItemMixin, XMLObject):
else:
raise ValueError("Unable to find rule template with id %s" % template_id)
business_configuration = self.getBusinessConfigurationValue()
self.install(rule, business_configuration)
return ['Rule should be defined',]
......@@ -58,8 +58,11 @@ class SaleTradeConditionConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.Reference
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
if fixit:
portal = self.getPortalObject()
business_configuration = self.getBusinessConfigurationValue()
business_process_id = \
business_configuration.getGlobalConfigurationAttr('business_process_id')
......@@ -84,3 +87,6 @@ class SaleTradeConditionConfiguratorItem(ConfiguratorItemMixin, XMLObject):
trade_condition.validate(comment=translateString("Validated by Configurator"))
self.install(trade_condition, business_configuration)
return ['Sale Trade Condition with reference %s should be created' % \
self.getReference(),]
......@@ -57,21 +57,26 @@ class SecurityCategoryMappingConfiguratorItem(SkinConfiguratorItemMixin,
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
script_id = 'ERP5Type_getSecurityCategoryMapping'
error_list = ['%s should be created' % script_id,]
if fixit:
portal_alarms = self.getPortalObject().portal_alarms
script_content = """return (
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['function']),
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['follow_up']),
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['function', 'follow_up']),
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['group']),
('ERP5Type_getSecurityCategoryRoot', ['group']),
)"""
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['function']),
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['follow_up']),
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['function', 'follow_up']),
('ERP5Type_getSecurityCategoryFromAssignmentStrict', ['group']),
('ERP5Type_getSecurityCategoryRoot', ['group']),
)"""
folder = self._createSkinFolder()
self._createZODBPythonScript(folder,
'ERP5Type_getSecurityCategoryMapping',
script_id,
'', script_content)
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(folder, business_configuration)
return error_list
......@@ -57,8 +57,9 @@ class ServiceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore
, PropertySheet.ConfiguratorItem )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal = self.getPortalObject()
error_list = []
for service_id, service_dict in iter(self.getConfigurationListList()):
if isinstance(service_dict, basestring):
warn(DeprecationWarning,
......@@ -67,9 +68,16 @@ class ServiceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
document = getattr(portal.service_module, service_id, None)
if document is None:
error_list.append(self._createConstraintMessage(
"Service %s should be created"))
if fixit:
document = portal.service_module.newContent(portal_type='Service',
id=service_id, **service_dict)
document.validate(comment=translateString("Validated by Configurator"))
if document:
## add to customer template
business_configuration = self.getBusinessConfigurationValue()
self.install(document, business_configuration)
return error_list
......@@ -55,14 +55,19 @@ class SitePropertyConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore
, PropertySheet.ConfiguratorItem )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
portal = self.getPortalObject()
id_list = []
for id, value, prop_type in self.getConfigurationList():
if fixit:
if portal.hasProperty(id):
portal._delProperty(id)
portal._setProperty(id, value, type=prop_type)
id_list.append(id)
if fixit:
business_configuration = self.getBusinessConfigurationValue()
bt = business_configuration.getSpecialiseValue()
bt.edit(template_site_property_id_list=id_list)
return ["The property %s should set on portal" % id for id in id_list]
......@@ -54,8 +54,10 @@ class SolverConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
if fixit:
portal = self.getPortalObject()
business_configuration = self.getBusinessConfigurationValue()
solver = getattr(portal.portal_solvers, self.getId(), None)
if solver is None:
......@@ -79,3 +81,5 @@ class SolverConfiguratorItem(ConfiguratorItemMixin, XMLObject):
action.edit(**information_dict)
self.install(solver, business_configuration)
return ['Solvers should be created',]
......@@ -59,14 +59,14 @@ class StandardBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.StandardBT5ConfiguratorItem
)
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
template_tool = self.getPortalObject().portal_templates
bt5_id = self.getBt5Id().split('.')[0]
if bt5_id in template_tool.getInstalledBusinessTemplateTitleList():
LOG("StandardBT5ConfiguratorItem", INFO,
"Business Template already Installed: %s for %s" % (bt5_id, self.getRelativeUrl()))
return
return []
def _getRepositoryBusinessTemplateTitleList():
return [bt.getTitle() for bt in \
......@@ -77,15 +77,13 @@ class StandardBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject):
cache_factory='erp5_content_long')()
if bt5_id in repository_bt_title_list:
if fixit:
template_tool.installBusinessTemplateListFromRepository([bt5_id],
update_catalog=self.getUpdateCatalog(0),
install_dependency=self.getInstallDependency(1),
activate=True)
LOG("StandardBT5ConfiguratorItem", INFO,
"Install %s for %s" % (bt5_id, self.getRelativeUrl()))
return
return [self._createConstraintMessage('%s should be installed' % bt5_id),]
raise ValueError("The business template %s was not found on available \
sources." % bt5_id)
......@@ -72,16 +72,22 @@ class SystemPreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
property_id_list.append('%s%s' % (prop.getReference(), list_prefix))
return property_id_list
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
error_list = []
portal = self.getPortalObject()
preference = portal.portal_preferences._getOb(self.object_id, None)
if preference is None:
error_list.append(self._createConstraintMessage(
"System Preference %s should be created" % self.object_id))
if fixit:
preference = portal.portal_preferences.newContent(
portal_type = 'System Preference',
id = self.object_id,
title = self.title,
description = self.description,
priority = 1)
else:
return error_list
preference_dict = {}
......@@ -96,9 +102,11 @@ class SystemPreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
preference.enable()
preference.edit(**preference_dict)
business_configuration = self.getBusinessConfigurationValue()
bt5_obj = business_configuration.getSpecialiseValue()
current_template_preference_list = list(bt5_obj.getTemplatePreferenceList())
if preference.getId() not in current_template_preference_list:
current_template_preference_list.append(preference.getId())
bt5_obj.edit(template_preference_list=current_template_preference_list,)
return error_list
......@@ -54,9 +54,11 @@ class WorkflowSecurityConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.CategoryCore
, PropertySheet.DublinCore )
def _build(self, business_configuration):
def _checkConsistency(self, fixit=False, filter=None, **kw):
return []
if fixit:
## NOT TESTED
return
business_configuration = self.getBusinessConfigurationValue()
table_dict = business_configuration.ConfigurationTemplate_readOOCalcFile(self.filename)
portal = self.getPortalObject()
suffix = '_security'
......
......@@ -28,12 +28,25 @@
#
##############################################################################
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
from Products.ERP5Type.Base import Base
from zLOG import LOG, INFO
import time
class ConfiguratorItemMixin:
""" This is the base class for all configurator item. """
def getBusinessConfigurationValue(self):
item = self
while item.getPortalType() != 'Business Configuration':
item = item.getParentValue()
return item
def _createConstraintMessage(self, message):
return ConsistencyMessage(self,
object_relative_url=self.getRelativeUrl(),
message=message)
def install(self, document, business_configuration, prefix=''):
""" Add object to customer customization template. """
bt5_obj = business_configuration.getSpecialiseValue()
......@@ -52,25 +65,6 @@ class ConfiguratorItemMixin:
current_template_path_list.extend(template_path_list)
bt5_obj.edit(template_path_list=current_template_path_list)
def addToCustomerBT5ByRelativeUrl(self, business_configuration,
relative_url_list):
""" Add object to customer customization template object by
its relative url. """
bt5_obj = business_configuration.getSpecialiseValue()
current_template_path_list = list(bt5_obj.getTemplatePathList())
current_template_path_list.extend(relative_url_list)
bt5_obj.edit(template_path_list=current_template_path_list)
def build(self, business_configuration_relative_url):
""" Invoke build process """
business_configuration = self.getPortalObject().restrictedTraverse(\
business_configuration_relative_url)
LOG('CONFIGURATOR', INFO, 'Building --> %s' % self)
start_build = time.time()
result = self._build(business_configuration)
LOG('CONFIGURATOR', INFO, 'Built --> %s (%.02fs)' % (self,
time.time()-start_build))
return result
class SkinConfiguratorItemMixin(ConfiguratorItemMixin):
""" Mixin which allows to create python scripts and/or skin
......
......@@ -89,7 +89,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
group=group_id, site='main', **kw)
self.tic()
item._build(configuration_save.getParentValue())
item.fixConsistency()
self.tic()
organisation = self.portal.portal_catalog.getResultValue(
......@@ -139,7 +139,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
title="title_%s" % category_id_1)
self.tic()
item0._build(bc)
item0.fixConsistency()
self.tic()
category_0 = getattr(self.portal.portal_categories.group, category_id_0, None)
......@@ -149,7 +149,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
category_1 = getattr(self.portal.portal_categories.group, category_id_1, None)
self.assertEqual(category_1, None)
item1._build(bc)
item1.fixConsistency()
self.tic()
category_1 = getattr(self.portal.portal_categories.group, category_id_1, None)
......@@ -164,7 +164,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
object_id=category_id_1,
title="new_title_%s" % category_id_1)
item2._build(bc)
item2.fixConsistency()
self.tic()
category_1 = getattr(self.portal.portal_categories.group,
......@@ -195,7 +195,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
self.tic()
item_eur._build(bc)
item_eur.fixConsistency()
self.tic()
eur = getattr(self.portal.currency_module, eur_currency_id , None)
......@@ -205,7 +205,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
brl = getattr(self.portal.currency_module, brl_currency_id , None)
self.assertEqual(brl, None)
item_brl._build(bc)
item_brl.fixConsistency()
self.tic()
brl = getattr(self.portal.currency_module, brl_currency_id , None)
......@@ -214,9 +214,9 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
# Build several times to not break portal.
item_brl._build(bc)
item_brl.fixConsistency()
self.tic()
item_brl._build(bc)
item_brl.fixConsistency()
self.tic()
def testSecurityCategoryMappingConfiguratorItem(self):
......@@ -240,7 +240,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
"Security Category Mapping Configurator Item")
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
# XXX Skin folder should be part of configuration and not always custom
......@@ -267,7 +267,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
"Account Configurator Item", **account_dict)
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
account = getattr(account_module, account_dict['account_id'], None)
......@@ -289,7 +289,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
"Account Configurator Item", **account_dict)
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
same_account = getattr(account_module, account_dict['account_id'], None)
......@@ -327,7 +327,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
property_map["active_sense_method_id"],
"", "context.setEnabled(0)")
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
alarm = getattr(self.portal.portal_alarms, "my_test_alarm", None)
......@@ -394,7 +394,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
person_module_type.manage_delObjects([i.id for i in role_list])
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
role_list = [i for i in person_type.objectValues(
......@@ -449,7 +449,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
configuration_spreadsheet_data = data)
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
base_category_list = ["group", "site", "business_application",
......@@ -499,7 +499,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
id = "rule_do_not_exist")
self.tic()
self.assertRaises(ValueError, item._build, bc)
self.assertRaises(ValueError, item.fixConsistency)
rule_reference = "testing_configurator_rule_%s" % self.newUniqueUID()
item = configuration_save.addConfigurationItem(
......@@ -509,7 +509,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
trade_phase_list = ['testing/order'])
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
template_id = item.getId()
......@@ -541,7 +541,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
reference = reference)
self.tic()
item._build(bc)
item.fixConsistency()
self.tic()
business_process = self.portal.portal_catalog.getResultValue(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment