Beispiel #1
0
        private string generatePrimaryData(long datasetVersionId)
        {
            try
            {
                DatasetManager datasetManager = new DatasetManager();
                DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId);


                if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure)
                {
                    OutputDataManager outputDataManager = new OutputDataManager();
                    SubmissionManager submissionManager = new SubmissionManager();

                    long datasetId = datasetVersion.Dataset.Id;

                    string fileName = submissionManager.GetFileNameForDataRepo(datasetId, datasetVersionId,
                                                                               _dataRepo.Name,
                                                                               "csv");

                    string filepath = outputDataManager.GenerateAsciiFile(
                        datasetId,
                        datasetVersionId,
                        fileName,
                        "text/txt");

                    return(filepath);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return("");
        }
Beispiel #2
0
        public string Convert(long datasetVersionId)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            DatasetManager           datasetManager           = new DatasetManager();


            SubmissionManager  submissionManager  = new SubmissionManager();
            PublicationManager publicationManager = new PublicationManager();


            try
            {
                DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId);

                _broker   = publicationManager.GetBroker(_broker.Id);
                _dataRepo = publicationManager.GetRepository(_dataRepo.Id);


                long   datasetId = datasetVersion.Dataset.Id;
                string name      = datasetManager.GetDatasetVersion(datasetVersionId).Dataset.MetadataStructure.Name;

                XmlDocument metadata = OutputMetadataManager.GetConvertedMetadata(datasetId,
                                                                                  TransmissionType.mappingFileExport, name, false);

                // create links to the api calls of the primary data?



                //add all to a zip


                //save document  and return filepath for download


                string path     = submissionManager.GetDirectoryPath(datasetId, _broker.Name);
                string filename = submissionManager.GetFileNameForDataRepo(datasetId, datasetVersionId, _dataRepo.Name, "xml");

                string filepath = Path.Combine(path, filename);

                FileHelper.CreateDicrectoriesIfNotExist(path);

                metadata.Save(filepath);


                return(filepath);
            }
            finally
            {
                datasetManager.Dispose();
                metadataStructureManager.Dispose();
                publicationManager.Dispose();
            }
        }
Beispiel #3
0
        //ToDO -> David <- do not store the files on the server
        public string Convert(long datasetVersionId)
        {
            DatasetManager datasetManager = new DatasetManager();

            PublicationManager publicationManager = new PublicationManager();

            try
            {
                _broker   = publicationManager.GetBroker(_broker.Id);
                _dataRepo = publicationManager.GetRepository(_dataRepo.Id);

                /***
                 *  Generate a txt file for pangaea
                 *  1. json metadata
                 *  2. tabseperated primary Data
                 *
                 *
                 * if data only unstructred, then only metadata
                 */

                string primaryDataFilePath = "";

                #region create primary Data


                primaryDataFilePath = generatePrimaryData(datasetVersionId);


                #endregion


                DatasetVersion datasetVersion      = datasetManager.GetDatasetVersion(datasetVersionId);
                long           datasetId           = datasetVersion.Dataset.Id;
                long           metadataStructureId = datasetVersion.Dataset.MetadataStructure.Id;

                DataStructureDataList datastructureDataList = OutputDataStructureManager.GetVariableList(datasetId);

                PanageaMetadata metadata = getMetadata(datasetVersion.Metadata, metadataStructureId);
                metadata.ParameterIDs = datastructureDataList.Variables;

                string json = JsonConvert.SerializeObject(metadata, Formatting.Indented);


                SubmissionManager submissionManager = new SubmissionManager();



                string path     = submissionManager.GetDirectoryPath(datasetId, _broker.Name);
                string filename = submissionManager.GetFileNameForDataRepo(datasetVersionId, datasetId, _dataRepo.Name, "txt");

                string filepath = Path.Combine(path, filename);

                try
                {
                    if (File.Exists(filepath))
                    {
                        File.Delete(filepath);
                    }

                    FileHelper.Create(filepath).Close();
                    File.WriteAllText(filepath, json + Environment.NewLine + Environment.NewLine);

                    if (!string.IsNullOrEmpty(primaryDataFilePath))
                    {
                        File.AppendAllText(filepath, File.ReadAllText(primaryDataFilePath));
                    }

                    return(filepath);
                }
                catch (Exception exception)
                {
                    throw exception;
                }



                return("");
            }
            finally
            {
                datasetManager.Dispose();
                publicationManager.Dispose();
            }
        }