diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b1fbaf36..803d3d930 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Removed deduplication check when adding and detaching attachments. - When copying a borehole, attachments won't be copied. - Removed layers settings for anonymous users. +- Removed csv lithology import. ### Fixed diff --git a/src/api/Controllers/UploadController.cs b/src/api/Controllers/UploadController.cs index 40e9848bc..b9ff80fcf 100644 --- a/src/api/Controllers/UploadController.cs +++ b/src/api/Controllers/UploadController.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using System.Collections; using System.Globalization; using System.Net; @@ -47,14 +46,13 @@ public UploadController(BdmsContext context, ILogger logger, L /// /// The of the new (s). /// The containing the borehole csv records that were uploaded. - /// The containing the lithology csv records that were uploaded. /// The list of containing the borehole attachments referred in . /// The number of the newly created s. [HttpPost] [Authorize(Policy = PolicyNames.Viewer)] [RequestSizeLimit(int.MaxValue)] [RequestFormLimits(MultipartBodyLengthLimit = MaxFileSize)] - public async Task> UploadFileAsync(int workgroupId, IFormFile boreholesFile, IFormFile? lithologyFile = null, IList? attachments = null) + public async Task> UploadFileAsync(int workgroupId, IFormFile boreholesFile, IList? attachments = null) { // Increase max allowed errors to be able to return more validation errors at once. ModelState.MaxAllowedErrors = 1000; @@ -74,19 +72,9 @@ public async Task> UploadFileAsync(int workgroupId, IFormFile // Checks if any of the provided attachments exceeds the maximum file size. if (attachments?.Any(a => a.Length > MaxFileSize) == true) return BadRequest($"One or more attachment exceed maximum file size of {MaxFileSize / 1024 / 1024} Mb."); - // if a lithology file is provided, checks if it is a CSV file. - if (lithologyFile != null && !FileTypeChecker.IsCsv(lithologyFile)) return BadRequest("Invalid file type for lithology csv."); - var boreholeImports = ReadBoreholesFromCsv(boreholesFile); ValidateBoreholeImports(workgroupId, boreholeImports, attachments); - var lithologyImports = new List(); - if (lithologyFile != null) - { - lithologyImports = ReadLithologiesFromCsv(lithologyFile); - ValidateLithologyImports(boreholeImports.Select(bhi => bhi.ImportId).ToList(), lithologyImports); - } - // If any validation error occured, return a bad request. if (!ModelState.IsValid) { @@ -175,69 +163,6 @@ public async Task> UploadFileAsync(int workgroupId, IFormFile } } - // Add lithology imports if provided - if (lithologyImports.Count > 0) - { - // Get the kind id of a lithostratigraphy. - var lithoStratiKindId = context.Codelists.Single(cl => cl.Schema == "layer_kind" && cl.IsDefault == true).Id; - - // Group lithology records by import id to get lithologies by boreholes. - var boreholeGroups = lithologyImports.GroupBy(l => l.ImportId); - - var codeLists = await context.Codelists.ToListAsync().ConfigureAwait(false); - - var stratiesToAdd = new List(); - var lithologiesToAdd = new List(); - foreach (var boreholeLithologies in boreholeGroups) - { - // Group lithology of one borehole by strati import id to get lithologies per stratigraphy. - var stratiGroups = boreholeLithologies.GroupBy(bhoGroup => bhoGroup.StratiImportId); - foreach (var stratiGroup in stratiGroups) - { - // Create a stratigraphy and assign it to the borehole with the provided import id. - var strati = new Stratigraphy - { - BoreholeId = boreholeImports.Single(bhi => bhi.ImportId == boreholeLithologies.Key).Id, - Date = stratiGroup.First().StratiDate != null ? DateTime.SpecifyKind(stratiGroup.First().StratiDate!.Value, DateTimeKind.Utc) : null, - Name = stratiGroup.First().StratiName, - }; - - // Create a lithology for each record in the group (same strati id) and assign it to the new stratigraphy. - var lithologies = stratiGroup.Select(sg => - { - var lithology = (Layer)sg; - lithology.ColorCodelistIds = ParseIds(sg.ColorIds); - lithology.DebrisCodelistIds = ParseIds(sg.DebrisIds); - lithology.GrainShapeCodelistIds = ParseIds(sg.GrainShapeIds); - lithology.GrainAngularityCodelistIds = ParseIds(sg.GrainGranularityIds); - lithology.OrganicComponentCodelistIds = ParseIds(sg.OrganicComponentIds); - lithology.Uscs3CodelistIds = ParseIds(sg.Uscs3Ids); - - lithology.LayerColorCodes = CreateLayerCodes(GetCodelists(lithology.ColorCodelistIds)); - lithology.LayerDebrisCodes = CreateLayerCodes(GetCodelists(lithology.DebrisCodelistIds)); - lithology.LayerGrainShapeCodes = CreateLayerCodes(GetCodelists(lithology.GrainShapeCodelistIds)); - lithology.LayerGrainAngularityCodes = CreateLayerCodes(GetCodelists(lithology.GrainAngularityCodelistIds)); - lithology.LayerOrganicComponentCodes = CreateLayerCodes(GetCodelists(lithology.OrganicComponentCodelistIds)); - lithology.LayerUscs3Codes = CreateLayerCodes(GetCodelists(lithology.Uscs3CodelistIds)); - - lithology.Stratigraphy = strati; - return lithology; - }).ToList(); - - stratiesToAdd.Add(strati); - lithologiesToAdd.AddRange(lithologies); - } - } - - // Add stratigraphies to database. - await context.Stratigraphies.AddRangeAsync(stratiesToAdd).ConfigureAwait(false); - await SaveChangesAsync(() => Ok(stratiesToAdd.Count)).ConfigureAwait(false); - - // Add litholigies to database. - await context.Layers.AddRangeAsync(lithologiesToAdd).ConfigureAwait(false); - await SaveChangesAsync(() => Ok(lithologiesToAdd.Count)).ConfigureAwait(false); - } - await transaction.CommitAsync().ConfigureAwait(false); return result; } @@ -252,51 +177,6 @@ public async Task> UploadFileAsync(int workgroupId, IFormFile } } - /// - /// Parses a string of IDs into a list of integers. - /// - /// The string of IDs to parse. IDs are expected to be separated by commas. - /// A list of integers parsed from the input string. - internal List ParseIds(string ids) - { - if (string.IsNullOrEmpty(ids)) - { - return new List(); - } - - return ids - .Split(',') - .Select(s => - { - if (!int.TryParse(s, out var num)) - { - logger.LogError($"Invalid code list value: {s}"); - throw new FormatException($"Invalid code list value: {s}"); - } - - return num; - }).ToList(); - } - - internal List GetCodelists(ICollection codelistIds) - { - return context.Codelists.Where(c => codelistIds.Contains(c.Id)).ToList(); - } - - internal List CreateLayerCodes(List codelists) - where T : ILayerCode, new() - { - return codelists.Select(c => new T { Codelist = c, CodelistId = c.Id }).ToList(); - } - - internal List ParseMultiValueCodeListIds(LithologyImport lithologyImport) - { - // Select all code list ids of all multi value code list properties. - return new[] { lithologyImport.ColorIds, lithologyImport.OrganicComponentIds, lithologyImport.GrainShapeIds, lithologyImport.GrainGranularityIds, lithologyImport.Uscs3Ids, lithologyImport.DebrisIds } - .SelectMany(str => str.Split(',')) - .Where(s => !string.IsNullOrEmpty(s)).Select(int.Parse).ToList() ?? new List(); - } - internal static int GetPrecision(IReaderRow row, string fieldName) { if (row.HeaderRecord != null && row.HeaderRecord.Any(h => h == fieldName)) @@ -375,72 +255,6 @@ private void ValidateBoreholeImports(int workgroupId, List boreh } } - private void ValidateLithologyImports(List importIds, List lithologyImports) - { - // Iterate over provided lithology imports, validate them, and create error messages when necessary. Use a non-zero based index for error message keys (e.g. 'Row1'). - foreach (var lithology in lithologyImports.Select((value, index) => (value, index: index + 1))) - { - if (lithology.value.ImportId == 0) - { - ModelState.AddModelError($"Row{lithology.index}", string.Format(CultureInfo.InvariantCulture, nullOrEmptyMsg, "import_id")); - } - - if (lithology.value.StratiImportId == 0) - { - ModelState.AddModelError($"Row{lithology.index}", string.Format(CultureInfo.InvariantCulture, nullOrEmptyMsg, "strati_import_id")); - } - - if (lithology.value.FromDepth == null) - { - ModelState.AddModelError($"Row{lithology.index}", string.Format(CultureInfo.InvariantCulture, nullOrEmptyMsg, "from_depth")); - } - - if (lithology.value.ToDepth == null) - { - ModelState.AddModelError($"Row{lithology.index}", string.Format(CultureInfo.InvariantCulture, nullOrEmptyMsg, "to_depth")); - } - - // Check if all import ids exist in the list of provided import ids (from borehole import file) - if (!importIds.Contains(lithology.value.ImportId)) - { - ModelState.AddModelError($"Row{lithology.index}", $"Borehole with {nameof(LithologyImport.ImportId)} '{lithology.value.ImportId}' not found."); - } - - // Check if all multi code list values are numbers - try - { - ParseMultiValueCodeListIds(lithology.value); - } - catch - { - ModelState.AddModelError($"Row{lithology.index}", $"One or more invalid (not a number) code list id in any of the following properties: {nameof(LithologyImport.ColorIds)}, {nameof(LithologyImport.OrganicComponentIds)}, {nameof(LithologyImport.GrainShapeIds)}, {nameof(LithologyImport.GrainGranularityIds)}, {nameof(LithologyImport.Uscs3Ids)}, {nameof(LithologyImport.DebrisIds)}."); - } - } - - // Group lithology records by import id to get lithologies per borehole. - var boreholeGroups = lithologyImports.GroupBy(l => l.ImportId); - - foreach (var boreholeLithologies in boreholeGroups) - { - // Group lithology records per borehole by strati import id to get lithologies per stratigraphy. - var stratiGroups = boreholeLithologies.GroupBy(bhoGroup => bhoGroup.StratiImportId); - foreach (var stratiGroup in stratiGroups) - { - // Check if all records with the same strati import id have the same strati name. - if (stratiGroup.Select(s => s.StratiName).Distinct().Count() > 1) - { - ModelState.AddModelError($"Row{stratiGroup.First().ImportId}", $"Lithology with {nameof(LithologyImport.StratiImportId)} '{stratiGroup.Key}' has various {nameof(LithologyImport.StratiName)}."); - } - - // Check if all records with the same strati import id have the same strati date. - if (stratiGroup.Select(s => s.StratiDate).Distinct().Count() > 1) - { - ModelState.AddModelError($"Row{stratiGroup.First().ImportId}", $"Lithology with {nameof(LithologyImport.StratiImportId)} '{stratiGroup.Key}' has various {nameof(LithologyImport.StratiDate)}."); - } - } - } - } - internal static bool CompareValuesWithTolerance(double? firstValue, double? secondValue, double tolerance) { if (firstValue == null && secondValue == null) return true; @@ -459,16 +273,6 @@ private List ReadBoreholesFromCsv(IFormFile file) return csv.GetRecords().ToList(); } - private List ReadLithologiesFromCsv(IFormFile? file) - { - using var reader = new StreamReader(file.OpenReadStream()); - using var csv = new CsvReader(reader, csvConfig); - - csv.Context.RegisterClassMap(new CsvImportLithologyMap()); - - return csv.GetRecords().ToList(); - } - private async Task UpdateBoreholeLocationAndCoordinates(Borehole borehole) { // Use origin spatial reference system @@ -593,60 +397,6 @@ public CsvImportBoreholeMap() } } - private sealed class CsvImportLithologyMap : ClassMap - { - private readonly CultureInfo swissCulture = new("de-CH"); - - public CsvImportLithologyMap() - { - var config = new CsvConfiguration(swissCulture) - { - IgnoreReferences = true, - PrepareHeaderForMatch = args => args.Header.Humanize(LetterCasing.Title), - }; - - AutoMap(config); - - // Define all optional properties of Layer (ef navigation properties do not need to be defined as optional). - Map(m => m.StratiDate).Optional(); - Map(m => m.StratiName).Optional(); - Map(m => m.Id).Optional(); - Map(m => m.StratigraphyId).Optional(); - Map(m => m.CreatedById).Optional(); - Map(m => m.Created).Optional(); - Map(m => m.UpdatedById).Optional(); - Map(m => m.Updated).Optional(); - Map(m => m.IsUndefined).Optional(); - Map(m => m.IsLast).Optional(); - Map(m => m.DescriptionQualityId).Optional(); - Map(m => m.LithologyId).Optional(); - Map(m => m.PlasticityId).Optional(); - Map(m => m.ConsistanceId).Optional(); - Map(m => m.AlterationId).Optional(); - Map(m => m.CompactnessId).Optional(); - Map(m => m.GrainSize1Id).Optional(); - Map(m => m.GrainSize2Id).Optional(); - Map(m => m.CohesionId).Optional(); - Map(m => m.Uscs1Id).Optional(); - Map(m => m.Uscs2Id).Optional(); - Map(m => m.OriginalUscs).Optional(); - Map(m => m.UscsDeterminationId).Optional(); - Map(m => m.Notes).Optional(); - Map(m => m.LithostratigraphyId).Optional(); - Map(m => m.HumidityId).Optional(); - Map(m => m.IsStriae).Optional(); - Map(m => m.GradationId).Optional(); - Map(m => m.LithologyTopBedrockId).Optional(); - Map(m => m.OriginalLithology).Optional(); - Map(m => m.ColorIds).Optional(); - Map(m => m.OrganicComponentIds).Optional(); - Map(m => m.GrainShapeIds).Optional(); - Map(m => m.GrainGranularityIds).Optional(); - Map(m => m.Uscs3Ids).Optional(); - Map(m => m.DebrisIds).Optional(); - } - } - private async Task> SaveChangesAsync(Func> successResult) { try diff --git a/src/client/cypress/e2e/mainPage/import.cy.js b/src/client/cypress/e2e/mainPage/import.cy.js index 3f5063b4c..d4c3f904a 100644 --- a/src/client/cypress/e2e/mainPage/import.cy.js +++ b/src/client/cypress/e2e/mainPage/import.cy.js @@ -42,21 +42,6 @@ describe("Test for importing boreholes.", () => { }); }); - // Select lithology csv file - let lithologyFile = new DataTransfer(); - getImportFileFromFixtures("lithology-single-valid.csv", null).then(fileContent => { - const file = new File([fileContent], "lithology-single-valid.csv", { - type: "text/csv", - }); - lithologyFile.items.add(file); - }); - cy.get('[data-cy="import-lithologyFile-input"]').within(() => { - cy.get("input[type=file]", { force: true }).then(input => { - input[0].files = lithologyFile.files; - input[0].dispatchEvent(new Event("change", { bubbles: true })); - }); - }); - // Intercept upload request cy.intercept("/api/v2/upload?workgroupId=1").as("borehole-upload"); @@ -106,59 +91,4 @@ describe("Test for importing boreholes.", () => { .should("contain", "Row5") .should("contain", "Borehole with same Coordinates (+/- 2m) and same TotalDepth is provided multiple times."); }); - - it("Displays lithology validation errors.", () => { - loginAsAdmin(); - cy.get('[data-cy="import-borehole-button"]').click(); - - // Select borehole csv file - getImportFileFromFixtures("boreholes-multiple-valid.csv", null) - .then(fileContent => { - const file = new File([fileContent], "boreholes-multiple-valid.csv", { - type: "text/csv", - }); - let boreholeFile = new DataTransfer(); - boreholeFile.items.add(file); - return boreholeFile; - }) - .then(boreholeFile => { - cy.get('[data-cy="import-boreholeFile-input"]').within(() => { - cy.get("input[type=file]", { force: true }).then(input => { - input[0].files = boreholeFile.files; - input[0].dispatchEvent(new Event("change", { bubbles: true })); - }); - }); - }); - - // Select lithology csv file - getImportFileFromFixtures("lithology-single-not-valid.csv", null, "invalid-lithology") - .then(fileContent => { - const file = new File([fileContent], "lithology-single-not-valid.csv", { - type: "text/csv", - }); - let lithologyFile = new DataTransfer(); - lithologyFile.items.add(file); - return lithologyFile; - }) - .then(lithologyFile => { - cy.get('[data-cy="import-lithologyFile-input"]').within(() => { - cy.get("input[type=file]", { force: true }).then(input => { - input[0].files = lithologyFile.files; - input[0].dispatchEvent(new Event("change", { bubbles: true })); - }); - }); - }); - - cy.intercept("/api/v2/upload?workgroupId=1").as("borehole-upload"); - - cy.get('[data-cy="import-button"]').click(); - - cy.wait("@borehole-upload"); - - cy.get('[data-cy="borehole-import-error-modal-content"]') - .should("not.contain", "Row0") - .should("contain", "Row1") - .should("contain", "Field 'to_depth' is required.") - .should("contain", "Borehole with ImportId '123456' not found."); - }); }); diff --git a/src/client/docs/import.md b/src/client/docs/import.md index d966dfb9a..d1096c46d 100644 --- a/src/client/docs/import.md +++ b/src/client/docs/import.md @@ -22,11 +22,7 @@ Zunächst sollte die CSV-Datei den Anforderungen und dem Format entsprechen, wie 1. Schaltfläche _Dateien hier ablegen oder klicken, um sie hochzuladen_ anklicken und die vorbereitete Datei(en) auswählen. -### Schritt 5: Lithologie CSV-Datei selektieren (optional) - -1. Schaltfläche _Dateien hier ablegen oder klicken, um sie hochzuladen_ anklicken und die vorbereitete Lithologie CSV-Datei auswählen. - -### Schritt 6: Dateien hochladen +### Schritt 5: Dateien hochladen 1. Import-Prozess mit einem Klick auf _Importieren_ starten. 2. Warten, bis der Upload abgeschlossen ist und die Daten in der Anwendung verfügbar sind. @@ -94,45 +90,6 @@ Die zu importierenden Daten müssen gemäss obigen Anforderungen im CSV-Format v | lithostratigraphy_id | ID (Codeliste) | Nein | Lithostratigraphie Top Fels | | attachments | Text | Nein | Kommaseparierte Dateinamen der Anhänge mit Dateiendung z.B. anhang_1.pdf,anhang_2.zip | -## Lithologie Datei Format - -Die zu importierenden Daten müssen gemäss obigen Anforderungen im CSV-Format vorliegen. Die erste Zeile wird als Spaltentitel/Spaltenname interpretiert, die restlichen Zeilen als Daten. - -| Feldname | Datentyp | Pflichtfeld | Beschreibung | -| ------------------------ | -------------- | ----------- | ------------------------------------------------------------------------------------------------------------- | -| import_id | Zahl | Ja | Zufällig gewählte Zahl. Wird nicht gepeichert. Muss mit einer import_id aus der Bohrloch Datei übereinstimmen | -| strati_import_id | Zahl | Ja | Zufällig gewählte Zahl. Wird nicht gepeichert. Muss pro Stratigraphie identisch sein | -| strati_date | Datum | Nein | Datum der Stratigraphie. Muss pro Stratigraphie identisch sein | -| strati_name | Text | Nein | Name der Stratigraphie. Muss pro Stratigraphie identisch sein | -| from_depth | Zahl | Ja | Von Tiefe der Schicht | -| to_depth | Zahl | Ja | Bis Tiefe der Schicht | -| is_last | True/False | Nein | Ist die Schicht die letzte in der Stratigraphie? | -| description_quality_id | ID (Codeliste) | Nein | Qualität der Beschreibung | -| lithology_id | ID (Codeliste) | Nein | Lithologie | -| original_uscs | Text | Nein | USCS Originalklassifikation | -| uscs_determination_id | ID (Codeliste) | Nein | USCS Bestimmungsmethode | -| uscs_1_id | ID (Codeliste) | Nein | USCS 1 | -| grain_size_1_id | ID (Codeliste) | Nein | Korngrösse 1 | -| uscs_2_id | ID (Codeliste) | Nein | USCS 2 | -| grain_size_2_id | ID (Codeliste) | Nein | Korngrösse 2 | -| is_striae | True/False | Nein | Striemung | -| consistance_id | ID (Codeliste) | Nein | Konsistenz | -| plasticity_id | ID (Codeliste) | Nein | Plastizität | -| compactness_id | ID (Codeliste) | Nein | Lagerungsdichte | -| cohesion_id | ID (Codeliste) | Nein | Kohäsion | -| humidity_id | ID (Codeliste) | Nein | Feuchtigkeit | -| alteration_id | ID (Codeliste) | Nein | Verwitterung | -| notes | Text | Nein | Notizen | -| original_lithology | Text | Nein | Ursprüngliche Lithologie | -| uscs_3_ids | ID (Codeliste) | Nein | Kommaseparierte Codeliste IDs der USCS 3 | -| grain_shape_ids | ID (Codeliste) | Nein | Kommaseparierte Codeliste IDs der Korn Formen | -| grain_granularity_ids | ID (Codeliste) | Nein | Kommaseparierte Codeliste IDs der Kornrundungen | -| organic_component_ids | ID (Codeliste) | Nein | Kommaseparierte Codeliste IDs der Organischen Komponenten | -| debris_ids | ID (Codeliste) | Nein | Kommaseparierte Codeliste IDs der Grobbestandteile | -| color_ids | ID (Codeliste) | Nein | Kommaseparierte Codeliste IDs der Farben | -| gradation_id | ID (Codeliste) | Nein | Abstufung | -| lithology_top_bedrock_id | ID (Codeliste) | Nein | Lithologie Grobbestandteile | - ## Validierung ### Fehlende Werte diff --git a/src/client/src/pages/overview/layout/mainSideNav.tsx b/src/client/src/pages/overview/layout/mainSideNav.tsx index adb08dc42..fade3cda4 100644 --- a/src/client/src/pages/overview/layout/mainSideNav.tsx +++ b/src/client/src/pages/overview/layout/mainSideNav.tsx @@ -46,7 +46,6 @@ const MainSideNav = ({ const [validationErrorModal, setValidationErrorModal] = useState(false); const [selectedFile, setSelectedFile] = useState(null); const [selectedBoreholeAttachments, setSelectedBoreholeAttachments] = useState(null); - const [selectedLithologyFile, setSelectedLithologyFile] = useState(null); const [errorsResponse, setErrorsResponse] = useState(null); const filterContext = useContext(FilterContext); @@ -176,7 +175,6 @@ const MainSideNav = ({ setValidationErrorModal={setValidationErrorModal} refresh={refresh} setSelectedFile={setSelectedFile} - setSelectedLithologyFile={setSelectedLithologyFile} setWorkgroup={setWorkgroupId} enabledWorkgroups={enabledWorkgroups} setSelectedBoreholeAttachments={setSelectedBoreholeAttachments} @@ -185,7 +183,6 @@ const MainSideNav = ({ selectedBoreholeAttachments={selectedBoreholeAttachments} modal={modal} upload={upload} - selectedLithologyFile={selectedLithologyFile} /> >; selectedFile: Blob[] | null; setSelectedFile: React.Dispatch>; - setSelectedLithologyFile: React.Dispatch>; } export interface ImportModalProps extends ImportContentProps { modal: boolean; creating: boolean; - selectedLithologyFile: Blob[] | null; selectedBoreholeAttachments: Blob[] | null; selectedFile: Blob[] | null; upload: boolean; @@ -43,6 +41,5 @@ export interface ImportModalProps extends ImportContentProps { setErrorsResponse: React.Dispatch>; setValidationErrorModal: React.Dispatch>; setSelectedFile: React.Dispatch>; - setSelectedLithologyFile: React.Dispatch>; refresh: () => void; } diff --git a/src/client/src/pages/overview/sidePanelContent/importer/importModal.tsx b/src/client/src/pages/overview/sidePanelContent/importer/importModal.tsx index e6df5c96b..db2f49592 100644 --- a/src/client/src/pages/overview/sidePanelContent/importer/importModal.tsx +++ b/src/client/src/pages/overview/sidePanelContent/importer/importModal.tsx @@ -24,8 +24,6 @@ const ImportModal = ({ enabledWorkgroups, workgroup, setWorkgroup, - selectedLithologyFile, - setSelectedLithologyFile, refresh, }: ImportModalProps) => { const { showAlert } = useContext(AlertContext); @@ -43,11 +41,6 @@ const ImportModal = ({ combinedFormData.append("attachments", attachment); }); } - if (selectedLithologyFile !== null) { - selectedLithologyFile.forEach((lithologyFile: string | Blob) => { - combinedFormData.append("lithologyFile", lithologyFile); - }); - } } importBoreholes(workgroup, combinedFormData).then(response => { setCreating(false); @@ -107,7 +100,6 @@ const ImportModal = ({

{capitalizeFirstLetter(t("workgroup"))}

diff --git a/src/client/src/pages/overview/sidePanelContent/importer/importModalContent.tsx b/src/client/src/pages/overview/sidePanelContent/importer/importModalContent.tsx index ad9c04e0d..261316aa2 100644 --- a/src/client/src/pages/overview/sidePanelContent/importer/importModalContent.tsx +++ b/src/client/src/pages/overview/sidePanelContent/importer/importModalContent.tsx @@ -35,12 +35,7 @@ const ExampleHeadings = (headings: string) => { ); }; -const ImportModalContent = ({ - setSelectedBoreholeAttachments, - setSelectedFile, - setSelectedLithologyFile, - selectedFile, -}: ImportContentProps) => { +const ImportModalContent = ({ setSelectedBoreholeAttachments, setSelectedFile, selectedFile }: ImportContentProps) => { const { t } = useTranslation(); const handleBoreholeAttachmentChange = useCallback( @@ -50,13 +45,6 @@ const ImportModalContent = ({ [setSelectedBoreholeAttachments], ); - const handleLithologyFileChange = useCallback( - (lithologyFileFromDropzone: Blob[]) => { - setSelectedLithologyFile(lithologyFileFromDropzone); - }, - [setSelectedLithologyFile], - ); - const handleBoreholeFileChange = useCallback( (boreholeFileFromDropzone: Blob[]) => { setSelectedFile(boreholeFileFromDropzone); @@ -115,30 +103,6 @@ const ImportModalContent = ({ /> {SeparatorLine()} -

{capitalizeFirstLetter(t("lithology"))}

- - - {t("csvFormatExplanation")} - {ExampleHeadings( - "import_id;strati_import_id;strati_date;strati_name;from_depth;to_depth;" + - "is_last;description_quality_id;lithology_id;" + - "original_uscs;uscs_determination_id;uscs_1_id;grain_size_1_id;uscs_2_id;grain_size_2_id;" + - "is_striae;consistance_id;plasticity_id;compactness_id;cohesion_id;humidity_id;alteration_id;" + - "notes;original_lithology;uscs_3_ids;grain_shape_ids;grain_granularity_ids;organic_component_ids;" + - "debris_ids;color_ids;gradation_id;lithology_top_bedrock_id;", - )} - - - - {SeparatorLine()} ); }; diff --git a/tests/api/BDMS.Test.csproj b/tests/api/BDMS.Test.csproj index 68c1d325a..4c2392288 100644 --- a/tests/api/BDMS.Test.csproj +++ b/tests/api/BDMS.Test.csproj @@ -38,45 +38,6 @@ Always - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - Always @@ -116,9 +77,6 @@ Always - - Always - Always diff --git a/tests/api/Controllers/UploadControllerTest.cs b/tests/api/Controllers/UploadControllerTest.cs index 406b02f88..e3697460b 100644 --- a/tests/api/Controllers/UploadControllerTest.cs +++ b/tests/api/Controllers/UploadControllerTest.cs @@ -77,137 +77,6 @@ public async Task TestCleanup() loggerMock.Verify(); } - [TestMethod] - public async Task UploadLithologyShouldSaveData() - { - httpClientFactoryMock - .Setup(cf => cf.CreateClient(It.IsAny())) - .Returns(() => new HttpClient()) - .Verifiable(); - - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: lithoCsvFile, attachments: null); - - ActionResultAssert.IsOk(response.Result); - OkObjectResult okResult = (OkObjectResult)response.Result!; - Assert.AreEqual(1, okResult.Value); - - // Assert imported values - var borehole = GetBoreholesWithIncludes(context.Boreholes).ToList().Find(b => b.OriginalName == "Seth Patel"); - Assert.AreEqual(1, borehole.WorkgroupId); - Assert.AreEqual("Seth Patel", borehole.OriginalName); - - // Assert imported stratigraphy & lithologies - Assert.AreEqual(2, borehole.Stratigraphies.Count); - - // First stratigraphy - var stratigraphy = borehole.Stratigraphies.First(); - Assert.AreEqual(new DateTime(2021, 8, 6), stratigraphy.Date?.Date); - Assert.AreEqual("Bennett", stratigraphy.Name); - Assert.AreEqual(2, stratigraphy.Layers.Count); - var lithology = stratigraphy.Layers.First(l => l.FromDepth == 0.125); - Assert.AreEqual(100, lithology.ToDepth); - Assert.AreEqual(false, lithology.IsLast); - Assert.AreEqual(9001, lithology.DescriptionQualityId); - Assert.AreEqual(15104915, lithology.LithologyId); - Assert.AreEqual(15302034, lithology.LithostratigraphyId); - Assert.AreEqual("Granite", lithology.OriginalUscs); - Assert.AreEqual(23107001, lithology.UscsDeterminationId); - Assert.AreEqual(23101005, lithology.Uscs1Id); - Assert.AreEqual(21101001, lithology.GrainSize1Id); - Assert.AreEqual(23101008, lithology.Uscs2Id); - Assert.AreEqual(21103008, lithology.GrainSize2Id); - Assert.AreEqual(false, lithology.IsStriae); - Assert.AreEqual(21103003, lithology.ConsistanceId); - Assert.AreEqual(21101001, lithology.PlasticityId); - Assert.AreEqual(21102007, lithology.CompactnessId); - Assert.AreEqual(21116005, lithology.CohesionId); - Assert.AreEqual(21105002, lithology.HumidityId); - Assert.AreEqual(21106004, lithology.AlterationId); - Assert.AreEqual("instruction set Dynamic backing up Lock", lithology.Notes); - Assert.AreEqual("trace back Peso", lithology.OriginalLithology); - Assert.AreEqual(30000018, lithology.GradationId); - Assert.AreEqual(15104916, lithology.LithologyTopBedrockId); - Assert.AreEqual(2, lithology.ColorCodelists.Count); - Assert.AreEqual(2, lithology.DebrisCodelists.Count); - Assert.AreEqual(2, lithology.GrainAngularityCodelists.Count); - Assert.AreEqual(2, lithology.GrainShapeCodelists.Count); - Assert.AreEqual(3, lithology.OrganicComponentCodelists.Count); - Assert.AreEqual(3, lithology.Uscs3Codelists.Count); - - lithology = stratigraphy.Layers.First(l => l.FromDepth == 11); - Assert.AreEqual(12, lithology.ToDepth); - - // Second stratigraphy - stratigraphy = borehole.Stratigraphies.Skip(1).First(); - Assert.AreEqual(1, stratigraphy.Layers.Count); - lithology = stratigraphy.Layers.First(); - Assert.AreEqual(55, lithology.FromDepth); - Assert.AreEqual(55.23, lithology.ToDepth); - } - - [TestMethod] - public async Task UploadLithologyWithMultiCodeListPropertiesProvidedShouldSaveData() - { - httpClientFactoryMock - .Setup(cf => cf.CreateClient(It.IsAny())) - .Returns(() => new HttpClient()) - .Verifiable(); - - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho_with_multi_code_list_properties/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho_with_multi_code_list_properties/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: lithoCsvFile, attachments: null); - - ActionResultAssert.IsOk(response.Result); - OkObjectResult okResult = (OkObjectResult)response.Result!; - Assert.AreEqual(1, okResult.Value); - - // Assert imported values - var borehole = GetBoreholesWithIncludes(context.Boreholes) - .ToList().Find(b => b.OriginalName == "Seth Patel"); - Assert.AreEqual(1, borehole.WorkgroupId); - Assert.AreEqual("Seth Patel", borehole.OriginalName); - - // Assert imported stratigraphy & lithologies - Assert.AreEqual(2, borehole.Stratigraphies.Count); - - // First stratigraphy - var stratigraphy = borehole.Stratigraphies.First(); - Assert.AreEqual(2, stratigraphy.Layers.Count); - var lithology = stratigraphy.Layers.First(l => l.FromDepth == 0.125); - Assert.AreEqual(100, lithology.ToDepth); - Assert.AreEqual(2, lithology.ColorCodelists.Count); - Assert.AreEqual(2, lithology.DebrisCodelists.Count); - Assert.AreEqual(3, lithology.GrainAngularityCodelists.Count); - Assert.AreEqual(3, lithology.GrainShapeCodelists.Count); - Assert.AreEqual(3, lithology.OrganicComponentCodelists.Count); - Assert.AreEqual(3, lithology.Uscs3Codelists.Count); - lithology = stratigraphy.Layers.First(l => l.FromDepth == 11); - Assert.AreEqual(12, lithology.ToDepth); - Assert.AreEqual(0, lithology.ColorCodelists.Count); - Assert.AreEqual(1, lithology.DebrisCodelists.Count); - Assert.AreEqual(0, lithology.GrainAngularityCodelists.Count); - Assert.AreEqual(0, lithology.GrainShapeCodelists.Count); - Assert.AreEqual(0, lithology.OrganicComponentCodelists.Count); - Assert.AreEqual(0, lithology.Uscs3Codelists.Count); - - // Second stratigraphy - stratigraphy = borehole.Stratigraphies.Skip(1).First(); - Assert.AreEqual(1, stratigraphy.Layers.Count); - lithology = stratigraphy.Layers.First(); - Assert.AreEqual(55, lithology.FromDepth); - Assert.AreEqual(55.23, lithology.ToDepth); - Assert.AreEqual(0, lithology.ColorCodelists.Count); - Assert.AreEqual(0, lithology.DebrisCodelists.Count); - Assert.AreEqual(0, lithology.GrainAngularityCodelists.Count); - Assert.AreEqual(0, lithology.GrainShapeCodelists.Count); - Assert.AreEqual(0, lithology.OrganicComponentCodelists.Count); - Assert.AreEqual(2, lithology.Uscs3Codelists.Count); - } - [TestMethod] public async Task UploadShouldSaveDataToDatabaseAsync() { @@ -265,7 +134,7 @@ public async Task UploadShouldSaveMinimalDatasetAsync() var boreholeCsvFile = GetFormFileByExistingFile("minimal_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, attachments: null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, attachments: null); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -304,7 +173,7 @@ public async Task UploadShouldSavePrecisionDatasetAsync() var boreholeCsvFile = GetFormFileByExistingFile("precision_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, attachments: null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, attachments: null); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -359,7 +228,7 @@ public async Task UploadShouldSaveBoreholeWithAttachmentsAsync() var ninthAttachmentFile = GetFormFileByExistingFile("borehole_attachment_4.zip"); var tenthAttachmentFile = GetFormFileByExistingFile("borehole_attachment_5.png"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFormFile, lithologyFile: null, new List() { firstAttachmentFile, secondAttachmentFile, thirdAttachmentFile, fourthAttachmentFile, fifthAttachmentFile, sixthAttachmentFile, seventhAttachmentFile, eighthAttachmentFile, ninthAttachmentFile, tenthAttachmentFile }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFormFile, new List() { firstAttachmentFile, secondAttachmentFile, thirdAttachmentFile, fourthAttachmentFile, fifthAttachmentFile, sixthAttachmentFile, seventhAttachmentFile, eighthAttachmentFile, ninthAttachmentFile, tenthAttachmentFile }); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -381,7 +250,7 @@ public async Task UploadShouldSaveBoreholesWithNotAllHaveAttachmentsAsync() var firstAttachmentFile = GetFormFileByExistingFile("borehole_attachment_1.pdf"); var secondAttachmentFile = GetFormFileByExistingFile("borehole_attachment_2.pdf"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFormFile, lithologyFile: null, new List() { firstAttachmentFile, secondAttachmentFile }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFormFile, new List() { firstAttachmentFile, secondAttachmentFile }); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -400,7 +269,7 @@ public async Task UploadShouldSaveBoreholeWithAttachmentFileNamesMixedCaseAsync( var firstPdfFormFile = GetFormFileByExistingFile("borehole_attachment_1.pdf"); var secondPdfFormFile = GetFormFileByExistingFile("borehole_attachment_2.pdf"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFormFile, lithologyFile: null, new List() { firstPdfFormFile, secondPdfFormFile }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFormFile, new List() { firstPdfFormFile, secondPdfFormFile }); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -417,7 +286,7 @@ public async Task UploadShouldSaveSpecialCharsDatasetAsync() var boreholeCsvFile = GetFormFileByExistingFile("special_chars_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -436,7 +305,7 @@ public async Task UploadWithMissingCoordinatesAsync() { var boreholeCsvFile = GetFormFileByExistingFile("no_coordinates_provided_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null); Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); ObjectResult result = (ObjectResult)response.Result!; @@ -458,7 +327,7 @@ public async Task UploadBoreholeWithLV95CoordinatesAsync() var boreholeCsvFile = GetFormFileByExistingFile("lv95_coordinates_provided_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -487,7 +356,7 @@ public async Task UploadBoreholeWithLV03CoordinatesAsync() var boreholeCsvFile = GetFormFileByExistingFile("lv03_coordinates_provided_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -516,7 +385,7 @@ public async Task UploadBoreholeWithLV03OutOfRangeCoordinatesAsync() var boreholeCsvFile = GetFormFileByExistingFile("lv03_out_of_range_coordinates_provided_testdata.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -540,7 +409,7 @@ public async Task UploadEmptyFileShouldReturnError() { var boreholeCsvFile = new FormFile(null, 0, 0, null, "non_existent_file.csv"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null); ActionResultAssert.IsBadRequest(response.Result); BadRequestObjectResult badRequestResult = (BadRequestObjectResult)response.Result!; @@ -552,7 +421,7 @@ public async Task UploadInvalidFileTypeBoreholeCsvShouldReturnError() { var invalidFileTypeBoreholeFile = GetFormFileByContent(fileContent: "This is the content of the file.", fileName: "invalid_file_type.txt"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, invalidFileTypeBoreholeFile, lithologyFile: null, null); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, invalidFileTypeBoreholeFile, null); ActionResultAssert.IsBadRequest(response.Result); BadRequestObjectResult badRequestResult = (BadRequestObjectResult)response.Result!; @@ -571,7 +440,7 @@ public async Task UploadBoreholeCsvFileWithoutAttachmentsButWithProvidedFilesSho var firstPdfFormFile = GetFormFileByExistingFile("borehole_attachment_1.pdf"); var secondPdfFormFile = GetFormFileByExistingFile("borehole_attachment_2.pdf"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, new List() { firstPdfFormFile, secondPdfFormFile }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, new List() { firstPdfFormFile, secondPdfFormFile }); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -595,7 +464,7 @@ public async Task UploadBoreholeCsvFileWithAttachmentsLinkedPdfsShouldCreateBore var firstPdfFormFile = GetFormFileByExistingFile(firstAttachmentFileName); var secondPdfFormFile = GetFormFileByExistingFile(secondAttachmentFileName); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, new List() { firstPdfFormFile, secondPdfFormFile }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, new List() { firstPdfFormFile, secondPdfFormFile }); ActionResultAssert.IsOk(response.Result); OkObjectResult okResult = (OkObjectResult)response.Result!; @@ -619,7 +488,7 @@ public async Task UploadBoreholeCsvFileWithNotPresentAttachmentsShouldReturnErro var firstPdfFormFile = GetFormFileByExistingFile("borehole_attachment_1.pdf"); var secondPdfFormFile = GetFormFileByExistingFile("borehole_attachment_2.pdf"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, new List() { firstPdfFormFile, secondPdfFormFile }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, new List() { firstPdfFormFile, secondPdfFormFile }); Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); ObjectResult result = (ObjectResult)response.Result!; @@ -640,7 +509,7 @@ public async Task UploadBoreholeCsvFileWithWhiteSpaceInAttachmentFileNameShouldR var firstPdfFormFile = GetFormFileByExistingFile("borehole_attachment_1.pdf"); var whiteSpacePdf = GetFormFileByExistingFile("white space.pdf"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: null, new List() { firstPdfFormFile, whiteSpacePdf }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, new List() { firstPdfFormFile, whiteSpacePdf }); ActionResultAssert.IsBadRequest(response.Result); BadRequestObjectResult badRequestResult = (BadRequestObjectResult)response.Result!; @@ -707,26 +576,6 @@ public async Task UploadMultipleRowsMissingRequiredFieldsShouldReturnError() problemDetails.Errors["Row3"]); } - [TestMethod] - public async Task UploadLithologyMultipleRowsMissingRequiredFieldsShouldReturnError() - { - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho_missing_required_fields/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho_missing_required_fields/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithoCsvFile); - - Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); - ObjectResult result = (ObjectResult)response.Result!; - ActionResultAssert.IsBadRequest(result); - - ValidationProblemDetails problemDetails = (ValidationProblemDetails)result.Value!; - Assert.AreEqual(3, problemDetails.Errors.Count); - - CollectionAssert.AreEquivalent(new[] { "Field 'to_depth' is required." }, problemDetails.Errors["Row1"]); - CollectionAssert.AreEquivalent(new[] { "Field 'from_depth' is required." }, problemDetails.Errors["Row2"]); - CollectionAssert.AreEquivalent(new[] { "Field 'from_depth' is required." }, problemDetails.Errors["Row3"]); - } - [TestMethod] public async Task UploadRequiredHeadersMissingShouldReturnError() { @@ -746,69 +595,6 @@ public async Task UploadRequiredHeadersMissingShouldReturnError() StringAssert.Contains(problemDetails.Detail, "Header with name 'ImportId'[0] was not found."); } - [TestMethod] - public async Task UploadLithologyRequiredHeadersMissingShouldReturnError() - { - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho_missing_required_headers/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho_missing_required_headers/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithoCsvFile); - - Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); - ObjectResult result = (ObjectResult)response.Result!; - ActionResultAssert.IsBadRequest(result); - - ProblemDetails problemDetails = (ProblemDetails)result.Value!; - StringAssert.Contains(problemDetails.Detail, "Header with name 'ImportId'[0] was not found."); - StringAssert.Contains(problemDetails.Detail, "Header with name 'StratiImportId'[0] was not found."); - StringAssert.Contains(problemDetails.Detail, "Header with name 'FromDepth'[0] was not found."); - StringAssert.Contains(problemDetails.Detail, "Header with name 'ToDepth'[0] was not found."); - } - - [TestMethod] - public async Task UploadLithologyDiffInStratiAttributesForSameStratiIdShouldReturnError() - { - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithoCsvFile); - - Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); - ObjectResult result = (ObjectResult)response.Result!; - ActionResultAssert.IsBadRequest(result); - - ValidationProblemDetails problemDetails = (ValidationProblemDetails)result.Value!; - Assert.AreEqual(1, problemDetails.Errors.Count); - - CollectionAssert.AreEquivalent( - new[] - { - $"Lithology with {nameof(LithologyImport.StratiImportId)} '1001' has various {nameof(LithologyImport.StratiName)}.", - $"Lithology with {nameof(LithologyImport.StratiImportId)} '1001' has various {nameof(LithologyImport.StratiDate)}.", - }, - problemDetails.Errors["Row1"]); - } - - [TestMethod] - public async Task UploadLithologyWithImportIdNotPresentInBoreholeFileShouldReturnError() - { - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho_import_id_not_present_in_borehole_file/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho_import_id_not_present_in_borehole_file/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithoCsvFile); - - Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); - ObjectResult result = (ObjectResult)response.Result!; - ActionResultAssert.IsBadRequest(result); - - ValidationProblemDetails problemDetails = (ValidationProblemDetails)result.Value!; - Assert.AreEqual(1, problemDetails.Errors.Count); - - CollectionAssert.AreEquivalent( - new[] { "Borehole with ImportId '2' not found." }, - problemDetails.Errors["Row2"]); - } - [TestMethod] public async Task UploadDuplicateBoreholesInFileShouldReturnError() { @@ -827,25 +613,6 @@ public async Task UploadDuplicateBoreholesInFileShouldReturnError() CollectionAssert.AreEquivalent(new[] { $"Borehole with same Coordinates (+/- 2m) and same {nameof(Borehole.TotalDepth)} is provided multiple times.", }, problemDetails.Errors["Row2"]); } - [TestMethod] - public async Task UploadLithologyWithInvalidCodeListIdsShouldSaveData() - { - var boreholeCsvFile = GetFormFileByExistingFile("data_sets/import_litho_with_invalid_code_list_ids/borehole.csv"); - var lithoCsvFile = GetFormFileByExistingFile("data_sets/import_litho_with_invalid_code_list_ids/litho.csv"); - - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, lithologyFile: lithoCsvFile, attachments: null); - - Assert.IsInstanceOfType(response.Result, typeof(ObjectResult)); - ObjectResult result = (ObjectResult)response.Result!; - ActionResultAssert.IsBadRequest(result); - - ValidationProblemDetails problemDetails = (ValidationProblemDetails)result.Value!; - Assert.AreEqual(2, problemDetails.Errors.Count); - - CollectionAssert.AreEquivalent(new[] { $"One or more invalid (not a number) code list id in any of the following properties: {nameof(LithologyImport.ColorIds)}, {nameof(LithologyImport.OrganicComponentIds)}, {nameof(LithologyImport.GrainShapeIds)}, {nameof(LithologyImport.GrainGranularityIds)}, {nameof(LithologyImport.Uscs3Ids)}, {nameof(LithologyImport.DebrisIds)}.", }, problemDetails.Errors["Row1"]); - CollectionAssert.AreEquivalent(new[] { $"One or more invalid (not a number) code list id in any of the following properties: {nameof(LithologyImport.ColorIds)}, {nameof(LithologyImport.OrganicComponentIds)}, {nameof(LithologyImport.GrainShapeIds)}, {nameof(LithologyImport.GrainGranularityIds)}, {nameof(LithologyImport.Uscs3Ids)}, {nameof(LithologyImport.DebrisIds)}.", }, problemDetails.Errors["Row2"]); - } - [TestMethod] public async Task UploadDuplicateBoreholesInDbShouldReturnError() { @@ -944,7 +711,7 @@ public async Task UploadWithAttachmentToLargeShouldThrowError() var attachment = new FormFile(stream, 0, stream.Length, "file", "dummy.txt"); - ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, null, new[] { attachment }); + ActionResult response = await controller.UploadFileAsync(workgroupId: 1, boreholeCsvFile, new[] { attachment }); ActionResultAssert.IsBadRequest(response.Result); BadRequestObjectResult badRequestResult = (BadRequestObjectResult)response.Result!; diff --git a/tests/api/TestData/data_sets/import_litho/borehole.csv b/tests/api/TestData/data_sets/import_litho/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho/litho.csv b/tests/api/TestData/data_sets/import_litho/litho.csv deleted file mode 100644 index c0100c623..000000000 --- a/tests/api/TestData/data_sets/import_litho/litho.csv +++ /dev/null @@ -1,4 +0,0 @@ -import_id;strati_import_id;strati_date;strati_name;from_depth;to_depth;is_last;description_quality_id;lithology_id;lithostratigraphy_id;chronostratigraphy_id;original_uscs;uscs_determination_id;uscs_1_id;grain_size_1_id;uscs_2_id;grain_size_2_id;is_striae;consistance_id;plasticity_id;compactness_id;cohesion_id;humidity_id;alteration_id;notes;original_lithology;uscs_3_ids;grain_shape_ids;grain_granularity_ids;organic_component_ids;debris_ids;color_ids;gradation_id;lithology_top_bedrock_id; -1;1001;2021-08-06 00:36:21.991827+00;Bennett;0.125;100;false;9001;15104915;15302034;15001069;Granite;23107001;23101005;21101001;23101008;21103008;false;21103003;21101001;21102007;21116005;21105002;21106004;instruction set Dynamic backing up Lock;trace back Peso;23101001,23101004,23101005;21110002,21110005;21115001,21115004;21108002,21108004,21108005;9100,9102;21112001,21112004;30000018;15104916; -1;1001;2021-08-06 00:36:21.991827+00;Bennett;11;12;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -1;2001;;;55;55.23;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/tests/api/TestData/data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/borehole.csv b/tests/api/TestData/data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/litho.csv b/tests/api/TestData/data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/litho.csv deleted file mode 100644 index 8ee841ebc..000000000 --- a/tests/api/TestData/data_sets/import_litho_diff_in_strati_attributes_for_same_starti_id/litho.csv +++ /dev/null @@ -1,3 +0,0 @@ -import_id;strati_import_id;strati_date;strati_name;from_depth;to_depth -1;1001;2021-08-06 00:36:21.991827+00;name1;01;1 -1;1001;2017-08-06 00:36:21.991827+00;name2;0;1 diff --git a/tests/api/TestData/data_sets/import_litho_import_id_not_present_in_borehole_file/borehole.csv b/tests/api/TestData/data_sets/import_litho_import_id_not_present_in_borehole_file/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho_import_id_not_present_in_borehole_file/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho_import_id_not_present_in_borehole_file/litho.csv b/tests/api/TestData/data_sets/import_litho_import_id_not_present_in_borehole_file/litho.csv deleted file mode 100644 index 7ad8e5909..000000000 --- a/tests/api/TestData/data_sets/import_litho_import_id_not_present_in_borehole_file/litho.csv +++ /dev/null @@ -1,3 +0,0 @@ -import_id;strati_import_id;from_depth;to_depth -1;1001;0.125;55 -2;2001;12;55.23 diff --git a/tests/api/TestData/data_sets/import_litho_missing_required_fields/borehole.csv b/tests/api/TestData/data_sets/import_litho_missing_required_fields/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho_missing_required_fields/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho_missing_required_fields/litho.csv b/tests/api/TestData/data_sets/import_litho_missing_required_fields/litho.csv deleted file mode 100644 index a5c7df706..000000000 --- a/tests/api/TestData/data_sets/import_litho_missing_required_fields/litho.csv +++ /dev/null @@ -1,4 +0,0 @@ -import_id;strati_import_id;from_depth;to_depth -1;1001;0.125; -1;1001;;12 -1;2001;;55.23 diff --git a/tests/api/TestData/data_sets/import_litho_missing_required_headers/borehole.csv b/tests/api/TestData/data_sets/import_litho_missing_required_headers/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho_missing_required_headers/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho_missing_required_headers/litho.csv b/tests/api/TestData/data_sets/import_litho_missing_required_headers/litho.csv deleted file mode 100644 index 00f996284..000000000 --- a/tests/api/TestData/data_sets/import_litho_missing_required_headers/litho.csv +++ /dev/null @@ -1,4 +0,0 @@ -alteration_id_cli; -1;1001;0.125; -1;1001;;12 -1;2001;;55.23 diff --git a/tests/api/TestData/data_sets/import_litho_with_invalid_code_list_ids/borehole.csv b/tests/api/TestData/data_sets/import_litho_with_invalid_code_list_ids/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho_with_invalid_code_list_ids/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho_with_invalid_code_list_ids/litho.csv b/tests/api/TestData/data_sets/import_litho_with_invalid_code_list_ids/litho.csv deleted file mode 100644 index 6e366743a..000000000 --- a/tests/api/TestData/data_sets/import_litho_with_invalid_code_list_ids/litho.csv +++ /dev/null @@ -1,3 +0,0 @@ -import_id;strati_import_id;from_depth;to_depth;color_ids;organic_component_ids;grain_shape_ids;grain_granularity_ids;uscs_3_ids;debris_ids -1;1001;0.125;100;21112001,21112004;NAN; -1;1001;0.125;100;1000000000000,21112004 diff --git a/tests/api/TestData/data_sets/import_litho_with_multi_code_list_properties/borehole.csv b/tests/api/TestData/data_sets/import_litho_with_multi_code_list_properties/borehole.csv deleted file mode 100644 index d54f3a7be..000000000 --- a/tests/api/TestData/data_sets/import_litho_with_multi_code_list_properties/borehole.csv +++ /dev/null @@ -1,2 +0,0 @@ -import_id;original_name;location_x;location_y -1;Seth Patel;2000000;1000000 diff --git a/tests/api/TestData/data_sets/import_litho_with_multi_code_list_properties/litho.csv b/tests/api/TestData/data_sets/import_litho_with_multi_code_list_properties/litho.csv deleted file mode 100644 index b15ace620..000000000 --- a/tests/api/TestData/data_sets/import_litho_with_multi_code_list_properties/litho.csv +++ /dev/null @@ -1,4 +0,0 @@ -import_id;strati_import_id;from_depth;to_depth;color_ids;organic_component_ids;grain_shape_ids;grain_granularity_ids;uscs_3_ids;debris_ids -1;1001;0.125;100;21112001,21112004;21108002,21108004,21108007;21110003,21110004,21110005;21115003,21115004,21115005;23101002,23101003,23101004;9100,9102 -1;1001;11;12;;;;;;9100 -1;2001;55;55.23;;;;;23101003,23101004;