Removed v7 import shit

This commit is contained in:
2020-05-01 01:00:39 +00:00
parent 026fa3a29c
commit bb10dc726d
15 changed files with 46 additions and 1241 deletions

View File

@@ -6,15 +6,12 @@ using EnumsNET;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
namespace AyaNova.Biz
{
internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object, ISearchAbleObject
internal class UserBiz : BizObject, IJobObject, ISearchAbleObject
{
public bool SeedOrImportRelaxedRulesMode { get; set; }
@@ -503,304 +500,6 @@ namespace AyaNova.Biz
}
public async Task<bool> ImportV7Async(JObject j, List<ImportAyaNova7MapItem> importMap, Guid jobId, Dictionary<string, Dictionary<Guid, string>> tagLists)
{
//NEEDS 3 of the tag lists
//TODO: Some of these items will need to be imported in future USEROPTIONS object that doesn't exist yet
#region V7 record format
/*
{
"DefaultLanguage": "Custom English",
"DefaultServiceTemplateID": "ca83a7b8-4e5f-4a7b-a02b-9cf78d5f983f",
"UserType": 2,
"Active": true,
"ClientID": "00000000-0000-0000-0000-000000000000",
"HeadOfficeID": "00000000-0000-0000-0000-000000000000",
* "MemberOfGroup": "0f8a80ff-4b03-4114-ae51-2d13b812dd65",
"Created": "03/21/2005 07:19 AM",
"Modified": "09/15/2015 12:22 PM",
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"Modifier": "1d859264-3f32-462a-9b0c-a67dddfdf4d3",
"ID": "1d859264-3f32-462a-9b0c-a67dddfdf4d3",
"FirstName": "Hank",
"LastName": "Rearden",
"Initials": "HR",
"EmployeeNumber": "EMP1236",
"PageAddress": "",
"PageMaxText": 24,
"Phone1": "",
"Phone2": "",
"EmailAddress": "",
"UserCertifications": [
{
"Created": "12/22/2005 02:07 PM",
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"Modified": "12/22/2005 02:08 PM",
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"ID": "4492360c-43e4-4209-9f33-30691b0808ed",
"UserCertificationID": "b2f26359-7c42-4218-923a-e949f3ef1f85",
"UserID": "1d859264-3f32-462a-9b0c-a67dddfdf4d3",
"ValidStartDate": "2005-10-11T00:00:00-07:00",
"ValidStopDate": "2006-10-11T00:00:00-07:00"
}
],
"UserSkills": [
{
"Created": "12/22/2005 02:06 PM",
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"Modified": "12/22/2005 02:08 PM",
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"ID": "1dc5ce96-f411-4885-856e-5bdb3ad79728",
"UserSkillID": "2e6f8b65-594c-4f6c-9cd6-e14a562daba8",
"UserID": "1d859264-3f32-462a-9b0c-a67dddfdf4d3"
},
{
"Created": "12/22/2005 02:06 PM",
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"Modified": "12/22/2005 02:08 PM",
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
"ID": "88e476d3-7526-45f5-a0dd-706c8053a63f",
"UserSkillID": "47a4ee94-b0e9-41b5-afe5-4b4f2c981877",
"UserID": "1d859264-3f32-462a-9b0c-a67dddfdf4d3"
}
],
"Notes": "",
"VendorID": "06e502c2-69ba-4e88-8efb-5b53c1687740",
* "RegionID": "f856423a-d468-4344-b7b8-121e466738c6",
* "DispatchZoneID": "00000000-0000-0000-0000-000000000000",
"SubContractor": false,//This is not actually a feature in v7, you can just pick a vendorId for subcontractor but still be of type technician
"DefaultWarehouseID": "d45eab37-b6e6-4ad2-9163-66d7ba83a98c",
"Custom1": "",
"Custom2": "",
"Custom3": "",
"Custom4": "",
"Custom5": "",
"Custom6": "",
"Custom7": "",
"Custom8": "",
"Custom9": "",
"Custom0": "",
"ScheduleBackColor": -2097216,
"TimeZoneOffset": null
}
*/
#endregion v7 record format
SeedOrImportRelaxedRulesMode = true;
//some types need to import from more than one source hence the seemingly redundant switch statement for futureproofing
switch (j["IMPORT_TASK"].Value<string>())
{
case "main":
{
#region Main import
var V7Id = new Guid(j["ID"].Value<string>());
//skip the administrator account but add it to the map for all the other import code that requires it
if (V7Id == new Guid("2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed"))
{
var mapItem = new ImportAyaNova7MapItem(V7Id, BizType, 1);
importMap.Add(mapItem);
return true;
}
//Copy values
User i = new User();
i.Name = j["FirstName"].Value<string>() + " " + j["LastName"].Value<string>();
var Temp = j["UserType"].Value<int>();
i.UserType = (UserType)Temp;
//If there is a vendorId set then this user is actually a subcontractor in v7 so set accordingly
var VendorId = new Guid(j["VendorID"].Value<string>());
if (VendorId != Guid.Empty)
{
i.UserType = UserType.Subcontractor;
}
i.Active = false;//Ignore incoming value and set all imports to false so that there's no chance of licensing getting circumvented; users all need to be edited anyway for pw and login
i.EmployeeNumber = j["EmployeeNumber"].Value<string>();
i.Notes = j["Notes"].Value<string>();
//TAGS
//member of group is actually security group not sched user group so this was wrong anyway but moot now
// var MemberOfGroupId = new Guid(j["MemberOfGroup"].Value<string>());
// if (MemberOfGroupId != Guid.Empty)
// {
// string sTag = string.Empty;
// if (tagLists["ScheduleableUserGroup"].TryGetValue(MemberOfGroupId, out sTag))
// {
// i.Tags.Add(sTag);
// }
// }
var RegionID = new Guid(j["RegionID"].Value<string>());
if (RegionID != Guid.Empty)
{
string sTag = string.Empty;
if (tagLists["Region"].TryGetValue(RegionID, out sTag))
{
i.Tags.Add(sTag);
}
}
var DispatchZoneID = new Guid(j["DispatchZoneID"].Value<string>());
if (DispatchZoneID != Guid.Empty)
{
string sTag = string.Empty;
if (tagLists["DispatchZone"].TryGetValue(DispatchZoneID, out sTag))
{
i.Tags.Add(sTag);
}
}
//User options
i.UserOptions = new UserOptions();
//TimeZone Offset
//NOT IMPORTED / SUPPORTED
//Email address
i.UserOptions.EmailAddress = j["EmailAddress"].Value<string>();
//UI colour
//TODO: this needs to be tested now that it's a web friendly value in the dbdump file
/*
Hexadecimal notation: #RGB[A]
R (red), G (green), B (blue), and A (alpha) are hexadecimal characters (09, AF). A is optional. The three-digit notation (#RGB) is a shorter version of the six-digit form (#RRGGBB). For example, #f09 is the same color as #ff0099. Likewise, the four-digit RGB notation (#RGBA) is a shorter version of the eight-digit form (#RRGGBBAA). For example, #0f38 is the same color as #00ff3388.
*/
// This is untested as of now, but should work, maybe if it doesn't the selector needs to be combined with dot notation instead of two array notations?
i.UserOptions.UiColor = j["jextra"]["hexaScheduleBackColor"].Value<string>();
//Set unusable random login credentials
i.Salt = Hasher.GenerateSalt();
i.Login = Hasher.GenerateSalt();
i.Password = Hasher.hash(i.Salt, Hasher.GenerateSalt());
//No rights
i.Roles = AuthorizationRoles.NoRole;
//temporary translation id to satisfy db settings
i.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
User o = await CreateAsync(i);
if (HasErrors)
{
//If there are any validation errors, log in joblog and move on
await JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
//This is a fundamental problem with the import as users are required for many things so bomb out entirely
//other things might be able to work around but this is too serious
throw new System.SystemException("UserBiz::ImportV7Async - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE WITHOUT ALL USERS BEING IMPORTED, SEE JOB ERROR LOG FOR DETAILS");
// return false;
}
else
{
await ct.SaveChangesAsync();
var mapItem = new ImportAyaNova7MapItem(V7Id, BizType, o.Id);
importMap.Add(mapItem);
}
#endregion
}
break;
case "eventlog":
{
await ImportAyaNova7Biz.LogEventCreatedModifiedEventsAsync(j, importMap, BizType, ct);
}
break;
case "translation":
{
#region set translation
//get the userId
//----
var V7Id = new Guid(j["ID"].Value<string>());
var MapItem = importMap.Where(m => m.V7ObjectId == V7Id).FirstOrDefault();
if (MapItem == null)
{
throw new System.Exception("UserBiz::ImportV7Async-translation - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE USER NOT FOUND IN IMPORTMAP");
}
var NewId = MapItem.NewObjectAyaTypeId.ObjectId;
User u = ct.User.Where(m => m.Id == NewId).FirstOrDefault();
if (u == null)
{
throw new System.Exception("UserBiz::ImportV7Async-translation - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE USER NOT FOUND IN DATABASE");
}
//handle translation entries for users now that we have the Translations created
var V7Translation = j["DefaultLanguage"].Value<string>();
//Get new translation name
var NewTranslationName = string.Empty;
switch (V7Translation)
{
case "Français":
NewTranslationName = "fr";
break;
case "Español":
NewTranslationName = "es";
break;
case "Deutsch":
NewTranslationName = "de";
break;
case "English":
NewTranslationName = "en";
break;
default:
{
//It's a custom translation, translate it from v7 original format to imported name format
//make lower and replace spaces with dashes
NewTranslationName = V7Translation.ToLowerInvariant().Replace(" ", "-");
//ensure each character is a valid path character
foreach (char c in System.IO.Path.GetInvalidFileNameChars())//is this kosher on linux? Original code was windows
{
NewTranslationName = NewTranslationName.Replace(c, '_');
}
}
break;
}
u.UserOptions.TranslationId = await TranslationBiz.TranslationNameToIdStaticAsync(NewTranslationName, ct);
ct.SaveChanges();
#endregion set translation
}
break;
case "clientid":
{
var V7Id = new Guid(j["ID"].Value<string>());
//handle setting client id for user client login
//throw new System.NotImplementedException();
}
break;
case "headofficeid":
{
var V7Id = new Guid(j["ID"].Value<string>());
//handle setting ho id for user headoffice login
//throw new System.NotImplementedException();
}
break;
}
//this is the equivalent of returning void for a Task signature with nothing to return
return true;
}
//Other job handlers here...