Locale -> Translation

This commit is contained in:
2020-03-06 19:36:36 +00:00
parent 884c834b3d
commit a234b3531d
58 changed files with 540 additions and 569 deletions

View File

@@ -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>

View File

@@ -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);

View File

@@ -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 });

View File

@@ -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));
}

View File

@@ -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>();