Skip to content

Commit

Permalink
feat: fake BE impl of create Data Offer
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Sep 13, 2024
1 parent b08feeb commit ab6c2f0
Showing 1 changed file with 64 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
import {DataOfferCreationRequest, IdResponseDto} from '@sovity.de/edc-client';
import {createAsset} from './asset-fake-service';
import {createPolicyDefinitionV2} from './policy-definition-fake-service';
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);
createPolicyDefinitionV2({
policyDefinitionId: request.policy,
expression: request.uiPolicyExpression!,

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,
},
},
],
});
// createContractDefinition();

return {id: 'test-id', lastUpdatedDate: new Date()};
return {id: commonId, lastUpdatedDate: new Date()};
};

0 comments on commit ab6c2f0

Please sign in to comment.