Commit ea05549c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

cleanup and implement several APIs to get configuration values for target solvers.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36691 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a79db1cd
...@@ -94,23 +94,11 @@ class SolverDecision(ConfigurableMixin, XMLObject): ...@@ -94,23 +94,11 @@ class SolverDecision(ConfigurableMixin, XMLObject):
configurable object configurable object
(implementation) (implementation)
""" """
# XXX To be implemented through type based method and using read solver_type = self.getSolverValue()
# transaction cache if solver_type is None:
try:
solver_portal_type = self.getSolverValue().getId()
except AttributeError:
return {} return {}
else:
solver = self.getParentValue().newContent( solver_type.getDefaultConfigurationPropertyDict()
portal_type=solver_portal_type,
temp_object=True,
delivery_list=self.getDeliveryList(),
causality_value=self)
method = solver._getTypeBasedMethod(
'getDefaultConfigurationPropertyDict',
fallback_script_id='Solver_getDefaultConfigurationPropertyDict')
return method(self)
def getExplanationMessage(self, all=False): def getExplanationMessage(self, all=False):
""" """
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.ERP5Type import ERP5TypeInformation from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5.Document.Predicate import Predicate from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5Type.Cache import getReadOnlyTransactionCache from Products.ERP5Type.Cache import getReadOnlyTransactionCache
...@@ -151,45 +151,74 @@ class SolverTypeInformation(Predicate, ERP5TypeInformation): ...@@ -151,45 +151,74 @@ class SolverTypeInformation(Predicate, ERP5TypeInformation):
configurable -- a configurable document (Solver Decision configurable -- a configurable document (Solver Decision
or Target Solver) or Target Solver)
""" """
# Implemented through type based method return self._callTypeBasetMethod(
# and using read transaction cache self, 'getDefaultConfigurationPropertyDict')
if configurable.getPortalType() == 'Solver Decision':
try:
solver_portal_type = configurable.getSolverValue().getId()
except AttributeError:
return {}
else:
solver_portal_type = configurable.getPortalType()
cache = getReadOnlyTransactionCache(self) def getDefaultConfigurationProperty(self, property, configurable):
if cache is not None:
key = ('getDefaultConfigurationPropertyDict', solver_portal_type,
configurable.getRelativeUrl())
try:
method = cache[key]
except KeyError:
method = self._getTypeBasedMethod(
'getDefaultConfigurationPropertyDict',
fallback_script_id='Solver_getDefaultConfigurationPropertyDict')
cache[key] = method
return method(configurable)
def getDefaultConfigurationPropertyList(self, id, configurable):
""" """
Returns a list of possible values for a given property Returns the default value for a given property
(public API) (public API)
configurable -- a configurable document (Solver Decision configurable -- a configurable document (Solver Decision
or Target Solver) or Target Solver)
TODO: XXX-JPS unify with IConfigurable
""" """
return self.getDefaultConfigurationPropertyDict().get(property, None)
def getDefaultConfigurationProperty(self, id, configurable): def getDefaultConfigurationPropertyListDict(self, configurable):
""" """
Returns the default value for a given property Returns a dictionary of possible values for specified
(public API) configurable object
(implementation)
configurable -- a configurable document (Solver Decision configurable -- a configurable document (Solver Decision
or Target Solver) or Target Solver)
"""
return self._callTypeBasetMethod(
self, 'getDefaultConfigurationPropertyListDict')
TODO: XXX-JPS unify with IConfigurable def getDefaultConfigurationPropertyList(self, property, configurable):
""" """
Returns a list of possible values for a given property
(public API)
configurable -- a configurable document (Solver Decision
or Target Solver)
"""
return self.getDefaultConfigurationPropertyListDict().get(property, [])
def _callTypeBasedMethod(self, method_id, configurable):
# Implemented through type based method
# and using read transaction cache
portal_type = configurable.getPortalType()
if portal_type == 'Solver Decision':
try:
solver_portal_type = self.getSolverValue().getId()
solver = None
except AttributeError:
return {}
elif interfaces.ISolver.providedBy(configurable):
solver_portal_type = portal_type
solver = configurable
else:
raise NotImplementedError, '%s is not supported for configurable argument' % portal_type
cache = getReadOnlyTransactionCache(self)
if cache is not None:
key = (method_id, solver_portal_type,
configurable.getRelativeUrl())
try:
method = cache[key]
except KeyError:
if solver is None:
solver = self.getParentValue().newContent(
portal_type=solver_portal_type,
temp_object=True,
delivery_list=configurable.getDeliveryList(),
causality_value=configurable)
method = solver._getTypeBasedMethod(
method_id,
fallback_script_id='Solver_%s' % method_id)
cache[key] = method
return method()
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