private CustomFileDetails GetLicenseFileInfo(int schemaId, int licenseId, int providerOrganizationId, int consumerOrganizationId) { // Get license var license = _licenses.FirstOrDefault(i => i.ID == licenseId); var result = new CustomFileDetails(); // Check whether license is custom var isCustom = license.CustomLicenseID != null; if (isCustom) { // Get content for custom license result = GetCustomLicenseForDownload(license.CustomLicenseID.Value); } else { // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == schemaId); // Setup url to download schema var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID); var application = _applications.FirstOrDefault(i => i.ID == license.ApplicationID); // Get content for templated license result = GetTemplatedLicenseForDownload(license, application.OrganizationID, consumerOrganizationId, urlToSchema); } // Return result return(result); }
public CustomFileDetails GetFileDetails(int fileId, LoggedInUserDetails user) { // Check whether user is admin if (!user.IsSysAdmin) { throw new BaseException("Access denied"); } // Get license template var licenseTemplate = _templates.FirstOrDefault(i => i.ID == fileId); // Check whether template not exists if (licenseTemplate == null) { throw new BaseException("File not found"); } // Get bytes for license content var bytes = Encoding.UTF8.GetBytes(licenseTemplate.LicenseText); // Setup file result var fileResult = new CustomFileDetails() { Content = bytes, FileName = licenseTemplate.Name + ".html", MimeType = "application/html" }; return(fileResult); }
private CustomFileDetails GetTemplatedLicenseForDownload(OrganizationLicense license, int providerOrgId, int consumerOrgId, string urlToSchema) { var result = new CustomFileDetails(); // Get license template var template = _licenseTemplates.FirstOrDefault(i => i.ID == license.LicenseTemplateID.Value); // Get license document var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: license.ID); // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == license.DataSchemaID); // Build content for templated license _licenseContentBuilder.InsertLicenseDetails(licenseDocument, urlToSchema, _config.DataLinkerHost, providerOrgId, consumerOrgId); // Generate pdf file with content var pdfDocument = new HtmlToPdfConverter { PageFooterHtml = _licenseContentBuilder.GetFooterText(license.Status, _config.DataLinkerHost) }; var bytes = pdfDocument.GeneratePdf(licenseDocument.OuterXml); // Setup result result.Content = bytes; result.MimeType = "application/pdf"; result.FileName = $"{template.Name}.pdf"; // Return result return(result); }
public FileResult GenerateReport() { // Setup report details CustomFileDetails fileResult = _templates.GetReportDetails(LoggedInUser); // Return File return(File(fileResult.Content, fileResult.MimeType, fileResult.FileName)); }
public FileResult Download(int fileId) { // Setup file details CustomFileDetails fileResult = _templates.GetFileDetails(fileId, LoggedInUser); // Return result return(File(fileResult.Content, fileResult.MimeType, fileResult.FileName)); }
public CustomFileDetails GetReportDetails(LoggedInUserDetails user) { // Check whether user is not admin if (!user.IsSysAdmin) { throw new BaseException("Access denied."); } // Get all valid license agreements var licenseAgreements = _agreements.Where(i => i.ExpiresAt == null); // Get all sections var licenseSections = _sections.All().ToList(); // Get section titles var sectionTitles = GetHeaderForReport(licenseSections); // Append Header for report var reportHeader = "Date executed,Provider,Consumer,Schema" + sectionTitles; var fileContent = new StringBuilder(); var reportBody = new StringBuilder(); // Process each license agreement foreach (var licenseAgreement in licenseAgreements) { // Add line to report for license agreement reportBody.AppendLine(GetRecordForLicense(licenseAgreement, licenseSections)); } // Add Header to file fileContent.AppendLine(reportHeader); // Add Body to file fileContent.Append(reportBody); // Setup file name var fileName = $"License_Agreements_{GetDate.ToString("yyyy MMMM dd")}.csv"; // Setup file result var fileResult = new CustomFileDetails { Content = Encoding.UTF8.GetBytes(fileContent.ToString()), FileName = fileName, MimeType = "text/csv" }; return(fileResult); }
private CustomFileDetails GetCustomLicenseForDownload(int licenseId) { // define result var result = new CustomFileDetails(); // Get license var customLicense = _customLicenses.FirstOrDefault(i => i.ID == licenseId); // Setup result result.Content = customLicense.Content; result.MimeType = customLicense.MimeType; result.FileName = customLicense.FileName; // Return result return(result); }
public CustomFileDetails GetReport(LoggedInUserDetails user) { // Check whether user has access if (!user.IsSysAdmin) { throw new BaseException("Access denied."); } // Get license matches for current month var consumerMatchesForMonth = _licenseMatches.GetAllMatchesForMonth(GetDate); // Setup string builder var fileContent = new StringBuilder(); fileContent.AppendLine("Provider Name: Endpoint Name,Schema Name,Consumer Name"); // Get all published licenses var providerLicenses = _orgLicenses.GetAllProviderLicensesForMonth(GetDate).ToList(); // Check whether any provider license was published this month if (!providerLicenses.Any()) { throw new BaseException($"No providers who published licenses in {GetDate.ToString("Y")}"); } // Each license process - add to csv provider + schema foreach (var providerLicense in providerLicenses) { fileContent.AppendLine(GetRecordForLicense(consumerMatchesForMonth.ToList(), providerLicense)); } // Setup result var result = new CustomFileDetails(); var fileName = $"Schema_usage_{GetDate.ToString("Y")}.csv"; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(fileContent.ToString()); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); result.FileName = fileName; result.MimeType = "text/csv"; result.Content = stream.ToArray(); return(result); }
public CustomFileDetails GetTemplatedLicenseForPreview(List <SectionsWithClauses> model, int orgId, int schemaId, LoggedInUserDetails user) { // Check access _security.CheckBasicAccess(user); // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException("Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator."); } // Define result var result = new CustomFileDetails(); // Get published license template var template = _licenseTemplates.FirstOrDefault(i => i.Status == (int)TemplateStatus.Active); // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == schemaId); // Setup url to download schema var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID); // Setup content for document var document = _licenseContentBuilder.GetDocument(model, schemaId, orgId, template, _config.DataLinkerHost, urlToSchema); // Create pdf document var pdfDocument = new HtmlToPdfConverter { PageFooterHtml = _licenseContentBuilder.GetFooterText((int)PublishStatus.Draft, _config.DataLinkerHost) }; // Get bytes from document var bytes = pdfDocument.GeneratePdf(document.OuterXml); // Setup result result.Content = bytes; result.MimeType = "application/pdf"; result.FileName = $"{template.Name}.pdf"; // Return result return(result); }
public CustomFileDetails GetFileDetails(int fileId) { // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.ID == fileId); // Check whether file exists if (schemaFile == null) { throw new BaseException("File not found"); } // Get metadata for schema file var schemaMeta = _schemas.FirstOrDefault(i => i.ID == schemaFile.DataSchemaID); // Setup file name var fileName = schemaMeta.Name + schemaFile.FileFormat; // Setup stream var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(schemaFile.SchemaText); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); // Setup result var result = new CustomFileDetails() { Content = stream.ToArray(), FileName = fileName, MimeType = "application/json" }; // Return result return(result); }
public CustomFileDetails GetAgreement(int agreementId, LoggedInUserDetails user) { // Get agreements var agreement = _agreements.FirstOrDefault(i => i.ID == agreementId); // Return error if data not found if (agreement == null) { throw new BaseException("License Agreement not found"); } // Check whether user has access _security.CheckBasicAccess(user); var consumerRegistration = _consumerProviderRegistrations.GetById(agreement.ConsumerProviderRegistrationId); var providerLicense = _licenses.FirstOrDefault(i => i.ID == consumerRegistration.OrganizationLicenseID); var consumerApp = _applications.FirstOrDefault(i => i.ID == consumerRegistration.ConsumerApplicationID); var providerApp = _applications.FirstOrDefault(i => i.ID == providerLicense.ApplicationID); var isFromConsumerSide = user.Organization.ID == consumerApp.OrganizationID; var isFromProviderSide = user.Organization.ID == providerApp.OrganizationID; var isFromAllowedOrganization = isFromProviderSide || isFromConsumerSide; // Return error if not access to data if (!user.IsSysAdmin && !isFromAllowedOrganization) { throw new BaseException("Access denied."); } // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException( "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator."); } // Get provider licese if (providerLicense.CustomLicenseID != null) { // Get uploaded by provider file var customLicenseResult = GetCustomLicenseForDownload(providerLicense.CustomLicenseID.Value); // Return custom license result return(customLicenseResult); } // Get template var template = _licenseTemplates.FirstOrDefault(i => i.ID == providerLicense.LicenseTemplateID.Value); // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == providerLicense.DataSchemaID); // Setup url to download schema var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID); // Setup license content var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: providerLicense.ID); // Insert provider details _licenseContentBuilder.InsertAgreementDetails(licenseDocument, agreement.ID, urlToSchema, _config.DataLinkerHost); // Get butes for generated pdf var bytes = new HtmlToPdfConverter().GeneratePdf(licenseDocument.OuterXml); var result = new CustomFileDetails { Content = bytes, FileName = template.Name + ".pdf", MimeType = "application/pdf" }; return(result); }