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
|
||||||
@@ -75,6 +75,7 @@ nav:
|
|||||||
- 'Report templates': 'form-adm-report-templates.md'
|
- 'Report templates': 'form-adm-report-templates.md'
|
||||||
- 'Attached files': 'form-adm-attachments.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'
|
- 'Vendors': 'form-vendors.md'
|
||||||
- Misc:
|
- Misc:
|
||||||
- 'About': 'form-ay-about.md'
|
- '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
|
//Save uploads to disk under temporary file names until we decide how to handle them
|
||||||
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
|
||||||
|
|
||||||
bool badRequest = false;
|
|
||||||
string UploadObjectType = string.Empty;
|
string UploadObjectType = string.Empty;
|
||||||
|
|
||||||
string errorMessage = string.Empty;
|
string errorMessage = string.Empty;
|
||||||
string Notes = string.Empty;
|
string Notes = string.Empty;
|
||||||
List<UploadFileData> FileData = new List<UploadFileData>();
|
List<UploadFileData> FileData = new List<UploadFileData>();
|
||||||
|
|
||||||
if (
|
if (!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
|
||||||
!uploadFormData.FormFieldData.ContainsKey("FileData"))//only filedata is required
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: FileData"));
|
||||||
{
|
|
||||||
badRequest = true;
|
|
||||||
errorMessage = "Missing required FormFieldData value: FileData";
|
if (uploadFormData.FormFieldData.ContainsKey("ObjectType"))
|
||||||
}
|
UploadObjectType = uploadFormData.FormFieldData["ObjectType"].ToString();
|
||||||
if (!badRequest)
|
else
|
||||||
{
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Missing required FormFieldData value: ObjectType"));
|
||||||
if (uploadFormData.FormFieldData.ContainsKey("ObjectType"))
|
|
||||||
UploadObjectType = uploadFormData.FormFieldData["ObjectType"].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());
|
||||||
|
|
||||||
//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
|
//Instantiate the business object handler
|
||||||
AyaType TheType = System.Enum.Parse<AyaType>(UploadObjectType, true);
|
AyaType TheType = System.Enum.Parse<AyaType>(UploadObjectType, true);
|
||||||
log.LogDebug($"Instantiating biz object handler for {TheType}");
|
log.LogDebug($"Instantiating biz object handler for {TheType}");
|
||||||
var biz = BizObjectFactory.GetBizObject(TheType, ct);
|
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
|
//We have our files now can parse and insert into db
|
||||||
if (uploadFormData.UploadedFiles.Count > 0)
|
if (uploadFormData.UploadedFiles.Count > 0)
|
||||||
|
|||||||
@@ -336,25 +336,26 @@ namespace AyaNova.Biz
|
|||||||
public async Task<List<string>> ImportData(JArray ja)
|
public async Task<List<string>> ImportData(JArray ja)
|
||||||
{
|
{
|
||||||
List<string> ImportResult = new List<string>();
|
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" }) });
|
var jsset = JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = new AyaNova.Util.JsonUtil.ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "CustomFields" }) });
|
||||||
foreach (JObject j in ja)
|
foreach (JObject j in ja)
|
||||||
{
|
{
|
||||||
var w = j.ToObject<Widget>(jsset);
|
var w = j.ToObject<Widget>(jsset);
|
||||||
if (j["CustomFields"] != null)
|
if (j["CustomFields"] != null)
|
||||||
w.CustomFields = j["CustomFields"].ToString();
|
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);
|
var res = await CreateAsync(w);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"{w.Name} - {this.GetErrorsAsString()}");
|
ImportResult.Add($"* {w.Name} - {this.GetErrorsAsString()}");
|
||||||
this.ClearErrors();
|
this.ClearErrors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImportResult.Add($"{w.Name} - ok");
|
ImportResult.Add($"{w.Name} - ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImportResult;
|
return ImportResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user