public function export(Export\ExportStream $stream, Export\ExportContext $context) {
        $this->datasourceName = $context->get('datasourceName');

        $dashboards = array();
        foreach (gd_dashboard_findall_by_datasource(LOAD_ENTITY,$this->datasourceName) as $dashboard) {
            $export = new stdClass();

            $export->id = (int) $dashboard->nid;
            $export->title = $dashboard->title;

            $export->uuid = get_node_field_value($dashboard,'field_dashboard_uuid',0,'value',true);
            $export->description = get_node_field_value($dashboard,'field_dashboard_desc');
            $export->public = (int) get_node_field_value($dashboard,'field_dashboard_public');
            $export->custom_view = get_node_field_value($dashboard,'field_dashboard_custom_view');
            $export->reports = (array) get_node_field_node_ref($dashboard,'field_dashboard_reports',null);
            $export->config = json_decode(get_node_field_value($dashboard,'field_dashboard_config',0,'value',true));

            $export->alias = array();
            if (!empty($dashboard->field_dashboard_alias)) {
                foreach($dashboard->field_dashboard_alias[$dashboard->language] as $alias) {
                    $export->alias[] = $alias['value'];
                }
            }

            $export->tags = array();
            if (!empty($dashboard->field_dashboard_tags)) {
                foreach($dashboard->field_dashboard_tags[$dashboard->language] as $tag) {
                    $export->tags[] = $tag['tid'];
                }
            }

            // replace report nid with report uuid
            $reportNodes = gd_report_load_multiple($export->reports);
            foreach ( $export->reports as $key => $value ) {
                foreach ( $reportNodes as $node ) {
                    if ( $node->nid == $value ) {
                        $export->reports[$key] = get_node_field_value($node,'field_report_uuid',0,'value',true);
                    }
                }
            }

            // replace references with uuid
            $this->processConfig($export);

            $dashboards[] = $export;
        }
        $stream->set('dashboards',$dashboards);
    }
    public function export(Export\ExportStream $stream, Export\ExportContext $context) {

        $metamodel = data_controller_get_metamodel();
        $datasetUuidMappings = array();

        // get datasets
        $datasetNids = array();
        foreach ($metamodel->datasets as $dataset) {
            $datasetUuidMappings[$dataset->source] = DatasetExportHelper::getExportDatasetName($dataset->name, $metamodel);
            if (!isset($dataset->nid)) {
                continue;
            }
            $datasetNids[] = $dataset->nid;
        }

        // find all references with above reference points
        $measures = array();
        if (!empty($datasetNids)) {
            $measureNodes = gd_measure_get_measures_4_dataset($datasetNids, LOAD_ENTITY);
            if (!empty($measureNodes)) {
                foreach ( $measureNodes as $measure ) {
                    $export = new stdClass();

                    $export->id = (int) $measure->nid;
                    $export->title = $measure->title;

                    $export->sysname = get_node_field_value($measure,'field_measure_sysname');
                    $export->description = get_node_field_value($measure,'field_measure_desc');

                    $dataset = node_load(get_node_field_value($measure, 'field_measure_dataset', 0, 'nid'));
                    $export->dataset = get_node_field_value($dataset, 'field_dataset_uuid');

                    $function = get_node_field_value($measure,'field_measure_function');

                    foreach($datasetUuidMappings as $source => $uuid) {
                        $function = str_replace($source, $uuid, $function);
                    }

                    $export->function = $function;

                    $measures[] = $export;
                }
            }
        }

        $stream->set('measures',$measures);
    }
    public function export(Export\ExportStream $stream, Export\ExportContext $context) {
        $datasource = gd_datasource_get_active();
        $readOnly = gd_datasource_is_property($datasource, 'readonly');
        if ($readOnly) {
            return;
        }

        $metamodel = data_controller_get_metamodel();

        // get datasets
        $datasets = array();
        foreach ($metamodel->datasets as $dataset) {
            if (!isset($dataset->nid)) {
                continue;
            }
            $datasets[] = $dataset;
        }

        $stream->set('datasets',$datasets);
    }
    public function export(Export\ExportStream $stream, Export\ExportContext $context) {
        $metamodel = data_controller_get_metamodel();

        $reports = array();
        foreach (gd_report_findall_by_datasource(LOAD_ENTITY,$context->get('datasourceName')) as $report) {
            $export = new stdClass();

            $export->id = (int) $report->nid;
            $export->title = $report->title;

            $export->description = get_node_field_value($report,'field_report_desc',0,'value');
            $export->uuid = get_node_field_value($report,'field_report_uuid',0,'value',true);
            $export->config = json_decode(get_node_field_value($report,'field_report_conf',0,'value',true));
            $export->custom_view = get_node_field_value($report,'field_report_custom_view');
            $export->datasets = (array) get_node_field_value($report,'field_report_dataset_sysnames',null,'value',true);
            $export->tags = array();
            if (!empty($report->field_report_tags)) {
                foreach($report->field_report_tags[$report->language] as $tag) {
                    $export->tags[] = $tag['tid'];
                }
            }

            // replace dataset name with dataset uuid
            foreach ( $export->datasets as $key => $value ) {
                $dataset = $metamodel->getDataset($value);
                if (isset($dataset->uuid)) {
                    $export->datasets[$key] = $dataset->uuid;
                } else {
                    $export->datasets[$key] = NameSpaceHelper::removeNameSpace($dataset->name);
                }
            }

            // replace dataset name with dataset uuid
            $this->processConfig($export->config);

            $reports[] = $export;
        }
        $stream->set('reports',$reports);
    }
    public function export(Export\ExportStream $stream, Export\ExportContext $context) {
        $datasource = gd_datasource_get_active();
        $readOnly = gd_datasource_is_property($datasource, 'readonly');
        if ($readOnly) {
            return;
        }

        $metamodel = data_controller_get_metamodel();

        // get reference points that have ref to the dataset in this datamart
        $datasetNames = array();
        foreach ( $stream->get('datasets') as $d ) {
            $datasetNames[] = $d->name;
        }

        $referencePoints = array();
        $referencePointNodes = gd_reference_get_reference_points_by_dataset($datasetNames, LOAD_ENTITY);
        $referencePointNids = array();
        foreach ( $referencePointNodes as $ref_point ) {
            $export = new stdClass();

            $export->id = (int) $ref_point->nid;
            $export->title = $ref_point->title;

            $dataset = $metamodel->getDataset(get_node_field_value($ref_point,'field_ref_point_dataset_sysname',0,'value',true));
            $export->dataset = $dataset->uuid;

            $export->columns = array();
            foreach ( (array) get_node_field_value($ref_point,'field_ref_point_column_sysname',null) as $column ) {
                $export->columns[] = $column;
            }

            $referencePoints[] = $export;
            $referencePointNids[] = (int) $ref_point->nid;
        }

        // find all references with above reference points
        $references = array();
        $referenceNodes = gd_reference_get_references_by_reference_points($referencePointNids, LOAD_ENTITY);
        foreach ( $referenceNodes as $reference ) {
            $export = new stdClass();

            $export->id = (int) $reference->nid;
            $export->title = $reference->title;

            $export->sysname = get_node_field_value($reference,'field_reference_sysname');

            foreach ( (array) get_node_field_node_ref($reference,'field_reference_point',null) as $referencePointNid ) {
                foreach ( $referencePoints as $referencePoint ){
                    if ( $referencePointNid == $referencePoint->id ) {
                        $export->referencePoints[] = $referencePoint;
                    }
                }
            }

            if ( empty($export->referencePoints) ) {
                throw new Exception('Reference missing reference points.');
            }

            $references[] = $export;
        }

        $stream->set('references',$references);
    }