public async Task <ActionResult> Post([FromQuery] string dataType) { if (string.IsNullOrEmpty(dataType)) { return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter.")); } string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType); if (string.IsNullOrEmpty(classRef)) { return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter.")); } object appModel = _altinnApp.CreateNewAppModel(classRef); int?partyId = HttpContext.User.GetPartyIdAsInt(); if (partyId.HasValue) { // runs prefill from repo configuration if config exists await _prefillService.PrefillDataModel(partyId.ToString(), dataType, appModel); } await _altinnApp.RunCalculation(appModel); return(Ok(appModel)); }
private async Task <ActionResult> CreateAppModelData( string org, string app, Instance instance, string dataType) { Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]); object appModel; string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType); if (Request.ContentType == null) { appModel = _altinnApp.CreateNewAppModel(classRef); } else { ModelDeserializer deserializer = new ModelDeserializer(_logger, _altinnApp.GetAppModelType(classRef)); appModel = await deserializer.DeserializeAsync(Request.Body, Request.ContentType); if (!string.IsNullOrEmpty(deserializer.Error)) { return(BadRequest(deserializer.Error)); } } // runs prefill from repo configuration if config exists await _prefillService.PrefillDataModel(instance.InstanceOwner.PartyId, dataType, appModel); // send events to trigger application business logic await _altinnApp.RunDataCreation(instance, appModel); Dictionary <string, string> updatedValues = DataHelper.GetUpdatedDataValues( _appResourcesService.GetApplication().PresentationFields, instance.PresentationTexts, dataType, appModel); if (updatedValues.Count > 0) { await _instanceService.UpdatePresentationTexts( int.Parse(instance.InstanceOwner.PartyId), Guid.Parse(instance.Id.Split("/")[1]), new PresentationTexts { Texts = updatedValues }); } int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId); DataElement dataElement = await _dataService.InsertFormData(appModel, instanceGuid, _altinnApp.GetAppModelType(classRef), org, app, instanceOwnerPartyId, dataType); SelfLinkHelper.SetDataAppSelfLinks(instanceOwnerPartyId, instanceGuid, dataElement, Request); return(Created(dataElement.SelfLinks.Apps, dataElement)); }
public async Task <ActionResult> Get( [FromRoute] string org, [FromRoute] string app, [FromQuery] string dataType) { if (string.IsNullOrEmpty(dataType)) { return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter.")); } string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType); if (string.IsNullOrEmpty(classRef)) { return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter.")); } if (GetPartyHeader(HttpContext).Count > 1) { return(BadRequest($"Invalid party. Only one allowed")); } InstanceOwner owner = await GetInstanceOwner(HttpContext); if (string.IsNullOrEmpty(owner.PartyId)) { return(StatusCode((int)HttpStatusCode.Forbidden)); } EnforcementResult enforcementResult = await AuthorizeAction(org, app, Convert.ToInt32(owner.PartyId), "read"); if (!enforcementResult.Authorized) { return(Forbidden(enforcementResult)); } object appModel = _altinnApp.CreateNewAppModel(classRef); // runs prefill from repo configuration if config exists await _prefillService.PrefillDataModel(owner.PartyId, dataType, appModel); Instance virutalInstance = new Instance() { InstanceOwner = owner }; await _altinnApp.RunProcessDataRead(virutalInstance, null, appModel); return(Ok(appModel)); }
private async Task <ActionResult> CreateAppModelData( string org, string app, Instance instance, string dataType) { Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]); object appModel; string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType); if (Request.ContentType == null) { appModel = _altinnApp.CreateNewAppModel(classRef); } else { appModel = ParseContentAndDeserializeServiceModel(_altinnApp.GetAppModelType(classRef), out ActionResult contentError); if (contentError != null) { return(contentError); } } // send events to trigger application business logic await _altinnApp.RunAppEvent(AppEventType.AppModelCreation, appModel); int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId); DataElement dataElement = await _dataService.InsertFormData(appModel, instanceGuid, _altinnApp.GetAppModelType(classRef), org, app, instanceOwnerPartyId, dataType); SelfLinkHelper.SetDataAppSelfLinks(instanceOwnerPartyId, instanceGuid, dataElement, Request); return(Created(dataElement.SelfLinks.Apps, dataElement)); }