21
21
using Org . Eclipse . TractusX . Portal . Backend . Framework . ErrorHandling ;
22
22
using Org . Eclipse . TractusX . Portal . Backend . Framework . Identity ;
23
23
using Org . Eclipse . TractusX . Portal . Backend . Framework . IO ;
24
+ using Org . Eclipse . TractusX . Portal . Backend . Framework . Processes . Library . Enums ;
25
+ using Org . Eclipse . TractusX . Portal . Backend . Framework . Processes . Library . Extensions ;
24
26
using Org . Eclipse . TractusX . Portal . Backend . PortalBackend . DBAccess ;
25
27
using Org . Eclipse . TractusX . Portal . Backend . PortalBackend . DBAccess . Models ;
26
28
using Org . Eclipse . TractusX . Portal . Backend . PortalBackend . DBAccess . Repositories ;
30
32
31
33
namespace Org . Eclipse . TractusX . Portal . Backend . Administration . Service . BusinessLogic ;
32
34
33
- public class SubscriptionConfigurationBusinessLogic : ISubscriptionConfigurationBusinessLogic
35
+ public class SubscriptionConfigurationBusinessLogic (
36
+ IOfferSubscriptionProcessService offerSubscriptionProcessService ,
37
+ IPortalRepositories portalRepositories ,
38
+ IIdentityService identityService )
39
+ : ISubscriptionConfigurationBusinessLogic
34
40
{
35
- private readonly IOfferSubscriptionProcessService _offerSubscriptionProcessService ;
36
- private readonly IPortalRepositories _portalRepositories ;
37
- private readonly IIdentityData _identityData ;
38
-
39
- public SubscriptionConfigurationBusinessLogic ( IOfferSubscriptionProcessService offerSubscriptionProcessService , IPortalRepositories portalRepositories , IIdentityService identityService )
40
- {
41
- _offerSubscriptionProcessService = offerSubscriptionProcessService ;
42
- _portalRepositories = portalRepositories ;
43
- _identityData = identityService . IdentityData ;
44
- }
41
+ private readonly IIdentityData _identityData = identityService . IdentityData ;
45
42
46
43
/// <inheritdoc />
47
44
public async Task < ProviderDetailReturnData > GetProviderCompanyDetailsAsync ( )
48
45
{
49
46
var companyId = _identityData . CompanyId ;
50
- var result = await _portalRepositories . GetInstance < ICompanyRepository > ( )
47
+ var result = await portalRepositories . GetInstance < ICompanyRepository > ( )
51
48
. GetProviderCompanyDetailAsync ( CompanyRoleId . SERVICE_PROVIDER , companyId )
52
49
. ConfigureAwait ( ConfigureAwaitOptions . None ) ;
53
50
if ( result == default )
54
51
{
55
52
throw ConflictException . Create ( AdministrationSubscriptionConfigurationErrors . SUBSCRIPTION_CONFLICT_COMPANY_NOT_FOUND , new ErrorParameter [ ] { new ( nameof ( companyId ) , companyId . ToString ( ) ) } ) ;
56
53
}
54
+
57
55
if ( ! result . IsProviderCompany )
58
56
{
59
57
throw ForbiddenException . Create ( AdministrationSubscriptionConfigurationErrors . SUBSCRIPTION_FORBIDDEN_COMPANY_NOT_SERVICE_PROVIDER , new ErrorParameter [ ] { new ( nameof ( companyId ) , companyId . ToString ( ) ) } ) ;
@@ -78,7 +76,7 @@ public Task SetProviderCompanyDetailsAsync(ProviderDetailData data)
78
76
79
77
private async Task SetOfferProviderCompanyDetailsInternalAsync ( ProviderDetailData data , Guid companyId )
80
78
{
81
- var companyRepository = _portalRepositories . GetInstance < ICompanyRepository > ( ) ;
79
+ var companyRepository = portalRepositories . GetInstance < ICompanyRepository > ( ) ;
82
80
var providerDetailData = await companyRepository
83
81
. GetProviderCompanyDetailsExistsForUser ( companyId )
84
82
. ConfigureAwait ( ConfigureAwaitOptions . None ) ;
@@ -92,9 +90,14 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat
92
90
{
93
91
companyRepository . AttachAndModifyProviderCompanyDetails (
94
92
providerDetailData . ProviderCompanyDetailId ,
95
- details => { details . AutoSetupUrl = providerDetailData . Url ; } ,
96
93
details =>
97
94
{
95
+ details . AutoSetupUrl = providerDetailData . Url ;
96
+ details . AutoSetupCallbackUrl = providerDetailData . CallbackUrl ;
97
+ } ,
98
+ details =>
99
+ {
100
+ details . AutoSetupCallbackUrl = data . CallbackUrl ;
98
101
details . AutoSetupUrl = data . Url ;
99
102
details . DateLastChanged = DateTimeOffset . UtcNow ;
100
103
} ) ;
@@ -106,9 +109,35 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat
106
109
hasChanges = true ;
107
110
}
108
111
112
+ if ( providerDetailData . CallbackUrl is not null && data . CallbackUrl is null )
113
+ {
114
+ await HandleOfferSetupProcesses ( companyId , companyRepository ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
115
+ hasChanges = true ;
116
+ }
117
+
109
118
if ( hasChanges )
110
119
{
111
- await _portalRepositories . SaveAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
120
+ await portalRepositories . SaveAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
121
+ }
122
+ }
123
+
124
+ private async Task HandleOfferSetupProcesses ( Guid companyId , ICompanyRepository companyRepository )
125
+ {
126
+ var processData = await companyRepository
127
+ . GetOfferSubscriptionProcessesForCompanyId ( companyId )
128
+ . ToListAsync ( )
129
+ . ConfigureAwait ( false ) ;
130
+
131
+ foreach ( var context in processData
132
+ . Where ( x => x . Process != null && x . ProcessSteps ? . Any ( ps => ps is
133
+ {
134
+ ProcessStepStatusId : ProcessStepStatusId . TODO ,
135
+ ProcessStepTypeId : ProcessStepTypeId . RETRIGGER_PROVIDER
136
+ } ) == true )
137
+ . Select ( data => data . CreateManualProcessData ( ProcessStepTypeId . RETRIGGER_PROVIDER , portalRepositories , ( ) => $ "processId { data . Process ! . Id } ") ) )
138
+ {
139
+ context . FinalizeProcessStep ( ) ;
140
+ context . ScheduleProcessSteps ( Enumerable . Repeat ( ProcessStepTypeId . AWAIT_START_AUTOSETUP , 1 ) ) ;
112
141
}
113
142
}
114
143
@@ -129,11 +158,7 @@ private static async Task HandleCreateProviderCompanyDetails(ProviderDetailData
129
158
130
159
companyRepository . CreateProviderCompanyDetail ( companyId , data . Url ! , providerDetails =>
131
160
{
132
- if ( data . CallbackUrl != null )
133
- {
134
- providerDetails . AutoSetupCallbackUrl = data . CallbackUrl ;
135
- }
136
-
161
+ providerDetails . AutoSetupCallbackUrl = data . CallbackUrl ;
137
162
providerDetails . DateLastChanged = DateTimeOffset . UtcNow ;
138
163
} ) ;
139
164
}
@@ -158,18 +183,17 @@ public Task RetriggerProviderCallback(Guid offerSubscriptionId) =>
158
183
public Task RetriggerCreateDimTechnicalUser ( Guid offerSubscriptionId ) =>
159
184
TriggerProcessStep ( offerSubscriptionId , ProcessStepTypeId . RETRIGGER_OFFERSUBSCRIPTION_CREATE_DIM_TECHNICAL_USER , true ) ;
160
185
161
- /// <inheritdoc />
162
186
private async Task TriggerProcessStep ( Guid offerSubscriptionId , ProcessStepTypeId stepToTrigger , bool mustBePending )
163
187
{
164
188
var nextStep = stepToTrigger . GetOfferSubscriptionStepToRetrigger ( ) ;
165
- var context = await _offerSubscriptionProcessService . VerifySubscriptionAndProcessSteps ( offerSubscriptionId , stepToTrigger , null , mustBePending )
189
+ var context = await offerSubscriptionProcessService . VerifySubscriptionAndProcessSteps ( offerSubscriptionId , stepToTrigger , null , mustBePending )
166
190
. ConfigureAwait ( ConfigureAwaitOptions . None ) ;
167
191
168
- _offerSubscriptionProcessService . FinalizeProcessSteps ( context , Enumerable . Repeat ( nextStep , 1 ) ) ;
169
- await _portalRepositories . SaveAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
192
+ offerSubscriptionProcessService . FinalizeProcessSteps ( context , Enumerable . Repeat ( nextStep , 1 ) ) ;
193
+ await portalRepositories . SaveAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
170
194
}
171
195
172
196
/// <inheritdoc />
173
197
public IAsyncEnumerable < ProcessStepData > GetProcessStepsForSubscription ( Guid offerSubscriptionId ) =>
174
- _portalRepositories . GetInstance < IOfferSubscriptionsRepository > ( ) . GetProcessStepsForSubscription ( offerSubscriptionId ) ;
198
+ portalRepositories . GetInstance < IOfferSubscriptionsRepository > ( ) . GetProcessStepsForSubscription ( offerSubscriptionId ) ;
175
199
}
0 commit comments