[Datasets] Task/rdmp 33 dataset update post load#2191
[Datasets] Task/rdmp 33 dataset update post load#2191JFriel wants to merge 3 commits intotask/RDMP-33-dataset-integration-interfacefrom
Conversation
| Assert.DoesNotThrow(cmd.Execute); | ||
| var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Dataset>().First(); | ||
| var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository,"catalogue"), null, false); | ||
| var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Datasets.Dataset>().First(); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, the assignment to founddataset on line 90 should be removed entirely, as it serves no purpose in the method. This will eliminate the "useless assignment" and make the code cleaner and more maintainable. No additional changes are required, as the removal does not affect the logic or functionality of the test.
| @@ -89,3 +89,2 @@ | ||
| Assert.DoesNotThrow(cmd.Execute); | ||
| var founddataset = GetMockActivator().RepositoryLocator.CatalogueRepository.GetAllObjects<Core.Curation.Data.Datasets.Dataset>().First(); | ||
| var linkCmd = new ExecuteCommandLinkCatalogueToDataset(GetMockActivator(), new Catalogue(GetMockActivator().RepositoryLocator.CatalogueRepository, "catalogue"), null, false); |
| base.SaveToDatabase(); | ||
| foreach (var dataset in CatalogueRepository.GetAllObjectsWhere<CatalogueDatasetLinkage>("Catalogue_ID", this.ID).Where(cdl => cdl.Autoupdate).Select(cld => cld.Dataset)) | ||
| { | ||
| var provider = CatalogueRepository.GetObjectByID<DatasetProviderConfiguration>((int)dataset.Provider_ID); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, the assignment to the provider variable on line 1163 should be removed entirely, as it is not used anywhere in the code. This will eliminate the unnecessary assignment and make the code cleaner. No additional changes are required, as the subsequent assignment to providerConfiguration already retrieves the necessary object.
| @@ -1162,3 +1162,2 @@ | ||
| { | ||
| var provider = CatalogueRepository.GetObjectByID<DatasetProviderConfiguration>((int)dataset.Provider_ID); | ||
| var providerConfiguration = CatalogueRepository.GetObjectByID<DatasetProviderConfiguration>((int)dataset.Provider_ID); |
| { | ||
| private int _catalogueID; | ||
| private int _datasetID; | ||
| private ICatalogueRepository _repository; |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, the readonly modifier should be added to the _repository field declaration. This change ensures that _repository can only be assigned during its declaration or within the constructors of the CatalogueDatasetLinkage class. No other changes are required, as the field is already only assigned in the constructors.
| @@ -20,3 +20,3 @@ | ||
| private int _datasetID; | ||
| private ICatalogueRepository _repository; | ||
| private readonly ICatalogueRepository _repository; | ||
|
|
| { | ||
| {"Catalogue_ID", catalogue.ID }, | ||
| { "Dataset_ID", dataset.ID}, | ||
| {"Autoupdate", autoupdate==true?1:0 } |
Check notice
Code scanning / CodeQL
Unnecessarily complex Boolean expression Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we will simplify the expression autoupdate == true to just autoupdate. This change will make the code more concise and easier to read while maintaining the same functionality. The modification will be applied to line 50 in the constructor of the CatalogueDatasetLinkage class.
| @@ -49,3 +49,3 @@ | ||
| { "Dataset_ID", dataset.ID}, | ||
| {"Autoupdate", autoupdate==true?1:0 } | ||
| {"Autoupdate", autoupdate ? 1 : 0 } | ||
| }); |
| qb.AddCustomLine($"{SpecialFieldNames.DataLoadRunID} = {dataLoadID}", FAnsi.Discovery.QuerySyntax.QueryComponent.WHERE); | ||
| var sql = qb.SQL; | ||
|
|
||
| var dt = new DataTable(); |
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable Warning
| if (_activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Dataset>("Url", fetchedDataset.Url).Any()) | ||
| { | ||
| dataset = _activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Dataset>("Url", fetchedDataset.Url).First(); | ||
| } | ||
| else | ||
| { | ||
| dataset = provider.AddExistingDatasetWithReturn(null, tbID.Text); | ||
| } |
Check notice
Code scanning / CodeQL
Missed ternary opportunity Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we will replace the if statement on line 37 with a single line using the ternary operator. This will assign the value to the dataset variable based on the condition in a more concise and readable manner. The functionality of the code will remain unchanged.
| @@ -36,10 +36,5 @@ | ||
| var fetchedDataset = provider.FetchDatasetByID(int.Parse(tbID.Text));//todo is it always ints? | ||
| if (_activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Dataset>("Url", fetchedDataset.Url).Any()) | ||
| { | ||
| dataset = _activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Dataset>("Url", fetchedDataset.Url).First(); | ||
| } | ||
| else | ||
| { | ||
| dataset = provider.AddExistingDatasetWithReturn(null, tbID.Text); | ||
| } | ||
| dataset = _activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Dataset>("Url", fetchedDataset.Url).Any() | ||
| ? _activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<Dataset>("Url", fetchedDataset.Url).First() | ||
| : provider.AddExistingDatasetWithReturn(null, tbID.Text); | ||
| if (!_activator.RepositoryLocator.CatalogueRepository.GetAllObjectsWhere<CatalogueDatasetLinkage>("Dataset_ID", dataset.ID).Where(l => l.Catalogue.ID == _catalogue.ID).Any()) |
|
|
||
| if(typeof(T) == typeof(CatalogueDatasetLinkage)) | ||
| { | ||
| return (T)(object)new CatalogueDatasetLinkage(repository.CatalogueRepository, WhenIHaveA<Catalogue>(repository), WhenIHaveA<Dataset>(repository)); |
Check warning
Code scanning / CodeQL
Useless upcast Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we will remove the explicit cast to (object) on line 611. The new CatalogueDatasetLinkage(...) expression can be directly cast to (T) without the intermediate cast to (object). This change will simplify the code while maintaining its functionality.
| @@ -610,3 +610,3 @@ | ||
| { | ||
| return (T)(object)new CatalogueDatasetLinkage(repository.CatalogueRepository, WhenIHaveA<Catalogue>(repository), WhenIHaveA<Dataset>(repository)); | ||
| return (T)new CatalogueDatasetLinkage(repository.CatalogueRepository, WhenIHaveA<Catalogue>(repository), WhenIHaveA<Dataset>(repository)); | ||
| } |
| } | ||
| if(typeof(T) == typeof(Dataset)) | ||
| { | ||
| return (T)(object)new Dataset(repository.CatalogueRepository, "Dataset"); |
Check warning
Code scanning / CodeQL
Useless upcast Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we will remove the explicit cast (object) from the expression new Dataset(repository.CatalogueRepository, "Dataset"). This will allow the implicit conversion to object to occur naturally, as all types in C# derive from object. The functionality of the code will remain unchanged.
| @@ -614,3 +614,3 @@ | ||
| { | ||
| return (T)(object)new Dataset(repository.CatalogueRepository, "Dataset"); | ||
| return (T)new Dataset(repository.CatalogueRepository, "Dataset"); | ||
| } |
| } | ||
| if (typeof(T) == typeof(PluginDataset)) | ||
| { | ||
| return (T)(object)new PluginDataset(repository.CatalogueRepository, "Plugin Dataset"); |
Check warning
Code scanning / CodeQL
Useless upcast Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we will remove the explicit cast (object) from the expression new PluginDataset(repository.CatalogueRepository, "Plugin Dataset"). This will eliminate the unnecessary upcast while preserving the functionality of the code. The return statement will still cast the result to type T, which is the intended behavior.
| @@ -618,3 +618,3 @@ | ||
| { | ||
| return (T)(object)new PluginDataset(repository.CatalogueRepository, "Plugin Dataset"); | ||
| return (T)new PluginDataset(repository.CatalogueRepository, "Plugin Dataset"); | ||
| } |
| } | ||
| if (typeof(T) == typeof(DatasetProviderConfiguration)) | ||
| { | ||
| return (T)(object)new DatasetProviderConfiguration(repository.CatalogueRepository, "","","",WhenIHaveA<DataAccessCredentials>(repository).ID,""); |
Check warning
Code scanning / CodeQL
Useless upcast Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we will remove the explicit cast to (object) on line 623. The DatasetProviderConfiguration object can be directly cast to the generic type T without the intermediate cast to object. This change will simplify the code without altering its functionality.
| @@ -622,3 +622,3 @@ | ||
| { | ||
| return (T)(object)new DatasetProviderConfiguration(repository.CatalogueRepository, "","","",WhenIHaveA<DataAccessCredentials>(repository).ID,""); | ||
| return (T)new DatasetProviderConfiguration(repository.CatalogueRepository, "","","",WhenIHaveA<DataAccessCredentials>(repository).ID,""); | ||
| } |
Proposed Change
Summarise your proposed changes here, including any notes for reviewers.
Type of change
What types of changes does your code introduce? Tick all that apply.
Checklist
By opening this PR, I confirm that I have: