This commit is contained in:
2020-10-27 14:32:24 +00:00
parent 30e9199fba
commit e5ee0f64aa
4 changed files with 24 additions and 19 deletions

View File

@@ -0,0 +1,3 @@
# ADM-IMPORT Placeholder
TODO: How to use the IMPORT feature, limitations, auto tag, etc

View File

@@ -74,7 +74,8 @@ nav:
- 'Translations': 'form-adm-translations.md'
- 'Report templates': 'form-adm-report-templates.md'
- 'Attached files': 'form-adm-attachments.md'
- 'History': 'form-adm-history.md'
- 'History': 'form-adm-history.md'
- 'Import': 'form-adm-import.md'
- 'Vendors': 'form-vendors.md'
- Misc:
- 'About': 'form-ay-about.md'

View File

@@ -68,35 +68,35 @@ namespace AyaNova.Api.Controllers
//Save uploads to disk under temporary file names until we decide how to handle them
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
bool badRequest = false;
string UploadObjectType = string.Empty;
string errorMessage = string.Empty;
string Notes = string.Empty;
List<UploadFileData> FileData = new List<UploadFileData>();
if (
!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
{
badRequest = true;
errorMessage = "Missing required FormFieldData value: FileData";
}
if (!badRequest)
{
if (uploadFormData.FormFieldData.ContainsKey("ObjectType"))
UploadObjectType = uploadFormData.FormFieldData["ObjectType"].ToString();
if (!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: FileData"));
if (uploadFormData.FormFieldData.ContainsKey("ObjectType"))
UploadObjectType = uploadFormData.FormFieldData["ObjectType"].ToString();
else
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: ObjectType"));
//fileData in JSON stringify format which contains the actual last modified dates etc
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
FileData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UploadFileData>>(uploadFormData.FormFieldData["FileData"].ToString());
//fileData in JSON stringify format which contains the actual last modified dates etc
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
FileData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UploadFileData>>(uploadFormData.FormFieldData["FileData"].ToString());
}
//Instantiate the business object handler
AyaType TheType = System.Enum.Parse<AyaType>(UploadObjectType, true);
log.LogDebug($"Instantiating biz object handler for {TheType}");
var biz = BizObjectFactory.GetBizObject(TheType, ct);
if (!(biz is IImportAbleObject))
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, $"Import not supported for {TheType} objects"));
//We have our files now can parse and insert into db
if (uploadFormData.UploadedFiles.Count > 0)

View File

@@ -336,25 +336,26 @@ namespace AyaNova.Biz
public async Task<List<string>> ImportData(JArray ja)
{
List<string> ImportResult = new List<string>();
string ImportTag=$"imported-{FileUtil.GetSafeDateFileName()}";
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
foreach (JObject j in ja)
{
var w = j.ToObject<Widget>(jsset);
if (j["CustomFields"] != null)
w.CustomFields = j["CustomFields"].ToString();
w.Tags.Add(ImportTag);//so user can find them all and revert later if necessary
var res = await CreateAsync(w);
if (res == null)
{
ImportResult.Add($"{w.Name} - {this.GetErrorsAsString()}");
ImportResult.Add($"* {w.Name} - {this.GetErrorsAsString()}");
this.ClearErrors();
}
else
{
ImportResult.Add($"{w.Name} - ok");
}
}
return ImportResult;
}