Example #1
0
File: metadata.py Project: azam/mm
def get_org_metadata(raw=False, selectBasedOnPackageXml=False, selectedIds=[], keyword=None, **kwargs):
    project = config.project
    if project.get_is_metadata_indexed():
        if raw:
            org_metadata_raw = util.get_file_as_string(os.path.join(project.location,"config",".org_metadata"))
            org_index = json.loads(org_metadata_raw)
            if selectBasedOnPackageXml:
                project.select_metadata_based_on_package_xml(org_index)
            elif len(selectedIds) > 0 or keyword != None:
                if keyword != None:
                    crawlJson.setVisibility(org_index, keyword)
                if len(selectedIds) > 0:
                    crawlJson.setChecked(org_index, selectedIds)
            return json.dumps(org_index)
        else:
            org_index = util.parse_json_from_file(os.path.join(project.location,"config",".org_metadata"))
            if selectBasedOnPackageXml:
                project.select_metadata_based_on_package_xml(org_index)
            elif len(selectedIds) > 0 or keyword != None:
                if keyword != None:
                    crawlJson.setVisibility(org_index, keyword)
                if len(selectedIds) > 0:
                    crawlJson.setChecked(org_index, selectedIds)
            return org_index
    else:
        IndexMetadataCommand(params=self.params).execute()
        org_index = util.parse_json_from_file(os.path.join(project.location,"config",".org_metadata"))
        project.select_metadata_based_on_package_xml(org_index)
        return org_index
Example #2
0
def get_org_metadata(raw=False, selectBasedOnPackageXml=False, selectedIds=[], keyword=None, **kwargs):
    project = config.project
    if project.get_is_metadata_indexed():
        if raw:
            org_metadata_raw = util.get_file_as_string(os.path.join(project.location,"config",".org_metadata"))
            org_index = json.loads(org_metadata_raw)
            if selectBasedOnPackageXml:
                project.select_metadata_based_on_package_xml(org_index)
            elif len(selectedIds) > 0 or keyword != None:
                if keyword != None:
                    crawlJson.setVisibility(org_index, keyword)
                if len(selectedIds) > 0:
                    crawlJson.setChecked(org_index, selectedIds)
            return json.dumps(org_index)
        else:
            org_index = util.parse_json_from_file(os.path.join(project.location,"config",".org_metadata"))
            if selectBasedOnPackageXml:
                project.select_metadata_based_on_package_xml(org_index)
            elif len(selectedIds) > 0 or keyword != None:
                if keyword != None:
                    crawlJson.setVisibility(org_index, keyword)
                if len(selectedIds) > 0:
                    crawlJson.setChecked(org_index, selectedIds)
            return org_index
    else:
        IndexMetadataCommand(params=self.params).execute()
        org_index = util.parse_json_from_file(os.path.join(project.location,"config",".org_metadata"))
        project.select_metadata_based_on_package_xml(org_index)
        return org_index
Example #3
0
    def execute(self):
        if 'script_name' in self.params:  #running an apex script
            self.params["body"] = util.get_file_as_string(
                os.path.join(config.project.location, "apex-scripts",
                             self.params["script_name"]))
        if 'debug_categories' not in self.params and not os.path.isfile(
                os.path.join(config.project.location, "config",
                             ".apex_script")):
            self.params["debug_categories"] = [{
                "category": "Apex_code",
                "level": "DEBUG"
            }]
        elif os.path.isfile(
                os.path.join(config.project.location, "config",
                             ".apex_script")):
            log_settings = util.parse_json_from_file(
                os.path.join(config.project.location, "config",
                             ".apex_script"))
            categories = []
            levels = log_settings["levels"]
            for category in levels.keys():
                categories.append({
                    "category": category,
                    "level": levels[category]
                })
            self.params["debug_categories"] = categories
        elif 'debug_categories' not in self.params:
            self.params["debug_categories"] = [{
                "category": "Apex_code",
                "level": "DEBUG"
            }]
        return_log = self.params.get("return_log", True)

        execute_result = config.sfdc_client.execute_apex(self.params)
        result = {
            'column': execute_result['column'],
            'compileProblem': execute_result['compileProblem'],
            'compiled': execute_result['compiled'],
            'exceptionMessage': execute_result['exceptionMessage'],
            'exceptionStackTrace': execute_result['exceptionStackTrace'],
            'line': execute_result['line'],
            'success': execute_result['success'],
        }
        if 'log' in execute_result and return_log:
            result['log'] = execute_result['log']
        if result['success']:
            log_apex = config.connection.get_plugin_client_setting(
                'mm_log_anonymous_apex', False)
            if log_apex:
                location = config.project.log_anonymous_apex(
                    self.params['body'], execute_result['log'],
                    self.params.get("script_name", None))
                result["log_location"] = location
        return util.generate_response(result)
Example #4
0
File: misc.py Project: azam/mm
    def execute(self):
        if 'script_name' in self.params: #running an apex script
            self.params["body"] = util.get_file_as_string(os.path.join(config.project.location,"apex-scripts",self.params["script_name"]))
        if 'debug_categories' not in self.params and not os.path.isfile(os.path.join(config.project.location,"config",".apex_script")):
            self.params["debug_categories"] = [
                {
                    "category"  : "Apex_code",
                    "level"     :  "DEBUG"
                }
            ]
        elif os.path.isfile(os.path.join(config.project.location,"config",".apex_script")):
            log_settings = util.parse_json_from_file(os.path.join(config.project.location,"config",".apex_script"))
            categories = []
            levels = log_settings["levels"]
            for category in levels.keys():
                categories.append({
                    "category"  : category,
                    "level"     : levels[category]
                })
            self.params["debug_categories"] = categories
        elif 'debug_categories' not in self.params:
            self.params["debug_categories"] = [
                {
                    "category"  : "Apex_code",
                    "level"     :  "DEBUG"
                }
            ]
        return_log = self.params.get("return_log", True)

        execute_result = config.sfdc_client.execute_apex(self.params)
        result = {
            'column'                : execute_result['column'],
            'compileProblem'        : execute_result['compileProblem'],
            'compiled'              : execute_result['compiled'],
            'exceptionMessage'      : execute_result['exceptionMessage'],
            'exceptionStackTrace'   : execute_result['exceptionStackTrace'],
            'line'                  : execute_result['line'],
            'success'               : execute_result['success'],
        }
        if 'log' in execute_result and return_log:
            result['log'] = execute_result['log']
        if result['success']:
            log_apex = config.connection.get_plugin_client_setting('mm_log_anonymous_apex', False)
            if log_apex:
                location = config.project.log_anonymous_apex(self.params['body'], execute_result['log'], self.params.get("script_name", None))
                result["log_location"] = location
        return util.generate_response(result)
Example #5
0
    def retrieve(self, **kwargs):
        # request = {
        #   'RetrieveRequest': {
        #     'unpackaged': {
        #       'types': {
        #         'ApexTrigger': '*'
        #       }
        #     },
        #     'apiVersion': {
        #       25.0
        #     }
        #   }
        # }
        # package = {
        #     'unpackaged' : {
        #         'types' : [
        #             {
        #                 "members": "*",
        #                 "name": "ApexClass"
        #             }
        #         ]
        #     }
        # }
        package_dict = None
        request_payload = None

        debug('retrieve request: ')
        debug(kwargs['package'])

        if 'package' in kwargs and type(kwargs['package']) is not dict:
            #if package is location of package.xml, we'll parse the xml and create a request
            package_dict = xmltodict.parse(
                util.get_file_as_string(kwargs['package']))
            api_version = package_dict['Package']['version']
            package_dict['unpackaged'] = package_dict.pop('Package')
            package_dict['unpackaged'].pop('version')
            package_dict['unpackaged'].pop("@xmlns", None)
            package_dict['unpackaged'].pop("#text", None)
            package_dict['apiVersion'] = api_version
            types = package_dict['unpackaged']['types']
            if type(types) is not list:
                types = [types]
            if type(package_dict['unpackaged']['types']) is not list:
                package_dict['unpackaged']['types'] = [
                    package_dict['unpackaged']['types']
                ]
            requested_types = []
            if 'type' in kwargs and kwargs['type'] != None and kwargs[
                    'type'] != '':  #if the request is for a certain type, only request that type
                for i, val in enumerate(types):
                    if val['name'] == kwargs['type']:
                        requested_types.append(val)
                package_dict['unpackaged']['types'] = requested_types
                types = requested_types
            for i, val in enumerate(types):
                try:
                    package_dict['unpackaged']['types'][i].pop("#text", None)
                except:
                    package_dict['unpackaged']['types'].pop("#text", None)

            #if custom object is asterisked, we need to explictly retrieve standard objects
            for t in package_dict['unpackaged']['types']:
                if 'name' in t:
                    metadata_type_def = util.get_meta_type_by_name(t['name'])
                    if 'inFolder' in metadata_type_def and metadata_type_def[
                            'inFolder']:
                        if 'members' in t and type(t['members']) is not list:
                            if t['members'] == "*" or t['members'] == []:
                                mlist = self.listMetadata(t['name'], False)
                                objs = []
                                for obj in mlist:
                                    objs.append(obj['fullName'])
                                objs.sort()
                                t['members'] = objs
                    elif t['name'] == 'CustomObject':
                        if 'members' in t and type(t['members']) is not list:
                            if t['members'] == "*":
                                mlist = self.listMetadata(
                                    'CustomObject', False)
                                objs = []
                                for obj in mlist:
                                    if ('__c') not in mlist:
                                        objs.append(obj['fullName'])
                                objs.append("*")
                                objs.sort()
                                t['members'] = objs

            request_payload = package_dict

        elif 'package' in kwargs and type(kwargs['package']) is dict:
            package = kwargs['package']
            if 'unpackaged' not in package:
                #{ "ApexClass"    : ["MultiselectControllerTest","MultiselectController"] }
                type_array = []
                for i, metadata_type in enumerate(package):
                    member_value = package[metadata_type]
                    type_array.append({
                        "name": metadata_type,
                        "members": member_value
                    })

                package = {
                    'unpackaged': {
                        'types': type_array
                    },
                    'apiVersion': util.SFDC_API_VERSION
                }

            #if custom object is asterisked, we need to explictly retrieve standard objects
            for t in package['unpackaged']['types']:
                debug('----> ')
                debug(t)
                if 'name' in t:
                    metadata_type_def = util.get_meta_type_by_name(t['name'])
                    debug(metadata_type_def)
                    if 'inFolder' in metadata_type_def and metadata_type_def[
                            'inFolder']:
                        if 'members' in t and (t['members'] == "*"
                                               or t['members'] == []):
                            #list_request_name = self.__transformFolderMetadataNameForListRequest(t['name'])
                            #mlist = self.listMetadata(list_request_name, False)
                            mlist = self.listMetadataAdvanced(t['name'])
                            objs = []
                            for obj in mlist:
                                debug('---obj')
                                debug(obj)
                                objs.append(obj['title'])
                                if 'children' in obj and type(
                                        obj['children'] is list):
                                    for child in obj['children']:
                                        objs.append(obj['title'] + "/" +
                                                    child['title'])
                            objs.sort()
                            t['members'] = objs
                    elif t['name'] == 'CustomObject':
                        if 'members' in t and type(t['members']) is not list:
                            if t['members'] == "*":
                                mlist = self.listMetadata(
                                    'CustomObject', False)
                                objs = []
                                for obj in mlist:
                                    if ('__c') not in mlist:
                                        objs.append(obj['fullName'])
                                objs.append("*")
                                objs.sort()
                                t['members'] = objs

            request_payload = package
            debug('---request payload---')
            debug(request_payload)
        result = self._handleResultTyping(
            self._sforce.service.retrieve(request_payload))
        if result.done == False:
            self._waitForRetrieveRequest(result.id)
            return self._getRetrieveBody(result.id)
        else:
            return result
Example #6
0
File: metadata.py Project: azam/mm
    def retrieve(self, **kwargs):
        # request = {
        #   'RetrieveRequest': {
        #     'unpackaged': {
        #       'types': {
        #         'ApexTrigger': '*'
        #       }
        #     },
        #     'apiVersion': {
        #       25.0
        #     }
        #   }
        # }
        # package = {
        #     'unpackaged' : {
        #         'types' : [
        #             {
        #                 "members": "*", 
        #                 "name": "ApexClass"
        #             }
        #         ]
        #     }
        # }
        package_dict = None
        request_payload = None

        debug('retrieve request: ')
        debug(kwargs['package'])
        
        if 'package' in kwargs and type(kwargs['package']) is not dict: 
            #if package is location of package.xml, we'll parse the xml and create a request
            package_dict = xmltodict.parse(util.get_file_as_string(kwargs['package']))
            api_version = package_dict['Package']['version']
            package_dict['unpackaged'] = package_dict.pop('Package')
            package_dict['unpackaged'].pop('version')
            package_dict['unpackaged'].pop("@xmlns", None)
            package_dict['unpackaged'].pop("#text", None)
            package_dict['apiVersion'] = api_version
            types = package_dict['unpackaged']['types']
            if type(types) is not list:
                types = [types]
            if type(package_dict['unpackaged']['types']) is not list:
                package_dict['unpackaged']['types'] = [package_dict['unpackaged']['types']]
            requested_types = []
            if 'type' in kwargs and kwargs['type'] != None and kwargs['type'] != '': #if the request is for a certain type, only request that type
                for i, val in enumerate(types):
                    if val['name'] == kwargs['type']:
                        requested_types.append(val)
                package_dict['unpackaged']['types'] = requested_types
                types = requested_types
            for i, val in enumerate(types):
                try:
                    package_dict['unpackaged']['types'][i].pop("#text", None)
                except:
                    package_dict['unpackaged']['types'].pop("#text", None)

            #if custom object is asterisked, we need to explictly retrieve standard objects
            for t in package_dict['unpackaged']['types']:
                if 'name' in t:
                    metadata_type_def = util.get_meta_type_by_name(t['name'])
                    if 'inFolder' in metadata_type_def and metadata_type_def['inFolder']:
                        if 'members' in t and type(t['members']) is not list:
                            if t['members'] == "*" or t['members'] == []:
                                mlist = self.listMetadata(t['name'], False)
                                objs = []
                                for obj in mlist:
                                    objs.append(obj['fullName'])
                                objs.sort()
                                t['members'] = objs
                    elif t['name'] == 'CustomObject':
                        if 'members' in t and type(t['members']) is not list:
                            if t['members'] == "*":
                                mlist = self.listMetadata('CustomObject', False)
                                objs = []
                                for obj in mlist:
                                    if ('__c') not in mlist:
                                        objs.append(obj['fullName'])
                                objs.append("*")
                                objs.sort()
                                t['members'] = objs

            request_payload = package_dict

        elif 'package' in kwargs and type(kwargs['package']) is dict:
            package = kwargs['package']
            if 'unpackaged' not in package:
                #{ "ApexClass"    : ["MultiselectControllerTest","MultiselectController"] }
                type_array = []
                for i, metadata_type in enumerate(package):
                    member_value = package[metadata_type]
                    type_array.append({ "name" : metadata_type, "members" : member_value })

                package = {
                    'unpackaged' : {
                        'types' : type_array
                    },
                    'apiVersion' : util.SFDC_API_VERSION
                }
            
            #if custom object is asterisked, we need to explictly retrieve standard objects
            for t in package['unpackaged']['types']:
                debug('----> ')
                debug(t)
                if 'name' in t:
                    metadata_type_def = util.get_meta_type_by_name(t['name'])
                    debug(metadata_type_def)
                    if 'inFolder' in metadata_type_def and metadata_type_def['inFolder']:
                        if 'members' in t and (t['members'] == "*" or t['members'] == []):
                            #list_request_name = self.__transformFolderMetadataNameForListRequest(t['name'])
                            #mlist = self.listMetadata(list_request_name, False)
                            mlist = self.listMetadataAdvanced(t['name'])
                            objs = []
                            for obj in mlist:
                                debug('---obj')
                                debug(obj)
                                objs.append(obj['title'])
                                if 'children' in obj and type(obj['children'] is list):
                                    for child in obj['children']:
                                        objs.append(obj['title']+"/"+child['title'])
                            objs.sort()
                            t['members'] = objs
                    elif t['name'] == 'CustomObject':              
                        if 'members' in t and type(t['members']) is not list:
                            if t['members'] == "*":
                                mlist = self.listMetadata('CustomObject', False)
                                objs = []
                                for obj in mlist:
                                    if ('__c') not in mlist:
                                        objs.append(obj['fullName'])
                                objs.append("*")
                                objs.sort()
                                t['members'] = objs
            
            request_payload = package
            debug('---request payload---')
            debug(request_payload)
        result = self._handleResultTyping(self._sforce.service.retrieve(request_payload))
        if result.done == False:
            self._waitForRetrieveRequest(result.id)
            return self._getRetrieveBody(result.id)
        else:
            return result