Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/90 114 remove appbase #7

Merged
merged 6 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Threading.Tasks;

using Altinn.App.Services.Interface;
using Altinn.Platform.Storage.Interface.Models;

Expand Down
1 change: 0 additions & 1 deletion src/Altinn.App.Api/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Altinn.App.Api.Controllers
Expand Down
27 changes: 11 additions & 16 deletions src/Altinn.App.Api/Controllers/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Altinn.App.Common.Helpers.Extensions;
using Altinn.App.Common.Models;
using Altinn.App.Common.Serialization;
using Altinn.App.Core.Interface;
using Altinn.App.PlatformServices.Extensions;
using Altinn.App.PlatformServices.Helpers;
using Altinn.App.Services.Helpers;
Expand All @@ -39,6 +40,7 @@ public class DataController : ControllerBase
private readonly IData _dataClient;
private readonly IInstance _instanceClient;
private readonly IAltinnApp _altinnApp;
private readonly IAppModel _appModel;
private readonly IAppResources _appResourcesService;
private readonly IPrefill _prefillService;

Expand All @@ -58,6 +60,7 @@ public DataController(
IInstance instanceClient,
IData dataClient,
IAltinnApp altinnApp,
IAppModel appModel,
IAppResources appResourcesService,
IPrefill prefillService)
{
Expand All @@ -66,6 +69,7 @@ public DataController(
_instanceClient = instanceClient;
_dataClient = dataClient;
_altinnApp = altinnApp;
_appModel = appModel;
_appResourcesService = appResourcesService;
_prefillService = prefillService;
}
Expand Down Expand Up @@ -383,11 +387,11 @@ private async Task<ActionResult> CreateAppModelData(

if (Request.ContentType == null)
{
appModel = _altinnApp.CreateNewAppModel(classRef);
appModel = _appModel.Create(classRef);
}
else
{
ModelDeserializer deserializer = new ModelDeserializer(_logger, _altinnApp.GetAppModelType(classRef));
ModelDeserializer deserializer = new ModelDeserializer(_logger, _appModel.GetModelType(classRef));
appModel = await deserializer.DeserializeAsync(Request.Body, Request.ContentType);

if (!string.IsNullOrEmpty(deserializer.Error))
Expand All @@ -399,23 +403,14 @@ private async Task<ActionResult> CreateAppModelData(
// runs prefill from repo configuration if config exists
await _prefillService.PrefillDataModel(instance.InstanceOwner.PartyId, dataType, appModel);

// send events to trigger application business logic
try
{
await _altinnApp.RunDataCreation(instance, appModel, null);
}
catch (NotImplementedException)
{
// Trigger application business logic the old way. DEPRICATED
await _altinnApp.RunDataCreation(instance, appModel);
}
await _altinnApp.RunDataCreation(instance, appModel, null);

await UpdatePresentationTextsOnInstance(instance, dataType, appModel);
await UpdateDataValuesOnInstance(instance, dataType, appModel);

int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId);

DataElement dataElement = await _dataClient.InsertFormData(appModel, instanceGuid, _altinnApp.GetAppModelType(classRef), org, app, instanceOwnerPartyId, dataType);
DataElement dataElement = await _dataClient.InsertFormData(appModel, instanceGuid, _appModel.GetModelType(classRef), org, app, instanceOwnerPartyId, dataType);
SelfLinkHelper.SetDataAppSelfLinks(instanceOwnerPartyId, instanceGuid, dataElement, Request);

return Created(dataElement.SelfLinks.Apps, dataElement);
Expand Down Expand Up @@ -502,7 +497,7 @@ private async Task<ActionResult> GetFormData(
// Get Form Data from data service. Assumes that the data element is form data.
object appModel = await _dataClient.GetFormData(
instanceGuid,
_altinnApp.GetAppModelType(appModelclassRef),
_appModel.GetModelType(appModelclassRef),
org,
app,
instanceOwnerId,
Expand Down Expand Up @@ -539,7 +534,7 @@ private async Task<ActionResult> PutFormData(string org, string app, Instance in
string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType);
Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]);

ModelDeserializer deserializer = new ModelDeserializer(_logger, _altinnApp.GetAppModelType(classRef));
ModelDeserializer deserializer = new ModelDeserializer(_logger, _appModel.GetModelType(classRef));
object serviceModel = await deserializer.DeserializeAsync(Request.Body, Request.ContentType);

if (!string.IsNullOrEmpty(deserializer.Error))
Expand All @@ -562,7 +557,7 @@ private async Task<ActionResult> PutFormData(string org, string app, Instance in
DataElement updatedDataElement = await _dataClient.UpdateData(
serviceModel,
instanceGuid,
_altinnApp.GetAppModelType(classRef),
_appModel.GetModelType(classRef),
org,
app,
instanceOwnerPartyId,
Expand Down
31 changes: 9 additions & 22 deletions src/Altinn.App.Api/Controllers/InstancesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Altinn.App.PlatformServices.Extensions;
using Altinn.App.PlatformServices.Helpers;
using Altinn.App.PlatformServices.Interface;
using Altinn.App.PlatformServices.Models;
using Altinn.App.Services.Configuration;
using Altinn.App.Services.Helpers;
using Altinn.App.Services.Interface;
Expand Down Expand Up @@ -65,6 +64,7 @@ public class InstancesController : ControllerBase

private readonly IAppResources _appResourcesService;
private readonly IAltinnApp _altinnApp;
private readonly IAppModel _appModel;
private readonly IPDP _pdp;
private readonly IPrefill _prefillService;
private readonly IProcessEngine _processEngine;
Expand All @@ -82,6 +82,7 @@ public InstancesController(
IData dataClient,
IAppResources appResourcesService,
IAltinnApp altinnApp,
IAppModel appModel,
IPDP pdp,
IEvents eventsService,
IOptions<AppSettings> appSettings,
Expand All @@ -95,6 +96,7 @@ public InstancesController(
_appResourcesService = appResourcesService;
_registerClient = registerClient;
_altinnApp = altinnApp;
_appModel = appModel;
_pdp = pdp;
_eventsService = eventsService;
_appSettings = appSettings.Value;
Expand Down Expand Up @@ -520,7 +522,7 @@ private async Task CopyDataFromSourceInstance(Application application, Instance
Type type;
try
{
type = _altinnApp.GetAppModelType(dt.AppLogic.ClassRef);
type = _appModel.GetModelType(dt.AppLogic.ClassRef);
}
catch (Exception altinnAppException)
{
Expand All @@ -535,16 +537,8 @@ private async Task CopyDataFromSourceInstance(Application application, Instance
}

await _prefillService.PrefillDataModel(instanceOwnerPartyId.ToString(), dt.Id, data);

try
{
await _altinnApp.RunDataCreation(targetInstance, data, null);
}
catch (NotImplementedException)
{
// Trigger application business logic the old way. DEPRECATED
await _altinnApp.RunDataCreation(targetInstance, data);
}

await _altinnApp.RunDataCreation(targetInstance, data, null);

await _dataClient.InsertFormData(
data,
Expand Down Expand Up @@ -854,7 +848,7 @@ private async Task StorePrefillParts(Instance instance, Application appInfo, Lis
Type type;
try
{
type = _altinnApp.GetAppModelType(dataType.AppLogic.ClassRef);
type = _appModel.GetModelType(dataType.AppLogic.ClassRef);
}
catch (Exception altinnAppException)
{
Expand All @@ -870,15 +864,8 @@ private async Task StorePrefillParts(Instance instance, Application appInfo, Lis
}

await _prefillService.PrefillDataModel(instance.InstanceOwner.PartyId, part.Name, data);
try
{
await _altinnApp.RunDataCreation(instance, data, null);
}
catch (NotImplementedException)
{
// Trigger application business logic the old way. DEPRECATED
await _altinnApp.RunDataCreation(instance, data);
}

await _altinnApp.RunDataCreation(instance, data, null);

dataElement = await _dataClient.InsertFormData(
data,
Expand Down
19 changes: 10 additions & 9 deletions src/Altinn.App.Api/Controllers/PagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;

using Altinn.App.Common.Serialization;
using Altinn.App.Core.Interface;
using Altinn.App.PlatformServices.Models;
using Altinn.App.Services.Implementation;
using Altinn.App.Services.Interface;
using Altinn.Platform.Storage.Interface.Models;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Altinn.App.Api.Controllers
{
Expand All @@ -25,9 +22,9 @@ namespace Altinn.App.Api.Controllers
[Route("{org}/{app}/instances/{instanceOwnerPartyId:int}/{instanceGuid:guid}/pages")]
public class PagesController : ControllerBase
{
private readonly IAltinnApp _altinnApp;
private readonly IPageOrder _pageOrder;
private readonly IAppModel _appModel;
private readonly IAppResources _resources;
private readonly IPageOrder _pageOrder;
private readonly ILogger _logger;

/// <summary>
Expand All @@ -37,9 +34,13 @@ public class PagesController : ControllerBase
/// <param name="resources">The app resource service</param>
/// <param name="logger">A logger provided by the logging framework.</param>
/// <param name="pageOrder">The page order service</param>
public PagesController(IAltinnApp altinnApp, IAppResources resources, IPageOrder pageOrder, ILogger<PagesController> logger)
public PagesController(
IAppModel appModel,
IAppResources resources,
IPageOrder pageOrder,
ILogger<PagesController> logger)
{
_altinnApp = altinnApp;
_appModel = appModel;
_resources = resources;
_pageOrder = pageOrder;
_logger = logger;
Expand Down Expand Up @@ -67,7 +68,7 @@ public async Task<ActionResult<List<string>>> GetPageOrder(

string classRef = _resources.GetClassRefForLogicDataType(dataTypeId);

object data = JsonConvert.DeserializeObject(formData.ToString(), _altinnApp.GetAppModelType(classRef));
object data = JsonConvert.DeserializeObject(formData.ToString(), _appModel.GetModelType(classRef));
return await _pageOrder.GetPageOrder(new AppIdentifier(org, app), new InstanceIdentifier(instanceOwnerPartyId, instanceGuid), layoutSetId, currentPage, dataTypeId, data);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/Altinn.App.Api/Controllers/StatelessDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Altinn.App.Api.Filters;
using Altinn.App.Common.Serialization;
using Altinn.App.Core.Interface;
using Altinn.App.PlatformServices.Extensions;
using Altinn.App.Services.Interface;
using Altinn.Authorization.ABAC.Xacml.JsonProfile;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class StatelessDataController : ControllerBase
{
private readonly ILogger<DataController> _logger;
private readonly IAltinnApp _altinnApp;
private readonly IAppModel _appModel;
private readonly IAppResources _appResourcesService;
private readonly IPrefill _prefillService;
private readonly IRegister _registerClient;
Expand All @@ -49,13 +51,15 @@ public class StatelessDataController : ControllerBase
public StatelessDataController(
ILogger<DataController> logger,
IAltinnApp altinnApp,
IAppModel appModel,
IAppResources appResourcesService,
IPrefill prefillService,
IRegister registerClient,
IPDP pdp)
{
_logger = logger;
_altinnApp = altinnApp;
_appModel = appModel;
_appResourcesService = appResourcesService;
_prefillService = prefillService;
_registerClient = registerClient;
Expand Down Expand Up @@ -111,7 +115,7 @@ public async Task<ActionResult> Get(
return Forbidden(enforcementResult);
}

object appModel = _altinnApp.CreateNewAppModel(classRef);
object appModel = _appModel.Create(classRef);

// runs prefill from repo configuration if config exists
await _prefillService.PrefillDataModel(owner.PartyId, dataType, appModel);
Expand Down Expand Up @@ -148,7 +152,7 @@ public async Task<ActionResult> GetAnonymous([FromQuery] string dataType)
return BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter.");
}

object appModel = _altinnApp.CreateNewAppModel(classRef);
object appModel = _appModel.Create(classRef);

var virutalInstance = new Instance();
await _altinnApp.RunProcessDataRead(virutalInstance, null, appModel);
Expand Down Expand Up @@ -205,7 +209,7 @@ public async Task<ActionResult> Post(
return Forbidden(enforcementResult);
}

ModelDeserializer deserializer = new ModelDeserializer(_logger, _altinnApp.GetAppModelType(classRef));
ModelDeserializer deserializer = new ModelDeserializer(_logger, _appModel.GetModelType(classRef));
object appModel = await deserializer.DeserializeAsync(Request.Body, Request.ContentType);

if (!string.IsNullOrEmpty(deserializer.Error))
Expand Down Expand Up @@ -248,7 +252,7 @@ public async Task<ActionResult> PostAnonymous([FromQuery] string dataType)
return BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter.");
}

ModelDeserializer deserializer = new ModelDeserializer(_logger, _altinnApp.GetAppModelType(classRef));
ModelDeserializer deserializer = new ModelDeserializer(_logger, _appModel.GetModelType(classRef));
object appModel = await deserializer.DeserializeAsync(Request.Body, Request.ContentType);

if (!string.IsNullOrEmpty(deserializer.Error))
Expand Down
15 changes: 9 additions & 6 deletions src/Altinn.App.Api/Controllers/StatelessPagesController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;

using Altinn.App.Core.Interface;
using Altinn.App.PlatformServices.Models;
using Altinn.App.Services.Interface;

Expand All @@ -19,19 +19,22 @@ namespace Altinn.App.Api.Controllers
[AllowAnonymous]
public class StatelessPagesController : ControllerBase
{
private readonly IAltinnApp _altinnApp;
private readonly IAppModel _appModel;
private readonly IAppResources _resources;
private readonly IPageOrder _pageOrder;

/// <summary>
/// Initializes a new instance of the <see cref="PagesController"/> class.
/// </summary>
/// <param name="altinnApp">The current App Core used to interface with custom logic</param>
/// <param name="appModel">The current appmodel implementation for getting the model Type</param>
/// <param name="resources">The app resource service</param>
/// <param name="pageOrder">The page order service</param>
public StatelessPagesController(IAltinnApp altinnApp, IAppResources resources, IPageOrder pageOrder)
public StatelessPagesController(
IAppModel appModel,
IAppResources resources,
IPageOrder pageOrder)
{
_altinnApp = altinnApp;
_appModel = appModel;
_resources = resources;
_pageOrder = pageOrder;
}
Expand All @@ -56,7 +59,7 @@ public async Task<ActionResult<List<string>>> GetPageOrder(

string classRef = _resources.GetClassRefForLogicDataType(dataTypeId);

object data = JsonConvert.DeserializeObject(formData.ToString(), _altinnApp.GetAppModelType(classRef));
object data = JsonConvert.DeserializeObject(formData.ToString(), _appModel.GetModelType(classRef));
return await _pageOrder.GetPageOrder(new AppIdentifier(org, app), InstanceIdentifier.NoInstance, layoutSetId, currentPage, dataTypeId, data);
}
}
Expand Down
Loading