• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 6237307473

19 Sep 2023 04:02PM UTC coverage: 57.015% (-0.4%) from 57.44%
6237307473

push

github

web-flow
Feature/rc4 (#1570)

* Syntax tidying
* Dependency updates
* Event handling singletons (ThrowImmediately and co)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: James A Sutherland <>
Co-authored-by: James Friel <jfriel001@dundee.ac.uk>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10734 of 20259 branches covered (0.0%)

Branch coverage included in aggregate %.

5922 of 5922 new or added lines in 565 files covered. (100.0%)

30687 of 52390 relevant lines covered (58.57%)

7361.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.07
/Rdmp.Core/DataExport/DataRelease/Potential/FlatFileReleasePotential.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Diagnostics;
9
using System.IO;
10
using System.Linq;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.DataExport.Data;
13
using Rdmp.Core.Repositories;
14

15
namespace Rdmp.Core.DataExport.DataRelease.Potential;
16

17
/// <summary>
18
/// Determines whether a given ExtractableDataSet in an ExtractionConfiguration, as generated by a Flat File extraction configuration is ready for Release.
19
/// This includes making sure that the current configuration
20
/// in the database matches the extracted flat files that are destined for release.  It also checks that the user hasn't snuck some additional files into
21
/// the extract directory etc.
22
/// </summary>
23
public class FlatFileReleasePotential : ReleasePotential
24
{
25
    public FlatFileReleasePotential(IRDMPPlatformRepositoryServiceLocator repositoryLocator,
26
        ISelectedDataSets selectedDataSets) : base(repositoryLocator, selectedDataSets)
36✔
27
    {
28
    }
36✔
29

30
    protected override Releaseability GetSupplementalSpecificAssessment(
31
        IExtractionResults supplementalExtractionResults) =>
32
        File.Exists(supplementalExtractionResults.DestinationDescription)
×
33
            ? Releaseability.Undefined
×
34
            : Releaseability.ExtractFilesMissing;
×
35

36
    protected override Releaseability GetSpecificAssessment(IExtractionResults extractionResults)
37
    {
38
        ExtractDirectory = new FileInfo(extractionResults.DestinationDescription).Directory;
22✔
39
        if (FilesAreMissing(extractionResults))
22!
40
            return Releaseability.ExtractFilesMissing;
×
41

42
        ThrowIfPollutionFoundInConfigurationRootExtractionFolder();
22✔
43
        return
22✔
44
            Releaseability
22✔
45
                .Undefined; // Assesment = SqlDifferencesVsLiveCatalogue() ? Releaseability.ColumnDifferencesVsCatalogue : Releaseability.Releaseable;
22✔
46
    }
47

48
    private bool FilesAreMissing(IExtractionResults extractionResults)
49
    {
50
        ExtractFile = new FileInfo(extractionResults.DestinationDescription);
22✔
51
        var metadataFile = new FileInfo(extractionResults.DestinationDescription.Replace(".csv", ".docx"));
22✔
52

53
        if (!ExtractFile.Exists)
22!
54
            return true; //extract is missing
×
55

56
        if (!ExtractFile.Extension.Equals(".csv"))
22!
57
            throw new Exception($"Extraction file had extension '{ExtractFile.Extension}' (expected .csv)");
×
58

59
        if (!metadataFile.Exists)
22!
60
            return true;
×
61

62
        //see if there is any other pollution in the extract directory
63
        var unexpectedFile = ExtractFile.Directory.EnumerateFiles().FirstOrDefault(f =>
22✔
64
            !(f.Name.Equals(ExtractFile.Name) || f.Name.Equals(metadataFile.Name)));
66✔
65

66
        if (unexpectedFile != null)
22!
67
            throw new Exception(
×
68
                $"Unexpected file found in extract directory {unexpectedFile.FullName} (pollution of extract directory is not permitted)");
×
69

70
        var unexpectedDirectory = ExtractFile.Directory.EnumerateDirectories().FirstOrDefault(d =>
22✔
71
            !(d.Name.Equals("Lookups") || d.Name.Equals("SupportingDocuments") ||
44!
72
              d.Name.Equals(SupportingSQLTable.ExtractionFolderName)));
44✔
73

74
        return unexpectedDirectory != null
22!
75
            ? throw new Exception(
22✔
76
                $"Unexpected directory found in extraction directory {unexpectedDirectory.FullName} (pollution of extract directory is not permitted)")
22✔
77
            : false;
22✔
78
    }
79

80
    private void ThrowIfPollutionFoundInConfigurationRootExtractionFolder()
81
    {
82
        Debug.Assert(ExtractDirectory.Parent != null,
83
            "Don't call this method until you have determined that an extracted file was actually produced!");
84

85
        if (ExtractDirectory.Parent.GetFiles().Any())
22!
86
            throw new Exception(
×
87
                $"The following pollutants were found in the extraction directory\" {ExtractDirectory.Parent.FullName}\" pollutants were:{ExtractDirectory.Parent.GetFiles().Aggregate("", (s, n) => $"{s}\"{n}\"")}");
×
88
    }
22✔
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc