public JsonResult CheckExportPossibility(string datarepo, long datasetid) { bool isDataConvertable = false; bool isMetadataConvertable = false; string metadataValidMessage = ""; bool exist = false; //get broker PublicationManager publicationManager = new PublicationManager(); // datasetversion DatasetManager dm = new DatasetManager(); long version = dm.GetDatasetLatestVersion(datasetid).Id; if (publicationManager.BrokerRepo.Get().Any(d => d.Name.ToLower().Equals(datarepo.ToLower()))) { Broker broker = publicationManager.BrokerRepo.Get().Where(d => d.Name.ToLower().Equals(datarepo.ToLower())).FirstOrDefault(); Publication publication = publicationManager.PublicationRepo.Get() .Where(p => p.Broker != null && p.Broker.Id.Equals(broker.Id) && p.DatasetVersion != null && p.DatasetVersion.Id.Equals(version)) .FirstOrDefault(); if (publication != null && !String.IsNullOrEmpty(publication.FilePath) && FileHelper.FileExist(Path.Combine(AppConfiguration.DataPath, publication.FilePath))) { //model.Exist = true; exist = true; } else { #region metadata // if no conversion is needed if (String.IsNullOrEmpty(broker.MetadataFormat)) { //model.IsMetadataConvertable = true; isMetadataConvertable = true; // Validate metadataValidMessage = OutputMetadataManager.IsValideAgainstSchema(datasetid, TransmissionType.mappingFileExport, datarepo); } else { //if convertion check ist needed //get all export attr from metadata structure List <string> exportNames = xmlDatasetHelper.GetAllTransmissionInformation(datasetid, TransmissionType.mappingFileExport, AttributeNames.name).ToList(); if (exportNames.Contains(broker.MetadataFormat)) { isMetadataConvertable = true; } metadataValidMessage = OutputMetadataManager.IsValideAgainstSchema(datasetid, TransmissionType.mappingFileExport, datarepo); } #endregion #region primary Data //todo need a check if the primary data is structured or not, if its unstructured also export should be possible if (broker.PrimaryDataFormat.ToLower().Contains("text/plain") || broker.PrimaryDataFormat.ToLower().Contains("text/csv") || broker.PrimaryDataFormat.ToLower().Contains("application/excel") || String.IsNullOrEmpty(broker.PrimaryDataFormat)) { isDataConvertable = true; } #endregion } //check if reporequirements are fit //e.g. GFBIO } return(Json(new { isMetadataConvertable = isMetadataConvertable, isDataConvertable = isDataConvertable, metadataValidMessage = metadataValidMessage, Exist = exist })); }
//ToDO -> David <- do not store the files on the server public string Convert(long datasetVersionId) { string datarepo = _dataRepo.Name; DatasetManager datasetManager = new DatasetManager(); DataStructureManager dataStructureManager = new DataStructureManager(); PublicationManager publicationManager = new PublicationManager(); SubmissionManager publishingManager = new SubmissionManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId); long datasetId = datasetVersion.Dataset.Id; Publication publication = publicationManager.GetPublication() .Where( p => p.DatasetVersion.Id.Equals(datasetVersion.Id) && p.Broker.Name.ToLower().Equals(_broker.Name)) .FirstOrDefault(); // if(broker exist) if (publication == null && _broker != null) { Broker broker = _broker; if (broker != null) { OutputMetadataManager.GetConvertedMetadata(datasetId, TransmissionType.mappingFileExport, broker.MetadataFormat); // get primary data // check the data sturcture type ... if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure) { OutputDataManager odm = new OutputDataManager(); // apply selection and projection string title = xmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.title); odm.GenerateAsciiFile(datasetId, title, broker.PrimaryDataFormat); } string zipName = publishingManager.GetZipFileName(datasetId, datasetVersion.Id); string zipPath = publishingManager.GetDirectoryPath(datasetId, broker.Name); string dynamicZipPath = publishingManager.GetDynamicDirectoryPath(datasetId, broker.Name); string zipFilePath = Path.Combine(zipPath, zipName); string dynamicFilePath = Path.Combine(dynamicZipPath, zipName); FileHelper.CreateDicrectoriesIfNotExist(Path.GetDirectoryName(zipFilePath)); if (FileHelper.FileExist(zipFilePath)) { if (FileHelper.WaitForFile(zipFilePath)) { FileHelper.Delete(zipFilePath); } } // add datastructure //ToDo put that functiom to the outputDatatructureManager #region datatructure long dataStructureId = datasetVersion.Dataset.DataStructure.Id; DataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId); if (dataStructure != null) { try { string dynamicPathOfDS = ""; dynamicPathOfDS = storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion, "datastructure", ".txt"); string datastructureFilePath = AsciiWriter.CreateFile(dynamicPathOfDS); string json = OutputDataStructureManager.GetVariableListAsJson(datasetId); AsciiWriter.AllTextToFile(datastructureFilePath, json); } catch (Exception ex) { throw ex; } } #endregion ZipFile zip = new ZipFile(); foreach (ContentDescriptor cd in datasetVersion.ContentDescriptors) { string path = Path.Combine(AppConfiguration.DataPath, cd.URI); string name = cd.URI.Split('\\').Last(); if (FileHelper.FileExist(path)) { zip.AddFile(path, ""); } } // add xsd of the metadata schema string xsdDirectoryPath = OutputMetadataManager.GetSchemaDirectoryPath(datasetId); if (Directory.Exists(xsdDirectoryPath)) { zip.AddDirectory(xsdDirectoryPath, "Schema"); } XmlDocument manifest = OutputDatasetManager.GenerateManifest(datasetId, datasetVersion.Id); if (manifest != null) { string dynamicManifestFilePath = OutputDatasetManager.GetDynamicDatasetStorePath(datasetId, datasetVersion.Id, "manifest", ".xml"); string fullFilePath = Path.Combine(AppConfiguration.DataPath, dynamicManifestFilePath); manifest.Save(fullFilePath); zip.AddFile(fullFilePath, ""); } string message = string.Format("dataset {0} version {1} was published for repository {2}", datasetId, datasetVersion.Id, broker.Name); LoggerFactory.LogCustom(message); //Session["ZipFilePath"] = dynamicFilePath; zip.Save(zipFilePath); return(zipFilePath); } } return(""); } finally { datasetManager.Dispose(); dataStructureManager.Dispose(); publicationManager.Dispose(); } }
public ActionResult LoadDataRepoRequirementView(string datarepo, long datasetid) { DataRepoRequirentModel model = new DataRepoRequirentModel(); model.DatasetId = datasetid; //get broker PublicationManager publicationManager = new PublicationManager(); // datasetversion DatasetManager dm = new DatasetManager(); try { long version = dm.GetDatasetLatestVersionId(datasetid); model.DatasetVersionId = version; if (publicationManager.BrokerRepo.Get().Any(d => d.Name.ToLower().Equals(datarepo.ToLower()))) { Broker broker = publicationManager.BrokerRepo.Get() .Where(d => d.Name.ToLower().Equals(datarepo.ToLower())) .FirstOrDefault(); Publication publication = publicationManager.PublicationRepo.Get() .Where(p => p.Broker.Id.Equals(broker.Id) && p.DatasetVersion.Id.Equals(version)) .FirstOrDefault(); if (publication != null && !String.IsNullOrEmpty(publication.FilePath) && FileHelper.FileExist(Path.Combine(AppConfiguration.DataPath, publication.FilePath))) { model.Exist = true; } else { //if convertion check ist needed //get all export attr from metadata structure List <string> exportNames = xmlDatasetHelper.GetAllTransmissionInformation(datasetid, TransmissionType.mappingFileExport, AttributeNames.name).ToList(); if (string.IsNullOrEmpty(broker.MetadataFormat) || exportNames.Contains(broker.MetadataFormat)) { model.IsMetadataConvertable = true; } // Validate model.metadataValidMessage = OutputMetadataManager.IsValideAgainstSchema(datasetid, TransmissionType.mappingFileExport, datarepo); #region primary Data if (broker.PrimaryDataFormat.ToLower().Contains("text/plain") || broker.PrimaryDataFormat.ToLower().Contains("text/csv") || broker.PrimaryDataFormat.ToLower().Contains("application/excel") || String.IsNullOrEmpty(broker.PrimaryDataFormat)) { model.IsDataConvertable = true; } #endregion } } return(PartialView("_dataRepositoryRequirementsView", model)); } catch (Exception ex) { throw ex; } finally { publicationManager.Dispose(); dm.Dispose(); } }