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

HicServices / RDMP / 9757025998

02 Jul 2024 07:49AM UTC coverage: 56.677% (-0.2%) from 56.914%
9757025998

Pull #1867

github

JFriel
remove with values
Pull Request #1867: Release/8.2.0

10911 of 20750 branches covered (52.58%)

Branch coverage included in aggregate %.

369 of 831 new or added lines in 38 files covered. (44.4%)

375 existing lines in 25 files now uncovered.

30965 of 53135 relevant lines covered (58.28%)

7844.83 hits per line

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

3.45
/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)
14✔
27
    {
28
    }
14✔
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
    {
UNCOV
38
        ExtractDirectory = new FileInfo(extractionResults.DestinationDescription).Directory;
×
UNCOV
39
        if (FilesAreMissing(extractionResults))
×
40
            return Releaseability.ExtractFilesMissing;
×
41

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

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

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

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

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

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

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

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

UNCOV
74
        return unexpectedDirectory != null
×
UNCOV
75
            ? throw new Exception(
×
UNCOV
76
                $"Unexpected directory found in extraction directory {unexpectedDirectory.FullName} (pollution of extract directory is not permitted)")
×
UNCOV
77
            : false;
×
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

UNCOV
85
        if (ExtractDirectory.Parent.GetFiles().Any())
×
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}\"")}");
×
UNCOV
88
    }
×
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