Skip to content

Commit

Permalink
chore: asset page, create asset, delete asset now use UI API Wrapper (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AnurosePrakash authored Aug 11, 2023
1 parent cf7098d commit c358d6c
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 95 deletions.
72 changes: 38 additions & 34 deletions fake-backend/json/assets.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
[
{
"properties": {
"asset:prop:id": "urn:artifact:db-rail-network-2023-jan",
"asset:prop:name": "Rail Network DB 2023 January",
"asset:prop:version": "1.1",
"asset:prop:originator": "https://example-connector.rail-mgmt.bahn.de/api/v1/ids/data",
"asset:prop:originatorOrganization": "Deutsche Bahn AG",
"asset:prop:keywords": "db, bahn, rail, Rail-Designer",
"asset:prop:contenttype": "application/json",
"asset:prop:description": "Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.",
"asset:prop:language": "https://w3id.org/idsa/code/EN",
"asset:prop:publisher": "https://my.cool-api.gg/about",
"asset:prop:standardLicense": "https://my.cool-api.gg/license",
"asset:prop:endpointDocumentation": "https://my.cool-api.gg/docs",
"http://w3id.org/mds#dataCategory": "Infrastructure and Logistics",
"http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes",
"http://w3id.org/mds#dataModel": "my-data-model-001",
"http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method",
"http://w3id.org/mds#transportMode": "Rail",
"asset:prop:some-unsupported-property": "F10E2821BBBEA527EA02200352313BC059445190"
{
"assets": [
{
"properties": {
"asset:prop:id": "urn:artifact:db-rail-network-2023-jan",
"asset:prop:name": "Rail Network DB 2023 January",
"asset:prop:version": "1.1",
"asset:prop:originator": "https://example-connector.rail-mgmt.bahn.de/api/v1/ids/data",
"asset:prop:originatorOrganization": "Deutsche Bahn AG",
"asset:prop:keywords": "db, bahn, rail, Rail-Designer",
"asset:prop:contenttype": "application/json",
"asset:prop:description": "Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.",
"asset:prop:language": "https://w3id.org/idsa/code/EN",
"asset:prop:publisher": "https://my.cool-api.gg/about",
"asset:prop:standardLicense": "https://my.cool-api.gg/license",
"asset:prop:endpointDocumentation": "https://my.cool-api.gg/docs",
"http://w3id.org/mds#dataCategory": "Infrastructure and Logistics",
"http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes",
"http://w3id.org/mds#dataModel": "my-data-model-001",
"http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method",
"http://w3id.org/mds#transportMode": "Rail",
"asset:prop:some-unsupported-property": "test"
},
"privateProperties": {}
},
{
"properties": {
"asset:prop:id": "urn:artifact:bitcoin-data",
"asset:prop:name": "Bitcoin Data",
"asset:prop:contenttype": "application/json",
"asset:prop:description": "description",
"asset:prop:version": "1.0",
"asset:prop:type": "HttpData",
"asset:prop:originator": "https://sovity-001.stage-sovity.azure.sovity.io/control/api/v1/ids/data"
},
"privateProperties": {}
}
},
{
"properties": {
"asset:prop:id": "urn:artifact:bitcoin-data",
"asset:prop:name": "Bitcoin Data",
"asset:prop:contenttype": "application/json",
"asset:prop:description": "description",
"asset:prop:version": "1.0",
"asset:prop:type": "HttpData",
"asset:prop:originator": "https://sovity-001.stage-sovity.azure.sovity.io/control/api/v1/ids/data"
}
}
]
]
}
10 changes: 5 additions & 5 deletions fake-backend/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ app.use((req, res, next) => setTimeout(next, 1000));

// Management API

const assets = json('json/assets.json');
app.get('/api/v1/data/assets', (req, res) => {
res.json(assets);
});

const policyDefinitions = json('json/policyDefinitions.json');
app.get('/api/v1/data/policydefinitions', (req, res) => {
res.json(policyDefinitions);
Expand Down Expand Up @@ -101,6 +96,11 @@ app.post(
);

// UI API Wrapper
const assetPage = json('json/assets.json');
app.get('/api/v1/data/wrapper/ui/pages/asset-page', (req, res) => {
res.json(assetPage);
});

const contractAgreementPage = json('json/contractAgreementPage.json');
app.get('/api/v1/data/wrapper/ui/pages/contract-agreement-page', (_, res) => {
res.json(contractAgreementPage);
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@ng-apimock/core": "^3.11.0",
"@ngxs/store": "^3.8.1",
"@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff",
"@sovity.de/edc-client": "0.20230711.54203-main-f9c4b8f7",
"@sovity.de/edc-client": "0.20230810.82616-main-89593380",
"clean-deep": "^3.4.0",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {Observable, Subject, isObservable} from 'rxjs';
import {filter, finalize, takeUntil} from 'rxjs/operators';
import {ContractNegotiationService} from '../../../core/services/api/contract-negotiation.service';
import {AssetService} from '../../../core/services/api/legacy-managent-api-client';
import {Asset} from '../../../core/services/models/asset';
import {NotificationService} from '../../../core/services/notification.service';
import {ContractAgreementTransferDialogData} from '../../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-data';
Expand All @@ -19,6 +18,7 @@ import {
import {PropertyGridGroup} from '../../property-grid/property-grid-group/property-grid-group';
import {AssetDetailDialogData} from './asset-detail-dialog-data';
import {AssetDetailDialogResult} from './asset-detail-dialog-result';
import {EdcApiService} from "../../../core/services/api/edc-api.service";

/**
* Asset Detail Dialog
Expand Down Expand Up @@ -50,8 +50,8 @@ export class AssetDetailDialogComponent implements OnDestroy {
}

constructor(
private edcApiService: EdcApiService,
private notificationService: NotificationService,
private assetService: AssetService,
private matDialog: MatDialog,
private matDialogRef: MatDialogRef<AssetDetailDialogComponent>,
@Inject(MAT_DIALOG_DATA)
Expand Down Expand Up @@ -79,7 +79,7 @@ export class AssetDetailDialogComponent implements OnDestroy {
successMessage: `Deleted asset ${this.asset.id}.`,
failureMessage: `Failed deleting asset ${this.asset.id}.`,
onsuccess: () => this.close({refreshList: true}),
req: () => this.assetService.removeAsset(this.asset.id),
req: () => this.edcApiService.deleteAsset(this.asset.id),
});
});
}
Expand Down
21 changes: 20 additions & 1 deletion src/app/core/services/api/edc-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {Inject, Injectable} from '@angular/core';
import {Observable, from} from 'rxjs';
import {
AssetPage,
ConnectorLimits,
ContractAgreementPage,
ContractAgreementTransferRequest,
EdcClient,
IdResponse,
IdResponseDto,
buildEdcClient,
} from '@sovity.de/edc-client';
import {AssetCreateRequest} from '@sovity.de/edc-client/dist/generated/models/AssetCreateRequest';
import {APP_CONFIG, AppConfig} from '../../config/app-config';

@Injectable({providedIn: 'root'})
Expand All @@ -21,13 +24,29 @@ export class EdcApiService {
});
}

createAsset(
assetCreateRequest: AssetCreateRequest,
): Observable<IdResponseDto> {
return from(this.edcClient.uiApi.createAsset({assetCreateRequest}));
}

getAssetPage(): Observable<AssetPage> {
return from(this.edcClient.uiApi.assetPage());
}

deleteAsset(
assetId: string,
): Observable<IdResponseDto> {
return from(this.edcClient.uiApi.deleteAsset({assetId}));
}

getContractAgreementPage(): Observable<ContractAgreementPage> {
return from(this.edcClient.uiApi.contractAgreementEndpoint());
}

initiateTranfer(
contractAgreementTransferRequest: ContractAgreementTransferRequest,
): Observable<IdResponseDto> {
): Observable<IdResponse> {
return from(
this.edcClient.uiApi.initiateTransfer({contractAgreementTransferRequest}),
);
Expand Down
18 changes: 11 additions & 7 deletions src/app/core/services/asset-entry-builder.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import {Injectable} from '@angular/core';
import {AssetEditorDialogFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/asset-editor-dialog-form-model';
import {AssetEntryDto} from './api/legacy-managent-api-client';
import {AssetCreateRequest} from '@sovity.de/edc-client/dist/generated/models/AssetCreateRequest';
import {
AssetEditorDialogFormValue
} from '../../routes/connector-ui/asset-page/asset-create-dialog/asset-editor-dialog-form-model';
import {AssetPropertyMapper} from './asset-property-mapper';
import {DataAddressMapper} from './data-address-mapper';


@Injectable()
export class AssetEntryBuilder {
constructor(
private assetPropertyMapper: AssetPropertyMapper,
private dataAddressMapper: DataAddressMapper,
) {}
) {
}

/**
* Build {@link AssetEntryDto} from {@link AssetEditorDialogFormValue}
* Build {@link AssetCreateRequest} from {@link AssetEditorDialogFormValue}
*
* @param formValue form value
* @return asset create dto
*/
buildAssetEntry(formValue: AssetEditorDialogFormValue): AssetEntryDto {
buildAssetCreateRequest(formValue: AssetEditorDialogFormValue): AssetCreateRequest {
let properties = this.assetPropertyMapper.buildProperties(formValue);
const dataAddress = this.dataAddressMapper.buildDataAddressProperties(
const dataAddressProperties = this.dataAddressMapper.buildDataAddressProperties(
formValue.datasource,
);
return {asset: {properties}, dataAddress};
return {properties, dataAddressProperties, privateProperties: {}};
}
}
12 changes: 6 additions & 6 deletions src/app/core/services/asset-service-mapped.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {AssetService} from './api/legacy-managent-api-client';
import {EdcApiService} from './api/edc-api.service';
import {AssetPropertyMapper} from './asset-property-mapper';
import {Asset} from './models/asset';

Expand All @@ -14,15 +14,15 @@ import {Asset} from './models/asset';
export class AssetServiceMapped {
constructor(
private assetPropertyMapper: AssetPropertyMapper,
private assetService: AssetService,
private edcApiService: EdcApiService,
) {}

fetchAssets(): Observable<Asset[]> {
return this.assetService
.getAllAssets(0, 10_000_000)
return this.edcApiService
.getAssetPage()
.pipe(
map((assets) =>
assets.map((asset) =>
map((assetPage) =>
assetPage.assets.map((asset) =>
this.assetPropertyMapper.buildAssetFromProperties(asset.properties),
),
),
Expand Down
3 changes: 1 addition & 2 deletions src/app/core/services/data-address-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Injectable} from '@angular/core';
import {AssetDatasourceFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/model/asset-datasource-form-model';
import {ContractAgreementTransferDialogFormValue} from '../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-form-model';
import {DataAddressDto} from './api/legacy-managent-api-client';
import {HttpRequestParamsMapper} from './http-params-mapper.service';

@Injectable({providedIn: 'root'})
Expand All @@ -13,7 +12,7 @@ export class DataAddressMapper {
| AssetDatasourceFormValue
| ContractAgreementTransferDialogFormValue
| undefined,
): DataAddressDto {
): Record<string, string> {
switch (formValue?.dataAddressType) {
case 'Custom-Data-Address-Json':
return JSON.parse(formValue.dataDestination?.trim()!!);
Expand Down
5 changes: 2 additions & 3 deletions src/app/core/services/http-params-mapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {HttpDatasourceQueryParamFormValue} from '../../routes/connector-ui/asset
import {ContractAgreementTransferDialogFormValue} from '../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-form-model';
import {removeNullValues} from '../utils/record-utils';
import {everythingAfter, everythingBefore} from '../utils/string-utils';
import {DataAddressDto} from './api/legacy-managent-api-client';
import {Asset} from './models/asset';
import {HttpRequestParams} from './models/http-request-params';

Expand All @@ -16,9 +15,9 @@ export class HttpRequestParamsMapper {
| AssetDatasourceFormValue
| ContractAgreementTransferDialogFormValue
| undefined,
): DataAddressDto {
): Record<string, string> {
const params = this.buildHttpRequestParams(formValue);
return {properties: this.encodeHttpRequestParams(params)};
return this.encodeHttpRequestParams(params);
}

encodeHttpProxyTransferRequestProperties(
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/services/login-polling.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {HttpErrorResponse} from '@angular/common/http';
import {Injectable, OnDestroy} from '@angular/core';
import {EMPTY, Observable, Subject, interval} from 'rxjs';
import {catchError, switchMap, takeUntil} from 'rxjs/operators';
import {AssetService} from './api/legacy-managent-api-client';
import {EdcApiService} from './api/edc-api.service';

@Injectable({providedIn: 'root'})
export class LoginPollingService implements OnDestroy {
private pollInterval = 1000 * 30;
private ngOnDestroy$ = new Subject();

constructor(private assetService: AssetService) {}
constructor(private edcApiService: EdcApiService) {}

startPolling(): void {
interval(this.pollInterval)
Expand All @@ -21,7 +21,7 @@ export class LoginPollingService implements OnDestroy {
}

private pollLogin(): Observable<unknown> {
return this.assetService.getAllAssets(0, 1).pipe(
return this.edcApiService.getAssetPage().pipe(
catchError((err) => {
if (!(err instanceof HttpErrorResponse) || err.status !== 401) {
console.warn('Error while polling for session', err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component, OnDestroy} from '@angular/core';
import {MatDialogRef} from '@angular/material/dialog';
import {Subject} from 'rxjs';
import {finalize, takeUntil} from 'rxjs/operators';
import {AssetService} from '../../../../core/services/api/legacy-managent-api-client';
import {EdcApiService} from '../../../../core/services/api/edc-api.service';
import {AssetEntryBuilder} from '../../../../core/services/asset-entry-builder';
import {NotificationService} from '../../../../core/services/notification.service';
import {ValidationMessages} from '../../../../core/validators/validation-messages';
Expand All @@ -29,22 +29,23 @@ export class AssetCreateDialogComponent implements OnDestroy {
methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];

constructor(
private edcApiService: EdcApiService,
public form: AssetCreateDialogForm,
public validationMessages: ValidationMessages,
private assetEntryBuilder: AssetEntryBuilder,
private notificationService: NotificationService,
private assetService: AssetService,
private dialogRef: MatDialogRef<AssetCreateDialogComponent>,
) {}

onSave() {
const formValue = this.form.value;
const assetEntryDto = this.assetEntryBuilder.buildAssetEntry(formValue);
const assetEntry =
this.assetEntryBuilder.buildAssetCreateRequest(formValue);

this.form.all.disable();
this.loading = true;
this.assetService
.createAsset(assetEntryDto)
this.edcApiService
.createAsset(assetEntry)
.pipe(
takeUntil(this.ngOnDestroy$),
finalize(() => {
Expand Down
Loading

0 comments on commit c358d6c

Please sign in to comment.