20
20
using Microsoft . Extensions . Options ;
21
21
using Org . Eclipse . TractusX . Portal . Backend . Framework . ErrorHandling ;
22
22
using Org . Eclipse . TractusX . Portal . Backend . Framework . Processes . Library . Enums ;
23
+ using Org . Eclipse . TractusX . Portal . Backend . Framework . Processes . Library . Extensions ;
24
+ using Org . Eclipse . TractusX . Portal . Backend . Framework . Processes . Library . Models ;
23
25
using Org . Eclipse . TractusX . Portal . Backend . PortalBackend . DBAccess ;
24
26
using Org . Eclipse . TractusX . Portal . Backend . PortalBackend . DBAccess . Repositories ;
25
27
using Org . Eclipse . TractusX . Portal . Backend . PortalBackend . PortalEntities . Enums ;
@@ -140,10 +142,12 @@ public async Task ProcessFinishSelfDescriptionLpForApplication(SelfDescriptionRe
140
142
/// <inheritdoc />
141
143
public async Task ProcessFinishSelfDescriptionLpForConnector ( SelfDescriptionResponseData data , CancellationToken cancellationToken )
142
144
{
143
- if ( ValidateConfirmationData ( data ) )
145
+ var connectorsRepository = portalRepositories . GetInstance < IConnectorsRepository > ( ) ;
146
+ var result = ValidateConfirmationData ( data ) ;
147
+ if ( result )
144
148
{
145
149
var documentId = await ProcessAndCreateDocument ( SdFactoryResponseModelTitle . Connector , data , cancellationToken ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
146
- portalRepositories . GetInstance < IConnectorsRepository > ( ) . AttachAndModifyConnector ( data . ExternalId , null , con =>
150
+ connectorsRepository . AttachAndModifyConnector ( data . ExternalId , null , con =>
147
151
{
148
152
con . SelfDescriptionDocumentId = documentId ;
149
153
con . StatusId = ConnectorStatusId . ACTIVE ;
@@ -152,21 +156,47 @@ public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResp
152
156
}
153
157
else
154
158
{
155
- portalRepositories . GetInstance < IConnectorsRepository > ( ) . AttachAndModifyConnector ( data . ExternalId , null , con =>
159
+ connectorsRepository . AttachAndModifyConnector ( data . ExternalId , null , con =>
156
160
{
157
161
con . SelfDescriptionMessage = data . Message ! ;
158
162
con . DateLastChanged = DateTimeOffset . UtcNow ;
159
163
} ) ;
160
164
}
165
+
166
+ var processData = await connectorsRepository . GetProcessDataForConnectorId ( data . ExternalId ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
167
+ if ( processData != null )
168
+ {
169
+ HandleSdCreationProcess ( processData , data , ProcessStepTypeId . AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE , ProcessStepTypeId . RETRIGGER_AWAIT_SELF_DESCRIPTION_CONNECTOR_RESPONSE ) ;
170
+ }
171
+ }
172
+
173
+ private void HandleSdCreationProcess ( VerifyProcessData < ProcessTypeId , ProcessStepTypeId > processData , SelfDescriptionResponseData data , ProcessStepTypeId processStepTypeId , ProcessStepTypeId retriggerProcessStepTypeId )
174
+ {
175
+ var context = processData . CreateManualProcessData ( processStepTypeId , portalRepositories , ( ) => $ "externalId { data . ExternalId } ") ;
176
+ if ( data . Status == SelfDescriptionStatus . Confirm )
177
+ {
178
+ context . FinalizeProcessStep ( ) ;
179
+ }
180
+ else
181
+ {
182
+ context . ScheduleProcessSteps ( [ retriggerProcessStepTypeId ] ) ;
183
+ context . FailProcessStep ( data . Message ) ;
184
+ }
161
185
}
162
186
163
187
public async Task ProcessFinishSelfDescriptionLpForCompany ( SelfDescriptionResponseData data , CancellationToken cancellationToken )
164
188
{
189
+ var companyRepository = portalRepositories . GetInstance < ICompanyRepository > ( ) ;
165
190
if ( data . Status == SelfDescriptionStatus . Confirm )
166
191
{
167
192
var documentId = await ProcessAndCreateDocument ( SdFactoryResponseModelTitle . LegalPerson , data , cancellationToken ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
168
- portalRepositories . GetInstance < ICompanyRepository > ( ) . AttachAndModifyCompany ( data . ExternalId , null ,
169
- c => { c . SelfDescriptionDocumentId = documentId ; } ) ;
193
+ companyRepository . AttachAndModifyCompany ( data . ExternalId , null , c => { c . SelfDescriptionDocumentId = documentId ; } ) ;
194
+ }
195
+
196
+ var processData = await companyRepository . GetProcessDataForCompanyIdId ( data . ExternalId ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ;
197
+ if ( processData != null )
198
+ {
199
+ HandleSdCreationProcess ( processData , data , ProcessStepTypeId . AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE , ProcessStepTypeId . RETRIGGER_AWAIT_SELF_DESCRIPTION_COMPANY_RESPONSE ) ;
170
200
}
171
201
}
172
202
@@ -176,7 +206,7 @@ private static bool ValidateConfirmationData(SelfDescriptionResponseData data)
176
206
switch ( confirm )
177
207
{
178
208
case false when string . IsNullOrEmpty ( data . Message ) :
179
- throw new ConflictException ( "Please provide a messsage " ) ;
209
+ throw new ConflictException ( "Please provide a message " ) ;
180
210
case true when data . Content == null :
181
211
throw new ConflictException ( "Please provide a selfDescriptionDocument" ) ;
182
212
}
0 commit comments