Esempio n. 1
0
    def get_formatted_result(self, label):
        """
        Runs the query and retrieves results tagged as "label".

        :param label: the tag of the results to be extracted out of
          the query rows.
        :type label: str
        :return: a list of the query results
        """

        results = super().get_formatted_result(label)

        if self._result_type == 'with_outgoing':
            result_name = 'incoming'
        elif self._result_type == 'with_incoming':
            result_name = 'outgoing'
        else:
            result_name = self.__label__

        from aiida.restapi.common.identifiers import construct_full_type

        for node_entry in results[result_name]:
            # construct full_type and add it to every node
            try:
                node_entry['full_type'] = construct_full_type(
                    node_entry['node_type'], node_entry['process_type'])
            except KeyError:
                node_entry['full_type'] = None

        return results
Esempio n. 2
0
    def get_formatted_result(self, label):
        """
        Runs the query and retrieves results tagged as "label".

        :param label: the tag of the results to be extracted out of
          the query rows.
        :type label: str
        :return: a list of the query results
        """

        results = super().get_formatted_result(label)

        if self._result_type == 'with_outgoing':
            result_name = 'incoming'
        elif self._result_type == 'with_incoming':
            result_name = 'outgoing'
        else:
            result_name = self.__label__

        for node_entry in results[result_name]:
            # construct full_type and add it to every node
            node_entry['full_type'] = (
                construct_full_type(node_entry.get('node_type'), node_entry.get('process_type'))
                if node_entry.get('node_type') or node_entry.get('process_type') else None
            )

        return results
Esempio n. 3
0
    def get_all_download_formats(full_type=None):
        """
        returns dict of possible node formats for all available node types
        """

        all_formats = {}

        if full_type:
            try:
                node_cls = load_entry_point_from_full_type(full_type)
            except (TypeError, ValueError):
                raise RestInputValidationError(f'The full type {full_type} is invalid.')
            except EntryPointError:
                raise RestFeatureNotAvailable('The download formats for this node type are not available.')

            try:
                available_formats = node_cls.get_export_formats()
                all_formats[full_type] = available_formats
            except AttributeError:
                pass
        else:
            entry_point_group = 'aiida.data'

            for name in get_entry_point_names(entry_point_group):
                try:
                    node_cls = load_entry_point(entry_point_group, name)
                    available_formats = node_cls.get_export_formats()
                except (AttributeError, LoadingEntryPointError):
                    continue

                if available_formats:
                    full_type = construct_full_type(node_cls.class_node_type, '')
                    all_formats[full_type] = available_formats

        return all_formats
Esempio n. 4
0
    def get_all_download_formats(full_type=None):
        """
        returns dict of possible node formats for all available node types
        """
        from aiida.plugins.entry_point import load_entry_point, get_entry_point_names
        from aiida.restapi.common.identifiers import load_entry_point_from_full_type, construct_full_type
        from aiida.common import EntryPointError
        from aiida.common.exceptions import LoadingEntryPointError
        from aiida.restapi.common.exceptions import RestFeatureNotAvailable, RestInputValidationError

        all_formats = {}

        if full_type:
            try:
                node_cls = load_entry_point_from_full_type(full_type)
            except (TypeError, ValueError):
                raise RestInputValidationError(
                    'The full type {} is invalid.'.format(full_type))
            except EntryPointError:
                raise RestFeatureNotAvailable(
                    'The download formats for this node type are not available.'
                )

            try:
                available_formats = node_cls.get_export_formats()
                all_formats[full_type] = available_formats
            except AttributeError:
                pass
        else:
            entry_point_group = 'aiida.data'

            for name in get_entry_point_names(entry_point_group):
                try:
                    node_cls = load_entry_point(entry_point_group, name)
                except LoadingEntryPointError:
                    pass
                else:
                    node_cls.get_export_formats()
                try:
                    available_formats = node_cls.get_export_formats()
                    if available_formats:
                        full_type = construct_full_type(
                            node_cls.class_node_type, '')
                        all_formats[full_type] = available_formats
                except AttributeError:
                    pass
        return all_formats