This commit is contained in:
2018-12-06 22:35:11 +00:00
parent 929910cb3f
commit d097391af6
2 changed files with 291 additions and 34 deletions

View File

@@ -88,8 +88,59 @@ namespace AyaNova.Biz
//Pass off the JSON data from the import file into the import job item by item
//NOTE: Many of these require a second pass - one to get the object imported and then another to set another imported object to that object
//for example scheduleable user groups are imported as tags, but then a second pass is required to tag the users of that group
////////////////////////////////////
//TAGS
//
//FIRST: import items that will become tags first into temporary cache lists
//IMPORT UNIT MODEL CATEGORIES AS TAGS
Dictionary<Guid, string> UnitModelCategoryTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.UnitModelCategory", job.GId, UnitModelCategoryTags, importFileName, zipEntries);
//IMPORT Unit service type AS TAGS
Dictionary<Guid, string> UnitServiceTypeTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.UnitServiceType", job.GId, UnitServiceTypeTags, importFileName, zipEntries);
//IMPORT Workorder Item Type AS TAGS
Dictionary<Guid, string> WorkorderItemTypeTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.WorkorderItemType", job.GId, WorkorderItemTypeTags, importFileName, zipEntries);
//IMPORT Client group AS TAGS
Dictionary<Guid, string> ClientGroupTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.ClientGroup", job.GId, ClientGroupTags, importFileName, zipEntries);
//IMPORT Workorder category AS TAGS
Dictionary<Guid, string> WorkorderCategoryTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.WorkorderCategory", job.GId, WorkorderCategoryTags, importFileName, zipEntries);
//IMPORT Part Category AS TAGS
Dictionary<Guid, string> PartCategoryTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.PartCategory", job.GId, PartCategoryTags, importFileName, zipEntries);
//IMPORT Dispatch zones AS TAGS
Dictionary<Guid, string> DispatchZoneTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.DispatchZone", job.GId, DispatchZoneTags, importFileName, zipEntries);
//IMPORT Scheduleable User Groups AS TAGS
Dictionary<Guid, string> ScheduleableUserGroupTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.ScheduleableUserGroup", job.GId, ScheduleableUserGroupTags, importFileName, zipEntries);
//Now can set users to correct tag for scheduleable user group
// await ImportTagList("GZTW.AyaNova.BLL.ScheduleableUserGroup", "scheduleableusergrouptags", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
//IMPORT REGIONS AS TAGS
Dictionary<Guid, string> RegionTags = new Dictionary<Guid, string>();
await ImportTagList("GZTW.AyaNova.BLL.Region", job.GId, RegionTags, importFileName, zipEntries);
////////////////////////////////////
// OBJECTS
//
//USERS
await DoImport("GZTW.AyaNova.BLL.User", "main", AyaType.User, job.GId, importMap, importFileName, zipEntries);
@@ -97,38 +148,6 @@ namespace AyaNova.Biz
await DoImport("GZTW.AyaNova.BLL.User", "eventlog", AyaType.User, job.GId, importMap, importFileName, zipEntries);
//TODO: these need to be done differently and after the main objects are imported or in parallel with them as there is no
//separate tag type object anymore
//I guess cache the list of each v7 string and id type and then use that to tag objects as they are import4ed that use them
// //IMPORT UNIT MODEL CATEGORIES AS TAGS
// await DoImport("GZTW.AyaNova.BLL.UnitModelCategory", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Unit service type AS TAGS
// await DoImport("GZTW.AyaNova.BLL.UnitServiceType", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Workorder Item Type AS TAGS
// await DoImport("GZTW.AyaNova.BLL.WorkorderItemType", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Client group AS TAGS
// await DoImport("GZTW.AyaNova.BLL.ClientGroup", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Workorder category AS TAGS
// await DoImport("GZTW.AyaNova.BLL.WorkorderCategory", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Part Category AS TAGS
// await DoImport("GZTW.AyaNova.BLL.PartCategory", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Dispatch zones AS TAGS
// await DoImport("GZTW.AyaNova.BLL.DispatchZone", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT Scheduleable User Groups AS TAGS
// await DoImport("GZTW.AyaNova.BLL.ScheduleableUserGroup", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //Now can set users to correct tag for scheduleable user group
// await DoImport("GZTW.AyaNova.BLL.ScheduleableUserGroup", "scheduleableusergrouptags", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
// //IMPORT REGIONS AS TAGS
// await DoImport("GZTW.AyaNova.BLL.Region", "main", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
//IMPORT LOCALES
await DoImport("GZTW.AyaNova.BLL.Locale", "main", AyaType.Locale, job.GId, importMap, importFileName, zipEntries);
@@ -233,6 +252,62 @@ namespace AyaNova.Biz
//Other job handlers here...
private async Task ImportTagList(string entryStartsWith, Guid jobId, Dictionary<Guid, string> tagDictionary, string importFileName, List<string> zipEntries)
{
var zipObjectList = zipEntries.Where(m => m.StartsWith(entryStartsWith)).ToList();
long importCount = 0;
long notImportCount = 0;
if (zipObjectList.Count > 0)
{
JobsBiz.LogJob(jobId, $"Starting import to TAGS of {entryStartsWith} objects", ct);
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
//IImportAyaNova7Object o = (IImportAyaNova7Object)BizObjectFactory.GetBizObject(importerType, ct);
foreach (JObject j in jList)
{
bool bImportSucceeded = false;
//some new types can import multiple old types and it might matter which is which to the importer
//so tag it with the original type
//------
j.Add("V7_TYPE", JToken.FromObject(entryStartsWith));
j.Add("IMPORT_TASK", JToken.FromObject(importTask));
bImportSucceeded = await o.ImportV7Async(j, importMap, jobId);
if (bImportSucceeded)
importCount++;
else
notImportCount++;
}
if (importCount > 0)
{
if (importTask != "main")
{
JobsBiz.LogJob(jobId, $"Successfully ran import subtask {importTask} on {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
}
else
{
JobsBiz.LogJob(jobId, $"Successfully imported {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
}
}
if (notImportCount > 0)
{
if (importTask != "main")
{
JobsBiz.LogJob(jobId, $"Failed to run import subtask {importTask} on {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
}
else
{
JobsBiz.LogJob(jobId, $"Did not import {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
}
}
}
}
@@ -254,7 +329,7 @@ namespace AyaNova.Biz
EventLogProcessor.LogEventToDatabase(new Event(Creator, RavenId, ayaType, AyaEvent.Created, Created), ct);
//MODIFIED
EventLogProcessor.LogEventToDatabase(new Event(Modifier, RavenId, ayaType, AyaEvent.Modified, Modified), ct);
}
/////////////////////////////////////////////////////////////////////

View File

@@ -36,5 +36,187 @@ namespace AyaNova.Biz
}
/*
/////////////////////////////////////////////////////////////////////
/// IMPORT v7 implementation
public async Task<bool> ImportV7Async(JObject j, List<ImportAyaNova7MapItem> importMap, Guid jobId)
{
//NO TASK TYPE, IT'S ALL THE SAME, KEEPING THIS FOR POSSIBLE FUTURE PURPOSES LIKE APPENDING OBJECT TYPE OR SOMETHING
string SourceType = j["V7_TYPE"].Value<string>();
switch (SourceType)
{
case "GZTW.AyaNova.BLL.Region":
case "GZTW.AyaNova.BLL.UnitModelCategory":
case "GZTW.AyaNova.BLL.UnitServiceType":
case "GZTW.AyaNova.BLL.WorkorderItemType":
case "GZTW.AyaNova.BLL.ClientGroup":
case "GZTW.AyaNova.BLL.WorkorderCategory":
case "GZTW.AyaNova.BLL.PartCategory":
case "GZTW.AyaNova.BLL.DispatchZone":
case "GZTW.AyaNova.BLL.ScheduleableUserGroup":
{
switch (j["IMPORT_TASK"].Value<string>())
{
case "main":
{
#region main import task
var NewTagName = j["Name"].Value<string>();
var ShortTypeName = string.Empty;
switch (SourceType)
{
case "GZTW.AyaNova.BLL.Region":
ShortTypeName = "rgn";
break;
case "GZTW.AyaNova.BLL.UnitModelCategory":
ShortTypeName = "unitmdlctgry";
break;
case "GZTW.AyaNova.BLL.UnitServiceType":
ShortTypeName = "unitsvtyp";
break;
case "GZTW.AyaNova.BLL.WorkorderItemType":
ShortTypeName = "woitemtyp";
break;
case "GZTW.AyaNova.BLL.ClientGroup":
ShortTypeName = "clntgrp";
break;
case "GZTW.AyaNova.BLL.WorkorderCategory":
ShortTypeName = "woctgry";
break;
case "GZTW.AyaNova.BLL.PartCategory":
ShortTypeName = "prtctgry";
break;
case "GZTW.AyaNova.BLL.DispatchZone":
ShortTypeName = "dspchzn";
break;
case "GZTW.AyaNova.BLL.ScheduleableUserGroup":
ShortTypeName = "schdusrgrp";
break;
}
NewTagName += "." + ShortTypeName;
var OldV7Id = new Guid(j["ID"].Value<string>());
//Ensure it follows the rules
NewTagName = CleanTagName(NewTagName);
//There might already be a tag of the same name since so many different types of V7 objects are becoming tags
//Weighed the pros and cons of uniquifying by object type versus just using the same name for different object types:
//it seems to me at this point that people might desire the same exact name because if they used it that way they probably
//intended it that way, so decision is to check if it already exists and then use that ID in the importMap instead
//for matching other objects imported to tags
//Already present?
var ExistingTag = ct.Tag.Where(m => m.Name == NewTagName).FirstOrDefault();
if (ExistingTag != null)
{
//map it to the existing tag of same name
var mapItem = new ImportAyaNova7MapItem(OldV7Id, AyaType.Tag, ExistingTag.Id);
}
else
{
Tag o = await CreateAsync(NewTagName);
if (HasErrors)
{
//If there are any validation errors, log in joblog and move on
JobsBiz.LogJob(jobId, $"TagBiz::ImportV7Async -> import object \"{NewTagName}\" of type \"{SourceType}\" source id {OldV7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
return false;
}
else
{
await ct.SaveChangesAsync();
var mapItem = new ImportAyaNova7MapItem(OldV7Id, AyaType.Tag, o.Id);
importMap.Add(mapItem);
ImportAyaNova7Biz.LogEventCreatedModifiedEvents(j, importMap, AyaType.Tag, ct);
}
}
#endregion
}
break;
case "scheduleableusergrouptags":
{
#region attribute sched user group tags
//
// {
// "ID": "871e77b2-979a-4f26-930b-46f7c05fc19f",
// "Created": "08/30/2018 08:12 AM",
// "Modified": "08/30/2018 08:13 AM",
// "Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "Name": "Yet another test group",
// "Active": true,
// "Description": "More testing yay!",
// "ScheduleableUsers": [
// {
// "Created": "08/30/2018 08:13 AM",
// "Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "Modified": "08/30/2018 08:13 AM",
// "Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "ID": "676475be-8301-47d0-bd54-af9dbd1fe7eb",
// "ScheduleableUserID": "1d859264-3f32-462a-9b0c-a67dddfdf4d3",
// "ScheduleableUserGroupID": "871e77b2-979a-4f26-930b-46f7c05fc19f"
// },
// {
// "Created": "08/30/2018 08:13 AM",
// "Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "Modified": "08/30/2018 08:13 AM",
// "Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "ID": "173499c3-a616-42a0-b08c-74008f8fa352",
// "ScheduleableUserID": "42b282bb-100b-4b31-aa14-5c831d7cda66",
// "ScheduleableUserGroupID": "871e77b2-979a-4f26-930b-46f7c05fc19f"
// },
// {
// "Created": "08/30/2018 08:13 AM",
// "Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "Modified": "08/30/2018 08:13 AM",
// "Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
// "ID": "19c9b3d6-eeb2-44ac-be4e-6ec93d15b02a",
// "ScheduleableUserID": "e6ff9bc6-a550-4242-8c41-857f740e2841",
// "ScheduleableUserGroupID": "871e77b2-979a-4f26-930b-46f7c05fc19f"
// }
// ]
// }
//
var V7Id = new Guid(j["ID"].Value<string>());
var RavenTagId = importMap.Where(m => m.V7ObjectId == V7Id).First().NewObjectAyaTypeId.ObjectId;
foreach (JToken t in j["ScheduleableUsers"])
{
var techId = new Guid(t["ScheduleableUserID"].Value<String>());
var RavenUserId = importMap.Where(m => m.V7ObjectId == techId).First().NewObjectAyaTypeId.ObjectId;
var Creator = importMap.Where(m => m.V7ObjectId == new Guid(t["Creator"].Value<string>())).First().NewObjectAyaTypeId.ObjectId;
TagMap tm = new TagMap();
tm.TagToObjectId = RavenUserId;
tm.TagToObjectType = AyaType.User;
tm.TagId = RavenTagId;
tm.OwnerId = Creator;
ct.TagMap.Add(tm);
}
ct.SaveChanges();
#endregion
}
break;
}
}
break;
}
//this is the equivalent of returning void for a Task signature with nothing to return
return true;
}
*/
}//eoc
}//ens