Ejemplo n.º 1
0
    def on_post_save(self, view):
        # Get current file name and Read file content
        file_name = view.file_name()
        try:
            body = open(file_name, encoding="utf-8").read()
        except:
            body = open(file_name, "rb").read()

        # Get component_name amd component_type
        component_name = util.get_component_name(file_name)
        component_type = util.get_component_type(file_name)

        # If this file is not ApexTrigger, ApexComponent,
        # ApexPage or ApexClass, just return
        if component_type not in ["ApexClass", "ApexPage", "ApexComponent", "ApexTrigger"]:
            return

        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Get component extension
        component_extension = toolingapi_settings[component_type]["extension"]

        # Get Workspace, if not exist, make it
        workspace = toolingapi_settings["workspace"] + "/history/" + component_type
        if not os.path.exists(workspace):
            os.makedirs(workspace)

        # Backup current file
        time_stamp = time.strftime("%Y-%m-%d-%H-%M", time.localtime())
        fp = open(workspace + "/" + component_name + "-" + time_stamp + component_extension, "w")

        fp.write(body)
        fp.close()
Ejemplo n.º 2
0
def check_visible(file_name):
    """
    Check whether file is ApexTrigger, ApexComponent, ApexPage or ApexClass

    Parameters:
        file_name: current file name

    Return: 
        Bool
    """
    if file_name == None:
        return False

    # Get toolingapi settings
    toolingapi_settings = context.get_toolingapi_settings()

    # Get component_type
    component_type = util.get_component_type(file_name)

    # If component type is not in range, just show error message
    if component_type not in toolingapi_settings["component_types"]:
        return False

    # Get component_url and component_id
    username = toolingapi_settings["username"]
    try:
        component_attribute = util.get_component_attribute(username, file_name)
    except KeyError as err:
        return False

    if component_attribute == None:
        return False

    return True
Ejemplo n.º 3
0
 def run(self):
     global projects
     toolingapi_settings = context.get_toolingapi_settings()
     projects = toolingapi_settings["projects"]
     projects = ["(" + str(projects[p]["default"]) + ") " + p for p in projects]
     projects = sorted(projects, reverse=True)
     self.window.show_quick_panel(projects, self.on_done)
Ejemplo n.º 4
0
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # Get output csv dir
        workspace = context.get_toolingapi_settings().get("workspace")
        outputdir = workspace + "/describe/global"
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        # Open output csv
        output_file_dir = outputdir + "/sobjects.csv"
        if util.is_python3x():
            fp = open(output_file_dir, "w", newline='')
        else:
            fp = open(output_file_dir, "wb")

        # Write list to csv
        util.list2csv(fp, result["sobjects"])

        # Output log
        print("global describe csv outputdir: " + output_file_dir)
Ejemplo n.º 5
0
def handle_execute_query(soql, timeout=120):
    def handle_new_view_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_new_view_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return None

        # No error, just display log in a new view
        view = sublime.active_window().new_file()
        view.run_command("newview", {
            "name": "Execute Query Result",
            "input": util.parse_execute_query_result(result)
        })

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.query, args=(soql, ))
    thread.start()
    handle_new_view_thread(thread, timeout)
Ejemplo n.º 6
0
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399 :
            util.sublime_error_message(result)
            return

        # Get output csv dir
        workspace = context.get_toolingapi_settings().get("workspace")
        outputdir = workspace + "/describe/global"
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        # Open output csv
        output_file_dir = outputdir + "/sobjects.csv"
        if util.is_python3x():
            fp = open(output_file_dir, "w", newline='')
        else:
            fp = open(output_file_dir, "wb")

        # Write list to csv
        util.list2csv(fp, result["sobjects"])

        # Output log
        print("global describe csv outputdir: " + output_file_dir)
Ejemplo n.º 7
0
def handle_refresh_components(toolingapi_settings, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed, something may happen,
        # for example, user password is expired
        if "status_code" in api.result and api.result["status_code"] > 399:
            util.sublime_error_message(api.result)
            return

        # Load COMPONENT_METADATA_SETTINGS Settings and put all result into it
        # Every org has one local repository
        component_metadata = api.result
        component_metadta = sublime.load_settings(COMPONENT_METADATA_SETTINGS)
        component_metadta.set(toolingapi_settings["username"], component_metadata)
        sublime.save_settings(COMPONENT_METADATA_SETTINGS)
        print (message.SEPRATE.format('All code are Downloaded.'))
        sublime.status_message(message.DOWNLOAD_ALL_SUCCESSFULLY)

        # After Refresh all succeed, start initiate sobject completions
        handle_initiate_sobjects_completions(120)

    print (message.WAIT_FOR_A_MOMENT)
    api = SalesforceApi(toolingapi_settings)
    component_types = context.get_toolingapi_settings()["component_types"]
    thread = threading.Thread(target=api.refresh_components, 
        args=(component_types, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 8
0
def handle_refresh_component(component_attribute, file_name, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        result = api.result
        status_code = result["status_code"]

        if status_code > 399:
            util.sublime_error_message(result)
            return

        fp = open(file_name, "wb")
        try:
            body = bytes(result[component_body], "UTF-8")
        except:
            body = result[component_body].encode("UTF-8")

        fp.write(body)
        print(message.SEPRATE.format(message.GET_SUCCESSFULLY))
        sublime.status_message(message.GET_SUCCESSFULLY)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    component_body = component_attribute["body"]
    component_url = component_attribute["url"]
    thread = threading.Thread(target=api.get, args=(component_url, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 9
0
def populate_components():
    """
    Get all components which NamespacePrefix is null in whole org
    """

    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in globals()[], just return it
    component_metadata = sublime.load_settings(
        "component_metadata.sublime-settings")
    if not component_metadata.has(username):
        return []

    return_component_attributes = {}
    for component_type in component_metadata.get(username).keys():
        component_attributes = component_metadata.get(username)[component_type]
        for component_name in component_attributes.keys():
            component_id = component_attributes[component_name]["id"]
            component_type = component_attributes[component_name]["type"]
            return_component_attributes[component_type + "-->" +
                                        component_name] = component_id

    return return_component_attributes
Ejemplo n.º 10
0
def handle_refresh_component(component_attribute, file_name, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda:handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return
        
        result = api.result
        status_code = result["status_code"]
        
        if status_code > 399:
            util.sublime_error_message(result)
            return

        fp = open(file_name, "wb")
        try:
            body = bytes(result[component_body], "UTF-8")
        except:
            body = result[component_body].encode("UTF-8")

        fp.write(body)
        print (message.SEPRATE.format(message.GET_SUCCESSFULLY))
        sublime.status_message(message.GET_SUCCESSFULLY)

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    component_body = component_attribute["body"]
    component_url = component_attribute["url"]
    thread = threading.Thread(target=api.get, args=(component_url, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 11
0
def populate_sobjects():
    """
    Get the sobjects list in org.
    """

    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in sobjects_completion.sublime-settings, just return it
    sobjects_completions = sublime.load_settings(
        "sobjects_completion.sublime-settings")
    if sobjects_completions.has(username):
        return sobjects_completions.get(username).keys()

    # If sobjects is not exist in globals(), post request to pouplate it
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global, args=())
    thread.start()

    while thread.is_alive() or api.result == None:
        time.sleep(1)

    sobjects = []
    for sobject in api.result["sobjects"]:
        sobjects.append(sobject["name"])

    globals()[username + "sobjects"] = sobjects
    return sobjects
Ejemplo n.º 12
0
def handle_delete_component(component_url, file_name, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda:handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        # If succeed
        result = api.result
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        os.remove(file_name)
        sublime.active_window().run_command("close")
        print (message.SEPRATE.format(message.DELETE_SUCCESSFULLY))
        sublime.status_message(message.DELETE_SUCCESSFULLY)

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.delete, args=(component_url, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 13
0
def handle_push_topic(sobject, timeout=120):      
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda:handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        # If succeed
        result = api.result
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        print (result)

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    post_url = "/services/data/v28.0/sobjects/PushTopic"
    post_data = {
        "Name": sobject + "PushTopic",
        "Query": get_sobject_soql(toolingapi_settings["username"], sobject),
        "ApiVersion": "28.0",
        "NotifyForOperations": "All",
        "NotifyForFields": "Referenced"
    }
    thread = threading.Thread(target=api.post, args=(post_url, post_data, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 14
0
def handle_push_topic(sobject, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        # If succeed
        result = api.result
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        print(result)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    post_url = "/services/data/v28.0/sobjects/PushTopic"
    post_data = {
        "Name": sobject + "PushTopic",
        "Query": get_sobject_soql(toolingapi_settings["username"], sobject),
        "ApiVersion": "28.0",
        "NotifyForOperations": "All",
        "NotifyForFields": "Referenced"
    }
    thread = threading.Thread(target=api.post, args=(
        post_url,
        post_data,
    ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 15
0
def populate_sobjects():
    """
    Get the sobjects list in org.
    """

    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in sobjects_completion.sublime-settings, just return it
    sobjects_completions = sublime.load_settings("sobjects_completion.sublime-settings")
    if sobjects_completions.has(username):
        return sobjects_completions.get(username).keys()

    # If sobjects is not exist in globals(), post request to pouplate it
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global, args=())
    thread.start()

    while thread.is_alive() or api.result == None:
        time.sleep(1)

    sobjects = []
    for sobject in api.result["sobjects"]:
        sobjects.append(sobject["name"])

    globals()[username + "sobjects"] = sobjects
    return sobjects
Ejemplo n.º 16
0
def check_visible(file_name):
    """
    Check whether file is ApexTrigger, ApexComponent, ApexPage or ApexClass

    Parameters:
        file_name: current file name

    Return: 
        Bool
    """
    if file_name == None:
        return False

    # Get toolingapi settings
    toolingapi_settings = context.get_toolingapi_settings()

    # Get component_type
    component_type = util.get_component_type(file_name)

    # If component type is not in range, just show error message
    if component_type not in toolingapi_settings["component_types"]:
        return False

    # Get component_url and component_id
    username = toolingapi_settings["username"]
    try:
        component_attribute = util.get_component_attribute(username, file_name)
    except KeyError as err:
        return False

    if component_attribute == None: 
        return False

    return True
Ejemplo n.º 17
0
def handle_execute_anonymous(apex_string, timeout=120):
    def handle_new_view_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_new_view_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            errorCode = util.none_value(result["errorCode"])
            message = util.none_value(result["message"])
            sublime.error_message(errorCode + "\n" + message)
            return

        # No error, just display log in a new view
        view = sublime.active_window().new_file()
        view.run_command("newview", {
            "name": "Execute Anonymous Result",
            "input": util.parse_execute_anonymous_xml(result)
        })

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.execute_anonymous, args=(apex_string, ))
    thread.start()
    handle_new_view_thread(thread, timeout)
Ejemplo n.º 18
0
def handle_run_test(class_id, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        # If error
        if "status_code" in result and result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # No error, just display log in a new view
        test_result = util.parse_test_result(result)

        # Sometimes, the test result will not show
        print (test_result)
        view = sublime.active_window().new_file()
        view.run_command("newview", {
            "name": "Test Result",
            "input": test_result
        })

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.run_test, args=(class_id, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 19
0
def handle_execute_query(soql, timeout=120):
    def handle_new_view_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(
                lambda: handle_new_view_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return None

        # No error, just display log in a new view
        view = sublime.active_window().new_file()
        view.run_command(
            "newview", {
                "name": "Execute Query Result",
                "input": util.parse_execute_query_result(result)
            })

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.query, args=(soql, ))
    thread.start()
    handle_new_view_thread(thread, timeout)
Ejemplo n.º 20
0
def handle_retrieve_fields(sobject, timeout=120):
    def handle_new_view_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_new_view_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # No error, just display log in a new view
        view = sublime.active_window().new_file()
        view.run_command("newview", {
            "name": sobject + " Describe Result",
            "input": util.parse_sobject_field_result(result)
        })

    print (message.WAIT_FOR_A_MOMENT)
    # Combine sobject url
    sobject_url = "/services/data/v28.0/sobjects/" + sobject+ "/describe"
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.get, args=(sobject_url, ))
    thread.start()
    handle_new_view_thread(thread, timeout)
Ejemplo n.º 21
0
def handle_save_component(component_name,
                          component_attribute,
                          body,
                          timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        result = api.result
        if "success" in result and result["success"]:
            print(message.SEPRATE.format(message.DEPLOY_SUCCESSFULLY))
            sublime.status_message(message.DEPLOY_SUCCESSFULLY)
        elif "message" in result:
            print(message.SEPRATE.format(result["message"]))
            sublime.status_message(result["message"])

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.save_component,
                              args=(
                                  component_attribute,
                                  body,
                              ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 22
0
def handle_delete_component(component_url, file_name, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        # If succeed
        result = api.result
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        os.remove(file_name)
        sublime.active_window().run_command("close")
        print(message.SEPRATE.format(message.DELETE_SUCCESSFULLY))
        sublime.status_message(message.DELETE_SUCCESSFULLY)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.delete, args=(component_url, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 23
0
def handle_retrieve_fields(sobject, timeout=120):
    def handle_new_view_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(
                lambda: handle_new_view_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # No error, just display log in a new view
        view = sublime.active_window().new_file()
        view.run_command(
            "newview", {
                "name": sobject + " Describe Result",
                "input": util.parse_sobject_field_result(result)
            })

    print(message.WAIT_FOR_A_MOMENT)
    # Combine sobject url
    sobject_url = "/services/data/v28.0/sobjects/" + sobject + "/describe"
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.get, args=(sobject_url, ))
    thread.start()
    handle_new_view_thread(thread, timeout)
Ejemplo n.º 24
0
def handle_run_test(class_id, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        # If error
        if "status_code" in result and result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # No error, just display log in a new view
        test_result = util.parse_test_result(result)

        # Sometimes, the test result will not show
        print(test_result)
        view = sublime.active_window().new_file()
        view.run_command("newview", {
            "name": "Test Result",
            "input": test_result
        })

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.run_test, args=(class_id, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 25
0
def handle_execute_anonymous(apex_string, timeout=120):
    def handle_new_view_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(
                lambda: handle_new_view_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            errorCode = util.none_value(result["errorCode"])
            message = util.none_value(result["message"])
            sublime.error_message(errorCode + "\n" + message)
            return

        # No error, just display log in a new view
        view = sublime.active_window().new_file()
        view.run_command(
            "newview", {
                "name": "Execute Anonymous Result",
                "input": util.parse_execute_anonymous_xml(result)
            })

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.execute_anonymous,
                              args=(apex_string, ))
    thread.start()
    handle_new_view_thread(thread, timeout)
Ejemplo n.º 26
0
def handle_generate_specified_workbooks(sobjects, timeout=120):
    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    threads = []
    for sobject in sobjects:
        thread = threading.Thread(target=api.generate_workbook, args=(sobject, ))
        threads.append(thread)
        thread.start()
Ejemplo n.º 27
0
 def run(self):
     global projects
     toolingapi_settings = context.get_toolingapi_settings()
     projects = toolingapi_settings["projects"]
     projects = [
         "(" + str(projects[p]["default"]) + ") " + p for p in projects
     ]
     projects = sorted(projects, reverse=True)
     self.window.show_quick_panel(projects, self.on_done)
Ejemplo n.º 28
0
def handle_generate_specified_workbooks(sobjects, timeout=120):
    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    threads = []
    for sobject in sobjects:
        thread = threading.Thread(target=api.generate_workbook,
                                  args=(sobject, ))
        threads.append(thread)
        thread.start()
Ejemplo n.º 29
0
    def on_query_completions(self, view, prefix, locations):
        if not view.match_selector(locations[0], "source.java"):
            return []

        # Load sobjects compoletions
        setting = sublime.load_settings("sobjects_completion.sublime-settings")

        # Load sobjects field meatadata
        toolingapi_settings = context.get_toolingapi_settings()
        username = toolingapi_settings["username"]

        # If current username is in settings, it means project is initiated
        if not setting.has(username):
            return

        location = locations[0]
        pt = locations[0] - len(prefix) - 1
        ch = view.substr(sublime.Region(pt, pt + 1))

        if ch != ".":
            return

        # Get the variable name
        variable_name = view.substr(view.word(pt))

        # Get the matched region by variable name
        # 1. Account.
        # 2. Account acc;
        # 3. Account acc = new Account()
        # 4. for (Account acc : accs)
        # 5. public static void updateAccount(Account acc)
        # 6. public Account acc {get; set;}
        matched_regions = view.find_all("\\w+\\s+" + variable_name +
                                        "\\s*[:;=)\s]")
        sobject = ""
        if len(matched_regions) > 0:
            matched_block = view.substr(matched_regions[0])
            sobject = matched_block.split(" ")[0]

        # If username is in settings, get the sobject fields describe dict
        metadata = setting.get(username)
        completion_list = []
        if sobject in metadata:
            sobject = sobject
        elif sobject.capitalize() in metadata:
            sobject = sobject.capitalize()
        else:
            return

        fields = metadata.get(sobject)
        for key in fields.keys():
            completion_list.append((sobject + "." + key, fields[key]))

        return (completion_list, sublime.INHIBIT_WORD_COMPLETIONS
                or sublime.INHIBIT_EXPLICIT_COMPLETIONS)
Ejemplo n.º 30
0
    def run(self):
        toolingapi_settings = context.get_toolingapi_settings()
        workflow_path = toolingapi_settings["workspace"] + "/metadata/unpackaged/workflows"
        if not os.path.exists(workflow_path):
            sublime.error_message(message.WORKFLOW_PATH_CHECK)
            return

        self.window.run_command("show_panel", 
            {"panel": "console", "toggle": False})

        processor.handle_parse_workflow()
Ejemplo n.º 31
0
def handle_describe_layout(sobject,
                           recordtype_name,
                           recordtype_id,
                           timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result

        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # If totalSize is 0
        if "totalSize" in result and result["totalSize"] == 0:
            util.sublime_error_message(result)
            return

        # Get output csv dir
        toolingapi_settings = context.get_toolingapi_settings()
        outputdir = toolingapi_settings["workspace"] + "/describe/layout"

        # If outputdir is not exist, just make it
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        output_file_dir = outputdir + "/" + sobject + "-" + recordtype_name + ".csv"

        if util.is_python3x():
            fp = open(output_file_dir, "w", newline='')
        else:
            fp = open(output_file_dir, "wb")
        util.parse_describe_layout_result(fp, result)

        print("Layout describe outputdir: " + output_file_dir)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_layout,
                              args=(
                                  sobject,
                                  recordtype_id,
                              ))
    thread.start()
    handle_thread(thread, 120)
Ejemplo n.º 32
0
    def on_query_completions(self, view, prefix, locations):
        if not view.match_selector(locations[0], "source.java"):
            return []

        # Load sobjects compoletions
        setting = sublime.load_settings("sobjects_completion.sublime-settings")

        # Load sobjects field meatadata
        toolingapi_settings = context.get_toolingapi_settings()
        username = toolingapi_settings["username"]

        # If current username is in settings, it means project is initiated
        if not setting.has(username):
            return

        location = locations[0]
        pt = locations[0] - len(prefix) - 1
        ch = view.substr(sublime.Region(pt, pt + 1))

        if ch != ".":
            return

        # Get the variable name
        variable_name = view.substr(view.word(pt))

        # Get the matched region by variable name
        # 1. Account.
        # 2. Account acc;
        # 3. Account acc = new Account()
        # 4. for (Account acc : accs)
        # 5. public static void updateAccount(Account acc)
        # 6. public Account acc {get; set;}
        matched_regions = view.find_all("\\w+\\s+" + variable_name + "\\s*[:;=)\s]")
        sobject = ""
        if len(matched_regions) > 0:
            matched_block = view.substr(matched_regions[0])
            sobject = matched_block.split(" ")[0]

        # If username is in settings, get the sobject fields describe dict
        metadata = setting.get(username)
        completion_list = []
        if sobject in metadata:
            sobject = sobject
        elif sobject.capitalize() in metadata:
            sobject = sobject.capitalize()
        else: 
            return

        fields = metadata.get(sobject)
        for key in fields.keys():
            completion_list.append((sobject + "." + key, fields[key]))

        return (completion_list, sublime.INHIBIT_WORD_COMPLETIONS or sublime.INHIBIT_EXPLICIT_COMPLETIONS)
Ejemplo n.º 33
0
    def run(self):
        toolingapi_settings = context.get_toolingapi_settings()
        workflow_path = toolingapi_settings["workspace"] + "/metadata/unpackaged/objects"
        if not os.path.exists(workflow_path):
            sublime.error_message(message.SOBJECTS_PATH_CHECK)
            return

        # Open Console
        self.window.run_command("show_panel", 
            {"panel": "console", "toggle": False})

        processor.handle_parse_validation_rule()
Ejemplo n.º 34
0
def handle_bulkapi_query(sobjects):
    # Login by user credential in toolingapi_settings
    toolingapi_settings = context.get_toolingapi_settings()
    login(toolingapi_settings, True)
    
    # Create workspace direcotry
    workspace = toolingapi_settings["workspace"] + "/bulkapi"
    if not os.path.exists(workspace):
        os.makedirs(workspace)

    for sobject in sobjects:
        thread = threading.Thread(target=process_bulk_query, args=(sobject, workspace, ))
        thread.start()
Ejemplo n.º 35
0
def handle_describe_customfield(sobject, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399:
            util.sublime_error_message(result)
            return

        # Get output csv dir
        workspace = context.get_toolingapi_settings().get("workspace")
        outputdir = workspace + "/describe/customfield"
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        # Open output csv
        output_file_dir = outputdir + "/" + sobject + ".csv"
        if util.is_python3x():
            fp = open(output_file_dir, "w", newline='')
        else:
            fp = open(output_file_dir, "wb")

        # Write list to csv
        util.list2csv(fp, result["records"])

        # Release fp
        fp.close()

        # Output log
        print(output_file_dir)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    query = """SELECT Id,TableEnumOrId,DeveloperName,NamespacePrefix,FullName 
               FROM CustomField 
               WHERE TableEnumOrId='{sobject}'""".format(sobject=sobject)
    thread = threading.Thread(target=api.query_all, args=(
        query,
        True,
    ))
    thread.start()
    handle_thread(thread, 10)
Ejemplo n.º 36
0
    def run(self):
        toolingapi_settings = context.get_toolingapi_settings()
        workflow_path = toolingapi_settings[
            "workspace"] + "/metadata/unpackaged/workflows"
        if not os.path.exists(workflow_path):
            sublime.error_message(message.WORKFLOW_PATH_CHECK)
            return

        self.window.run_command("show_panel", {
            "panel": "console",
            "toggle": False
        })

        processor.handle_parse_workflow()
Ejemplo n.º 37
0
def handle_create_component(data, component_name, component_type, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        # If create Succeed
        result = api.result
        status_code = result["status_code"]

        if status_code > 399:
            util.sublime_error_message(result)
            return

        # Get the created component id
        component_id = result.get("id")

        # Save it to component.sublime-settings
        s = sublime.load_settings(COMPONENT_METADATA_SETTINGS)
        username = toolingapi_settings["username"]
        components_dict = s.get(username)
        components_dict[component_type][component_name] = {
            "id": component_id,
            "url": post_url + "/" + component_id,
            "body": toolingapi_settings[component_type]["body"],
            "extension": toolingapi_settings[component_type]["extension"],
            "type": component_type,
            "is_test": False
        }
        s.set(username, components_dict)

        # Save settings and show success message
        sublime.save_settings(COMPONENT_METADATA_SETTINGS)
        print(message.SEPRATE.format(message.CREATE_SUCCESSFULLY))
        sublime.status_message(message.CREATE_SUCCESSFULLY)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    post_url = "/services/data/v27.0/sobjects/" + component_type
    thread = threading.Thread(target=api.post, args=(
        post_url,
        data,
    ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 38
0
    def run(self): 
        # Create Project Directory
        context.make_dir()

        # Get toolingapi_settings
        toolingapi_settings = context.get_toolingapi_settings()
        context.add_project_to_workspace(toolingapi_settings["workspace"])

        # Open Console
        self.window.run_command("show_panel", 
            {"panel": "console", "toggle": False})

        # Handle Refresh All
        processor.handle_refresh_components(toolingapi_settings)
Ejemplo n.º 39
0
    def run(self):
        toolingapi_settings = context.get_toolingapi_settings()
        workflow_path = toolingapi_settings[
            "workspace"] + "/metadata/unpackaged/objects"
        if not os.path.exists(workflow_path):
            sublime.error_message(message.SOBJECTS_PATH_CHECK)
            return

        # Open Console
        self.window.run_command("show_panel", {
            "panel": "console",
            "toggle": False
        })

        processor.handle_parse_validation_rule()
Ejemplo n.º 40
0
    def run(self):
        # Create Project Directory
        context.make_dir()

        # Get toolingapi_settings
        toolingapi_settings = context.get_toolingapi_settings()
        context.add_project_to_workspace(toolingapi_settings["workspace"])

        # Open Console
        self.window.run_command("show_panel", {
            "panel": "console",
            "toggle": False
        })

        # Handle Refresh All
        processor.handle_refresh_components(toolingapi_settings)
Ejemplo n.º 41
0
def populate_classes():
    """
    Get dict (Class Name => Class Id) which NamespacePrefix is null in whole org

    @return: {
        classname: classid
        ...
    }
    """
    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in globals()[], just return it
    component_metadata = sublime.load_settings(
        "component_metadata.sublime-settings")
    if component_metadata.has(username):
        return component_metadata.get(username).get("ApexClass")

    if username + "classes" in globals():
        return globals()[username + "classes"]

    # If sobjects is not exist in globals(), post request to pouplate it
    api = SalesforceApi(toolingapi_settings)
    query = "SELECT Id, Name, Body FROM ApexClass WHERE NamespacePrefix = null"
    thread = threading.Thread(target=api.query_all, args=(query, ))
    thread.start()

    while thread.is_alive() or api.result == None:
        time.sleep(1)

    classes = {}
    for record in api.result["records"]:
        name = record["Name"]
        body = record["Body"]
        component_attr = {"id": record["Id"]}
        if "@isTest" in body or "testMethod" in body or\
            "testmethod" in body or "test" in name or "Test" in name:

            component_attr["is_test"] = True
        else:
            component_attr["is_test"] = False

        classes[name] = component_attr

    globals()[username + "classes"] = classes
    return classes
Ejemplo n.º 42
0
def handle_describe_customfield(sobject, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        # If error
        if result["status_code"] > 399 :
            util.sublime_error_message(result)
            return

        # Get output csv dir
        workspace = context.get_toolingapi_settings().get("workspace")
        outputdir = workspace + "/describe/customfield"
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        # Open output csv
        output_file_dir = outputdir + "/" + sobject + ".csv"
        if util.is_python3x():
            fp = open(output_file_dir, "w", newline='')
        else:
            fp = open(output_file_dir, "wb")

        # Write list to csv
        util.list2csv(fp, result["records"])

        # Release fp
        fp.close()

        # Output log
        print(output_file_dir)

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    query = """SELECT Id,TableEnumOrId,DeveloperName,NamespacePrefix,FullName 
               FROM CustomField 
               WHERE TableEnumOrId='{sobject}'""".format(sobject=sobject)
    thread = threading.Thread(target=api.query_all, args=(query, True,))
    thread.start()
    handle_thread(thread, 10)
Ejemplo n.º 43
0
def populate_classes():
    """
    Get dict (Class Name => Class Id) which NamespacePrefix is null in whole org

    @return: {
        classname: classid
        ...
    }
    """
    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in globals()[], just return it
    component_metadata = sublime.load_settings("component_metadata.sublime-settings")
    if component_metadata.has(username):
        return component_metadata.get(username).get("ApexClass")

    if username + "classes" in globals():
        return globals()[username + "classes"]

    # If sobjects is not exist in globals(), post request to pouplate it
    api = SalesforceApi(toolingapi_settings)
    query = "SELECT Id, Name, Body FROM ApexClass WHERE NamespacePrefix = null"
    thread = threading.Thread(target=api.query_all, args=(query, ))
    thread.start()

    while thread.is_alive() or api.result == None:
        time.sleep(1)

    classes = {}
    for record in api.result["records"]:
        name = record["Name"]
        body = record["Body"]
        component_attr = {"id": record["Id"]}
        if "@isTest" in body or "testMethod" in body or\
            "testmethod" in body or "test" in name or "Test" in name:
            
            component_attr["is_test"] = True
        else:
            component_attr["is_test"] = False

        classes[name] = component_attr

    globals()[username + "classes"] = classes
    return classes
Ejemplo n.º 44
0
def handle_describe_layout(sobject, recordtype_name, recordtype_id, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        
        # If error
        if result["status_code"] > 399 :
            util.sublime_error_message(result)
            return

        # If totalSize is 0
        if "totalSize" in result and result["totalSize"] == 0 :
            util.sublime_error_message(result)
            return

        # Get output csv dir
        toolingapi_settings = context.get_toolingapi_settings()
        outputdir = toolingapi_settings["workspace"] + "/describe/layout"

        # If outputdir is not exist, just make it
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        output_file_dir = outputdir + "/" + sobject + "-" + recordtype_name + ".csv"

        if util.is_python3x():
            fp = open(output_file_dir, "w", newline='')
        else:
            fp = open(output_file_dir, "wb")
        util.parse_describe_layout_result(fp, result)
        
        print("Layout describe outputdir: " + output_file_dir)

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_layout, args=(sobject, recordtype_id, ))
    thread.start()
    handle_thread(thread, 120)
Ejemplo n.º 45
0
def handle_create_component(data, component_name, component_type, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda:handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return
        
        # If create Succeed
        result = api.result
        status_code = result["status_code"]
        
        if status_code > 399:
            util.sublime_error_message(result)
            return
        
        # Get the created component id
        component_id = result.get("id")
        
        # Save it to component.sublime-settings
        s = sublime.load_settings(COMPONENT_METADATA_SETTINGS)
        username = toolingapi_settings["username"]
        components_dict = s.get(username)
        components_dict[component_type][component_name] = {
            "id": component_id,
            "url": post_url + "/" + component_id,
            "body": toolingapi_settings[component_type]["body"],
            "extension": toolingapi_settings[component_type]["extension"],
            "type": component_type,
            "is_test": False
        }
        s.set(username, components_dict)

        # Save settings and show success message
        sublime.save_settings(COMPONENT_METADATA_SETTINGS)
        print (message.SEPRATE.format(message.CREATE_SUCCESSFULLY))
        sublime.status_message(message.CREATE_SUCCESSFULLY)
                
    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    post_url = "/services/data/v27.0/sobjects/" + component_type
    thread = threading.Thread(target=api.post, args=(post_url, data, ))
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 46
0
def get_component_attribute(file_name):
    # Get toolingapi settings
    toolingapi_settings = context.get_toolingapi_settings()

    # Get component type
    component_name = util.get_component_name(file_name)
    component_type = util.get_component_type(file_name)

    # If component type is not in range, just show error message
    if component_type not in toolingapi_settings["component_types"]:
        return

    # Get component_url and component_id
    username = toolingapi_settings["username"]
    component_attribute = util.get_component_attribute(username, file_name)

    return (component_attribute, component_name)
Ejemplo n.º 47
0
def get_component_attribute(file_name):
    # Get toolingapi settings
    toolingapi_settings = context.get_toolingapi_settings()

    # Get component type
    component_name = util.get_component_name(file_name)
    component_type = util.get_component_type(file_name)

    # If component type is not in range, just show error message
    if component_type not in toolingapi_settings["component_types"]:
        return

    # Get component_url and component_id
    username = toolingapi_settings["username"]
    component_attribute = util.get_component_attribute(username, file_name)

    return (component_attribute, component_name)
Ejemplo n.º 48
0
    def run(self, startURL=""):
        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Combine Login URL
        show_params = {
            "un": toolingapi_settings["username"],
            "pw": toolingapi_settings["password"],
            "startURL": startURL
        }

        if util.is_python3x():
            show_params = urllib.parse.urlencode(show_params)
        else:
            show_params = urllib.urlencode(show_params)

        show_url = toolingapi_settings["login_url"] + '?%s' % show_params

        # Open this component in salesforce web
        webbrowser.open_new_tab(show_url)
Ejemplo n.º 49
0
    def run(self, startURL=""):
        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Combine Login URL
        show_params = {
            "un": toolingapi_settings["username"],
            "pw": toolingapi_settings["password"],
            "startURL": startURL
        }

        if util.is_python3x():
            show_params = urllib.parse.urlencode(show_params)
        else:
            show_params = urllib.urlencode(show_params)

        show_url = toolingapi_settings["login_url"] + '?%s' % show_params

        # Open this component in salesforce web
        webbrowser.open_new_tab(show_url)
Ejemplo n.º 50
0
def handle_generate_all_workbooks(timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return
        
        # If succeed
        result = api.result
        for sobject in result:
            thread = threading.Thread(target=api.generate_workbook, args=(sobject, ))
            thread.start()

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global_common, args=())
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 51
0
    def on_post_save(self, view):
        # Get current file name and Read file content
        file_name = view.file_name()
        try:
            body = open(file_name, encoding="utf-8").read()
        except:
            body = open(file_name, "rb").read()

        # Get component_name amd component_type
        component_name = util.get_component_name(file_name)
        component_type = util.get_component_type(file_name)

        # If this file is not ApexTrigger, ApexComponent,
        # ApexPage or ApexClass, just return
        if component_type not in [
                "ApexClass", "ApexPage", "ApexComponent", "ApexTrigger",
                "StaticResource"
        ]:
            return

        # Get toolingapi settings
        toolingapi_settings = context.get_toolingapi_settings()

        # Get component extension
        component_extension = toolingapi_settings[component_type]["extension"]

        # Get Workspace, if not exist, make it
        workspace = toolingapi_settings[
            "workspace"] + "/history/" + component_type
        if not os.path.exists(workspace):
            os.makedirs(workspace)

        # Backup current file
        time_stamp = time.strftime("%Y-%m-%d-%H-%M", time.localtime())
        fp = open(workspace + "/" + component_name + "-" +\
            time_stamp + component_extension, "w")

        fp.write(body)
        fp.close()
Ejemplo n.º 52
0
def handle_backup_all_sobjects(timeout=120):
    """
    Firstly get all common used sobject names, and then use bulkapi to backup all
    """

    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        sobjects = api.result
        bulkapi.handle_bulkapi_query(sobjects)

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global_common, args=())
    thread.start()
    handle_thread(thread, 10)
Ejemplo n.º 53
0
def populate_sobject_recordtypes():
    """
    Get dict ([sobject, recordtype name] => recordtype id) in whole org

    @return: {
        username + "sobject_recordtypes": {
            sobject + rtname: rtid
        }
        ...
    }
    """

    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in globals()[], just return it
    if (username + "sobject_recordtypes") in globals(): 
        return globals()[username + "sobject_recordtypes"]

    # If sobjects is not exist in globals(), post request to pouplate it
    api = SalesforceApi(toolingapi_settings)
    query = "SELECT Id, Name, SobjectType FROM RecordType"
    thread = threading.Thread(target=api.query_all, args=(query, ))
    thread.start()

    while thread.is_alive() or api.result == None:
        time.sleep(1)

    records = api.result["records"]
    sobject_recordtypes = {}
    for recordtype in records:
        sobjectype = recordtype["SobjectType"]
        rtname = recordtype["Name"]
        rtid = recordtype["Id"]
        sobject_recordtypes[sobjectype + ", " + rtname] = rtid

    globals()[username + "sobject_recordtypes"] = sobject_recordtypes
    return sobject_recordtypes  
Ejemplo n.º 54
0
def populate_sobject_recordtypes():
    """
    Get dict ([sobject, recordtype name] => recordtype id) in whole org

    @return: {
        username + "sobject_recordtypes": {
            sobject + rtname: rtid
        }
        ...
    }
    """

    # Get username
    toolingapi_settings = context.get_toolingapi_settings()
    username = toolingapi_settings["username"]

    # If sobjects is exist in globals()[], just return it
    if (username + "sobject_recordtypes") in globals():
        return globals()[username + "sobject_recordtypes"]

    # If sobjects is not exist in globals(), post request to pouplate it
    api = SalesforceApi(toolingapi_settings)
    query = "SELECT Id, Name, SobjectType FROM RecordType"
    thread = threading.Thread(target=api.query_all, args=(query, ))
    thread.start()

    while thread.is_alive() or api.result == None:
        time.sleep(1)

    records = api.result["records"]
    sobject_recordtypes = {}
    for recordtype in records:
        sobjectype = recordtype["SobjectType"]
        rtname = recordtype["Name"]
        rtid = recordtype["Id"]
        sobject_recordtypes[sobjectype + ", " + rtname] = rtid

    globals()[username + "sobject_recordtypes"] = sobject_recordtypes
    return sobject_recordtypes
Ejemplo n.º 55
0
def handle_backup_all_sobjects(timeout=120):
    """
    Firstly get all common used sobject names, and then use bulkapi to backup all
    """
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        sobjects = api.result
        bulkapi.handle_bulkapi_query(sobjects)

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global_common, args=())
    thread.start()
    handle_thread(thread, 10)
Ejemplo n.º 56
0
def handle_parse_validation_rule(timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        sobjects = api.result
        util.parse_validation_rule(toolingapi_settings, sobjects)

        print("Your validation rules are exported to " +\
            toolingapi_settings["workspace"] + "/describe/validation rules/validation rules.csv")

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global_common, args=())
    thread.start()
    handle_thread(thread, 10)
Ejemplo n.º 57
0
def handle_generate_all_workbooks(timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        result = api.result
        for sobject in result:
            thread = threading.Thread(target=api.generate_workbook,
                                      args=(sobject, ))
            thread.start()

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global_common, args=())
    thread.start()
    handle_thread(thread, timeout)
Ejemplo n.º 58
0
def handle_parse_validation_rule(timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda: handle_thread(thread, timeout),
                                timeout)
            return
        elif api.result == None:
            sublime.status_message(message.TOOLING_API_CONNECTING_FAILED)
            return

        # If succeed
        sobjects = api.result
        util.parse_validation_rule(toolingapi_settings, sobjects)

        print("Your validation rules are exported to " +\
            toolingapi_settings["workspace"] + "/describe/validation rules/validation rules.csv")

    print(message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.describe_global_common, args=())
    thread.start()
    handle_thread(thread, 10)
Ejemplo n.º 59
0
def handle_save_component(component_name, component_attribute, body, timeout=120):
    def handle_thread(thread, timeout):
        if thread.is_alive():
            sublime.set_timeout(lambda:handle_thread(thread, timeout), timeout)
            return
        elif api.result == None:
            sublime.error_message(message.AUTHORIZATION_FAILED_MESSAGE)
            return

        result = api.result
        if "success" in result and result["success"]:
            print (message.SEPRATE.format(message.DEPLOY_SUCCESSFULLY))
            sublime.status_message(message.DEPLOY_SUCCESSFULLY)
        elif "message" in result:
            print (message.SEPRATE.format(result["message"]))
            sublime.status_message(result["message"])

    print (message.WAIT_FOR_A_MOMENT)
    toolingapi_settings = context.get_toolingapi_settings()
    api = SalesforceApi(toolingapi_settings)
    thread = threading.Thread(target=api.save_component, args=(component_attribute, body, ))
    thread.start()
    handle_thread(thread, timeout)