Example #1
0
    def _instanciate_from_xml(cls, xml):
        """ Instanciate a BonitaProcess object from its xml definition """
        if not isinstance(xml,(str,unicode)):
                    raise TypeError('xml must be a string or unicode not %s' % (type(xml)))

        soup = BeautifulSoup(xml,'xml')

        try:
            process_soup = xml_find(soup,'ProcessDefinition')
            uuid = xml_find(process_soup,'uuid').string
            
            process = BonitaProcess(uuid)

            process._name = xml_find(process_soup,'name').string
            process._version = xml_find(process_soup,'version').string
        except XMLSchemaParseError as exc:
            raise

        return process
Example #2
0
def build_bonita_membership_xml(uuid,role,group, dbid=''):
    """ Build XML for a Bonita Membership information """
    # Build XML body
    soup = BeautifulSoup('','xml')

    tag_membership = soup.new_tag('Membership')
    tag_uuid = soup.new_tag('uuid')
    tag_dbid = soup.new_tag('dbid')

    tag_uuid.string = uuid
    tag_dbid.string = dbid
    membership_tags = [tag_uuid,tag_dbid]

    for tag in membership_tags:
        tag_membership.append(tag)

    if isinstance(group,BonitaGroup):
        # Build group XML definition
        group_xml = build_bonita_group_xml(group.uuid, group.name, group.description, group.label,parent=group.parent,with_class=True)
        group_soup = BeautifulSoup(group_xml,'xml')
        tag_membership.append(xml_find(group_soup,'group'))
    else:
        # group XML is directly in group param
        group_soup = BeautifulSoup(group,'xml')
        tag_membership.append(group_soup.contents[0])

    if isinstance(role,BonitaRole):
        # Build group XML definition
        role_xml = build_bonita_role_xml(role.uuid,role.name,role.description,role.label,role.dbid if 'dbid' in dir(role) else '',with_class=True)
        role_soup = BeautifulSoup(role_xml,'xml')
        tag_membership.append(xml_find(role_soup,'role'))
    else:
        # group XML is directly in group param
        role_soup = BeautifulSoup(role,'xml')
        tag_membership.append(role_soup.contents[0])

    return unicode(tag_membership)
Example #3
0
def build_bonita_user_xml(uuid,password='',username='',additional_properties = {}):
    """ Build XML for a Bonita User information """
    # Build XML body
    soup = BeautifulSoup('','xml')
    tag_user = soup.new_tag('user')
    tag_uuid = soup.new_tag('uuid')
    tag_password = soup.new_tag('password')
    tag_username = soup.new_tag('username')

    tag_uuid.string = uuid
    tag_password.string = password
    tag_username.string = username
    user_tags = [tag_uuid,tag_password,tag_username]

    for tag in user_tags:
        tag_user.append(tag)

    # Extract memberships
    memberships = additional_properties.pop('memberships',[])

    # Add additional properties
    for (property_key, property_value) in additional_properties.iteritems():
        # Create an additional tag
        tag_property = soup.new_tag(property_key)
        tag_property.string = property_value
        # Add the new property to the User tag
        tag_user.append(tag_property)

    # Add memberships
    for membership in memberships:
        tag_memberships = soup.new_tag('memberships')
        if isinstance(membership, BonitaMembership):
            membership_xml = build_bonita_membership_xml(membership.uuid,membership.role,membership.group)
            membership_soup = BeautifulSoup(membership_xml,'xml')
            tag_memberships.append(xml_find(membership_soup,'membership'))
        tag_user.append(tag_memberships)

    return unicode(tag_user)