Ejemplo n.º 1
0
def example_Label_object():
    """Generates an example Label metadata document.
    >>> root = example_Label_object()
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
      <labels>
        <fullName>AColleague</fullName>
        <categories>ChooseAnAttendee</categories>
        <language>en_US</language>
        <protected>true</protected>
        <description>A Colleague</description>
        <value>A Colleague</value>
      </labels>
      <labels>
        <fullName>ZipPostalCode</fullName>
        <categories>Address</categories>
        <language>en_US</language>
        <protected>true</protected>
        <description>A ZipPostalCode</description>
        <value>Zip/Postal Code</value>
      </labels>
    </CustomLabels>
    <BLANKLINE>
    """
    root = sforce_root('CustomLabels')
    root = labels_element(root, 'AColleague', 'ChooseAnAttendee', 'en_US',
                          'true', 'A Colleague', 'A Colleague')
    root = labels_element(root, 'ZipPostalCode', 'Address', 'en_US', 'true',
                          'A ZipPostalCode', 'Zip/Postal Code')
    return root
Ejemplo n.º 2
0
def example_Account_object():
    """Generates an example InstalledPackage metadata document.
    >>> root = example_Account_object()
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
      <fieldSets>
        <fullName>CompanySearchResults</fullName>
        <description>Create Company Account</description>
        <displayedFields>
          <field>AccountNumber</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </displayedFields>
      </fieldSets>
      <fieldSets>
        <fullName>CompanyMatchingAccounts</fullName>
        <description>Company Search Result card</description>
        <displayedFields>
          <field>AnnualRevenue</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </displayedFields>
      </fieldSets>
    </CustomObject>
    <BLANKLINE>
    """
    root = sforce_root('CustomObject')
    root = field_sets_element(root,'CompanySearchResults',
                              'Create Company Account','AccountNumber',
                              'false', 'false')
    root = field_sets_element(root, 'CompanyMatchingAccounts',
                          'Company Search Result card', 'AnnualRevenue',
                          'false','false')
    return root
Ejemplo n.º 3
0
def extract_elements(source_root,
                     target_root,
                     root_name='Profile',
                     test_mode=False):
    """Creates profile document from target containing the named elements.
    names = diff_elements(prune_elements(example_profile_source(),False),
                          target,False),False)

    >>> source_root = prune_elements(example_profile_metadata_source(), True)
    >>> target_root = prune_elements(example_profile_metadata_target(), True)
    >>> root = extract_elements(source_root,target_root,'Profile', True)
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <Profile xmlns="http://soap.sforce.com/2006/04/metadata">
      <classAccesses>
        <apexClass>AccountHierarchyBuilder</apexClass>
        <enabled>true</enabled>
      </classAccesses>
    </Profile>
    <BLANKLINE>
    """
    my_extract_elements = ExtractElements()
    my_extract_elements.my_test_mode = test_mode
    root = sforce_root(root_name)
    for parent_name in PARENTS:
        children = PARENTS.get(parent_name)
        names = diff_elements(source_root, target_root, parent_name, test_mode)
        root = my_extract_elements.do(target_root, root, parent_name,
                                      children[EXTRACT_CHILD], names)
    return root
Ejemplo n.º 4
0
def example_apex_class():
    """Generates the XML tree representing an example ApexClass metadata
    document.

    >>> root = example_apex_class()
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
      <apiVerson>12.0</apiVerson>
      <packageVersions>
        <majorNumber>1</majorNumber>
        <minorNumber>2</minorNumber>
        <namespace>Example</namespace>
      </packageVersions>
      <status>Active</status>
    </ApexClass>
    <BLANKLINE>
    """
    root = sforce_root('ApexClass')
    api_version = etree.SubElement(root, 'apiVerson')
    package_versions = etree.SubElement(root, 'packageVersions')
    status = etree.SubElement(root, 'status')
    api_version.text = '12.0'
    status.text = 'Active'
    major_number = etree.SubElement(package_versions, 'majorNumber')
    minor_number = etree.SubElement(package_versions, 'minorNumber')
    namespace = etree.SubElement(package_versions, 'namespace')
    major_number.text = '1'
    minor_number.text = '2'
    namespace.text = 'Example'
    return root
Ejemplo n.º 5
0
def example_account_object():
    """Generates an example Account  document.
    >>> root = example_account_object()
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
      <fieldSets>
        <fullName>CompanySearchResults</fullName>
        <description>Create Company Account</description>
        <displayedFields>
          <field>AccountNumber</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </displayedFields>
      </fieldSets>
      <fieldSets>
        <fullName>CompanyMatchingAccounts</fullName>
        <description>Company Search Result card</description>
        <displayedFields>
          <field>AnnualRevenue</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </displayedFields>
      </fieldSets>
      <listViews>
        <fullName>AllAccounts</fullName>
        <columns>ACCOUNT.NAME</columns>
        <filterScope>Everything</filterScope>
        <label>All Accounts</label>
      </listViews>
      <listViews>
        <fullName>NewThisWeek</fullName>
        <columns>ACCOUNT.NAME</columns>
        <filterScope>Everything</filterScope>
        <label>New This Week</label>
      </listViews>
    </CustomObject>
    <BLANKLINE>
    """
    root = sforce_root('CustomObject')
    root = field_sets_element(root, 'CompanySearchResults',
                              'Create Company Account', 'AccountNumber',
                              'false', 'false')
    root = field_sets_element(root, 'CompanyMatchingAccounts',
                              'Company Search Result card', 'AnnualRevenue',
                              'false', 'false')
    root = list_views_element(root, 'AllAccounts', 'ACCOUNT.NAME',
                              'Everything', 'All Accounts')
    root = list_views_element(root, 'NewThisWeek', 'ACCOUNT.NAME',
                              'Everything', 'New This Week')
    return root
Ejemplo n.º 6
0
def example_installed_package():
    """Generates an example InstalledPackage metadata document.

    >>> root = example_installed_package()
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata">
      <versionNumber>1.2.3</versionNumber>
    </InstalledPackage>
    <BLANKLINE>
    """
    root = sforce_root('InstalledPackage')
    version_number = etree.SubElement(root, 'versionNumber')
    version_number.text = '1.2.3'
    return root
Ejemplo n.º 7
0
def example_profile_metadata_source():
    """Generates an example profile metadata document.

    >>> root = example_profile_metadata_source()
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <Profile xmlns="http://soap.sforce.com/2006/04/metadata">
      <classAccesses>
        <apexClass>ARTransactionsTest</apexClass>
        <enabled>false</enabled>
      </classAccesses>
      <classAccesses>
        <apexClass>AccountAddressManager</apexClass>
        <enabled>true</enabled>
      </classAccesses>
    </Profile>
    <BLANKLINE>
    """
    root = sforce_root('Profile')
    example_class_access_element(root, 'ARTransactionsTest', 'false')
    example_class_access_element(root, 'AccountAddressManager', 'true')
    return root
Ejemplo n.º 8
0
def modify_field_sets(root, fields, test_mode=False):
    """
    >>> root = modify_field_sets(example_Account_object(), TEST_LIST, True)
    >>> print_tree(root)
    <?xml version='1.0' encoding='UTF-8'?>
    <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
      <fieldSets>
        <fullName>CompanySearchResults</fullName>
        <description>Create Company Account</description>
        <displayedFields>
          <field>AccountNumber</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </displayedFields>
        <availableFields>
          <field>AccountSource</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </availableFields>
        <availableFields>
          <field>AnnualRevenue</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </availableFields>
      </fieldSets>
      <fieldSets>
        <fullName>CompanyMatchingAccounts</fullName>
        <description>Company Search Result card</description>
        <displayedFields>
          <field>AnnualRevenue</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </displayedFields>
        <availableFields>
          <field>AccountNumber</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </availableFields>
        <availableFields>
          <field>AccountSource</field>
          <isFieldManaged>false</isFieldManaged>
          <isRequired>false</isRequired>
        </availableFields>
      </fieldSets>
    </CustomObject>
    <BLANKLINE>
    """
    modified = False
    ns = namespace_declare(test_mode)
    field_sets_match = namespace_prepend('fieldSets', test_mode)
    field_sets = root.findall(field_sets_match, ns)
    for field_set in field_sets:
        add_available = []
        displayedFields_match = namespace_prepend('displayedFields', test_mode)

        displayed_fields = field_set.findall(displayedFields_match, namespaces=ns)
        field_match = namespace_prepend('field', test_mode)
        displayed_list = []
        for field in displayed_fields:
            found = field.findtext(field_match, namespaces=ns)
            displayed_list.append(found)

        for field in fields:
            if field not in displayed_list:
                add_available.append(field)

        if len(add_available) > 0:
            for add_field in add_available:
                parent = etree.SubElement(field_set,'availableFields')
                field = etree.SubElement(parent,'field')
                field.text = add_field
                sub_element_text(parent, 'isFieldManaged','false')
                sub_element_text(parent, 'isRequired', 'false')
                modified = True

    return root if modified else sforce_root('CustomObject')