Пример #1
0
    def apply(self, node, obj):
        "Import this attribute from the given node to the object."
        input = UNSET
        if node.hasAttribute(self.domAttr):
            input = node.getAttribute(self.domAttr)
        if input is UNSET:
            if self.required:
                raise ConfigurationError(
                    "'%s' element requires attribute '%s'." %
                    (node.nodeName, self.domAttr))
            else:
                # Not required and no input given: just don't do anything.
                return

        # Preparatory steps
        if self.encoding is not None:
            input = input.encode(self.encoding)

        # Convert the input into the correct data type
        if self.datatype in [list, tuple]:
            value = self.datatype(utils.flexSplit(input))
            if not value:
                # XXX This allows giving no input even when input is required.
                return

        elif self.datatype == bool:
            try:
                value = utils.makeBoolFromUnicode(input)
            except ValueError:
                import sys
                raise ConfigurationError(str(sys.exc_info()[1]))
        else:
            # do not try to convert strings or empty values
            if not (issubclass(self.datatype, basestring) or input == ''):
                try:
                    value = self.datatype(input)
                except ValueError:
                    raise ConfigurationError, \
                          "%s.%s must be of %s" % (node.nodeName, self.domAttr,
                                                   self.datatype)
            else:
                value = input

            if value == '':
                return

        # After conversion: check for containment in vocabulary
        if self.vocabulary is not None and value not in self.vocabulary:
            raise ConfigurationError, \
                  "%s.%s must be one of %s" % (node.nodeName, self.domAttr,
                                               self.vocabulary)

        setattr(obj, self.classAttr, value)
Пример #2
0
def import_child_elements(node,
                          context,
                          node_names=None,
                          ignore=(),
                          default=None):
    seen_ids = set(context.objectIds())
    if default and default.getId():
        seen_ids.remove(default.getId())
    children = []
    for node in get_element_children(node):
        if (node_names is not None and node.nodeName not in node_names
                or node.nodeName in ignore):
            continue
        element_importer = zope.component.getAdapter(
            context,
            gocept.alphaflow.xmlimport.interfaces.IDOMImporter,
            name=node.nodeName)
        for element in element_importer(node, default):
            element_id = getattr(element, "id", None)
            if element_id:
                if element_id in seen_ids:
                    raise ConfigurationError("Multiple element id: %s" %
                                             element_id)
                else:
                    seen_ids.add(element_id)
            children.append(element)
    return children
Пример #3
0
 def apply(self, node, obj):
     assignees = node.getElementsByTagName('assignees')
     # defaults will be used if assignees is empty
     if len(assignees) == 1:
         self._parse_assignee(assignees[0], obj)
     elif len(assignees) > 1:
         raise ConfigurationError(
             '<assignees> is only allowed once per activity.')
Пример #4
0
 def apply(self, node, obj):
     if node.hasAttribute('configures_all'):
         setattr(obj, self.classAttr, None)  # None is marker for "all"
     elif node.hasAttribute('configures'):
         super(ConfiguresAttribute, self).apply(node, obj)
     else:
         raise ConfigurationError(
             "%r: Attribute configures or configures_all needed." %
             node.nodeName)
Пример #5
0
    def _parse_assignee(self, assignee, obj):
        has = assignee.hasAttribute
        get = assignee.getAttribute

        configure_attributes(assignee, obj, self.assigneesKind)
        kind = obj.assigneesKind

        statements = has('roles') + has('expression') + has('groups')

        if statements > 1:
            raise ConfigurationError(
                '<assignees> can only have one of roles or expression.')
        if statements < 1:
            raise ConfigurationError(
                '<assignees> must have one of roles or expression.')
        if has('roles'):
            configure_attributes(assignee, obj, self.roles)
        elif has('groups'):
            configure_attributes(assignee, obj, self.groups)
        elif has('expression'):
            if kind == 'possible':
                raise NotImplementedError(
                    "Can not combine `possible` and `expression`.")
            configure_attributes(assignee, obj, self.assigneesExpression)
Пример #6
0
 def __call__(self, node, recipient=None):
     notify = gocept.alphaflow.activities.notify
     recipient_type = node.getAttribute("type")
     if recipient_type == "owner":
         recipient = notify.RecipientOwner()
     elif recipient_type == "next_assignees":
         recipient = notify.RecipientNextAssignees()
     elif recipient_type == "current_assignees":
         recipient = notify.RecipientCurrentAssignees()
     elif recipient_type == "previous_assignees":
         recipient = notify.RecipientPreviousAssignees()
     elif recipient_type == "actual_role":
         recipient = notify.RecipientActualRole()
         configure_attributes(node, recipient, self.actual_role)
     else:
         raise ConfigurationError(
             "Unknown recipient type: " + recipient_type)
     return [recipient]