Skip to content

Commit

Permalink
changes on dataset reading
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmanos committed Oct 7, 2024
1 parent b26e955 commit 101085e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 175 deletions.
26 changes: 17 additions & 9 deletions dataset-reader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function parsePidData(filePath) {

// Convert worksheet to JSON format
const data = XLSX.utils.sheet_to_json(worksheet, {
defval: undefined,
defval: null,
dateNF: 'd"/"m"/"yyyy'
// skipHidden: true,
// header: 0
Expand All @@ -32,7 +32,7 @@ function parsePidData(filePath) {
row = Object.values(row)
const obj = {};
row.map((cell, index) => {
obj[headers[index]] = cell; // Assign key-value pairs
obj[headers[index]] = String(cell).trim(); // Assign key-value pairs
});

return obj;
Expand All @@ -56,12 +56,19 @@ function parseEhicData(filePath) {
const worksheet = workbook.Sheets[sheetName];

// Convert worksheet to JSON format
const data = XLSX.utils.sheet_to_json(worksheet, {
defval: undefined,
let data = XLSX.utils.sheet_to_json(worksheet, {
defval: null,
dateNF: 'd"/"m"/"yyyy'
// skipHidden: true,
// header: 0
});

data = data.map((row) => {
Object.keys(row).map((k) => {
row[k] = String(row[k]).trim();
})
return row;
})
return data;
}

Expand All @@ -82,23 +89,24 @@ function parsePda1Data(filePath) {

// Convert worksheet to JSON format
const data = XLSX.utils.sheet_to_json(worksheet, {
defval: undefined,
defval: null,
dateNF: 'd"/"m"/"yyyy'
// skipHidden: true,
// header: 0
});

let headers = Object.values(data[0]).map((h) => h.trim());
let headers = Object.values(data[0]).map((h) => h);

const ncols = Object.keys(headers);
console.log("headers = ", headers)
// const ncols = Object.keys(headers);


const result = data.slice(1).map(row => {
row = Object.values(row)

console.log("all values", row)
const obj = {};
row.forEach((cell, index) => {
obj[headers[index]] = cell; // Assign key-value pairs
obj[headers[index]] = String(cell).trim(); // Assign key-value pairs
});
return obj;
});
Expand Down
6 changes: 6 additions & 0 deletions dataset-reader/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { parsePda1Data, parseEhicData, parsePidData } = require('.')


const res = parsePda1Data('./dataset.xlsx')

console.log("Res = ", res[0])

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,13 @@ export class PickupCodeEHICSupportedCredentialSdJwt implements SupportedCredenti
ehic_institution_name: claims.ehic_institution_name,
ehic_institution_country_code: claims.ehic_institution_country_code,
pid_id: undefined,
family_name: undefined,
given_name: undefined,
birth_date: undefined,
"id": holderDID,
},
"credentialStatus": {
"id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.familyName ?? "", userSession.personalIdentifier)).id}`,
"id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.family_name ?? "", userSession.personalIdentifier)).id}`,
"type": "CertificateRevocationList"
},
"credentialBranding": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ export class VIDAuthenticationComponent extends AuthenticationComponent {
return;
}
authorizationServerState.personalIdentifier = personalIdentifier;
authorizationServerState.familyName = familyName;
authorizationServerState.family_name = familyName;
req.session.authenticationChain.vidAuthenticationComponent = {
personalIdentifier: personalIdentifier,
familyName: familyName,
};

console.log("Personal identifier = ", personalIdentifier)
req.authorizationServerState.personalIdentifier = personalIdentifier;
req.authorizationServerState.familyName = familyName;
req.authorizationServerState.family_name = familyName;

await AppDataSource.getRepository(AuthorizationServerState).save(authorizationServerState);
return res.redirect(this.protectedEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class PDA1SupportedCredentialSdJwt implements SupportedCredentialProtocol
throw new Error("issuer_state was not found user session");
}

console.log("Family name = ", userSession.familyName)
console.log("Family name = ", userSession.family_name)

console.log('type of issuer state ', typeof userSession.issuer_state);
if (!userSession.personalIdentifier) {
Expand Down Expand Up @@ -175,10 +175,13 @@ export class PDA1SupportedCredentialSdJwt implements SupportedCredentialProtocol
pda1_expiry_date: undefined, // hide this field
pda1_starting_date: undefined, // hide this field
pda1_ending_date: undefined, // hide this field
family_name: undefined,
given_name: undefined,
birth_date: undefined,
"id": holderDID,
},
"credentialStatus": {
"id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.familyName ?? "", claims.pid_id)).id}`,
"id": `${config.crl.url}#${(await CredentialStatusList.insert(userSession.family_name ?? "", claims.pid_id)).id}`,
"type": "CertificateRevocationList"
},
"credentialBranding": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class VIDAuthenticationComponent extends AuthenticationComponent {
return;
}
authorizationServerState.personalIdentifier = personalIdentifier;
authorizationServerState.familyName = familyName;
authorizationServerState.family_name = familyName;

req.session.authenticationChain.vidAuthenticationComponent = {
personalIdentifier: personalIdentifier,
Expand All @@ -137,7 +137,7 @@ export class VIDAuthenticationComponent extends AuthenticationComponent {

console.log("Personal identifier = ", personalIdentifier)
req.authorizationServerState.personalIdentifier = personalIdentifier;
req.authorizationServerState.familyName = familyName;
req.authorizationServerState.family_name = familyName;

await AppDataSource.getRepository(AuthorizationServerState).save(authorizationServerState);
return res.redirect(this.protectedEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ export class VIDSupportedCredentialSdJwt implements SupportedCredentialProtocol


async getProfile(userSession: AuthorizationServerState): Promise<CredentialView | null> {
if (!userSession?.personalIdentifier) {
return null;
}
if (!userSession.given_name || !userSession.family_name || !userSession.birth_date) {
throw new Error("Cannot generate credential: (given_name, family_name, birth_date) is missing");
}


const dataset = parsePidData("/datasets/dataset.xlsx");
const vids = dataset.filter((user: any) => user.pid_id == userSession.personalIdentifier);
const credentialViews: CredentialView[] = vids
const data = dataset.filter((user: any) =>
user.given_name == userSession.given_name &&
user.family_name == userSession.family_name &&
user.birth_date.toISOString() == userSession.birth_date
);
const credentialViews: CredentialView[] = data
.map((vid: any) => {
const rows: CategorizedRawCredentialViewRow[] = [
{ name: "Family Name", value: vid.family_name },
Expand All @@ -64,13 +69,16 @@ export class VIDSupportedCredentialSdJwt implements SupportedCredentialProtocol
}

async generateCredentialResponse(userSession: AuthorizationServerState, holderDID: string): Promise<{ format: VerifiableCredentialFormat; credential: any; }> {
if (!userSession.personalIdentifier) {
throw new Error("Cannot generate credential: Taxis id is missing");
if (!userSession.given_name || !userSession.family_name || !userSession.birth_date) {
throw new Error("Cannot generate credential: (given_name, family_name, birth_date) is missing");
}


const dataset = parsePidData("/datasets/dataset.xlsx");
const data = dataset.filter((user: any) => user.pid_id == userSession.personalIdentifier)[0];
const data = dataset.filter((user: any) =>
user.given_name == userSession.given_name &&
user.family_name == userSession.family_name &&
user.birth_date.toISOString() == userSession.birth_date
)[0];
const payload = {
"@context": ["https://www.w3.org/2018/credentials/v1"],
"type": this.getTypes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export class LocalAuthenticationComponent extends AuthenticationComponent {
if (!req.session.authenticationChain?.localAuthenticationComponent?.username) {
return false;
}
const username = req.session.authenticationChain.localAuthenticationComponent.username;
if (!username || this.users.filter((u: any) => u.User == username).length != 1) return false;
// const username = req.session.authenticationChain.localAuthenticationComponent.username;
// if (!username || this.users.filter((u: any) => u.User == username).length != 1) return false;

const usersFound = this.users.filter((u: any) => u.User == username) as any;
req.authorizationServerState.personalIdentifier = usersFound[0].pid_id;
await AppDataSource.getRepository(AuthorizationServerState).save(req.authorizationServerState);
// const usersFound = this.users.filter((u: any) => u.User == username) as any;
// req.authorizationServerState.personalIdentifier = usersFound[0].pid_id;
// await AppDataSource.getRepository(AuthorizationServerState).save(req.authorizationServerState);
return true;
}

Expand Down Expand Up @@ -94,7 +94,9 @@ export class LocalAuthenticationComponent extends AuthenticationComponent {
username: username
};

req.authorizationServerState.personalIdentifier = (usersFound[0] as any).pid_id;
req.authorizationServerState.family_name = (usersFound[0] as any).family_name;
req.authorizationServerState.given_name = (usersFound[0] as any).given_name;
req.authorizationServerState.birth_date = new Date((usersFound[0] as any).birth_date).toISOString();
await AppDataSource.getRepository(AuthorizationServerState).save(req.authorizationServerState);
return res.redirect(this.protectedEndpoint);
}
Expand Down

0 comments on commit 101085e

Please sign in to comment.