Skip to content

Commit

Permalink
fix: uri and sparql query
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianNoise committed Oct 15, 2020
1 parent 052e79d commit 587dce4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable, of, from } from 'rxjs';
import { ConnectionPool, IResult } from 'mssql';
import { DGTExchange, DGTPurpose, DGTConnector, DGTLDTriple, DGTSource, DGTConnection, DGTLDTermType, DGTLDResource, DGTLDTransformer } from '@digita-ai/dgt-shared-data';
import { DGTExchange, DGTPurpose, DGTConnector, DGTLDTriple, DGTSource, DGTConnection, DGTLDTermType, DGTLDResource, DGTLDTransformer, DGTLDDataType } from '@digita-ai/dgt-shared-data';
import { switchMap, map, tap } from 'rxjs/operators';
import { DGTMap, DGTLoggerService, DGTInjectable } from '@digita-ai/dgt-shared-utils';
import { DGTSourceMSSQLConfiguration } from '../models/dgt-source-mssql-configuration.model';
Expand Down Expand Up @@ -67,7 +67,8 @@ export class DGTSourceMSSQLConnector extends DGTConnector<DGTSourceMSSQLConfigur
predicate: field,
object: {
value,
termType: DGTLDTermType.LITERAL
termType: DGTLDTermType.LITERAL,
dataType: DGTLDDataType.STRING
},
originalValue: value,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
Authorization: 'Bearer ' + token,
}
)
)
);
)
);
})
).pipe(map((response) => data.entities as T[]))
)
);
)
);
}

public delete<T extends DGTLDResource>(domainEntities: T[], connection: DGTConnectionSolid, source: DGTSourceSolid, transformer: DGTLDTransformer<T>): Observable<T[]> {
Expand Down Expand Up @@ -335,6 +335,7 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
source
).pipe(
switchMap((token) => {
this.logger.debug(DGTSourceSolidConnector.name, 'Using token for auth', token);
if (update.delta.original.triples.length === 0) {
return this.http.patch(
update.delta.updated.documentUri,
Expand Down Expand Up @@ -384,22 +385,23 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
exchange: DGTExchange,
): Observable<T> {
this.logger.debug(DGTSourceSolidConnector.name, 'upstream syncing',
{domainEntity, connection, source, transformer, purpose, exchange});

{ domainEntity, connection, source, transformer, purpose, exchange });

domainEntity.documentUri = connection.configuration.webId;
// find possible existing values
return this.query(connection.configuration.webId, purpose, exchange, connection, source, transformer).pipe(
switchMap(existingValues => {
if (existingValues[0]) {
// convert to list of {original: Object, updated: Object}
const updateDomainEntity = {original: existingValues[0], updated: domainEntity};
this.logger.debug(DGTSourceSolidConnector.name, 'Updating value in pod', updateDomainEntity);
return this.update([updateDomainEntity], connection, source, transformer).pipe( map(triples => triples[0]));
} else {
this.logger.debug(DGTSourceSolidConnector.name, 'adding value to pod', domainEntity);
return this.add([domainEntity], connection, source, transformer).pipe( map(triples => triples[0]));
}
}),
switchMap(existingValues => {
const foundTriple = existingValues.find( v => domainEntity.triples[0].predicate === v.triples[0].predicate);
if (foundTriple) {
// convert to list of {original: Object, updated: Object}
const updateDomainEntity = { original: foundTriple, updated: domainEntity };
this.logger.debug(DGTSourceSolidConnector.name, 'Updating value in pod', updateDomainEntity);
return this.update([updateDomainEntity], connection, source, transformer).pipe(map(triples => triples[0]));
} else {
this.logger.debug(DGTSourceSolidConnector.name, 'adding value to pod', domainEntity);
return this.add([domainEntity], connection, source, transformer).pipe(map(triples => triples[0]));
}
}),
);
}

Expand Down Expand Up @@ -848,16 +850,16 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
.then((encodedParams) => {
params = encodedParams;
})
);
}
}),
map((data) => {
const url = new URL(endpoint);
url.search = this.encode(params);
);
}
}),
map((data) => {
const url = new URL(endpoint);
url.search = this.encode(params);

return url.href;
})
);
return url.href;
})
);
}

public retrieveWebId(connection: DGTConnectionSolid): string {
Expand Down Expand Up @@ -1045,7 +1047,7 @@ export class DGTSourceSolidConnector extends DGTConnector<DGTSourceSolidConfigur
connection: DGTConnectionSolid,
source: DGTSourceSolid
): Observable<string> {
this.logger.debug(DGTSourceSolidConnector.name, 'Generating Token...', {uri, connection, source});
this.logger.debug(DGTSourceSolidConnector.name, 'Generating Token...', { uri, connection, source });
if (source.state === DGTSourceState.NOTPREPARED) {
return this.prepare(connection, source).pipe(
tap(src => this.logger.debug(DGTSourceSolidConnector.name, 'Preparing source', src)),
Expand Down

0 comments on commit 587dce4

Please sign in to comment.