From cda2458d010285c4df739712ab3f1887cd17ac60 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 31 Aug 2018 20:58:07 +0000 Subject: [PATCH] --- .../AyaNova/Controllers/TagMapController.cs | 3 +- server/AyaNova/biz/TagBiz.cs | 211 ++++++++++++------ 2 files changed, 141 insertions(+), 73 deletions(-) diff --git a/server/AyaNova/Controllers/TagMapController.cs b/server/AyaNova/Controllers/TagMapController.cs index c08e9c71..dbd44040 100644 --- a/server/AyaNova/Controllers/TagMapController.cs +++ b/server/AyaNova/Controllers/TagMapController.cs @@ -137,7 +137,8 @@ namespace AyaNova.Api.Controllers await ct.SaveChangesAsync(); //BIZLOG: Not going to log this for now, it's too common an operation and would require bringing in more info. If decide to implement should log the parent object with text of tag instead - + //and don't forget about import from v7 as well + return CreatedAtAction("GetTagMap", new { id = o.Id }, new ApiCreatedResponse(o)); } } diff --git a/server/AyaNova/biz/TagBiz.cs b/server/AyaNova/biz/TagBiz.cs index 21344c92..2d180e47 100644 --- a/server/AyaNova/biz/TagBiz.cs +++ b/server/AyaNova/biz/TagBiz.cs @@ -258,89 +258,156 @@ namespace AyaNova.Biz case "GZTW.AyaNova.BLL.DispatchZone": case "GZTW.AyaNova.BLL.ScheduleableUserGroup": { - var NewTagName = j["Name"].Value(); - - var ShortTypeName = string.Empty; - switch (SourceType) + switch (j["IMPORT_TASK"].Value()) { - 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; - } + case "main": + { + #region main import task + var NewTagName = j["Name"].Value(); + + 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()); + NewTagName += "." + ShortTypeName; + var OldV7Id = new Guid(j["ID"].Value()); - //Ensure it follows the rules - NewTagName = CleanTagName(NewTagName); + //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 + //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 - { + //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); - await ImportAyaNova7Biz.LogEventCreatedModifiedEvents(j, importMap, AyaType.Tag, ct); - } + 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); + await 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()); + var RavenTagId = importMap.Where(m => m.V7ObjectId == V7Id).First().NewObjectAyaTypeId.ObjectId; + + foreach (JToken t in j["ScheduleableUsers"]) + { + var techId = new Guid(t["ScheduleableUserID"].Value()); + var RavenUserId = importMap.Where(m => m.V7ObjectId == techId).First().NewObjectAyaTypeId.ObjectId; + var Creator = importMap.Where(m => m.V7ObjectId == new Guid(t["Creator"].Value())).First().NewObjectAyaTypeId.ObjectId; + + TagMap tm = new TagMap(); + tm.TagToObjectId = RavenUserId; + tm.TagId = RavenTagId; + tm.OwnerId = Creator; + ct.TagMap.Add(tm); + } + ct.SaveChanges(); + //handle tag entries for users now that we have the SUG tags created + // throw new System.NotImplementedException(); + #endregion + } + break; } } break; - case "scheduleableusergrouptags": - { - var V7Id = new Guid(j["ID"].Value()); - var RavenId = importMap.Where(m => m.V7ObjectId == V7Id).First().NewObjectAyaTypeId.ObjectId; - //handle tag entries for users now that we have the SUG tags created - // throw new System.NotImplementedException(); - } - break; + }