forked from eclipse-edc/DataDashboard
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use CreateDataOffer API (#825)
- Loading branch information
Showing
7 changed files
with
137 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/app/core/services/api/fake-backend/connector-fake-impl/data-offer-fake-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
DataOfferCreationRequest, | ||
DataOfferCreationRequestPolicyEnum, | ||
IdResponseDto, | ||
UiCriterionLiteralType, | ||
} from '@sovity.de/edc-client'; | ||
import {ALWAYS_TRUE_POLICY_ID} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/model/always-true-policy-id'; | ||
import {assetIdAvailable, createAsset} from './asset-fake-service'; | ||
import { | ||
contractDefinitionIdAvailable, | ||
createContractDefinition, | ||
} from './contract-definition-fake-service'; | ||
import { | ||
createPolicyDefinitionV2, | ||
policyDefinitionIdAvailable, | ||
} from './policy-definition-fake-service'; | ||
|
||
const checkIdAvailability = (id: string): void => { | ||
if ( | ||
!policyDefinitionIdAvailable(id).available || | ||
!assetIdAvailable(id).available || | ||
!contractDefinitionIdAvailable(id).available | ||
) { | ||
throw new Error('Id already exists'); | ||
} | ||
}; | ||
|
||
export const createDataOffer = ( | ||
request: DataOfferCreationRequest, | ||
): IdResponseDto => { | ||
const commonId = request.uiAssetCreateRequest.id; | ||
let accessPolicyId = null; | ||
let contractPolicyId = null; | ||
|
||
checkIdAvailability(commonId); | ||
createAsset(request.uiAssetCreateRequest); | ||
|
||
switch (request.policy) { | ||
case DataOfferCreationRequestPolicyEnum.DontPublish: | ||
return {id: commonId, lastUpdatedDate: new Date()}; | ||
case DataOfferCreationRequestPolicyEnum.PublishRestricted: | ||
createPolicyDefinitionV2({ | ||
policyDefinitionId: commonId, | ||
expression: request.uiPolicyExpression!, | ||
}); | ||
accessPolicyId = commonId; | ||
contractPolicyId = commonId; | ||
break; | ||
case DataOfferCreationRequestPolicyEnum.PublishUnrestricted: | ||
accessPolicyId = ALWAYS_TRUE_POLICY_ID; | ||
contractPolicyId = ALWAYS_TRUE_POLICY_ID; | ||
break; | ||
} | ||
|
||
createContractDefinition({ | ||
contractDefinitionId: commonId, | ||
accessPolicyId, | ||
contractPolicyId, | ||
assetSelector: [ | ||
{ | ||
operandLeft: commonId, | ||
operator: 'EQ', | ||
operandRight: { | ||
type: UiCriterionLiteralType.Value, | ||
value: commonId, | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
return {id: commonId, lastUpdatedDate: new Date()}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters