protected function create(Import\ImportStream $stream, Import\ImportContext $context) {
        $dashboards = (array) $stream->get('dashboards');
        if (empty($dashboards)) {
            return;
        }

        $this->datasourceName = $context->get('datasourceName');

        $this->reports = (array) $stream->get('reports');

        $readOnly = gd_datasource_is_property($this->datasourceName, 'readonly');
        if ($readOnly) {
            $metamodel = data_controller_get_metamodel();
            $this->datasets = $metamodel->datasets;
        } else {
            $this->datasets = (array) $stream->get('datasets');
        }

        if ( !empty($reports) && empty($datasets) ) {
            throw new Exception('Missing datasets for dashboard reports.');
        }

        foreach ( $dashboards as $dashboardKey => $dashboard ) {
            $node = $this->createDashboard($dashboard);
            if ( !empty($node->nid ) ) {
                $dashboards[$dashboardKey] = $node;
            } else {
                throw new Exception('Dashboard node creation failed');
            }
        }

        // update report/dashboard ids in config, for linking
        foreach ( $dashboards as $dashboardKey => $dashboard ) {
            $config = json_decode($dashboard->field_dashboard_config[$dashboard->language][0]['value']);

            $this->processConfigDashboards($config);

            $dashboards[$dashboardKey]->field_dashboard_config[$dashboards[$dashboardKey]->language][0]['value'] = json_encode($config);
            gd_dashboard_save($dashboards[$dashboardKey]);
        }

        $stream->set('dashboards',$dashboards);
    }
    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {
        $references = $stream->get('references');
        if (empty($references)) {
            return;
        }

        $metamodel = data_controller_get_metamodel();
        $this->datasets = $metamodel->datasets;

        foreach ( $references as $referenceKey => $reference ) {

            // rename reference point datasets
            foreach ( $reference->referencePoints as $referencePoint ) {
                foreach ( $this->datasets as $dataset ) {
                    if ( isset($dataset->uuid) && $dataset->uuid == $referencePoint->dataset ) {
                        $referencePoint->dataset = $dataset->name;
                    }
                }
            }

            $existingReferenceNode = $this->findExistingReference($reference);
            if ( !$existingReferenceNode ) {
                // create
                $node = $this->createReference($reference);
                if ( !empty($node->nid ) ) {
                    $references[$referenceKey] = $node;
                } else {
                    throw new Exception('Reference node creation failed');
                }
            } else {

                $existingReferenceNode->title = $reference->title;

                // really, just update columns
                $existingReferencePointNids = get_node_field_node_ref($existingReferenceNode,'field_reference_point',null);
                foreach ( $existingReferencePointNids as $existingReferencePointNid ) {
                    $existingReferencePointNode = node_load($existingReferencePointNid);
                    foreach ( $reference->referencePoints as $referencePoint ) {
                        if ( $referencePoint->dataset == get_node_field_value($existingReferencePointNode,'field_ref_point_dataset_sysname') ) {
                            $existingReferencePointNode->field_ref_point_column_sysname[$existingReferencePointNode->language] = array();
                            foreach ( $referencePoint->columns as $column ) {
                                $existingReferencePointNode->field_ref_point_column_sysname[$existingReferencePointNode->language][] = array('value' => $column);
                            }
                        }
                    }
                    node_save($existingReferencePointNode);
                }

                node_save($existingReferenceNode);

                $references[$referenceKey] = $existingReferenceNode;
            }
        }

        $stream->set('references',$references);
    }
    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {

        $this->datasourceName = $context->get('datasourceName');

        $reports = $stream->get('reports');
        if (empty($reports)) {
            return;
        }

        $metamodel = data_controller_get_metamodel();
        $this->datasets = $metamodel->datasets;

        foreach ( $reports as $reportKey => $report ) {
            $report = (object) $report;
            $existingReport = gd_report_get_by_uuid($report->uuid,$this->datasourceName);
            if ( !$existingReport ) {
                // create
                $node = $this->createReport($report);
                if ( !empty($node->nid ) ) {
                    $reports[$reportKey] = $node;
                } else {
                    throw new Exception('Report node creation failed');
                }
            } else {
                $existingReport->title = $report->title;
                $existingReport->field_report_desc[$existingReport->language][0]['value'] = $report->description;
                $existingReport->field_report_datasource[$existingReport->language][0]['value'] = $this->datasourceName;
                $existingReport->field_report_custom_view[$existingReport->language][0]['value'] = $report->custom_view;
                $existingReport->field_report_tags[$existingReport->language] = array();
                if (!empty($report->tags)) {
                    foreach ($report->tags as $tid) {
                        $existingReport->field_report_tags[$existingReport->language][] = array('tid' => $tid);
                    }
                }

                // update dataset references
                $existingReport->field_report_dataset_sysnames[$existingReport->language] = array();
                foreach ( $report->datasets as $datasetIdentifier ) {
                    $dataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($this->datasets,$datasetIdentifier);
                    if (!isset($dataset)) {
                        $datasetName = NameSpaceHelper::addNameSpace(gd_datasource_get_active(), $datasetIdentifier);
                        $dataset = $metamodel->getDataset($datasetName);
                    }
                    $existingReport->field_report_dataset_sysnames[$existingReport->language][] = array('value'=>$dataset->name);
                }

                $this->processConfig($report->config);
                $existingReport->field_report_conf[$existingReport->language][0]['value'] = json_encode($report->config);

                gd_report_save($existingReport);

                $event = new DefaultEvent();
                $event->type = 101; // see gd_health_monitoring_database_install() for more details
                $event->owner = $existingReport->nid;
                EventRecorderFactory::getInstance()->record($event);

                $reports[$reportKey] = $existingReport;
            }
        }

        $stream->set('reports',$reports);
    }
    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {
        $datasets = $stream->get('datasets');
        if (empty($datasets)) {
            return;
        }

        gd_datasource_set_active($context->get('datasourceName'));
        $metamodel = data_controller_get_metamodel();

        $environment_metamodel = data_controller_get_environment_metamodel();
        $datasource = $environment_metamodel->getDataSource($context->get('datasourceName'));

        foreach ( $datasets as $dataset ) {
            $existingDataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($metamodel->datasets, $dataset->uuid);
            if ( !$existingDataset ) {

                // map for re-linking dependent objects
                $dataset->originalName = $dataset->name;

                // create new name
                $newDatasetName = GD_NamingConvention::generateDatasetName();
                $dataset->name = $newDatasetName;
                $dataset->source = $newDatasetName;
                $dataset->datasourceName = $datasource->name;
            } else {
                // map for re-linking dependent objects
                $dataset->originalName = $dataset->name;

                $dataset->name = $existingDataset->name;
                $dataset->source = $existingDataset->source;
                $dataset->datasourceName = $existingDataset->datasourceName;
            }
        }

        // prepare dataset columns for import
        $this->prepareColumns($datasets);

        // prepares the metadata object, has to be of type RecordMetaData
        foreach ( $datasets as $key => $dataset ) {
            $metadata = new DatasetMetaData();
            $metadata->initializeFrom($dataset);
            $datasets[$key] = $metadata;
        }

        // ensure datasets are created in order to satisfy dependencies
        usort($datasets, array(new ReferencedDatasetComparator(), 'compare'));

        foreach ( $datasets as $dataset ) {
            $existingDataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($metamodel->datasets, $dataset->uuid);
            if ($existingDataset) {
                gd_data_controller_ddl_modify_dataset($dataset);
            } else {
                MetaModelFactory::getInstance()->startGlobalModification();
                try {
                    $transaction = db_transaction();
                    try {
                        gd_data_controller_ddl_create_dataset($dataset);
                    } catch (Exception $e) {
                        $transaction->rollback();
                        throw $e;
                    }
                } catch (Exception $e) {
                    MetaModelFactory::getInstance()->finishGlobalModification(false);
                    throw $e;
                }
                MetaModelFactory::getInstance()->finishGlobalModification(true);
            }
        }

        $stream->set('datasets',$datasets);
    }
    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {
        $measures = $stream->get('measures');
        if (empty($measures)) {
            return;
        }

        $metamodel = data_controller_get_metamodel();
        $this->datasets = $metamodel->datasets;

        foreach ( $measures as $k => $measure ) {
            foreach ( $this->datasets as $dataset ) {
                if ( DatasetExportHelper::getExportDatasetName($dataset->name, $metamodel) == $measure->dataset ) {
                    $measure->dataset = $dataset->name;
                    $measure->function = str_replace(DatasetExportHelper::getExportDatasetName($dataset->name, $metamodel), $dataset->source, $measure->function);

                    $existingMeasureNode = $this->findExistingMeasure($measure->sysname);
                    if ( !$existingMeasureNode ) {
                        // create
                        $node = gd_measure_create($measure, $dataset);
                        if ( !empty($node->nid ) ) {
                            $measures[$k] = $node;
                        } else {
                            throw new Exception('Measure node creation failed');
                        }
                    } else {

                        $existingMeasureNode->title = $measure->title;
                        $existingMeasureNode->field_measure_desc[$existingMeasureNode->language][] = array('value' => $measure->description);
                        $existingMeasureNode->field_measure_dataset[$existingMeasureNode->language][] = array('value' => $measure->dataset);
                        $existingMeasureNode->field_measure_function[$existingMeasureNode->language][] = array('value' => $measure->function);

                        node_save($existingMeasureNode);
                    }
                    break;
                }
            }
        }

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