Locale -> Translation
This commit is contained in:
@@ -2,13 +2,13 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
internal static class UserLocaleIdFromContext
|
||||
internal static class UserTranslationIdFromContext
|
||||
{
|
||||
internal static long Id(IDictionary<object, object> HttpContextItems)
|
||||
{
|
||||
long? l = (long?)HttpContextItems["AY_LOCALE_ID"];
|
||||
long? l = (long?)HttpContextItems["AY_TRANSLATION_ID"];
|
||||
if (l == null)
|
||||
return AyaNova.Util.ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
return AyaNova.Util.ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||
return (long)l;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace AyaNova.Api.Controllers
|
||||
<a href=""/docs"" target=""_blank"">AyaNova manual</a><br/><br/>
|
||||
<a href=""/api-docs"" target=""_blank"">API explorer</a><br/><br/>
|
||||
<a href=""mailto:support@ayanova.com"">Email AyaNova support</a><br/><br/>
|
||||
<h4>{await LocaleBiz.GetDefaultLocalizedTextAsync("HelpLicense")}</h4>
|
||||
<h4>{await TranslationBiz.GetDefaultLocalizedTextAsync("HelpLicense")}</h4>
|
||||
<pre>{AyaNova.Core.License.LicenseInfo}</pre>
|
||||
<h4>Schema version</h4>
|
||||
<pre>{AySchema.currentSchema.ToString()}</pre>
|
||||
|
||||
@@ -232,9 +232,8 @@ namespace AyaNova.Api.Controllers
|
||||
//EVENT LOG
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
|
||||
|
||||
//SEARCH INDEXING
|
||||
// Search.ProcessNewObjectKeywords( UserLocaleIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment, v.DisplayFileName, v.DisplayFileName, v.Notes, v.StoredFileName);
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment, v.DisplayFileName);
|
||||
//SEARCH INDEXING
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment, v.DisplayFileName);
|
||||
SearchParams.AddText(v.Notes).AddText(v.DisplayFileName).AddText(v.StoredFileName);
|
||||
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
long LocaleId = UserLocaleIdFromContext.Id(HttpContext.Items);
|
||||
List<string> LocaleKeysToFetch = new List<string>();
|
||||
long TranslationId = UserTranslationIdFromContext.Id(HttpContext.Items);
|
||||
List<string> TranslationKeysToFetch = new List<string>();
|
||||
|
||||
List<NameIdItem> ReturnList = new List<NameIdItem>();
|
||||
|
||||
@@ -90,14 +90,14 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
else if (keyNameInLowerCase == StringUtil.TrimTypeName(typeof(UserType).ToString()).ToLowerInvariant())
|
||||
{
|
||||
LocaleKeysToFetch.Add("UserTypesAdministrator");
|
||||
LocaleKeysToFetch.Add("UserTypesSchedulable");
|
||||
LocaleKeysToFetch.Add("UserTypesNonSchedulable");
|
||||
LocaleKeysToFetch.Add("UserTypesClient");
|
||||
LocaleKeysToFetch.Add("UserTypesHeadOffice");
|
||||
LocaleKeysToFetch.Add("UserTypesSubContractor");
|
||||
LocaleKeysToFetch.Add("UserTypesUtility");
|
||||
var LT = LocaleBiz.GetSubsetStaticAsync(LocaleKeysToFetch, LocaleId).Result;
|
||||
TranslationKeysToFetch.Add("UserTypesAdministrator");
|
||||
TranslationKeysToFetch.Add("UserTypesSchedulable");
|
||||
TranslationKeysToFetch.Add("UserTypesNonSchedulable");
|
||||
TranslationKeysToFetch.Add("UserTypesClient");
|
||||
TranslationKeysToFetch.Add("UserTypesHeadOffice");
|
||||
TranslationKeysToFetch.Add("UserTypesSubContractor");
|
||||
TranslationKeysToFetch.Add("UserTypesUtility");
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesAdministrator"], Id = (long)UserType.Administrator });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypesSchedulable"], Id = (long)UserType.Schedulable });
|
||||
@@ -110,26 +110,26 @@ namespace AyaNova.Api.Controllers
|
||||
else if (keyNameInLowerCase == StringUtil.TrimTypeName(typeof(AuthorizationRoles).ToString()).ToLowerInvariant())
|
||||
{
|
||||
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleNoRole");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleBizAdminLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleBizAdminFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleDispatchLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleDispatchFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleInventoryLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleInventoryFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleAccountingFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleTechLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleTechFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSubContractorLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSubContractorFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleCustomerLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleCustomerFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleOpsAdminLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleOpsAdminFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSalesLimited");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleSalesFull");
|
||||
LocaleKeysToFetch.Add("AuthorizationRoleAll");
|
||||
var LT = LocaleBiz.GetSubsetStaticAsync(LocaleKeysToFetch, LocaleId).Result;
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleNoRole");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleBizAdminLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleBizAdminFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleDispatchLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleDispatchFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleInventoryLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleInventoryFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleAccountingFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleTechLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleTechFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleSubContractorLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleSubContractorFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleCustomerLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleCustomerFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleOpsAdminLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleOpsAdminFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleSalesLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleSalesFull");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleAll");
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleNoRole"], Id = (long)AuthorizationRoles.NoRole });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleBizAdminLimited"], Id = (long)AuthorizationRoles.BizAdminLimited });
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Do the search
|
||||
var SearchResults = await Search.DoSearchAsync(ct, UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items), searchParams);
|
||||
var SearchResults = await Search.DoSearchAsync(ct, UserTranslationIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items), searchParams);
|
||||
|
||||
return Ok(ApiOkResponse.Response(SearchResults, true));
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace AyaNova.Api.Controllers
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class LocaleController : ControllerBase
|
||||
public class TranslationController : ControllerBase
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<LocaleController> log;
|
||||
private readonly ILogger<TranslationController> log;
|
||||
private readonly ApiServerState serverState;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace AyaNova.Api.Controllers
|
||||
/// <param name="dbcontext"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="apiServerState"></param>
|
||||
public LocaleController(AyContext dbcontext, ILogger<LocaleController> logger, ApiServerState apiServerState)
|
||||
public TranslationController(AyContext dbcontext, ILogger<TranslationController> logger, ApiServerState apiServerState)
|
||||
{
|
||||
ct = dbcontext;
|
||||
log = logger;
|
||||
@@ -52,12 +52,12 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Locale all values
|
||||
/// Get Translation all values
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>A single Locale and it's values</returns>
|
||||
/// <returns>A single Translation and it's values</returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetLocale([FromRoute] long id)
|
||||
public async Task<IActionResult> GetTranslation([FromRoute] long id)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
{
|
||||
@@ -70,9 +70,8 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
// LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
//Instantiate the business object handler
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await biz.GetAsync(id);
|
||||
|
||||
@@ -87,11 +86,11 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get Locale pick list
|
||||
/// Get Translation pick list
|
||||
/// </summary>
|
||||
/// <returns>Picklist in alphabetical order of all locales</returns>
|
||||
/// <returns>Picklist in alphabetical order of all Translations</returns>
|
||||
[HttpGet("PickList")]
|
||||
public async Task<IActionResult> LocalePickList()
|
||||
public async Task<IActionResult> TranslationPickList()
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
{
|
||||
@@ -99,8 +98,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
//LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var l = await biz.GetPickListAsync();
|
||||
return Ok(ApiOkResponse.Response(l, true));
|
||||
@@ -109,11 +107,11 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
#if (DEBUG)
|
||||
/// <summary>
|
||||
/// Get a coverage report of locale keys used versus unused
|
||||
/// Get a coverage report of translation keys used versus unused
|
||||
/// </summary>
|
||||
/// <returns>Report of all unique locale keys requested since last server reboot</returns>
|
||||
[HttpGet("LocaleKeyCoverage")]
|
||||
public async Task<IActionResult> LocaleKeyCoverage()
|
||||
/// <returns>Report of all unique translation keys requested since last server reboot</returns>
|
||||
[HttpGet("TranslationKeyCoverage")]
|
||||
public async Task<IActionResult> TranslationKeyCoverage()
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
{
|
||||
@@ -121,19 +119,18 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
//LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
var l = await biz.LocaleKeyCoverageAsync();
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var l = await biz.TranslationKeyCoverageAsync();
|
||||
return Ok(ApiOkResponse.Response(l, true));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get subset of locale values
|
||||
/// Get subset of translation values
|
||||
/// </summary>
|
||||
/// <param name="inObj">List of locale key strings</param>
|
||||
/// <param name="inObj">List of translation key strings</param>
|
||||
/// <returns>A key value array of localized text values</returns>
|
||||
[HttpPost("SubSet")]
|
||||
public async Task<IActionResult> SubSet([FromBody] List<string> inObj)
|
||||
@@ -144,10 +141,9 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
//LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
|
||||
//Instantiate the business object handler
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var l = await biz.GetSubsetAsync(inObj);
|
||||
return Ok(ApiOkResponse.Response(l, true));
|
||||
@@ -155,11 +151,11 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Duplicates an existing locale with a new name
|
||||
/// Duplicates an existing translation with a new name
|
||||
/// </summary>
|
||||
/// <param name="inObj">NameIdItem object containing source locale Id and new name</param>
|
||||
/// <param name="inObj">NameIdItem object containing source translation Id and new name</param>
|
||||
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||
/// <returns>Error response or newly created locale</returns>
|
||||
/// <returns>Error response or newly created translation</returns>
|
||||
[HttpPost("Duplicate")]
|
||||
public async Task<IActionResult> Duplicate([FromBody] NameIdItem inObj, ApiVersion apiVersion)
|
||||
{
|
||||
@@ -169,8 +165,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
// LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await biz.DuplicateAsync(inObj);
|
||||
|
||||
@@ -181,20 +176,20 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
return CreatedAtAction(nameof(LocaleController.GetLocale), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||
return CreatedAtAction(nameof(TranslationController.GetTranslation), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Put (UpdateLocaleItemDisplayText)
|
||||
/// Put (UpdateTranslationItemDisplayText)
|
||||
/// Update a single key with new display text
|
||||
/// </summary>
|
||||
/// <param name="inObj">NewText/Id/Concurrency token object. NewText is new display text, Id is LocaleItem Id, concurrency token is required</param>
|
||||
/// <param name="inObj">NewText/Id/Concurrency token object. NewText is new display text, Id is TranslationItem Id, concurrency token is required</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("UpdateLocaleItemDisplayText")]
|
||||
public async Task<IActionResult> PutLocalItemDisplayText([FromBody] NewTextIdConcurrencyTokenItem inObj)
|
||||
[HttpPut("UpdateTranslationItemDisplayText")]
|
||||
public async Task<IActionResult> PutTranslationItemDisplayText([FromBody] NewTextIdConcurrencyTokenItem inObj)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
@@ -206,39 +201,38 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
var oFromDb = await ct.LocaleItem.SingleOrDefaultAsync(m => m.Id == inObj.Id);
|
||||
var oFromDb = await ct.TranslationItem.SingleOrDefaultAsync(m => m.Id == inObj.Id);
|
||||
|
||||
if (oFromDb == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
//Now fetch locale for rights and to ensure not stock
|
||||
var oDbParent = await ct.Locale.SingleOrDefaultAsync(x => x.Id == oFromDb.LocaleId);
|
||||
//Now fetch translation for rights and to ensure not stock
|
||||
var oDbParent = await ct.Translation.SingleOrDefaultAsync(x => x.Id == oFromDb.TranslationId);
|
||||
if (oDbParent == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.Locale))
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.Translation))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
// LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
//Instantiate the business object handler
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
try
|
||||
{
|
||||
if (!await biz.PutLocaleItemDisplayTextAsync(oFromDb, inObj, oDbParent))
|
||||
if (!await biz.PutTranslationItemDisplayTextAsync(oFromDb, inObj, oDbParent))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await biz.LocaleItemExistsAsync(inObj.Id))
|
||||
if (!await biz.TranslationItemExistsAsync(inObj.Id))
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
@@ -256,13 +250,13 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put (UpdateLocaleName)
|
||||
/// Update a locale to change the name (non-stock locales only)
|
||||
/// Put (UpdateTranslationName)
|
||||
/// Update a translation to change the name (non-stock Translations only)
|
||||
/// </summary>
|
||||
/// <param name="inObj">NewText/Id/Concurrency token object. NewText is new locale name, Id is Locale Id, concurrency token is required</param>
|
||||
/// <param name="inObj">NewText/Id/Concurrency token object. NewText is new translation name, Id is Translation Id, concurrency token is required</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("UpdateLocaleName")]
|
||||
public async Task<IActionResult> PutLocaleName([FromBody] NewTextIdConcurrencyTokenItem inObj)
|
||||
[HttpPut("UpdateTranslationName")]
|
||||
public async Task<IActionResult> PutTranslationName([FromBody] NewTextIdConcurrencyTokenItem inObj)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
@@ -274,7 +268,7 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
var oFromDb = await ct.Locale.SingleOrDefaultAsync(m => m.Id == inObj.Id);
|
||||
var oFromDb = await ct.Translation.SingleOrDefaultAsync(m => m.Id == inObj.Id);
|
||||
|
||||
if (oFromDb == null)
|
||||
{
|
||||
@@ -282,18 +276,17 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.Locale))
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.Translation))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
//LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
//Instantiate the business object handler
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
try
|
||||
{
|
||||
if (!await biz.PutLocaleNameAsync(oFromDb, inObj))
|
||||
if (!await biz.PutTranslationNameAsync(oFromDb, inObj))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
@@ -301,7 +294,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!await biz.LocaleExistsAsync(inObj.Id))
|
||||
if (!await biz.TranslationExistsAsync(inObj.Id))
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
@@ -319,12 +312,12 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete Locale
|
||||
/// Delete Translation
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>Ok</returns>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteLocale([FromRoute] long id)
|
||||
public async Task<IActionResult> DeleteTranslation([FromRoute] long id)
|
||||
{
|
||||
|
||||
if (!serverState.IsOpen)
|
||||
@@ -338,22 +331,22 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
//Fetch locale and it's children
|
||||
//Fetch translation and it's children
|
||||
//(fetch here so can return proper REST responses on failing basic validity)
|
||||
var dbObj = await ct.Locale.Include(x => x.LocaleItems).SingleOrDefaultAsync(m => m.Id == id);
|
||||
var dbObj = await ct.Translation.Include(x => x.TranslationItems).SingleOrDefaultAsync(m => m.Id == id);
|
||||
if (dbObj == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
if (!Authorized.HasDeleteRole(HttpContext.Items, AyaType.Locale))
|
||||
if (!Authorized.HasDeleteRole(HttpContext.Items, AyaType.Translation))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
|
||||
//Instantiate the business object handler
|
||||
LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext);
|
||||
TranslationBiz biz = TranslationBiz.GetBiz(ct, HttpContext);
|
||||
if (!await biz.DeleteAsync(dbObj))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
@@ -364,14 +357,14 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
#if (DEBUG)
|
||||
public class LocaleCoverageInfo
|
||||
public class TranslationCoverageInfo
|
||||
{
|
||||
public List<string> RequestedKeys { get; set; }
|
||||
public int RequestedKeyCount { get; set; }
|
||||
public List<string> NotRequestedKeys { get; set; }
|
||||
public int NotRequestedKeyCount { get; set; }
|
||||
|
||||
public LocaleCoverageInfo()
|
||||
public TranslationCoverageInfo()
|
||||
{
|
||||
RequestedKeys = new List<string>();
|
||||
NotRequestedKeys = new List<string>();
|
||||
@@ -455,7 +455,7 @@ namespace AyaNova.DataList
|
||||
case UiFieldDataType.InternalId:
|
||||
case UiFieldDataType.Integer: //whole numbers, not only integer
|
||||
{
|
||||
//case 1795 - it's numeric, convert to locale independant format
|
||||
//case 1795 - it's numeric, convert to translation independant format
|
||||
//RAVEN NOTE: this code looks suspect to me, but I'll leave it in for now
|
||||
NumberFormatInfo nfi = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
|
||||
switch (DataType)
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace AyaNova
|
||||
logger.Debug("BOOT: User - {0}", Environment.UserName);
|
||||
logger.Debug("BOOT: .Net Version - {0}", Environment.Version.ToString());
|
||||
logger.Debug("BOOT: CPU count - {0}", Environment.ProcessorCount);
|
||||
logger.Debug("BOOT: Default language - \"{0}\"", ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE);
|
||||
logger.Debug("BOOT: Default language - \"{0}\"", ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -368,12 +368,11 @@ namespace AyaNova
|
||||
var ct = context.RequestServices.GetService<AyContext>();
|
||||
|
||||
//get the user record
|
||||
//var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, localeId = m.LocaleId }).First();
|
||||
var u = await ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, localeId = m.LocaleId }).FirstAsync();
|
||||
var u = await ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, translationId = m.TranslationId }).FirstAsync();
|
||||
context.Request.HttpContext.Items["AY_ROLES"] = u.roles;
|
||||
context.Request.HttpContext.Items["AY_USERNAME"] = u.name;
|
||||
context.Request.HttpContext.Items["AY_USER_ID"] = u.id;
|
||||
context.Request.HttpContext.Items["AY_LOCALE_ID"] = u.localeId;
|
||||
context.Request.HttpContext.Items["AY_TRANSLATION_ID"] = u.translationId;
|
||||
}
|
||||
await next.Invoke();
|
||||
});
|
||||
@@ -443,9 +442,9 @@ namespace AyaNova
|
||||
//Initialize license
|
||||
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
|
||||
|
||||
//Ensure locales are present, not missing any keys and that there is a server default locale that exists
|
||||
LocaleBiz lb = new LocaleBiz(dbContext, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.OpsAdminFull);
|
||||
lb.ValidateLocalesAsync().Wait();
|
||||
//Ensure translations are present, not missing any keys and that there is a server default translation that exists
|
||||
TranslationBiz lb = new TranslationBiz(dbContext, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.OpsAdminFull);
|
||||
lb.ValidateTranslationsAsync().Wait();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace AyaNova.Biz
|
||||
ServerStateChange=9,
|
||||
SeedDatabase=10
|
||||
|
||||
//NEW ITEMS REQUIRE LOCALE KEYS AND UPDATE EventLogProcessor code that prefetches required keys
|
||||
//NEW ITEMS REQUIRE translation KEYS AND UPDATE EventLogProcessor code that prefetches required keys
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace AyaNova.Biz
|
||||
AyaNova7Import = 10,
|
||||
TrialSeeder = 11,
|
||||
Metrics = 12,
|
||||
Locale = 13,
|
||||
Translation = 13,
|
||||
UserOptions = 14,
|
||||
DEPRECATED_REUSELATER_15 = 15,
|
||||
DEPRECATED_REUSELATER_16 = 16,
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace AyaNova.Biz
|
||||
internal AyaType BizType { get; set; }
|
||||
internal AyaNova.Models.AyContext ct { get; set; }
|
||||
internal long UserId { get; set; }
|
||||
internal long UserLocaleId { get; set; }
|
||||
internal long UserTranslationId { get; set; }
|
||||
internal AuthorizationRoles CurrentUserRoles { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -24,22 +24,22 @@ namespace AyaNova.Biz
|
||||
switch (aytype)
|
||||
{
|
||||
case AyaType.User:
|
||||
return new UserBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
return new UserBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
|
||||
case AyaType.Widget:
|
||||
return new WidgetBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
return new WidgetBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
|
||||
case AyaType.JobOperations:
|
||||
return new JobOperationsBiz(dbcontext, userId, roles);
|
||||
case AyaType.AyaNova7Import:
|
||||
return new ImportAyaNova7Biz(dbcontext, userId, roles);
|
||||
case AyaType.TrialSeeder:
|
||||
return new TrialBiz(dbcontext, userId, roles);
|
||||
case AyaType.Locale:
|
||||
return new LocaleBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
case AyaType.Translation:
|
||||
return new TranslationBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
|
||||
case AyaType.DataListView:
|
||||
return new DataListViewBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
return new DataListViewBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
|
||||
|
||||
case AyaType.FormCustom:
|
||||
return new FormCustomBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||
return new FormCustomBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
|
||||
|
||||
|
||||
default:
|
||||
|
||||
@@ -121,9 +121,9 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//LOCALE
|
||||
//TRANSLATION
|
||||
//
|
||||
roles.Add(AyaType.Locale, new BizRoleSet()
|
||||
roles.Add(AyaType.Translation, new BizRoleSet()
|
||||
{
|
||||
Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull,
|
||||
//Anyone can read it because they need to to open a form, but also in UI
|
||||
@@ -174,8 +174,8 @@ namespace AyaNova.Biz
|
||||
// System.Diagnostics.Debugger.Log(1, "JSONFRAGMENTFORCLIENT", json);
|
||||
|
||||
//ONGOING VALIDATION TO CATCH MISMATCH WHEN NEW ROLES ADDED (wont' catch changes to existing unfortunately)
|
||||
//var lastRoles = "{\"User\":{\"Change\":2,\"ReadFullRecord\":1},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1},\"Widget\":{\"Change\":34,\"ReadFullRecord\":17},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":32767},\"License\":{\"Change\":16386,\"ReadFullRecord\":8193},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576},\"JobOperations\":{\"Change\":16384,\"ReadFullRecord\":8195},\"AyaNova7Import\":{\"Change\":16384,\"ReadFullRecord\":0},\"Metrics\":{\"Change\":0,\"ReadFullRecord\":24576},\"Locale\":{\"Change\":16386,\"ReadFullRecord\":32767},\"DataListFilter\":{\"Change\":2,\"ReadFullRecord\":32767},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":32767}}";
|
||||
var lastRoles = "{\"User\":{\"Change\":2,\"ReadFullRecord\":1},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1},\"Widget\":{\"Change\":34,\"ReadFullRecord\":17},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":131071},\"License\":{\"Change\":16386,\"ReadFullRecord\":8193},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576},\"JobOperations\":{\"Change\":16384,\"ReadFullRecord\":8195},\"AyaNova7Import\":{\"Change\":16384,\"ReadFullRecord\":0},\"Metrics\":{\"Change\":0,\"ReadFullRecord\":24576},\"Locale\":{\"Change\":16386,\"ReadFullRecord\":131071},\"DataListView\":{\"Change\":2,\"ReadFullRecord\":131071},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":131071}}";
|
||||
//var lastRoles = "{\"User\":{\"Change\":2,\"ReadFullRecord\":1},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1},\"Widget\":{\"Change\":34,\"ReadFullRecord\":17},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":32767},\"License\":{\"Change\":16386,\"ReadFullRecord\":8193},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576},\"JobOperations\":{\"Change\":16384,\"ReadFullRecord\":8195},\"AyaNova7Import\":{\"Change\":16384,\"ReadFullRecord\":0},\"Metrics\":{\"Change\":0,\"ReadFullRecord\":24576},\"Translation\":{\"Change\":16386,\"ReadFullRecord\":32767},\"DataListFilter\":{\"Change\":2,\"ReadFullRecord\":32767},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":32767}}";
|
||||
var lastRoles = "{\"User\":{\"Change\":2,\"ReadFullRecord\":1},\"UserOptions\":{\"Change\":2,\"ReadFullRecord\":1},\"Widget\":{\"Change\":34,\"ReadFullRecord\":17},\"ServerState\":{\"Change\":16384,\"ReadFullRecord\":131071},\"License\":{\"Change\":16386,\"ReadFullRecord\":8193},\"LogFile\":{\"Change\":0,\"ReadFullRecord\":24576},\"JobOperations\":{\"Change\":16384,\"ReadFullRecord\":8195},\"AyaNova7Import\":{\"Change\":16384,\"ReadFullRecord\":0},\"Metrics\":{\"Change\":0,\"ReadFullRecord\":24576},\"Translation\":{\"Change\":16386,\"ReadFullRecord\":131071},\"DataListView\":{\"Change\":2,\"ReadFullRecord\":131071},\"FormCustom\":{\"Change\":2,\"ReadFullRecord\":131071}}";
|
||||
Dictionary<AyaType, BizRoleSet> lastRolesDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<AyaType, BizRoleSet>>(lastRoles);
|
||||
if (lastRolesDeserialized.Count != roles.Count)
|
||||
{
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace AyaNova.Biz
|
||||
internal class DataListViewBiz : BizObject
|
||||
{
|
||||
|
||||
internal DataListViewBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
|
||||
internal DataListViewBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = UserRoles;
|
||||
BizType = AyaType.DataListView;
|
||||
}
|
||||
@@ -28,9 +28,9 @@ namespace AyaNova.Biz
|
||||
internal static DataListViewBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
{
|
||||
if (httpContext != null)
|
||||
return new DataListViewBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
return new DataListViewBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
else
|
||||
return new DataListViewBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
|
||||
return new DataListViewBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ namespace AyaNova.Biz
|
||||
//EVENT LOG
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
//SEARCH INDEXING
|
||||
// Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name);
|
||||
|
||||
|
||||
return outObj;
|
||||
|
||||
@@ -178,8 +177,7 @@ namespace AyaNova.Biz
|
||||
//Log modification and save context
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
|
||||
//Update keywords
|
||||
// Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Name);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace AyaNova.Biz
|
||||
internal class FormCustomBiz : BizObject
|
||||
{
|
||||
|
||||
internal FormCustomBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
|
||||
internal FormCustomBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = UserRoles;
|
||||
BizType = AyaType.FormCustom;
|
||||
}
|
||||
@@ -27,9 +27,9 @@ namespace AyaNova.Biz
|
||||
internal static FormCustomBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
{
|
||||
if (httpContext != null)
|
||||
return new FormCustomBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
return new FormCustomBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
else//when called internally for internal ops there will be no context so need to set default values for that
|
||||
return new FormCustomBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
|
||||
return new FormCustomBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,7 @@ namespace AyaNova.Biz
|
||||
//EVENT LOG
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
//SEARCH INDEXING
|
||||
// Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name);
|
||||
|
||||
|
||||
return outObj;
|
||||
|
||||
}
|
||||
@@ -136,9 +134,7 @@ namespace AyaNova.Biz
|
||||
//Log modification and save context
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
|
||||
//Update keywords
|
||||
// Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Name);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -155,10 +155,10 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
//IMPORT LOCALES
|
||||
await DoImportAsync("GZTW.AyaNova.BLL.Locale", "main", AyaType.Locale, job.GId, importMap, importFileName, zipEntries, TagLists);
|
||||
//Now can do user locale settings properly
|
||||
await DoImportAsync("GZTW.AyaNova.BLL.User", "locale", AyaType.User, job.GId, importMap, importFileName, zipEntries, TagLists);
|
||||
//IMPORT TRANSLATIONS
|
||||
await DoImportAsync("GZTW.AyaNova.BLL.Translation", "main", AyaType.Translation, job.GId, importMap, importFileName, zipEntries, TagLists);
|
||||
//Now can do user translation settings properly
|
||||
await DoImportAsync("GZTW.AyaNova.BLL.User", "translation", AyaType.User, job.GId, importMap, importFileName, zipEntries, TagLists);
|
||||
|
||||
//TODO: CLIENT
|
||||
//do import for client here
|
||||
|
||||
@@ -9,7 +9,7 @@ using AyaNova.Models;
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
//Prime the database with initial, minimum required data to boot and do things (manager account, locales)
|
||||
//Prime the database with initial, minimum required data to boot and do things (manager account, translations)
|
||||
public static class PrimeData
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace AyaNova.Biz
|
||||
u.Password = Hasher.hash(u.Salt, "l3tm3in");
|
||||
u.Roles = AuthorizationRoles.All;//AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull;
|
||||
|
||||
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first
|
||||
u.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;//Ensure primeTranslations is called first
|
||||
u.UserType = UserType.Administrator;
|
||||
u.UserOptions = new UserOptions();
|
||||
await ct.User.AddAsync(u);
|
||||
@@ -38,14 +38,14 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Prime the locales
|
||||
/// Prime the Translations
|
||||
/// This may be called before there are any users on a fresh db boot
|
||||
/// </summary>
|
||||
public static async Task PrimeLocales()
|
||||
public static async Task PrimeTranslations()
|
||||
{//
|
||||
|
||||
|
||||
//Read in each stock locale from a text file and then create them in the DB
|
||||
//Read in each stock translation from a text file and then create them in the DB
|
||||
var ResourceFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource");
|
||||
if (!Directory.Exists(ResourceFolderPath))
|
||||
{
|
||||
@@ -53,30 +53,30 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
await ImportLocale(ResourceFolderPath, "en");
|
||||
await ImportLocale(ResourceFolderPath, "es");
|
||||
await ImportLocale(ResourceFolderPath, "fr");
|
||||
await ImportLocale(ResourceFolderPath, "de");
|
||||
await ImportTranslation(ResourceFolderPath, "en");
|
||||
await ImportTranslation(ResourceFolderPath, "es");
|
||||
await ImportTranslation(ResourceFolderPath, "fr");
|
||||
await ImportTranslation(ResourceFolderPath, "de");
|
||||
|
||||
//Ensure locales are present, not missing any keys and that there is a server default locale that exists
|
||||
LocaleBiz lb = LocaleBiz.GetBiz(ServiceProviderProvider.DBContext);
|
||||
await lb.ValidateLocalesAsync();
|
||||
//Ensure Translations are present, not missing any keys and that there is a server default translation that exists
|
||||
TranslationBiz lb = TranslationBiz.GetBiz(ServiceProviderProvider.DBContext);
|
||||
await lb.ValidateTranslationsAsync();
|
||||
|
||||
}
|
||||
|
||||
private static async Task ImportLocale(string resourceFolderPath, string localeCode)
|
||||
private static async Task ImportTranslation(string resourceFolderPath, string translationCode)
|
||||
{
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
var LocalePath = Path.Combine(resourceFolderPath, $"{localeCode}.json");
|
||||
if (!File.Exists(LocalePath))
|
||||
var TranslationPath = Path.Combine(resourceFolderPath, $"{translationCode}.json");
|
||||
if (!File.Exists(TranslationPath))
|
||||
{
|
||||
throw new System.Exception($"E1013: stock locale file \"{localeCode}\" not found where expected: \"{LocalePath}\", installation damaged?");
|
||||
throw new System.Exception($"E1013: stock translation file \"{translationCode}\" not found where expected: \"{TranslationPath}\", installation damaged?");
|
||||
}
|
||||
|
||||
JObject o = JObject.Parse(await File.ReadAllTextAsync(LocalePath));
|
||||
JObject o = JObject.Parse(await File.ReadAllTextAsync(TranslationPath));
|
||||
|
||||
Locale l = new Locale();
|
||||
l.Name = localeCode;
|
||||
Translation l = new Translation();
|
||||
l.Name = translationCode;
|
||||
|
||||
l.Stock = true;
|
||||
l.CjkIndex = false;
|
||||
@@ -85,10 +85,10 @@ namespace AyaNova.Biz
|
||||
{
|
||||
var key = t.Path;
|
||||
var display = t.First.Value<string>();
|
||||
l.LocaleItems.Add(new LocaleItem() { Key = key, Display = display });//, Locale = l
|
||||
l.TranslationItems.Add(new TranslationItem() { Key = key, Display = display });
|
||||
}
|
||||
|
||||
await ct.Locale.AddAsync(l);
|
||||
await ct.Translation.AddAsync(l);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
public static async Task<SearchReturnObject> DoSearchAsync(AyContext ct, long localeId, AuthorizationRoles currentUserRoles, SearchRequestParameters searchParameters)
|
||||
public static async Task<SearchReturnObject> DoSearchAsync(AyContext ct, long translationId, AuthorizationRoles currentUserRoles, SearchRequestParameters searchParameters)
|
||||
{
|
||||
var ReturnObject = new SearchReturnObject();
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace AyaNova.Biz
|
||||
searchParameters.Phrase = searchParameters.Phrase.Replace("*", "%");
|
||||
|
||||
//BREAK SEARCH PHRASE INTO SEPARATE TERMS
|
||||
var PhraseItems = await BreakSearchPhraseAsync(localeId, searchParameters.Phrase);
|
||||
var PhraseItems = await BreakSearchPhraseAsync(translationId, searchParameters.Phrase);
|
||||
|
||||
//SPLIT OUT WILDCARDS FROM NON WILDCARDS
|
||||
List<string> WildCardSearchTerms = new List<string>();
|
||||
@@ -374,7 +374,7 @@ namespace AyaNova.Biz
|
||||
//Class to hold process input parameters
|
||||
public class SearchIndexProcessObjectParameters
|
||||
{
|
||||
public long LocaleId { get; set; }
|
||||
public long TranslationId { get; set; }
|
||||
public long ObjectId { get; set; }
|
||||
public AyaType ObjectType { get; set; }
|
||||
public string Name { get; set; }
|
||||
@@ -382,11 +382,11 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
public SearchIndexProcessObjectParameters(long localeId, long objectID, AyaType objectType, string name)
|
||||
public SearchIndexProcessObjectParameters(long translationId, long objectID, AyaType objectType, string name)
|
||||
{
|
||||
Words = new List<string>();
|
||||
|
||||
LocaleId = localeId;
|
||||
TranslationId = translationId;
|
||||
ObjectId = objectID;
|
||||
ObjectType = objectType;
|
||||
Name = name;
|
||||
@@ -436,14 +436,14 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
public static async Task ProcessNewObjectKeywordsAsync(SearchIndexProcessObjectParameters searchIndexObjectParameters)//(long localeId, long objectID, AyaType objectType, string name, params string[] text)
|
||||
public static async Task ProcessNewObjectKeywordsAsync(SearchIndexProcessObjectParameters searchIndexObjectParameters)
|
||||
{
|
||||
await ProcessKeywordsAsync(searchIndexObjectParameters, true);//localeId, objectID, objectType, true, name, text);
|
||||
await ProcessKeywordsAsync(searchIndexObjectParameters, true);
|
||||
}
|
||||
|
||||
public static async Task ProcessUpdatedObjectKeywordsAsync(SearchIndexProcessObjectParameters searchIndexObjectParameters)// localeId, long objectID, AyaType objectType, string name, params string[] text)
|
||||
public static async Task ProcessUpdatedObjectKeywordsAsync(SearchIndexProcessObjectParameters searchIndexObjectParameters)
|
||||
{
|
||||
await ProcessKeywordsAsync(searchIndexObjectParameters, false);//localeId, objectID, objectType, false, name, text);
|
||||
await ProcessKeywordsAsync(searchIndexObjectParameters, false);
|
||||
}
|
||||
|
||||
public static async Task ProcessDeletedObjectKeywordsAsync(long objectID, AyaType objectType)
|
||||
@@ -463,11 +463,11 @@ namespace AyaNova.Biz
|
||||
/// Process the keywords into the dictionary
|
||||
/// NOTE: NAME parameter is in ADDITION to the NAME also being one of the strings passed in text parameter
|
||||
/// </summary>
|
||||
private static async Task ProcessKeywordsAsync(SearchIndexProcessObjectParameters p, bool newRecord)//long localeId, long objectID, AyaType objectType, string name, params string[] text)
|
||||
private static async Task ProcessKeywordsAsync(SearchIndexProcessObjectParameters p, bool newRecord)
|
||||
{
|
||||
|
||||
#if (DEBUG)
|
||||
if (p.ObjectType == AyaType.JobOperations || p.ObjectType == AyaType.Locale)
|
||||
if (p.ObjectType == AyaType.JobOperations || p.ObjectType == AyaType.Translation)
|
||||
{
|
||||
throw new System.NotSupportedException($"Search::ProcessKeywords - Invalid type presented {p.ObjectType}");
|
||||
}
|
||||
@@ -481,10 +481,10 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
//BREAK OBJECT TEXT STRINGS INTO KEYWORD LIST
|
||||
List<string> KeyWordList = await BreakAsync(p.LocaleId, p.Words);
|
||||
List<string> KeyWordList = await BreakAsync(p.TranslationId, p.Words);
|
||||
|
||||
//BREAK NAME STRING
|
||||
List<string> NameKeyWordList = await BreakAsync(p.LocaleId, p.Name);
|
||||
List<string> NameKeyWordList = await BreakAsync(p.TranslationId, p.Name);
|
||||
|
||||
|
||||
//EARLY EXIT IF NO KEYWORDS OR NAME RECORD OR TAGS TO PROCESS
|
||||
@@ -573,7 +573,7 @@ Async the keyword processing
|
||||
|
||||
Removing use of EF entirely in search indexing processing in favor of direct sql queries
|
||||
|
||||
cache or provide directly the locale to save time repeatedly fetching it when doing bulk ops!!!
|
||||
cache or provide directly the translation to save time repeatedly fetching it when doing bulk ops!!!
|
||||
-After doing this 500=21 That's as fast as when I stripped out all the text, what a huge overhead saving right there!:
|
||||
2020-01-24 12:00:41.2547|INFO|Seeder|Seeding 500 Widgets....
|
||||
2020-01-24 12:00:51.9138|INFO|Seeder|500 Widgets seeded in 10649 ms
|
||||
@@ -692,27 +692,27 @@ cache or provide directly the locale to save time repeatedly fetching it when do
|
||||
|
||||
#region Breaker
|
||||
|
||||
//Class to hold relevant locale data for breaking text
|
||||
public class LocaleWordBreakingData
|
||||
//Class to hold relevant translation data for breaking text
|
||||
public class TranslationWordBreakingData
|
||||
{
|
||||
public bool CJKIndex { get; set; }
|
||||
public List<string> StopWords { get; set; }
|
||||
public LocaleWordBreakingData()
|
||||
public TranslationWordBreakingData()
|
||||
{
|
||||
CJKIndex = false;
|
||||
StopWords = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCache = new Dictionary<long, LocaleWordBreakingData>();
|
||||
private static Dictionary<long, TranslationWordBreakingData> translationWordBreakingDataCache = new Dictionary<long, TranslationWordBreakingData>();
|
||||
|
||||
// //called at startup to populate cache
|
||||
//WAS GOING TO ADD THIS IN RESPONSE TO AN ISSUE WITH EXCEPTION ATTEMPTING TO ADD ALREADY EXISTING DICTIONARY ID 1, BUT IT NEVER HAPPENED AGAIN, SO :SHRUGEMOJI:
|
||||
//IF IT DOES, MAKE THIS CODE AND POPULATE IT AT SERVER BOOT AND SHOULD BE ADEQUATE
|
||||
//OR GO NUTS WITH A FULL MEMORY CACHE: https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-3.1
|
||||
// internal static async Task CacheAllLocaleWordBreakingData(){
|
||||
// //iterate all locales, cache the word break data
|
||||
// l = await ct.Locale
|
||||
// internal static async Task CacheAllTranslationWordBreakingData(){
|
||||
// //iterate all Translations, cache the word break data
|
||||
// l = await ct.Translation
|
||||
// .AsNoTracking()
|
||||
// .OrderBy(m => m.Name)
|
||||
// .Select(m => new NameIdItem()
|
||||
@@ -720,17 +720,17 @@ private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCa
|
||||
// Id = m.Id,
|
||||
// Name = m.Name
|
||||
// }).ToListAsync();
|
||||
// localeWordBreakingDataCache.Add(localeId, await GetLocaleSearchDataAsync(localeId));
|
||||
// TranslationWordBreakingDataCache.Add(TranslationId, await GetTranslationSearchDataAsync(TranslationId));
|
||||
// }
|
||||
internal static async Task<LocaleWordBreakingData> GetLocaleSearchDataAsync(long localeId, AyContext ct = null)
|
||||
internal static async Task<TranslationWordBreakingData> GetTranslationSearchDataAsync(long translationId, AyContext ct = null)
|
||||
{
|
||||
LocaleWordBreakingData LSD = new LocaleWordBreakingData();
|
||||
TranslationWordBreakingData LSD = new TranslationWordBreakingData();
|
||||
if (ct == null)
|
||||
ct = ServiceProviderProvider.DBContext;
|
||||
//Get stopwords
|
||||
//Validate locale id, if not right then use default instead
|
||||
//Validate translation id, if not right then use default instead
|
||||
var Param = new List<string>();
|
||||
localeId = await LocaleBiz.ReturnSpecifiedLocaleIdIfExistsOrDefaultLocaleId(localeId, ct);
|
||||
translationId = await TranslationBiz.ReturnSpecifiedTranslationIdIfExistsOrDefaultTranslationId(translationId, ct);
|
||||
Param.Add("StopWords1");
|
||||
Param.Add("StopWords2");
|
||||
Param.Add("StopWords3");
|
||||
@@ -738,18 +738,18 @@ private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCa
|
||||
Param.Add("StopWords5");
|
||||
Param.Add("StopWords6");
|
||||
Param.Add("StopWords7");
|
||||
var Stops = await LocaleBiz.GetSubsetStaticAsync(Param, localeId);
|
||||
var Stops = await TranslationBiz.GetSubsetStaticAsync(Param, translationId);
|
||||
|
||||
foreach (KeyValuePair<string, string> kvp in Stops)
|
||||
{
|
||||
//Each stopwords locale key is a space delimited list of words and in the case of an empty local string (i.e. StopWords7) it's value is a single question mark
|
||||
//Each stopwords translation key is a space delimited list of words and in the case of an empty local string (i.e. StopWords7) it's value is a single question mark
|
||||
if (kvp.Value != "?")
|
||||
{
|
||||
LSD.StopWords.AddRange(kvp.Value.Split(" "));
|
||||
}
|
||||
}
|
||||
|
||||
LSD.CJKIndex = await LocaleBiz.GetCJKIndexAsync(localeId, ct);
|
||||
LSD.CJKIndex = await TranslationBiz.GetCJKIndexAsync(translationId, ct);
|
||||
return LSD;
|
||||
}
|
||||
|
||||
@@ -763,34 +763,34 @@ private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCa
|
||||
/// keywords suitable for passing to a
|
||||
/// stored procedure or other function
|
||||
///
|
||||
/// Use Locale setting CJKIndex=true to handle Chinese, Japanese, Korean etc
|
||||
/// Use Translation setting CJKIndex=true to handle Chinese, Japanese, Korean etc
|
||||
/// (languages with no easily identifiable word boundaries as in english)
|
||||
/// </summary>
|
||||
/// <returns>List of strings</returns>
|
||||
internal static async Task<List<string>> BreakAsync(long localeId, List<string> textStrings)
|
||||
internal static async Task<List<string>> BreakAsync(long translationId, List<string> textStrings)
|
||||
{
|
||||
return await BreakCoreAsync(localeId, false, textStrings);
|
||||
return await BreakCoreAsync(translationId, false, textStrings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal static async Task<List<string>> BreakAsync(long localeId, string textString)
|
||||
internal static async Task<List<string>> BreakAsync(long translationId, string textString)
|
||||
{
|
||||
List<string> textStrings = new List<string>(1);
|
||||
textStrings.Add(textString);
|
||||
return await BreakCoreAsync(localeId, false, textStrings);
|
||||
return await BreakCoreAsync(translationId, false, textStrings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to Process users search phrase and preserve wild
|
||||
/// cards entered
|
||||
/// </summary>
|
||||
internal static async Task<List<string>> BreakSearchPhraseAsync(long localeId, string searchPhrase)
|
||||
internal static async Task<List<string>> BreakSearchPhraseAsync(long translationId, string searchPhrase)
|
||||
{
|
||||
List<string> textStrings = new List<string>();
|
||||
textStrings.Add(searchPhrase);
|
||||
return await BreakCoreAsync(localeId, true, textStrings);
|
||||
return await BreakCoreAsync(translationId, true, textStrings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -798,24 +798,17 @@ private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCa
|
||||
/// used for eliminating noise words from search dictionary
|
||||
/// </summary>
|
||||
|
||||
|
||||
// //called by Locale in the rare circumstance that a locale has changed that is cached
|
||||
// //and might affect word breaking (stopwords cjkindex etc)
|
||||
// internal static void ClearLocaleWordBreakingDataCache(long localeId)
|
||||
// {
|
||||
// localeWordBreakingDataCache.Remove(localeId);
|
||||
// }
|
||||
|
||||
internal static async Task<List<string>> BreakCoreAsync(long localeId, bool KeepWildCards, List<string> textStrings)
|
||||
internal static async Task<List<string>> BreakCoreAsync(long translationId, bool KeepWildCards, List<string> textStrings)
|
||||
{
|
||||
//For stopwords and CJKIndex flag value
|
||||
//if not provided (will be provided by seeder for performance but normally never) then fetch
|
||||
|
||||
if (!localeWordBreakingDataCache.ContainsKey(localeId))
|
||||
if (!translationWordBreakingDataCache.ContainsKey(translationId))
|
||||
{
|
||||
localeWordBreakingDataCache.Add(localeId, await GetLocaleSearchDataAsync(localeId));
|
||||
translationWordBreakingDataCache.Add(translationId, await GetTranslationSearchDataAsync(translationId));
|
||||
}
|
||||
var localeWordBreakData = localeWordBreakingDataCache[localeId];
|
||||
var translationWordBreakData = translationWordBreakingDataCache[translationId];
|
||||
|
||||
|
||||
int MAXWORDLENGTH = 255;
|
||||
@@ -851,7 +844,7 @@ private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCa
|
||||
//get it as a character
|
||||
char c = t.GetTextElement()[0];
|
||||
|
||||
if (!localeWordBreakData.CJKIndex)
|
||||
if (!translationWordBreakData.CJKIndex)
|
||||
{
|
||||
#region regular tokenizer
|
||||
|
||||
@@ -1081,7 +1074,7 @@ private static Dictionary<long, LocaleWordBreakingData> localeWordBreakingDataCa
|
||||
if (s.Length >= MINWORDLENGTH || (KeepWildCards && s.Contains('%')))
|
||||
{
|
||||
//Add only non stopwords
|
||||
if (!localeWordBreakData.StopWords.Contains(s))
|
||||
if (!translationWordBreakData.StopWords.Contains(s))
|
||||
{
|
||||
ReturnList.Add(s);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
@@ -11,45 +9,43 @@ using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
internal class LocaleBiz : BizObject, IImportAyaNova7Object
|
||||
internal class TranslationBiz : BizObject, IImportAyaNova7Object
|
||||
{
|
||||
public bool SeedOrImportRelaxedRulesMode { get; set; }
|
||||
|
||||
internal LocaleBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles userRoles)
|
||||
internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = userRoles;
|
||||
BizType = AyaType.Locale;
|
||||
BizType = AyaType.Translation;
|
||||
SeedOrImportRelaxedRulesMode = false;//default
|
||||
}
|
||||
|
||||
internal static LocaleBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
{
|
||||
if (httpContext != null)
|
||||
return new LocaleBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
return new TranslationBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
else
|
||||
return new LocaleBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
|
||||
return new TranslationBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DUPLICATE - only way to create a new locale
|
||||
//DUPLICATE - only way to create a new translation
|
||||
//
|
||||
internal async Task<Locale> DuplicateAsync(NameIdItem inObj)
|
||||
internal async Task<Translation> DuplicateAsync(NameIdItem inObj)
|
||||
{
|
||||
|
||||
//make sure sourceid exists
|
||||
if (!await LocaleExistsAsync(inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Id", "Source locale id does not exist");
|
||||
if (!await TranslationExistsAsync(inObj.Id))
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Id", "Source translation id does not exist");
|
||||
|
||||
//Ensure name is unique and not too long and not empty
|
||||
await ValidateAsync(inObj.Name, true);
|
||||
@@ -57,37 +53,37 @@ namespace AyaNova.Biz
|
||||
if (HasErrors)
|
||||
return null;
|
||||
|
||||
//fetch the existing locale for duplication
|
||||
var SourceLocale = await ct.Locale.Include(x => x.LocaleItems).SingleOrDefaultAsync(m => m.Id == inObj.Id);
|
||||
//fetch the existing translation for duplication
|
||||
var SourceTranslation = await ct.Translation.Include(x => x.TranslationItems).SingleOrDefaultAsync(m => m.Id == inObj.Id);
|
||||
|
||||
//replicate the source to a new dest and save
|
||||
Locale NewLocale = new Locale();
|
||||
NewLocale.Name = inObj.Name;
|
||||
Translation NewTranslation = new Translation();
|
||||
NewTranslation.Name = inObj.Name;
|
||||
|
||||
NewLocale.Stock = false;
|
||||
NewLocale.CjkIndex = false;
|
||||
foreach (LocaleItem i in SourceLocale.LocaleItems)
|
||||
NewTranslation.Stock = false;
|
||||
NewTranslation.CjkIndex = false;
|
||||
foreach (TranslationItem i in SourceTranslation.TranslationItems)
|
||||
{
|
||||
NewLocale.LocaleItems.Add(new LocaleItem() { Key = i.Key, Display = i.Display });
|
||||
NewTranslation.TranslationItems.Add(new TranslationItem() { Key = i.Key, Display = i.Display });
|
||||
}
|
||||
|
||||
//Add it to the context so the controller can save it
|
||||
await ct.Locale.AddAsync(NewLocale);
|
||||
await ct.Translation.AddAsync(NewTranslation);
|
||||
await ct.SaveChangesAsync();
|
||||
//Log
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, NewLocale.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||
return NewLocale;
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, NewTranslation.Id, AyaType.Translation, AyaEvent.Created), ct);
|
||||
return NewTranslation;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
|
||||
//Get entire locale
|
||||
internal async Task<Locale> GetAsync(long fetchId)
|
||||
//Get entire translation
|
||||
internal async Task<Translation> GetAsync(long fetchId)
|
||||
{
|
||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
||||
return await ct.Locale.Include(x => x.LocaleItems).SingleOrDefaultAsync(m => m.Id == fetchId);
|
||||
return await ct.Translation.Include(x => x.TranslationItems).SingleOrDefaultAsync(m => m.Id == fetchId);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +92,7 @@ namespace AyaNova.Biz
|
||||
internal async Task<List<NameIdItem>> GetPickListAsync()
|
||||
{
|
||||
List<NameIdItem> l = new List<NameIdItem>();
|
||||
l = await ct.Locale
|
||||
l = await ct.Translation
|
||||
.AsNoTracking()
|
||||
.OrderBy(m => m.Name)
|
||||
.Select(m => new NameIdItem()
|
||||
@@ -111,10 +107,10 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
#if (DEBUG)
|
||||
internal async Task<AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo> LocaleKeyCoverageAsync()
|
||||
internal async Task<AyaNova.Api.Controllers.TranslationController.TranslationCoverageInfo> TranslationKeyCoverageAsync()
|
||||
{
|
||||
AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo L = new AyaNova.Api.Controllers.LocaleController.LocaleCoverageInfo();
|
||||
L.RequestedKeys = ServerBootConfig.LocaleKeysRequested;
|
||||
AyaNova.Api.Controllers.TranslationController.TranslationCoverageInfo L = new AyaNova.Api.Controllers.TranslationController.TranslationCoverageInfo();
|
||||
L.RequestedKeys = ServerBootConfig.TranslationKeysRequested;
|
||||
L.RequestedKeys.Sort();
|
||||
var AllKeys = await GetKeyListAsync();
|
||||
foreach (string StockKey in AllKeys)
|
||||
@@ -136,16 +132,16 @@ namespace AyaNova.Biz
|
||||
//or the UI needs to be tested in a way that triggers every key to be used even errors etc
|
||||
internal static void TrackRequestedKey(string key)
|
||||
{
|
||||
if (!ServerBootConfig.LocaleKeysRequested.Contains(key))
|
||||
ServerBootConfig.LocaleKeysRequested.Add(key);
|
||||
if (!ServerBootConfig.TranslationKeysRequested.Contains(key))
|
||||
ServerBootConfig.TranslationKeysRequested.Add(key);
|
||||
}
|
||||
|
||||
internal static void TrackRequestedKey(List<string> keys)
|
||||
{
|
||||
foreach (string Key in keys)
|
||||
{
|
||||
if (!ServerBootConfig.LocaleKeysRequested.Contains(Key))
|
||||
ServerBootConfig.LocaleKeysRequested.Add(Key);
|
||||
if (!ServerBootConfig.TranslationKeysRequested.Contains(Key))
|
||||
ServerBootConfig.TranslationKeysRequested.Add(Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,37 +154,37 @@ namespace AyaNova.Biz
|
||||
#if (DEBUG)
|
||||
TrackRequestedKey(param);
|
||||
#endif
|
||||
var ret = await ct.LocaleItem.Where(x => x.LocaleId == UserLocaleId && param.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display);
|
||||
var ret = await ct.TranslationItem.Where(x => x.TranslationId == UserTranslationId && param.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display);
|
||||
return ret.ToList();
|
||||
}
|
||||
|
||||
//Get the keys for a list of keys provided, static format for calling from other internal classes
|
||||
internal static async Task<Dictionary<string, string>> GetSubsetStaticAsync(List<string> param, long localeId)
|
||||
internal static async Task<Dictionary<string, string>> GetSubsetStaticAsync(List<string> param, long translationId)
|
||||
{
|
||||
#if (DEBUG)
|
||||
TrackRequestedKey(param);
|
||||
#endif
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
|
||||
if (!await ct.Locale.AnyAsync(e => e.Id == localeId))
|
||||
localeId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
var ret = await ct.LocaleItem.Where(x => x.LocaleId == localeId && param.Contains(x.Key)).AsNoTracking().ToDictionaryAsync(x => x.Key, x => x.Display);
|
||||
if (!await ct.Translation.AnyAsync(e => e.Id == translationId))
|
||||
translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||
var ret = await ct.TranslationItem.Where(x => x.TranslationId == translationId && param.Contains(x.Key)).AsNoTracking().ToDictionaryAsync(x => x.Key, x => x.Display);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//Get the CJKIndex value for the locale specified
|
||||
internal static async Task<bool> GetCJKIndexAsync(long localeId, AyContext ct = null)
|
||||
//Get the CJKIndex value for the translation specified
|
||||
internal static async Task<bool> GetCJKIndexAsync(long translationId, AyContext ct = null)
|
||||
{
|
||||
if (ct == null)
|
||||
ct = ServiceProviderProvider.DBContext;
|
||||
var ret = await ct.Locale.Where(x => x.Id == localeId).AsNoTracking().Select(m => m.CjkIndex).SingleOrDefaultAsync();
|
||||
var ret = await ct.Translation.Where(x => x.Id == translationId).AsNoTracking().Select(m => m.CjkIndex).SingleOrDefaultAsync();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the value of the key provided in the default locale chosen
|
||||
/// Get the value of the key provided in the default translation chosen
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
@@ -200,14 +196,14 @@ namespace AyaNova.Biz
|
||||
TrackRequestedKey(key);
|
||||
#endif
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
return await ct.LocaleItem.Where(m => m.LocaleId == ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID && m.Key == key).Select(m => m.Display).AsNoTracking().FirstOrDefaultAsync();
|
||||
return await ct.TranslationItem.Where(m => m.TranslationId == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID && m.Key == key).Select(m => m.Display).AsNoTracking().FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
//Get all stock keys that are valid (used for import)
|
||||
internal static async Task<List<string>> GetKeyListAsync()
|
||||
{
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
return await ct.LocaleItem.Where(m => m.LocaleId == 1).OrderBy(m => m.Key).Select(m => m.Key).AsNoTracking().ToListAsync();
|
||||
return await ct.TranslationItem.Where(m => m.TranslationId == 1).OrderBy(m => m.Key).Select(m => m.Key).AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -216,12 +212,12 @@ namespace AyaNova.Biz
|
||||
//
|
||||
|
||||
|
||||
internal async Task<bool> PutLocaleItemDisplayTextAsync(LocaleItem dbObj, NewTextIdConcurrencyTokenItem inObj, Locale dbParent)
|
||||
internal async Task<bool> PutTranslationItemDisplayTextAsync(TranslationItem dbObj, NewTextIdConcurrencyTokenItem inObj, Translation dbParent)
|
||||
{
|
||||
|
||||
if (dbParent.Stock == true)
|
||||
{
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "LocaleItem is from a Stock locale and cannot be modified");
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "TranslationItem is from a Stock translation and cannot be modified");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -241,17 +237,17 @@ namespace AyaNova.Biz
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbParent.Id, AyaType.Locale, AyaEvent.Modified), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbParent.Id, AyaType.Translation, AyaEvent.Modified), ct);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
internal async Task<bool> PutLocaleNameAsync(Locale dbObj, NewTextIdConcurrencyTokenItem inObj)
|
||||
internal async Task<bool> PutTranslationNameAsync(Translation dbObj, NewTextIdConcurrencyTokenItem inObj)
|
||||
{
|
||||
if (dbObj.Stock == true)
|
||||
{
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "Locale is a Stock locale and cannot be modified");
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "Translation is a Stock translation and cannot be modified");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -268,7 +264,7 @@ namespace AyaNova.Biz
|
||||
|
||||
await ct.SaveChangesAsync();
|
||||
//Log
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.Locale, AyaEvent.Modified), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.Translation, AyaEvent.Modified), ct);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -280,16 +276,16 @@ namespace AyaNova.Biz
|
||||
//DELETE
|
||||
//
|
||||
|
||||
internal async Task<bool> DeleteAsync(Locale dbObj)
|
||||
internal async Task<bool> DeleteAsync(Translation dbObj)
|
||||
{
|
||||
//Determine if the object can be deleted, do the deletion tentatively
|
||||
await ValidateCanDeleteAsync(dbObj);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.Locale.Remove(dbObj);
|
||||
ct.Translation.Remove(dbObj);
|
||||
await ct.SaveChangesAsync();
|
||||
//Log
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, AyaType.Locale, dbObj.Id, dbObj.Name, ct);
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, AyaType.Translation, dbObj.Id, dbObj.Name, ct);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -312,7 +308,7 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 char max");
|
||||
|
||||
//Name must be unique
|
||||
if (await ct.Locale.AnyAsync(m => m.Name == inObjName))
|
||||
if (await ct.Translation.AnyAsync(m => m.Name == inObjName))
|
||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
||||
|
||||
return;
|
||||
@@ -320,25 +316,25 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
//Can delete?
|
||||
private async Task ValidateCanDeleteAsync(Locale inObj)
|
||||
private async Task ValidateCanDeleteAsync(Translation inObj)
|
||||
{
|
||||
//Decided to short circuit these; if there is one issue then return immediately (fail fast rule)
|
||||
|
||||
//Ensure it's not a stock locale
|
||||
//Ensure it's not a stock translation
|
||||
if (inObj.Stock == true)
|
||||
{
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "Locale is a Stock locale and cannot be deleted");
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "Translation is a Stock translation and cannot be deleted");
|
||||
return;
|
||||
}
|
||||
|
||||
if (inObj.Id == ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID)
|
||||
if (inObj.Id == ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID)
|
||||
{
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "Locale is set as the default server locale (AYANOVA_DEFAULT_LANGUAGE_ID) and can not be deleted");
|
||||
AddError(ApiErrorCode.INVALID_OPERATION, "object", "Translation is set as the default server translation (AYANOVA_DEFAULT_LANGUAGE_ID) and can not be deleted");
|
||||
return;
|
||||
}
|
||||
|
||||
//See if any users exist with this locale selected in which case it's not deleteable
|
||||
if (await ct.User.AnyAsync(e => e.LocaleId == inObj.Id))
|
||||
//See if any users exist with this translation selected in which case it's not deleteable
|
||||
if (await ct.User.AnyAsync(e => e.TranslationId == inObj.Id))
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "object", "Can't be deleted in use by one or more Users");
|
||||
return;
|
||||
@@ -350,61 +346,57 @@ namespace AyaNova.Biz
|
||||
//UTILITIES
|
||||
//
|
||||
|
||||
public async Task<long> LocaleNameToIdAsync(string localeName)
|
||||
public async Task<long> TranslationNameToIdAsync(string translationName)
|
||||
{
|
||||
var v = await ct.Locale.AsNoTracking().FirstOrDefaultAsync(c => c.Name == localeName);
|
||||
var v = await ct.Translation.AsNoTracking().FirstOrDefaultAsync(c => c.Name == translationName);
|
||||
if (v == null) return 0;
|
||||
return v.Id;
|
||||
}
|
||||
|
||||
public static async Task<long> LocaleNameToIdStaticAsync(string localeName, AyContext ct = null)
|
||||
public static async Task<long> TranslationNameToIdStaticAsync(string translationName, AyContext ct = null)
|
||||
{
|
||||
if (ct == null)
|
||||
{
|
||||
ct = ServiceProviderProvider.DBContext;
|
||||
}
|
||||
var v = await ct.Locale.AsNoTracking().FirstOrDefaultAsync(c => c.Name == localeName);
|
||||
if (v == null) return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
var v = await ct.Translation.AsNoTracking().FirstOrDefaultAsync(c => c.Name == translationName);
|
||||
if (v == null) return ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||
return v.Id;
|
||||
}
|
||||
|
||||
public async Task<bool> LocaleExistsAsync(string localeName)
|
||||
public async Task<bool> TranslationExistsAsync(string translationName)
|
||||
{
|
||||
return await ct.Locale.AnyAsync(c => c.Name == localeName);
|
||||
return await ct.Translation.AnyAsync(c => c.Name == translationName);
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> LocaleExistsAsync(long id)
|
||||
public async Task<bool> TranslationExistsAsync(long id)
|
||||
{
|
||||
return await ct.Locale.AnyAsync(e => e.Id == id);
|
||||
return await ct.Translation.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
|
||||
// public static async Task<bool> LocaleExistsStaticAsync(long id, AyContext ct)
|
||||
// {
|
||||
// return await ct.Locale.AnyAsync(e => e.Id == id);
|
||||
// }
|
||||
|
||||
//this is only called by Search.cs to cache a local cjk and stopwords, no one else calls it currently
|
||||
public static async Task<long> ReturnSpecifiedLocaleIdIfExistsOrDefaultLocaleId(long id, AyContext ct)
|
||||
public static async Task<long> ReturnSpecifiedTranslationIdIfExistsOrDefaultTranslationId(long id, AyContext ct)
|
||||
{
|
||||
if (!await ct.Locale.AnyAsync(e => e.Id == id))
|
||||
return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
if (!await ct.Translation.AnyAsync(e => e.Id == id))
|
||||
return ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||
return id;
|
||||
}
|
||||
|
||||
public async Task<bool> LocaleItemExistsAsync(long id)
|
||||
public async Task<bool> TranslationItemExistsAsync(long id)
|
||||
{
|
||||
return await ct.LocaleItem.AnyAsync(e => e.Id == id);
|
||||
return await ct.TranslationItem.AnyAsync(e => e.Id == id);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Used by import, translate the old v7 locale key name into the new shorter version
|
||||
/// Used by import, translate the old v7 translation key name into the new shorter version
|
||||
/// </summary>
|
||||
/// <param name="oldKey"></param>
|
||||
/// <returns></returns>
|
||||
public string Translatev7LocaleKey(string oldKey)
|
||||
public string Translatev7TranslationKey(string oldKey)
|
||||
{
|
||||
string s = oldKey.Replace(".Label.", ".", StringComparison.InvariantCultureIgnoreCase);
|
||||
if (s.StartsWith("O.", StringComparison.InvariantCultureIgnoreCase))
|
||||
@@ -483,37 +475,36 @@ namespace AyaNova.Biz
|
||||
return s;
|
||||
}
|
||||
|
||||
//LocaleBiz::ImportV7 - old Key "Locale.Label.UI.DestLocale" translates to new Key "LocaleDestLocale" which is not valid!
|
||||
//LocaleUIDestLocale
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ensure stock locales and setup defaults
|
||||
/// Called by boot preflight check code AFTER it has already ensured the locale is a two letter code if stock one was chosen
|
||||
/// Ensure stock Translations and setup defaults
|
||||
/// Called by boot preflight check code AFTER it has already ensured the translation is a two letter code if stock one was chosen
|
||||
/// </summary>
|
||||
public async Task ValidateLocalesAsync()
|
||||
public async Task ValidateTranslationsAsync()
|
||||
{
|
||||
//Ensure default locales are present and that there is a server default locale that exists
|
||||
//Ensure default translations are present and that there is a server default translation that exists
|
||||
|
||||
if (!await LocaleExistsAsync("en"))
|
||||
if (!await TranslationExistsAsync("en"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale English (en) not found in database!");
|
||||
throw new System.Exception($"E1015: stock translation English (en) not found in database!");
|
||||
}
|
||||
if (!await LocaleExistsAsync("es"))
|
||||
if (!await TranslationExistsAsync("es"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale Spanish (es) not found in database!");
|
||||
throw new System.Exception($"E1015: stock translation Spanish (es) not found in database!");
|
||||
}
|
||||
if (!await LocaleExistsAsync("de"))
|
||||
if (!await TranslationExistsAsync("de"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale German (de) not found in database!");
|
||||
throw new System.Exception($"E1015: stock translation German (de) not found in database!");
|
||||
}
|
||||
if (!await LocaleExistsAsync("fr"))
|
||||
if (!await TranslationExistsAsync("fr"))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale French (fr) not found in database!");
|
||||
throw new System.Exception($"E1015: stock translation French (fr) not found in database!");
|
||||
}
|
||||
|
||||
//Ensure chosen default locale exists
|
||||
switch (ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE)
|
||||
//Ensure chosen default translation exists
|
||||
switch (ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION)
|
||||
{
|
||||
case "en":
|
||||
case "es":
|
||||
@@ -521,16 +512,16 @@ namespace AyaNova.Biz
|
||||
case "fr":
|
||||
break;
|
||||
default:
|
||||
if (!await LocaleExistsAsync(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE))
|
||||
if (!await TranslationExistsAsync(ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION))
|
||||
{
|
||||
throw new System.Exception($"E1015: stock locale {ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE} not found in database!");
|
||||
throw new System.Exception($"E1015: stock translation {ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION} not found in database!");
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
//Put the default locale ID number into the ServerBootConfig for later use
|
||||
ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID = await LocaleNameToIdAsync(ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE);
|
||||
//Put the default translation ID number into the ServerBootConfig for later use
|
||||
ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID = await TranslationNameToIdAsync(ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION);
|
||||
|
||||
}
|
||||
|
||||
@@ -546,17 +537,17 @@ namespace AyaNova.Biz
|
||||
{
|
||||
case "main":
|
||||
{
|
||||
//Get source locale name from filename using regex
|
||||
var SourceLocaleFileName = j["V7_SOURCE_FILE_NAME"].Value<string>();
|
||||
Regex RxExtractLocaleName = new Regex(@"locale\.(.*)\.json");
|
||||
var v = RxExtractLocaleName.Match(SourceLocaleFileName);
|
||||
var SourceLocaleName = v.Groups[1].ToString();
|
||||
//Get source translation name from filename using regex
|
||||
var SourceTranslationFileName = j["V7_SOURCE_FILE_NAME"].Value<string>();
|
||||
Regex RxExtractTranslationName = new Regex(@"translation\.(.*)\.json");
|
||||
var v = RxExtractTranslationName.Match(SourceTranslationFileName);
|
||||
var SourceTranslationName = v.Groups[1].ToString();
|
||||
|
||||
//Ensure doesn't already exist
|
||||
if (await LocaleExistsAsync(SourceLocaleName))
|
||||
if (await TranslationExistsAsync(SourceTranslationName))
|
||||
{
|
||||
//If there are any validation errors, log in joblog and move on
|
||||
await JobsBiz.LogJobAsync(jobId, $"LocaleBiz::ImportV7Async -> - Locale \"{SourceLocaleName}\" already exists in database, can not import over an existing locale", ct);
|
||||
await JobsBiz.LogJobAsync(jobId, $"TranslationBiz::ImportV7Async -> - Translation \"{SourceTranslationName}\" already exists in database, can not import over an existing translation", ct);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -568,7 +559,7 @@ namespace AyaNova.Biz
|
||||
SkipKeys.Add("IMPORT_TASK");
|
||||
|
||||
List<string> ValidKeys = await GetKeyListAsync();
|
||||
Dictionary<string, string> NewLocaleDict = new Dictionary<string, string>();
|
||||
Dictionary<string, string> NewTranslationDict = new Dictionary<string, string>();
|
||||
foreach (var Pair in j.Children())
|
||||
{
|
||||
var V7Value = Pair.First.Value<string>().Replace(" && ", " ").Replace(" & ", " ").Replace("&", "");//clean out LT values that had double ampersands for old Windows menu shortcut scheme
|
||||
@@ -576,57 +567,57 @@ namespace AyaNova.Biz
|
||||
|
||||
if (!SkipKeys.Contains(V7KeyName))
|
||||
{
|
||||
var RavenKeyName = Translatev7LocaleKey(V7KeyName);
|
||||
var RavenKeyName = Translatev7TranslationKey(V7KeyName);
|
||||
if (!ValidKeys.Contains(RavenKeyName))
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"LocaleBiz::ImportV7 - old Key \"{V7KeyName}\" translates to new Key \"{RavenKeyName}\" which is not valid!");
|
||||
throw new System.ArgumentOutOfRangeException($"TranslationBiz::ImportV7 - old Key \"{V7KeyName}\" translates to new Key \"{RavenKeyName}\" which is not valid!");
|
||||
}
|
||||
|
||||
if (!NewLocaleDict.ContainsKey(RavenKeyName))
|
||||
if (!NewTranslationDict.ContainsKey(RavenKeyName))
|
||||
{
|
||||
NewLocaleDict.Add(RavenKeyName, V7Value);
|
||||
NewTranslationDict.Add(RavenKeyName, V7Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Use the shortest V7Value string in the case of dupes
|
||||
if (NewLocaleDict[RavenKeyName].Length > V7Value.Length)
|
||||
if (NewTranslationDict[RavenKeyName].Length > V7Value.Length)
|
||||
{
|
||||
NewLocaleDict[RavenKeyName] = V7Value;
|
||||
NewTranslationDict[RavenKeyName] = V7Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Now add keys that were added after v7 for RAVEN using default locale values
|
||||
//Now add keys that were added after v7 for RAVEN using default translation values
|
||||
foreach (string s in ValidKeys)
|
||||
{
|
||||
if (!NewLocaleDict.ContainsKey(s))
|
||||
if (!NewTranslationDict.ContainsKey(s))
|
||||
{
|
||||
NewLocaleDict.Add(s, await GetDefaultLocalizedTextAsync(s));
|
||||
NewTranslationDict.Add(s, await GetDefaultLocalizedTextAsync(s));
|
||||
}
|
||||
}
|
||||
|
||||
//Validate it's the correct number of keys expected
|
||||
if (NewLocaleDict.Count != ValidKeys.Count)
|
||||
if (NewTranslationDict.Count != ValidKeys.Count)
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException($"LocaleBiz::ImportV7 - Import locale \"{SourceLocaleName}\" has an unexpected number of keys: {NewLocaleDict.Count}, expected {ValidKeys.Count} ");
|
||||
throw new System.ArgumentOutOfRangeException($"TranslationBiz::ImportV7 - Import translation \"{SourceTranslationName}\" has an unexpected number of keys: {NewTranslationDict.Count}, expected {ValidKeys.Count} ");
|
||||
}
|
||||
|
||||
//have file name, have all localized text
|
||||
Locale l = new Locale();
|
||||
l.Name = SourceLocaleName;
|
||||
Translation l = new Translation();
|
||||
l.Name = SourceTranslationName;
|
||||
l.Stock = false;
|
||||
|
||||
foreach (KeyValuePair<string, string> K in NewLocaleDict)
|
||||
foreach (KeyValuePair<string, string> K in NewTranslationDict)
|
||||
{
|
||||
l.LocaleItems.Add(new LocaleItem() { Key = K.Key, Display = K.Value });
|
||||
l.TranslationItems.Add(new TranslationItem() { Key = K.Key, Display = K.Value });
|
||||
}
|
||||
|
||||
await ct.Locale.AddAsync(l);
|
||||
await ct.Translation.AddAsync(l);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log now that we have the Id, note that there is no source created / modified for this so just attributing to current userId
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, l.Id, AyaType.Locale, AyaEvent.Created), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, l.Id, AyaType.Translation, AyaEvent.Created), ct);
|
||||
|
||||
}
|
||||
break;
|
||||
@@ -19,11 +19,11 @@ namespace AyaNova.Biz
|
||||
|
||||
public bool SeedOrImportRelaxedRulesMode { get; set; }
|
||||
|
||||
internal UserBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles userRoles)
|
||||
internal UserBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = userRoles;
|
||||
BizType = AyaType.User;
|
||||
SeedOrImportRelaxedRulesMode = false;//default
|
||||
@@ -41,9 +41,9 @@ namespace AyaNova.Biz
|
||||
internal static UserBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
{
|
||||
if (httpContext != null)
|
||||
return new UserBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
return new UserBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
else//when called internally for internal ops there will be no context so need to set default values for that
|
||||
return new UserBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
|
||||
return new UserBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace AyaNova.Biz
|
||||
private async Task SearchIndexAsync(User obj, bool isNew)
|
||||
{
|
||||
//SEARCH INDEXING
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, obj.Id, BizType, obj.Name);
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType, obj.Name);
|
||||
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.EmployeeNumber).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
||||
|
||||
if (isNew)
|
||||
@@ -456,7 +456,7 @@ namespace AyaNova.Biz
|
||||
Active = o.Active,
|
||||
Name = o.Name,
|
||||
Roles = o.Roles,
|
||||
LocaleId = o.LocaleId,
|
||||
TranslationId = o.TranslationId,
|
||||
UserType = o.UserType,
|
||||
EmployeeNumber = o.EmployeeNumber,
|
||||
Notes = o.Notes,
|
||||
@@ -672,8 +672,8 @@ namespace AyaNova.Biz
|
||||
//No rights
|
||||
i.Roles = AuthorizationRoles.NoRole;
|
||||
|
||||
//temporary locale id to satisfy db settings
|
||||
i.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
//temporary translation id to satisfy db settings
|
||||
i.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||
|
||||
User o = await CreateAsync(i);
|
||||
if (HasErrors)
|
||||
@@ -702,62 +702,62 @@ namespace AyaNova.Biz
|
||||
await ImportAyaNova7Biz.LogEventCreatedModifiedEventsAsync(j, importMap, BizType, ct);
|
||||
}
|
||||
break;
|
||||
case "locale":
|
||||
case "translation":
|
||||
{
|
||||
#region set locale
|
||||
#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-locale - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE USER NOT FOUND IN IMPORTMAP");
|
||||
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-locale - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE USER NOT FOUND IN DATABASE");
|
||||
throw new System.Exception("UserBiz::ImportV7Async-translation - FATAL ERROR, IMPORT FROM V7 CANNOT CONTINUE USER NOT FOUND IN DATABASE");
|
||||
}
|
||||
|
||||
//handle locale entries for users now that we have the locales created
|
||||
var V7Locale = j["DefaultLanguage"].Value<string>();
|
||||
//handle translation entries for users now that we have the Translations created
|
||||
var V7Translation = j["DefaultLanguage"].Value<string>();
|
||||
|
||||
//Get new locale name
|
||||
var NewLocaleName = string.Empty;
|
||||
switch (V7Locale)
|
||||
//Get new translation name
|
||||
var NewTranslationName = string.Empty;
|
||||
switch (V7Translation)
|
||||
{
|
||||
case "Français":
|
||||
NewLocaleName = "fr";
|
||||
NewTranslationName = "fr";
|
||||
break;
|
||||
case "Español":
|
||||
NewLocaleName = "es";
|
||||
NewTranslationName = "es";
|
||||
break;
|
||||
case "Deutsch":
|
||||
NewLocaleName = "de";
|
||||
NewTranslationName = "de";
|
||||
break;
|
||||
case "English":
|
||||
NewLocaleName = "en";
|
||||
NewTranslationName = "en";
|
||||
break;
|
||||
default:
|
||||
{
|
||||
//It's a custom locale, translate it from v7 original format to imported name format
|
||||
//It's a custom translation, translate it from v7 original format to imported name format
|
||||
//make lower and replace spaces with dashes
|
||||
NewLocaleName = V7Locale.ToLowerInvariant().Replace(" ", "-");
|
||||
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
|
||||
{
|
||||
NewLocaleName = NewLocaleName.Replace(c, '_');
|
||||
NewTranslationName = NewTranslationName.Replace(c, '_');
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
u.LocaleId = await LocaleBiz.LocaleNameToIdStaticAsync(NewLocaleName, ct);
|
||||
u.TranslationId = await TranslationBiz.TranslationNameToIdStaticAsync(NewTranslationName, ct);
|
||||
|
||||
ct.SaveChanges();
|
||||
#endregion set locale
|
||||
#endregion set translation
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace AyaNova.Biz
|
||||
internal class WidgetBiz : BizObject, IJobObject
|
||||
{
|
||||
|
||||
internal WidgetBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
|
||||
internal WidgetBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = UserRoles;
|
||||
BizType = AyaType.Widget;
|
||||
}
|
||||
@@ -25,9 +25,9 @@ namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
if (httpContext != null)
|
||||
return new WidgetBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
return new WidgetBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
else//when called internally for internal ops there will be no context so need to set default values for that
|
||||
return new WidgetBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
|
||||
return new WidgetBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace AyaNova.Biz
|
||||
private async Task SearchIndexAsync(Widget obj, bool isNew)
|
||||
{
|
||||
//SEARCH INDEXING
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, obj.Id, BizType, obj.Name);
|
||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType, obj.Name);
|
||||
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.Serial).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
||||
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace AyaNova.Models
|
||||
public virtual DbSet<FileAttachment> FileAttachment { get; set; }
|
||||
public virtual DbSet<OpsJob> OpsJob { get; set; }
|
||||
public virtual DbSet<OpsJobLog> OpsJobLog { get; set; }
|
||||
public virtual DbSet<Locale> Locale { get; set; }
|
||||
public virtual DbSet<LocaleItem> LocaleItem { get; set; }
|
||||
public virtual DbSet<Translation> Translation { get; set; }
|
||||
public virtual DbSet<TranslationItem> TranslationItem { get; set; }
|
||||
public virtual DbSet<DataListView> DataListView { get; set; }
|
||||
public virtual DbSet<Tag> Tag { get; set; }
|
||||
public virtual DbSet<FormCustom> FormCustom { get; set; }
|
||||
@@ -82,9 +82,9 @@ namespace AyaNova.Models
|
||||
modelBuilder.Entity<FileAttachment>().HasIndex(p => p.StoredFileName);
|
||||
|
||||
//Relationships
|
||||
modelBuilder.Entity<Locale>()
|
||||
.HasMany(c => c.LocaleItems)
|
||||
.WithOne(e => e.Locale)
|
||||
modelBuilder.Entity<Translation>()
|
||||
.HasMany(c => c.TranslationItems)
|
||||
.WithOne(e => e.Translation)
|
||||
.IsRequired();//default delete behaviour is cascade when set to isrequired
|
||||
|
||||
modelBuilder.Entity<User>()
|
||||
|
||||
@@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
||||
namespace AyaNova.Models
|
||||
{
|
||||
// [JsonObject(IsReference = true)]
|
||||
public partial class Locale
|
||||
public partial class Translation
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public uint ConcurrencyToken { get; set; }
|
||||
@@ -18,7 +18,7 @@ namespace AyaNova.Models
|
||||
public bool? Stock { get; set; }
|
||||
public bool CjkIndex { get; set; }
|
||||
|
||||
//TODO: Defaults for user options locale settings:
|
||||
//TODO: Defaults for user options translation settings:
|
||||
// short date, short time formats
|
||||
// currency symbol
|
||||
//digit grouping separator symbol
|
||||
@@ -27,18 +27,18 @@ namespace AyaNova.Models
|
||||
|
||||
//Relationship
|
||||
//was this but..
|
||||
// public ICollection<LocaleItem> LocaleItems { get; set; }
|
||||
// public ICollection<TranslationItem> TranslationItems { get; set; }
|
||||
|
||||
//Not perhaps so useful here but this is a good way to lazy initialize collections which
|
||||
//is more efficient when there are many child collections (workorder) and means no need to null check the collection
|
||||
//https://stackoverflow.com/a/20773057/8939
|
||||
|
||||
private ICollection<LocaleItem> _localeItem;
|
||||
public virtual ICollection<LocaleItem> LocaleItems
|
||||
private ICollection<TranslationItem> _translationItem;
|
||||
public virtual ICollection<TranslationItem> TranslationItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._localeItem ?? (this._localeItem = new HashSet<LocaleItem>());
|
||||
return this._translationItem ?? (this._translationItem = new HashSet<TranslationItem>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using Newtonsoft.Json;
|
||||
namespace AyaNova.Models
|
||||
{
|
||||
|
||||
public partial class LocaleItem
|
||||
public partial class TranslationItem
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public uint ConcurrencyToken { get; set; }
|
||||
@@ -19,10 +19,10 @@ namespace AyaNova.Models
|
||||
[Required]
|
||||
public string Display { get; set; }
|
||||
|
||||
public long LocaleId { get; set; }
|
||||
public long TranslationId { get; set; }
|
||||
|
||||
//Relation
|
||||
[JsonIgnore]
|
||||
public Locale Locale { get; set; }
|
||||
public Translation Translation { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace AyaNova.Models
|
||||
[Required]
|
||||
public AuthorizationRoles Roles { get; set; }
|
||||
[Required]
|
||||
public long LocaleId { get; set; }
|
||||
public long TranslationId { get; set; }
|
||||
public string DlKey { get; set; }
|
||||
public DateTime? DlKeyExpire { get; set; }
|
||||
|
||||
|
||||
@@ -368,18 +368,18 @@
|
||||
"LoanItemRateWeek": "Week rate",
|
||||
"LoanItemRateYear": "Year rate",
|
||||
"LoanItemSerial": "Seriennummer",
|
||||
"LocaleCustomizeText": "Customize text",
|
||||
"LocaleExport": "Gebietsschema in Datei exportieren",
|
||||
"LocaleImport": "Gebietsschema aus Datei importieren",
|
||||
"LocaleList": "Lokalisierte Textsammlung",
|
||||
"LocaleLocaleFile": "AyaNova übertragbare Gebietsschemadatei (*.xml)",
|
||||
"LocaleUIDestLocale": "Neuer Name für Gebietsschema",
|
||||
"LocaleUISourceLocale": "Quellgebietsschema",
|
||||
"LocaleWarnLocaleLocked": "Your user account is using the \"English\" locale text.\r\nThis locale is read only and can not be edited.\r\nPlease change your locale in your user settings to any other value than \"English\" to proceed.",
|
||||
"LocalizedTextDisplayText": "Standardanzeigetext",
|
||||
"LocalizedTextDisplayTextCustom": "Angepasster Anzeigetext",
|
||||
"LocalizedTextKey": "Schlüssel",
|
||||
"LocalizedTextLocale": "Sprache",
|
||||
"TranslationCustomizeText": "Customize text",
|
||||
"TranslationExport": "Gebietsschema in Datei exportieren",
|
||||
"TranslationImport": "Gebietsschema aus Datei importieren",
|
||||
"TranslationList": "Lokalisierte Textsammlung",
|
||||
"TranslationFile": "AyaNova übertragbare Gebietsschemadatei (*.xml)",
|
||||
"TranslationDest": "Neuer Name für Gebietsschema",
|
||||
"TranslationSource": "Quellgebietsschema",
|
||||
"TranslationWarnLocked": "Your user account is using the \"English\" translation text.\r\nThis translation is read only and can not be edited.\r\nPlease change your translation in your user settings to any other value than \"English\" to proceed.",
|
||||
"TranslationDisplayText": "Standardanzeigetext",
|
||||
"TranslationDisplayTextCustom": "Angepasster Anzeigetext",
|
||||
"TranslationKey": "Schlüssel",
|
||||
"Translation": "Übersetzung",
|
||||
"MemoForward": "Weiterleiten",
|
||||
"MemoReply": "Antworten",
|
||||
"MemoEventCreated": "Memo - eingehend",
|
||||
@@ -450,7 +450,7 @@
|
||||
"HeadOffice": "Hauptsitz",
|
||||
"LoanItem": "Leihposten",
|
||||
"Locale": "Gebietsschema",
|
||||
"LocalizedText": "Lokalisierter Text",
|
||||
"TranslatedText": "Übersetzter Text",
|
||||
"Maintenance": "AyaNova - Interne Wartung",
|
||||
"Memo": "Memo",
|
||||
"NameFetcher": "Namenabrufer-Objekt",
|
||||
|
||||
@@ -368,18 +368,18 @@
|
||||
"LoanItemRateWeek": "Week rate",
|
||||
"LoanItemRateYear": "Year rate",
|
||||
"LoanItemSerial": "Serial number",
|
||||
"LocaleCustomizeText": "Customize text",
|
||||
"LocaleExport": "Export locale to file",
|
||||
"LocaleImport": "Import locale from file",
|
||||
"LocaleList": "Localized text collection",
|
||||
"LocaleLocaleFile": "AyaNova transportable Locale file (*.xml)",
|
||||
"LocaleUIDestLocale": "New locale name",
|
||||
"LocaleUISourceLocale": "Source locale",
|
||||
"LocaleWarnLocaleLocked": "Your user account is using the \"English\" locale text.\r\nThis locale is read only and can not be edited.\r\nPlease change your locale in your user settings to any other value than \"English\" to proceed.",
|
||||
"LocalizedTextDisplayText": "Standard display text",
|
||||
"LocalizedTextDisplayTextCustom": "Custom display text",
|
||||
"LocalizedTextKey": "Key",
|
||||
"LocalizedTextLocale": "Language",
|
||||
"TranslationCustomizeText": "Customize text",
|
||||
"TranslationExport": "Export translation to file",
|
||||
"TranslationImport": "Import translation from file",
|
||||
"TranslationList": "Translation text collection",
|
||||
"TranslationFile": "AyaNova transportable Translation file (*.xml)",
|
||||
"TranslationDest": "New translation name",
|
||||
"TranslationSource": "Source translation",
|
||||
"TranslationWarnLocked": "Your user account is using the \"English\" translation text.\r\nThis translation is read only and can not be edited.\r\nPlease change your translation in your user settings to any other value than \"English\" to proceed.",
|
||||
"TranslationDisplayText": "Standard display text",
|
||||
"TranslationDisplayTextCustom": "Custom display text",
|
||||
"TranslationKey": "Key",
|
||||
"Translation": "Translation",
|
||||
"MemoForward": "Forward",
|
||||
"MemoReply": "Reply",
|
||||
"MemoEventCreated": "Memo - incoming",
|
||||
@@ -449,8 +449,8 @@
|
||||
"GridFilter": "GridFilter",
|
||||
"HeadOffice": "Head Office",
|
||||
"LoanItem": "Loan item",
|
||||
"Locale": "Locale",
|
||||
"LocalizedText": "Localized text",
|
||||
"Locale": "Translation",
|
||||
"TranslatedText": "Translated text",
|
||||
"Maintenance": "AyaNova internal maintenance",
|
||||
"Memo": "Memo",
|
||||
"NameFetcher": "NameFetcher object",
|
||||
|
||||
@@ -368,18 +368,18 @@
|
||||
"LoanItemRateWeek": "Week rate",
|
||||
"LoanItemRateYear": "Year rate",
|
||||
"LoanItemSerial": "Número de serie",
|
||||
"LocaleCustomizeText": "Customize text",
|
||||
"LocaleExport": "Exportar localización en archivo",
|
||||
"LocaleImport": "Importar localización desde archivo",
|
||||
"LocaleList": "Colección texto localizado",
|
||||
"LocaleLocaleFile": "Archivo de localización transportable AyaNova (*.xml)",
|
||||
"LocaleUIDestLocale": "Nuevo nombre localización",
|
||||
"LocaleUISourceLocale": "Localización origen",
|
||||
"LocaleWarnLocaleLocked": "Your user account is using the \"English\" locale text.\r\nThis locale is read only and can not be edited.\r\nPlease change your locale in your user settings to any other value than \"English\" to proceed.",
|
||||
"LocalizedTextDisplayText": "Texto estándar de visualización",
|
||||
"LocalizedTextDisplayTextCustom": "Texto campo personalizado",
|
||||
"LocalizedTextKey": "Clave",
|
||||
"LocalizedTextLocale": "Idioma",
|
||||
"TranslationCustomizeText": "Customize text",
|
||||
"TranslationExport": "Exportar localización en archivo",
|
||||
"TranslationImport": "Importar localización desde archivo",
|
||||
"TranslationList": "Colección texto localizado",
|
||||
"TranslationFile": "Archivo de localización transportable AyaNova (*.xml)",
|
||||
"TranslationDest": "Nuevo nombre localización",
|
||||
"TranslationSource": "Localización origen",
|
||||
"TranslationWarnLocked": "Your user account is using the \"English\" translation text.\r\nThis translation is read only and can not be edited.\r\nPlease change your translation in your user settings to any other value than \"English\" to proceed.",
|
||||
"TranslationDisplayText": "Texto estándar de visualización",
|
||||
"TranslationDisplayTextCustom": "Texto campo personalizado",
|
||||
"TranslationKey": "Clave",
|
||||
"Translation": "Traducción",
|
||||
"MemoForward": "Reenviar",
|
||||
"MemoReply": "Respuesta",
|
||||
"MemoEventCreated": "Memorándum - entrada",
|
||||
@@ -450,7 +450,7 @@
|
||||
"HeadOffice": "Sede",
|
||||
"LoanItem": "Elemento en préstamo",
|
||||
"Locale": "Localización",
|
||||
"LocalizedText": "Texto localizado",
|
||||
"TranslatedText": "Texto traducido",
|
||||
"Maintenance": "Mantenimiento interno AyaNova",
|
||||
"Memo": "Memorándum",
|
||||
"NameFetcher": "Objeto recopilador de nombres",
|
||||
|
||||
@@ -368,18 +368,18 @@
|
||||
"LoanItemRateWeek": "Week rate",
|
||||
"LoanItemRateYear": "Year rate",
|
||||
"LoanItemSerial": "Numéro de série",
|
||||
"LocaleCustomizeText": "Customize text",
|
||||
"LocaleExport": "Exporter les paramètres régionaux dans le fichier",
|
||||
"LocaleImport": "Importer les paramètres régionaux du fichier",
|
||||
"LocaleList": "Ensemble de textes localisés",
|
||||
"LocaleLocaleFile": "Fichier transportable de paramètres régionaux AyaNova (*.xml)",
|
||||
"LocaleUIDestLocale": "Nouveau nom de paramètres régionaux",
|
||||
"LocaleUISourceLocale": "Paramètres régionaux source",
|
||||
"LocaleWarnLocaleLocked": "Your user account is using the \"English\" locale text.\r\nThis locale is read only and can not be edited.\r\nPlease change your locale in your user settings to any other value than \"English\" to proceed.",
|
||||
"LocalizedTextDisplayText": "Texte standard",
|
||||
"LocalizedTextDisplayTextCustom": "Texte personnalisé",
|
||||
"LocalizedTextKey": "Clé",
|
||||
"LocalizedTextLocale": "Langue",
|
||||
"TranslationCustomizeText": "Customize text",
|
||||
"TranslationExport": "Exporter les paramètres régionaux dans le fichier",
|
||||
"TranslationImport": "Importer les paramètres régionaux du fichier",
|
||||
"TranslationList": "Ensemble de textes localisés",
|
||||
"TranslationFile": "Fichier transportable de paramètres régionaux AyaNova (*.xml)",
|
||||
"TranslationDest": "Nouveau nom de paramètres régionaux",
|
||||
"TranslationSource": "Paramètres régionaux source",
|
||||
"TranslationWarnLocked": "Your user account is using the \"English\" translation text.\r\nThis translation is read only and can not be edited.\r\nPlease change your translation in your user settings to any other value than \"English\" to proceed.",
|
||||
"TranslationDisplayText": "Texte standard",
|
||||
"TranslationDisplayTextCustom": "Texte personnalisé",
|
||||
"TranslationKey": "Clé",
|
||||
"Translation": "Traduction",
|
||||
"MemoForward": "Faire suivre",
|
||||
"MemoReply": "Répondre",
|
||||
"MemoEventCreated": "Mémo - entrant",
|
||||
@@ -450,7 +450,7 @@
|
||||
"HeadOffice": "Siège social",
|
||||
"LoanItem": "Élément de prêt",
|
||||
"Locale": "Paramètres linguistiques",
|
||||
"LocalizedText": "Texte localisé",
|
||||
"TranslatedText": "Texte traduit",
|
||||
"Maintenance": "Maintenance interne AyaNova",
|
||||
"Memo": "Mémo",
|
||||
"NameFetcher": "Objet NameFetcher",
|
||||
|
||||
@@ -150,25 +150,25 @@ namespace AyaNova.Util
|
||||
|
||||
await ExecQueryAsync("CREATE TABLE asearchkey (id BIGSERIAL PRIMARY KEY, wordid bigint not null REFERENCES asearchdictionary (id), objectid bigint not null, objecttype integer not null, inname bool not null)");
|
||||
|
||||
//create locale text tables
|
||||
await ExecQueryAsync("CREATE TABLE alocale (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, stock bool, cjkindex bool default false)");
|
||||
//create translation text tables
|
||||
await ExecQueryAsync("CREATE TABLE atranslation (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, stock bool, cjkindex bool default false)");
|
||||
//LOOKAT: I don't think this is doing anything:
|
||||
//exec("CREATE UNIQUE INDEX alocale_name_idx ON alocale (name)");
|
||||
//exec("CREATE UNIQUE INDEX atranslation_name_idx ON atranslation (name)");
|
||||
|
||||
await ExecQueryAsync("CREATE TABLE alocaleitem (id BIGSERIAL PRIMARY KEY, localeid bigint not null REFERENCES alocale (id), key text not null, display text not null)");
|
||||
await ExecQueryAsync("CREATE TABLE atranslationitem (id BIGSERIAL PRIMARY KEY, translationid bigint not null REFERENCES atranslation (id), key text not null, display text not null)");
|
||||
|
||||
//LOOKAT: this is for what exactly??
|
||||
// exec("CREATE INDEX alocaleitem_localeid_key_idx ON alocaleitem (localeid,key)");
|
||||
// exec("CREATE INDEX atranslationitem_translationid_key_idx ON atranslationitem (translationid,key)");
|
||||
//This seems more appropriate
|
||||
await ExecQueryAsync("CREATE INDEX alocaleitem_localeid_key_display_idx ON alocaleitem (localeid,key, display)");
|
||||
await ExecQueryAsync("CREATE INDEX atranslationitem_translationid_key_display_idx ON atranslationitem (translationid,key, display)");
|
||||
|
||||
//Load the default LOCALES
|
||||
await AyaNova.Biz.PrimeData.PrimeLocales();
|
||||
//Load the default TRANSLATIONS
|
||||
await AyaNova.Biz.PrimeData.PrimeTranslations();
|
||||
|
||||
|
||||
//Add user table
|
||||
await ExecQueryAsync("CREATE TABLE auser (id BIGSERIAL PRIMARY KEY, active bool not null, name varchar(255) not null unique, " +
|
||||
"login text not null, password text not null, salt text not null, roles integer not null, localeid bigint not null REFERENCES alocale (id), " +
|
||||
"login text not null, password text not null, salt text not null, roles integer not null, translationid bigint not null REFERENCES atranslation (id), " +
|
||||
"dlkey text, dlkeyexpire timestamp, usertype integer not null, employeenumber varchar(255), notes text, customerid bigint, " +
|
||||
"headofficeid bigint, subvendorid bigint, customfields text, tags varchar(255) ARRAY)");
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace AyaNova.Util
|
||||
string text = reader.ReadToEnd();
|
||||
var j = JObject.Parse(text);
|
||||
|
||||
//Here add v7 import file name as sometimes it's needed later (locales)
|
||||
//Here add v7 import file name as sometimes it's needed later (Translations)
|
||||
j.Add("V7_SOURCE_FILE_NAME", JToken.FromObject(importFileName));
|
||||
jList.Add(j);
|
||||
}
|
||||
|
||||
@@ -508,10 +508,10 @@ namespace AyaNova.Util
|
||||
//TEST NOT ACTIVE - this is used for a test to see if inactive user can login
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, false, "TEST_INACTIVE", "TEST_INACTIVE");
|
||||
|
||||
//Alternate locale users for each stock locale
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.All, UserType.Administrator, true, "de", "de", await LocaleBiz.LocaleNameToIdStaticAsync("de"));
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.All, UserType.Administrator, true, "es", "es", await LocaleBiz.LocaleNameToIdStaticAsync("es"));
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.All, UserType.Administrator, true, "fr", "fr", await LocaleBiz.LocaleNameToIdStaticAsync("fr"));
|
||||
//Alternate translation users for each stock translation
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.All, UserType.Administrator, true, "de", "de", await TranslationBiz.TranslationNameToIdStaticAsync("de"));
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.All, UserType.Administrator, true, "es", "es", await TranslationBiz.TranslationNameToIdStaticAsync("es"));
|
||||
await GenSeedUserAsync(log, 1, AuthorizationRoles.All, UserType.Administrator, true, "fr", "fr", await TranslationBiz.TranslationNameToIdStaticAsync("fr"));
|
||||
|
||||
|
||||
}
|
||||
@@ -548,10 +548,10 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
public static async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
||||
bool active = true, string login = null, string password = null, long localeId = 0)
|
||||
bool active = true, string login = null, string password = null, long translationId = 0)
|
||||
{
|
||||
if (localeId == 0)
|
||||
localeId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
if (translationId == 0)
|
||||
translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||
|
||||
//Don't do the following commented out, it's slower
|
||||
// using (var ct = ServiceProviderProvider.DBContext)
|
||||
@@ -582,7 +582,7 @@ namespace AyaNova.Util
|
||||
else
|
||||
u.Password = u.Login;
|
||||
u.Roles = roles;
|
||||
u.LocaleId = localeId;
|
||||
u.TranslationId = translationId;
|
||||
u.UserType = userType;
|
||||
u.EmployeeNumber = "A-" + (454 + SeededUserCount).ToString() + "-Y";
|
||||
u.Notes = Fake.Lorem.Sentence();//Fake.Lorem.Paragraph(2);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AyaNova.Util
|
||||
|
||||
//Diagnostic static values used during development, may not be related to config at all, this is just a convenient class to put them in
|
||||
#if (DEBUG)
|
||||
internal static List<string> LocaleKeysRequested { get; set; }
|
||||
internal static List<string> TranslationKeysRequested { get; set; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,9 +31,9 @@ namespace AyaNova.Util
|
||||
internal static string AYANOVA_CONTENT_ROOT_PATH { get; set; } //Note: set in startup.cs, not in program.cs as it requires startup IHostingEnvironment
|
||||
|
||||
|
||||
//LANGUAGE / LOCALE
|
||||
internal static string AYANOVA_DEFAULT_LANGUAGE { get; set; }
|
||||
internal static long AYANOVA_DEFAULT_LANGUAGE_ID { get; set; } //internal setting set at boot by LocaleBiz::ValidateLocales
|
||||
//LANGUAGE / Translation
|
||||
internal static string AYANOVA_DEFAULT_TRANSLATION { get; set; }
|
||||
internal static long AYANOVA_DEFAULT_TRANSLATION_ID { get; set; } //internal setting set at boot by TranslationBiz::ValidateTranslations
|
||||
|
||||
//API
|
||||
internal static string AYANOVA_JWT_SECRET { get; set; }
|
||||
@@ -73,7 +73,7 @@ namespace AyaNova.Util
|
||||
{
|
||||
|
||||
#if (DEBUG)
|
||||
LocaleKeysRequested = new List<string>();
|
||||
TranslationKeysRequested = new List<string>();
|
||||
#endif
|
||||
|
||||
bool? bTemp = null;
|
||||
@@ -81,33 +81,33 @@ namespace AyaNova.Util
|
||||
#region SERVER BASICS
|
||||
|
||||
//LANGUAGE
|
||||
//LocaleBiz will validate this later at boot pfc and ensure a sane default is set (English)
|
||||
AYANOVA_DEFAULT_LANGUAGE = config.GetValue<string>("AYANOVA_DEFAULT_LANGUAGE");
|
||||
AYANOVA_DEFAULT_LANGUAGE = string.IsNullOrWhiteSpace(AYANOVA_DEFAULT_LANGUAGE) ? "en" : AYANOVA_DEFAULT_LANGUAGE;
|
||||
string lowLocale = AYANOVA_DEFAULT_LANGUAGE.ToLowerInvariant();
|
||||
switch (lowLocale)
|
||||
//TranslationBiz will validate this later at boot pfc and ensure a sane default is set (English)
|
||||
AYANOVA_DEFAULT_TRANSLATION = config.GetValue<string>("AYANOVA_DEFAULT_TRANSLATION");
|
||||
AYANOVA_DEFAULT_TRANSLATION = string.IsNullOrWhiteSpace(AYANOVA_DEFAULT_TRANSLATION) ? "en" : AYANOVA_DEFAULT_TRANSLATION;
|
||||
string lowTranslation = AYANOVA_DEFAULT_TRANSLATION.ToLowerInvariant();
|
||||
switch (lowTranslation)
|
||||
{
|
||||
case "en":
|
||||
case "english":
|
||||
AYANOVA_DEFAULT_LANGUAGE = "en";
|
||||
AYANOVA_DEFAULT_TRANSLATION = "en";
|
||||
break;
|
||||
case "de":
|
||||
case "deutsch":
|
||||
case "german":
|
||||
AYANOVA_DEFAULT_LANGUAGE = "de";
|
||||
AYANOVA_DEFAULT_TRANSLATION = "de";
|
||||
break;
|
||||
case "es":
|
||||
case "español":
|
||||
case "spanish":
|
||||
AYANOVA_DEFAULT_LANGUAGE = "es";
|
||||
AYANOVA_DEFAULT_TRANSLATION = "es";
|
||||
break;
|
||||
case "fr":
|
||||
case "français":
|
||||
case "french":
|
||||
AYANOVA_DEFAULT_LANGUAGE = "fr";
|
||||
AYANOVA_DEFAULT_TRANSLATION = "fr";
|
||||
break;
|
||||
default:
|
||||
AYANOVA_DEFAULT_LANGUAGE = "en";
|
||||
AYANOVA_DEFAULT_TRANSLATION = "en";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user