Skip to content

Commit

Permalink
feat: removed Entity superclass from Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianNoise committed Nov 2, 2020
1 parent 217ad68 commit 5d0ca57
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class DGTSourceGravatarConnector extends DGTConnector<DGTSourceGravatarCo
return {
triples,
uri: holderUri,
exchange: exchange.id,
exchange: exchange.uri,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as _ from 'lodash';
export class DGTSourceMSSQLConnector extends DGTConnector<DGTSourceMSSQLConfiguration, DGTConnectionMSSQLConfiguration> {

/**
* Map of DGTSource IDs -> ConnectionPools
* Map of DGTSource uri -> ConnectionPools
*/
private pools: DGTMap<string, ConnectionPool>;

Expand Down Expand Up @@ -79,7 +79,7 @@ export class DGTSourceMSSQLConnector extends DGTConnector<DGTSourceMSSQLConfigur
return {
triples,
uri,
exchange: exchange.id,
exchange: exchange.uri,
};
}

Expand Down Expand Up @@ -212,24 +212,24 @@ export class DGTSourceMSSQLConnector extends DGTConnector<DGTSourceMSSQLConfigur
}

private getPool(source: DGTSource<any>): Observable<ConnectionPool> {
if (!this.pools || !this.pools.get(source.id)) {
if (!this.pools || !this.pools.get(source.uri)) {
try {
const config = this.extractConfig(source);
this.logger.debug(DGTSourceMSSQLConnector.name, 'Creating connection pool');
const pool = new ConnectionPool(config);
pool.on('error', err => {
this.logger.debug(DGTSourceMSSQLConnector.name, 'Caught error in connection pool', err);
});
this.pools.set(source.id, pool);
this.pools.set(source.uri, pool);
this.logger.debug(DGTSourceMSSQLConnector.name, 'Connect to connection pool');
return from(this.pools.get(source.id).connect()).pipe(
map(() => this.pools.get(source.id)),
return from(this.pools.get(source.uri).connect()).pipe(
map(() => this.pools.get(source.uri)),
);
} catch (err) {
this.logger.debug(DGTSourceMSSQLConnector.name, 'Caught error in create connection', { err, pools: this.pools, source });
throw new DGTErrorArgument(err, err);
}
}
return of(this.pools.get(source.id));
return of(this.pools.get(source.uri));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('DGTSourceSolidConnector', () => {

expect(() => {
testService.service.query('bla', {
id: null,
uri: null,
icon: null,
description: null,
fields: null,
Expand All @@ -42,25 +42,30 @@ describe('DGTSourceSolidConnector', () => {
:me dgt-events:event :1.`;
const webId = 'https://john.my.id/';
const exchange: DGTExchange = {
id: 'e-1',
uri: 'e-1',
exchange: null,
triples: null,
purpose: null,
holder: null,
source: 's-1',
connection: 'c-1',
};
const source: DGTSourceSolid = {
id: 's-1',
uri: 's-1',
exchange: null,
triples: null,
icon: null,
description: null,
type: null,
configuration: null,
};
const connection: DGTConnectionSolid = {
id: 'c-1',
uri: 'c-1',
exchange: null,
triples: null,
configuration: null,
state: null,
source: 's-1',
subject: null,
};

const expectedResult: DGTLDTriple[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
switchMap(data => transformer.toDomain([{
triples: data.triples,
uri: data.uri,
exchange: data.exchange.id
exchange: data.exchange.uri
}])),
// tap(data => this.logger.debug(DGTSourceSolidConnector.name, 'Transformed resources', { data })),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DGTLDResource } from '../../linked-data/models/dgt-ld-resource.model';

export interface DGTCategory extends DGTLDResource {
icon: string;
title: string;
description: string;
filter: DGTLDFilter;
groupId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class DGTConnectorService {
return this.sources.get(destination).pipe(
map(source => ({ source })),
// get connection
mergeMap(data => this.connections.query({ holder: exchange.holder, source: data.source.id }).pipe(
mergeMap(data => this.connections.query({ holder: exchange.holder, source: data.source.uri }).pipe(
tap(connection => this.logger.debug(DGTConnectorService.name, 'found connection for upstream', connection)),
map(connection => connection.length > 0 ? connection : [null]),
map(connection => ({ ...data, connection: connection[0] })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export class DGTConsentSolidService extends DGTConsentService {
expirationDate = new Date(year + 100, month, day);

const resource: DGTConsent = {
id: v4(),
uri: null,
uri: v4(),
triples: null,
expirationDate,
purposeLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export class DGTConsentTransformerService implements DGTLDTransformer<DGTConsent
value: '#',
termType: DGTLDTermType.REFERENCE
};
const consentId = consent.id ? consent.id : v4();
this.logger.debug(DGTConsentTransformerService.name, 'starting to transform to linked data without id for consent', { consent })
const consentId = consent.uri ? consent.uri : v4();
this.logger.debug(DGTConsentTransformerService.name, 'starting to transform to linked data without uri for consent', { consent })
const consentSubjectUri = `${consent.uri}#${consentId}`;
const consentSubject = {
value: consentSubjectUri,
Expand Down Expand Up @@ -172,10 +172,9 @@ export class DGTConsentTransformerService implements DGTLDTransformer<DGTConsent
);

return {
uri,
expirationDate: expirationDate ? expirationDate.object.value : null,
triples: [...consentTriples, consentSubjectValue],
id: v4(),
uri: v4(),
purposeLabel: purposeLabel ? purposeLabel.object.value : '',
controller: controller ? controller.object.value : '',
exchange: resource.exchange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DGTLDTriple } from './dgt-ld-triple.model';

export interface DGTLDResource {
id?: string; // TEMP FOR COMPATIBILITY
uri: string;
exchange: string;
triples: DGTLDTriple[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DGTLDFilterRunnerConnectionService implements DGTLDFilterRunnerServ
private runOne(filter: DGTLDFilterConnection, resource: DGTLDResource): Observable<boolean> {
this.paramChecker.checkParametersNotNull({ filter, resource });
return this.exchanges.get(resource.exchange).pipe(
map(exchange => exchange && exchange.connection ? filter.connections.find(connection => connection.id === exchange.connection) : null),
map(exchange => exchange && exchange.connection ? filter.connections.find(connection => connection.uri === exchange.connection) : null),
map(holder => holder !== null && holder !== undefined ? true : false)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DGTLDFilterRunnerExchangeService implements DGTLDFilterRunnerServic
private runOne(filter: DGTLDFilterExchange, resource: DGTLDResource): boolean {
this.paramChecker.checkParametersNotNull({ filter, resource });
const match = filter.exchanges.find(
exchange => exchange.id === resource.exchange
exchange => exchange.uri === resource.exchange
);
return match ? true : false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DGTLDFilterRunnerHolderService implements DGTLDFilterRunnerService<
private runOne(filter: DGTLDFilterHolder, resource: DGTLDResource): Observable<boolean> {
this.paramChecker.checkParametersNotNull({ filter, resource });
return this.exchanges.get(resource.exchange).pipe(
map(exchange => exchange && exchange.holder ? filter.holders.find(holder => holder.id === exchange.holder) : null),
map(exchange => exchange && exchange.holder ? filter.holders.find(holder => holder.uri === exchange.holder) : null),
map(holder => holder !== null && holder !== undefined ? true : false)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DGTMap } from '@digita-ai/dgt-shared-utils';
import { DGTEntity } from './dgt-entity.model';
import { DGTLDResource } from '@digita-ai/dgt-shared-data/public-api';

export class DGTMockDatabase extends DGTMap<string, DGTEntity[]> {
constructor(map: DGTMap<string, DGTEntity[]> | Array<{ key: string, value: DGTEntity[] }> = null) {
export class DGTMockDatabase extends DGTMap<string, DGTLDResource[]> {
constructor(map: DGTMap<string, DGTLDResource[]> | Array<{ key: string, value: DGTLDResource[] }> = null) {
super(map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export class DGTCategoryRemoteService extends DGTCategoryService {
super();
}

get(id: string): Observable<DGTCategory> {
this.logger.debug(DGTCategoryRemoteService.name, 'Starting to get', { id });
get(uri: string): Observable<DGTCategory> {
this.logger.debug(DGTCategoryRemoteService.name, 'Starting to get', { uri });

if (!id) {
throw new DGTErrorArgument('Argument id should be set.', id);
if (!uri) {
throw new DGTErrorArgument('Argument uri should be set.', uri);
}

return of({ id })
return of({ uri })
.pipe(
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}category/${data.id}` })),
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}category/${data.uri}` })),
switchMap(data => this.store.select(state => state.app.accessToken).pipe(map(accessToken => ({ ...data, accessToken })))),
switchMap(data => this.http.get<DGTCategory>(data.uri, { Authorization: `Bearer ${data.accessToken}` })),
map(response => response.data),
Expand All @@ -49,5 +49,4 @@ export class DGTCategoryRemoteService extends DGTCategoryService {
delete(resource: DGTCategory): Observable<DGTCategory> {
throw new Error('Method not implemented.');
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export class DGTConnectionRemoteService extends DGTConnectionService {
throw new DGTErrorNotImplemented();
}

public get(id: string): Observable<DGTConnection<any>> {
this.logger.debug(DGTConnectionRemoteService.name, 'Starting to get', { id });
public get(uri: string): Observable<DGTConnection<any>> {
this.logger.debug(DGTConnectionRemoteService.name, 'Starting to get', { uri });

if (!id) {
throw new DGTErrorArgument('Argument id should be set.', id);
if (!uri) {
throw new DGTErrorArgument('Argument uri should be set.', uri);
}

return of({ id })
return of({ uri })
.pipe(
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}connection/${data.id}` })),
map(data => ({ ...data, uri: `${this.config.get(c => c.server.uri)}connection/${data.uri}` })),
switchMap(data => this.store.select(state => state.app.accessToken).pipe(map(accessToken => ({ ...data, accessToken })))),
switchMap(data => this.http.get<DGTConnection<any>>(data.uri, { Authorization: `Bearer ${data.accessToken}` })),
map(response => response.data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ export class DGTConnectionStateService extends DGTConnectionService {
throw new DGTErrorNotImplemented();
}

public get(id: string): Observable<DGTConnection<any>> {
this.logger.debug(DGTConnectionStateService.name, 'Starting to get', { id });
public get(uri: string): Observable<DGTConnection<any>> {
this.logger.debug(DGTConnectionStateService.name, 'Starting to get', { uri });

if (!id) {
throw new DGTErrorArgument('Argument id should be set.', id);
if (!uri) {
throw new DGTErrorArgument('Argument uri should be set.', uri);
}

return of({ id })
return of({ uri })
.pipe(
switchMap(data => this.store.select<DGTConnection<any>[]>(state => state.app.connections)
.pipe(map(connections => ({ ...data, connections })))),
map(data => data.connections ? data.connections.find(c => c.id === data.id) : null),
map(data => data.connections ? data.connections.find(c => c.uri === data.uri) : null),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</dgt-section-icon>

<dgt-section-title>
{{ 'common.data.categories.' + category.id + '-title' | translate}}
{{ 'common.data.categories.' + category.title + '-title' | translate}}
</dgt-section-title>

<dgt-section-subtitle>
{{ 'common.data.categories.' + category.id + '-description' | translate}}
{{ 'common.data.categories.' + category.title + '-description' | translate}}
</dgt-section-subtitle>

<dgt-section-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('DGTBrowserDataCategoryComponent', () => {
it('should dispatch Navigate', () => {
spyOn(testService.component.store, 'dispatch');
testService.component.viewCategoryPage(mockCategoryName);
expect(testService.component.store.dispatch).toHaveBeenCalledWith(new Navigate( { path: [`/data/category/${mockCategoryName.id}`] } ));
expect(testService.component.store.dispatch).toHaveBeenCalledWith(new Navigate( { path: [`/data/category/${mockCategoryName.title}`] } ));
});
});

Expand All @@ -46,7 +46,7 @@ describe('DGTBrowserDataCategoryComponent', () => {
const newValue = {value: mockValueRole, newObject: 'test-role'};
testService.component.onValueUpdated(newValue);
expect(testService.component.valuesToUpdate.size).toBeGreaterThan(originalLength);
expect(testService.component.valuesToUpdate.get(newValue.value.id)).toBeTruthy();
expect(testService.component.valuesToUpdate.get(newValue.value.uri)).toBeTruthy();
});
});

Expand Down Expand Up @@ -78,13 +78,13 @@ describe('DGTBrowserDataCategoryComponent', () => {
expect(button).toBeFalsy();
});
it('should display when valuesToUpdate has values', () => {
testService.component.valuesToUpdate.set(mockValueName.id, {value: mockValueName, newObject: 'test-name-two'});
testService.component.valuesToUpdate.set(mockValueName.uri, {value: mockValueName, newObject: 'test-name-two'});
testService.fixture.detectChanges();
const button: HTMLButtonElement = hostElement.querySelector('dgt-section-content dgt-button button');
const button: HTMLButtonElement = hostElement.querySelector('dgt-section-content dgt-button button');
expect(button).toBeTruthy();
});
it('should call updateValues on click', () => {
testService.component.valuesToUpdate.set(mockValueName.id, {value: mockValueName, newObject: 'test-name-two'});
testService.component.valuesToUpdate.set(mockValueName.uri, {value: mockValueName, newObject: 'test-name-two'});
testService.fixture.detectChanges();
spyOn(testService.component, 'updateValues');
const button: HTMLButtonElement = hostElement.querySelector('dgt-section-content dgt-button button');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class DGTDataCategoryComponent implements AfterViewInit {
*/
public onValueUpdated(val: {value: DGTDataValue, newObject: any}): void {
this.paramChecker.checkParametersNotNull({val}, 1);
this.valuesToUpdate.set(val.value.id, val);
this.valuesToUpdate.set(val.value.uri, val);
}

public updateValues(values: Map<string, {value: DGTDataValue, newObject: any}>): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<dgt-page-content-group-header>{{ 'common.data.groups.' + group.id | translate}}</dgt-page-content-group-header>
<ng-container *ngIf="categories">
<dgt-data-category *ngFor="let category of categories"
[values]="groupedValues.get(category.id)"
[category]="groupedCategories[category.id][0]"
[values]="groupedValues.get(category.uri)"
[category]="groupedCategories[category.uri][0]"
(valueUpdated)="onValueUpdated($event)"
(infoClicked)="onInfoClicked($event)">
</dgt-data-category>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export class DGTDataGroupComponent implements OnInit {
@Output()
infoClicked: EventEmitter<DGTCategory>;

/** Data values grouped by category ID */
/** Data values grouped by category uri */
public groupedValues;
/** Categories grouped by category ID */
/** Categories grouped by category uri */
public groupedCategories;

constructor(
Expand All @@ -61,7 +61,7 @@ export class DGTDataGroupComponent implements OnInit {

/**
* This function will be called when values or categories get updated
* It groups the categories and values by category ID
* It groups the categories and values by category uri
* @param values values to group
* @param categories categories to group
*/
Expand All @@ -71,18 +71,18 @@ export class DGTDataGroupComponent implements OnInit {
if (values && categories) {
// Categories for which a value exists
if (this.categories.length > 0) {
this.groupedCategories = _.groupBy(categories, category => category.id);
this.groupedCategories = _.groupBy(categories, category => category.uri);

// grouping values by category
this.categories.forEach(category => {
if (category.id) {
if (category.uri) {
this.datavalueService.getValuesOfCategories([category], values)
.subscribe(valuesOfCategory => {
this.groupedValues.set(
category.id,
category.uri,
valuesOfCategory
);
})
});
}
});
}
Expand Down
Loading

0 comments on commit 5d0ca57

Please sign in to comment.