This commit is contained in:
3
docs/8.0/ayanova/docs/form-adm-import.md
Normal file
3
docs/8.0/ayanova/docs/form-adm-import.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# ADM-IMPORT Placeholder
|
||||
|
||||
TODO: How to use the IMPORT feature, limitations, auto tag, etc
|
||||
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user