-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DI-1132] Add Delete By Id Functionality (#47)
* Add IsDeleteOperation to DataMap * Allow UI to set,edit IsDeleteOperation * Enable DataMap editing for delete by id use case * Updating DataImport exe. Successfully deleting by id * Simplify UI for use case * Delete by Id disclaimer * Naming and formatting * DataMapSerializerTests coverage of new serialize and deserialize paths * Update pkg with vulnerabiities * Fix param order * troubleshooting build * Fix python.exe process tests having to do with accessing process name after process has completed. * Add Web tests * use await on migrate commands * Try only one test project * Force test projects to run in series * Move delete serialization to dedicated class
- Loading branch information
1 parent
7af04dc
commit 8ac5a9e
Showing
30 changed files
with
2,939 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
{ | ||
"PythonExecutableLocation": "..\\..\\..\\..\\.tools\\python\\python.exe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace DataImport.Models | ||
{ | ||
public class DeleteDataMapSerializer | ||
{ | ||
public string Serialize(DataMapper[] mappings) | ||
{ | ||
return SerializeObjectForDeleteById(mappings.Single()).ToString(Formatting.Indented); | ||
} | ||
|
||
public DataMapper[] Deserialize(string jsonMap) | ||
{ | ||
JObject jobject; | ||
try | ||
{ | ||
jobject = JObject.Parse(jsonMap); | ||
} | ||
catch (Exception exception) | ||
{ | ||
throw new ArgumentException( | ||
"Cannot deserialize mappings from JSON, because the map text is not a valid JSON object. " + | ||
"Check the inner exception for details. Invalid JSON Map text:" + | ||
$"{Environment.NewLine}{Environment.NewLine}{jsonMap}" | ||
, exception); | ||
} | ||
|
||
return Deserialize(jobject); | ||
} | ||
public DataMapper[] Deserialize(JObject jsonMap) | ||
{ | ||
return DeserializeObjectForDeleteById(jsonMap).ToArray(); | ||
} | ||
|
||
private JObject SerializeObjectForDeleteById(DataMapper node) | ||
{ | ||
var result = new JObject { new JProperty("Id", new JObject { new JProperty("Column", node.SourceColumn) }) }; | ||
return result; | ||
} | ||
|
||
private List<DataMapper> DeserializeObjectForDeleteById(JToken objectToken) | ||
{ | ||
var jobject = objectToken as JObject; | ||
|
||
if (jobject == null) | ||
throw new InvalidOperationException( | ||
"Cannot deserialize mappings from JSON, because an object literal was expected. " + | ||
"Instead, found: " + | ||
$"{objectToken.ToString(Formatting.Indented)}"); | ||
|
||
var result = new List<DataMapper>(); | ||
|
||
var nodes = jobject.Children().Cast<JProperty>().ToArray(); | ||
|
||
var node = nodes.Single(n => n.Name == "Id"); | ||
|
||
var propertyValue = node.Children().Single(); | ||
|
||
var sourceColumn = ((JObject) propertyValue).Children().Cast<JProperty>().Single().Value; | ||
|
||
result.Add(new DataMapper() { Name = "Id", SourceColumn = DeserializeRawValue(sourceColumn) }); | ||
|
||
return result; | ||
} | ||
|
||
private static string DeserializeRawValue(object rawValue) | ||
{ | ||
if (rawValue == null) | ||
return null; | ||
|
||
if (rawValue is bool) | ||
return rawValue.ToString().ToLower(); | ||
|
||
return rawValue.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.