diff --git a/validation-tool-backend/src/app.controller.ts b/validation-tool-backend/src/app.controller.ts index 56edb0d..466e9f1 100644 --- a/validation-tool-backend/src/app.controller.ts +++ b/validation-tool-backend/src/app.controller.ts @@ -22,4 +22,9 @@ export class AppController { async login(@Request() req) { return this.authService.login(req.user); } + + @Get('/ping') + async getPingResponse(@Request() req) { + return 'Service is running.'; + } } diff --git a/validation-tool-backend/src/auth/auth.service.ts b/validation-tool-backend/src/auth/auth.service.ts index 8ddc6fb..25e4c06 100644 --- a/validation-tool-backend/src/auth/auth.service.ts +++ b/validation-tool-backend/src/auth/auth.service.ts @@ -22,9 +22,8 @@ export class AuthService { async login(user: any) { const payload = { - source_id: user.source_id, + id: user.id, email: user.email, - sub: user.source_id, first_name: user.first_name, last_name: user.last_name, }; diff --git a/validation-tool-backend/src/review/review.controller.ts b/validation-tool-backend/src/review/review.controller.ts index d0748b2..3ca8f05 100644 --- a/validation-tool-backend/src/review/review.controller.ts +++ b/validation-tool-backend/src/review/review.controller.ts @@ -29,8 +29,8 @@ export class ReviewController { page_number = 0; } const user: User = req.user; - return await this.reviewService.getReviewItens( - user.source_id, + return await this.reviewService.getReviewItems( + user.id, page_size, page_number, ); @@ -40,7 +40,7 @@ export class ReviewController { @UseGuards(JwtAuthGuard) async getReviewItensCount(@Req() req) { const user: User = req.user; - const result = await this.reviewService.getReviewItensCount(user.source_id); + const result = await this.reviewService.getReviewItensCount(user.id); return result; } @@ -51,7 +51,7 @@ export class ReviewController { @Body() body: ValidationGenericMetadataDto, ) { const user: User = req.user; - await this.reviewService.reviewDatasetMentionAlias(user.source_id, body); + await this.reviewService.reviewDatasetMentionAlias(user.id, body); return true; } @@ -63,7 +63,7 @@ export class ReviewController { ) { const user: User = req.user; await this.reviewService.reviewDatasetMentionParentAlias( - user.source_id, + user.id, body, ); return true; diff --git a/validation-tool-backend/src/review/review.interface.ts b/validation-tool-backend/src/review/review.interface.ts index 43a28b8..2cd268f 100644 --- a/validation-tool-backend/src/review/review.interface.ts +++ b/validation-tool-backend/src/review/review.interface.ts @@ -5,7 +5,7 @@ export interface ReviewItem { publication_id: number; publication_doi: string; publication_title: string; - dataset_mention_alias: string; + alias_candidate: string; dataset_mention_alias_url: string; dataset_mention_parent_alias: string; dataset_mention_parent_alias_url: string; @@ -13,6 +13,9 @@ export interface ReviewItem { dataset_mention_answered: boolean; dataset_mention_parent_answered: boolean; publication_year: number; + dataset_correct: number; + alias_correct: number; + dataset_alias: string; } export interface ValidationGenericMetadataDto { @@ -35,6 +38,7 @@ export interface ValidationTableItemDto { export interface ReviewReportItem { user_metadata_source_id: number; + organization_source_id: number; email: string; organization_name: string; assigned_items: number; diff --git a/validation-tool-backend/src/review/review.service.ts b/validation-tool-backend/src/review/review.service.ts index 0521cb0..fa88d2d 100644 --- a/validation-tool-backend/src/review/review.service.ts +++ b/validation-tool-backend/src/review/review.service.ts @@ -12,7 +12,7 @@ import { export class ReviewService { constructor(private databaseService: DatabaseService) {} - async getReviewItens( + async getReviewItems( source_id: number, page_size = 10, page_number = 0, @@ -21,68 +21,37 @@ export class ReviewService { const pool = await this.databaseService.getConnection(); const result = await pool .request() - .input('EntityID', BigInt, source_id) + .input('EntityID', BigInt, source_id) // EntityID or source_id is the ID of the user. .input('Fetch', BigInt, page_size) - .input('Offset', BigInt, page_number * page_size).query(`select distinct - gm.entity_id as user_metadata_source_id, - gm2.generic_metadata_id as dataset_mention_generic_metadata_id, - gm2.metadata as dataset_mention, - pda.publication_dataset_alias_id as publication_dataset_alias_id, - p.publication_id as publication_id, - p.title as publication_title, - p.year as publication_year, - p.doi as publication_doi, - da.alias as dataset_mention_alias, + .input('Offset', BigInt, page_number * page_size).query(`SELECT + su.id as user_metadata_source_id, + sv.id as dataset_mention_generic_metadata_id, + pda.snippet as dataset_mention, + pda.id as publication_dataset_alias_id, + pda.publication_id as publication_id, + pu.title as publication_title, + pu.year as publication_year, + pu.doi as publication_doi, + pda.mention_candidate as alias_candidate, da.url as dataset_mention_alias_url, - CASE - WHEN v_alias.value is null - THEN CAST(0 AS BIT) - ELSE CAST(1 AS BIT) - END as dataset_mention_answered, - CASE - WHEN v_alias_parent.value is null - THEN CAST(0 AS BIT) - ELSE CAST(1 AS BIT) - END as dataset_mention_parent_answered, - case - when da2.alias is null - then da.alias - else da2.alias - end as dataset_mention_parent_alias, - case - when da2.alias is null - then da.url - else da2.url - end as dataset_mention_parent_alias_url - from - generic_metadata gm - left join - generic_metadata gm2 on cast(gm.metadata as INT) = gm2.generic_metadata_id - left join - publication_dataset_alias pda on pda.publication_dataset_alias_id = gm2.entity_id - left join - publication p on p.publication_id = pda.publication_id - left JOIN - dataset_alias da on da.alias_id = pda.alias_id - LEFT JOIN - dataset_alias da2 on da2.alias_id = da.parent_alias_id and da.alias_id <> da.parent_alias_id - left join - validation v_alias - on gm2.generic_metadata_id = v_alias.entity_id - and v_alias.source_id = @EntityID - and v_alias.entity_type = 'generic_metadata' - and v_alias.validation_type = 'text_snippet_dataset_alias' - left join - validation v_alias_parent - on gm2.generic_metadata_id = v_alias_parent.entity_id - and v_alias_parent.source_id = @EntityID - and v_alias_parent.entity_type = 'generic_metadata' - and v_alias_parent.validation_type = 'dataset_alias_official_name' - where - gm.metadata_name = 'text_snippet_to_review' - AND gm.entity_id = @EntityID - ORDER BY dataset_mention_generic_metadata_id - OFFSET @Offset ROWS FETCH NEXT @Fetch ROWS ONLY;`); + CASE WHEN sv.is_dataset_reference is null THEN CAST(0 AS BIT) ELSE CAST(1 AS BIT) END as dataset_mention_answered, + CASE WHEN sv.agency_dataset_identified is null THEN CAST(0 AS BIT) ELSE CAST(1 AS BIT)END as dataset_mention_parent_answered, + CASE WHEN da_parent.alias is null THEN da.alias ELSE da_parent.alias END AS dataset_mention_parent_alias, + CASE WHEN da_parent.alias is null THEN da.url ELSE da_parent.url END as dataset_mention_parent_alias_url, + sv.is_dataset_reference as dataset_correct, + sv.agency_dataset_identified as alias_correct, + da.alias as dataset_alias + FROM susd_user su + JOIN reviewer re ON re.susd_user_id=su.id + JOIN snippet_validation sv ON sv.reviewer_id = re.id and sv.run_id=re.run_id + JOIN publication_dataset_alias pda ON pda.id = sv.publication_dataset_alias_id AND pda.run_id=sv.run_id + JOIN publication pu ON pu.id = pda.publication_id AND pu.run_id=pda.run_id + LEFT JOIN dataset_alias da ON da.id = pda.dataset_alias_id AND da.run_id = sv.run_id + LEFT JOIN dataset_alias da_parent ON da.parent_alias_id = da_parent.alias_id AND da_parent.run_id = sv.run_id + JOIN agency_run ar ON ar.id=re.run_id + WHERE su.id = @EntityID + ORDER BY pda.id + OFFSET @Offset ROWS FETCH NEXT @Fetch ROWS ONLY;`); if (result.recordset && result.recordset.length > 0) { items = result.recordset as ReviewItem[]; } @@ -94,41 +63,20 @@ export class ReviewService { ): Promise<{ total: number; answered: number }> { const pool = await this.databaseService.getConnection(); const result = await pool.request().input('EntityID', BigInt, source_id) - .query(`select count(distinct gm2.generic_metadata_id) as items_number, - sum( - case when (v_alias.value is null or v_alias_parent.value is null) - then 0 - else 1 end - ) as answered, - gm.entity_id - from - generic_metadata gm - left join - generic_metadata gm2 on cast(gm.metadata as INT) = gm2.generic_metadata_id - left join - publication_dataset_alias pda on pda.publication_dataset_alias_id = gm2.entity_id - left join - publication p on p.publication_id = pda.publication_id - left JOIN - dataset_alias da on da.alias_id = pda.alias_id - LEFT JOIN - dataset_alias da2 on da2.alias_id = da.parent_alias_id and da.alias_id <> da.parent_alias_id - left join - validation v_alias - on gm2.generic_metadata_id = v_alias.entity_id - and v_alias.source_id = @EntityID - and v_alias.entity_type = 'generic_metadata' - and v_alias.validation_type = 'text_snippet_dataset_alias' - left join - validation v_alias_parent - on gm2.generic_metadata_id = v_alias_parent.entity_id - and v_alias_parent.source_id = @EntityID - and v_alias_parent.entity_type = 'generic_metadata' - and v_alias_parent.validation_type = 'dataset_alias_official_name' - where - gm.metadata_name = 'text_snippet_to_review' - AND gm.entity_id = @EntityID - group by gm.entity_id`); + .query(`SELECT + COUNT(*) as items_number, + SUM (CASE WHEN sv.agency_dataset_identified is not null and sv.is_dataset_reference is not null THEN 1 ELSE 0 END) as answered, + su.id as entity_id + from susd_user su + join reviewer re on re.susd_user_id=su.id + join snippet_validation sv on sv.reviewer_id = re.id and sv.run_id=re.run_id + join publication_dataset_alias pda on pda.id = sv.publication_dataset_alias_id and pda.run_id=sv.run_id + join publication pu on pu.id = pda.publication_id and pu.run_id=pda.run_id + join dataset_alias da on da.id = pda.dataset_alias_id and da.run_id = sv.run_id + left join dataset_alias da_parent on da.parent_alias_id = da_parent.alias_id and da_parent.run_id = sv.run_id + join agency_run ar on ar.id=re.run_id + where su.id = @EntityID + group by su.id`); const count_result = { total: 0, answered: 0, @@ -144,106 +92,49 @@ export class ReviewService { return count_result; } - async addDatasetMentionAliasReview( - source_id: number, - validation: ValidationGenericMetadataDto, - ) { - const pool = await this.databaseService.getConnection(); - const result = await pool - .request() - .input('SourceID', BigInt, source_id) - .input('EntityID', BigInt, validation.dataset_mention_generic_metadata_id) - .input('Value', BigInt, validation.value).query(`INSERT INTO validation - (entity_id, source_id, entity_type, value, validation_type) - VALUES - ( @EntityID, @SourceID, 'generic_metadata', @Value, 'text_snippet_dataset_alias' );`); - return result.rowsAffected; - } - async updateDatasetMentionAliasReview( - source_id: number, + async updateDatasetAliasCandidateReview( + user_id: number, validation: ValidationGenericMetadataDto, ) { const pool = await this.databaseService.getConnection(); const result = await pool .request() - .input('SourceID', BigInt, source_id) - .input('EntityID', BigInt, validation.dataset_mention_generic_metadata_id) + .input('ID', BigInt, validation.dataset_mention_generic_metadata_id) .input('Value', BigInt, validation.value) - .query(`update validation set value = @Value - where source_id = @SourceID - and entity_type = 'generic_metadata' - and validation_type = 'text_snippet_dataset_alias' - and entity_id = @EntityID`); + .query(`update snippet_validation set is_dataset_reference = @Value + where id = @ID`); return result.rowsAffected; } async reviewDatasetMentionAlias( - source_id: number, + user_id: number, validation: ValidationGenericMetadataDto, ) { - const row = await this.getValidation( - source_id, - 'generic_metadata', - validation.dataset_mention_generic_metadata_id, - 'text_snippet_dataset_alias', - ); - if (!row) { - return this.addDatasetMentionAliasReview(source_id, validation); - } else { - return this.updateDatasetMentionAliasReview(source_id, validation); - } + return this.updateDatasetAliasCandidateReview(user_id, validation); } - async addDatasetMentionParentAliasReview( - source_id: number, - validation: ValidationGenericMetadataDto, - ) { - const pool = await this.databaseService.getConnection(); - const result = await pool - .request() - .input('SourceID', BigInt, source_id) - .input('EntityID', BigInt, validation.dataset_mention_generic_metadata_id) - .input('Value', BigInt, validation.value).query(`INSERT INTO validation - ( entity_id, source_id, entity_type, value, validation_type) - VALUES - ( @EntityID, @SourceID, 'generic_metadata', @Value, 'dataset_alias_official_name' );`); - return result.rowsAffected; - } - async updateDatasetMentionParentAliasReview( + async updateParentAliasReview( source_id: number, validation: ValidationGenericMetadataDto, ) { const pool = await this.databaseService.getConnection(); const result = await pool .request() - .input('SourceID', BigInt, source_id) - .input('EntityID', BigInt, validation.dataset_mention_generic_metadata_id) + .input('ID', BigInt, validation.dataset_mention_generic_metadata_id) .input('Value', BigInt, validation.value) - .query(`update validation set value = @Value - where source_id = @SourceID - and entity_type = 'generic_metadata' - and validation_type = 'dataset_alias_official_name' - and entity_id = @EntityID`); + .query(`update snippet_validation set agency_dataset_identified = @Value + where id = @ID`); return result.rowsAffected; } + async reviewDatasetMentionParentAlias( source_id: number, validation: ValidationGenericMetadataDto, ) { - const row = await this.getValidation( - source_id, - 'generic_metadata', - validation.dataset_mention_generic_metadata_id, - 'dataset_alias_official_name', - ); - if (!row) { - return this.addDatasetMentionParentAliasReview(source_id, validation); - } else { - return this.updateDatasetMentionParentAliasReview(source_id, validation); - } + return this.updateParentAliasReview(source_id, validation); } async getValidation( @@ -285,11 +176,12 @@ export class ReviewService { let items: ReviewReportItem[] = []; const pool = await this.databaseService.getConnection(); const result = await pool.request().query(` select - ms.source_id as user_metadata_source_id, ms.email, ms.organization_name, + ms.source_id as user_metadata_source_id, ms2.source_id as organization_source_id, ms.email, ms.organization_name, sum(case when gm.generic_metadata_id is not null then 1 else 0 end) as assigned_items, sum(case when gm.generic_metadata_id is not null and (v_alias.value is null or v_alias_parent.value is null) then 1 else 0 end) as not_answered from metadata_source ms + join metadata_source ms2 on (ms2.organization_name = ms.organization_name and ms2.source_type = 'org') left join generic_metadata gm on ms.source_id = gm.entity_id and gm.metadata_name = 'text_snippet_to_review'-- added to see emails left join generic_metadata gm2 on cast(gm.metadata as INT) = gm2.generic_metadata_id --removed double casting @@ -312,16 +204,17 @@ sum(case when gm.generic_metadata_id is not null then 1 else 0 end) as assigned_ return items; } - async assignitems(source_id: number, organization_name: string) { + async assignitems(source_id: number, organization_source_id: number, organization_name: string) { const pool = await this.databaseService.getConnection(); const result = await pool .request() .input('SourceID', BigInt, source_id) + .input('OrganizationSourceID', BigInt, organization_source_id) .input('OrganizationName', VarChar, organization_name) .query(`INSERT INTO generic_metadata (source_id, entity_id, entity_type, metadata_name, metadata, last_updated_date) SELECT TOP 50 - 1, + @OrganizationSourceID, @SourceID, 'metadata_source', 'text_snippet_to_review', @@ -359,12 +252,12 @@ sum(case when gm.generic_metadata_id is not null then 1 else 0 end) as assigned_ const report = await this.getReviewReport(); for (const reportItem of report) { if ( - reportItem.not_answered === 0 && - ![6, 7].includes(reportItem.user_metadata_source_id) + reportItem.not_answered === 0 ) { await this.deleteAssignments(reportItem.user_metadata_source_id); await this.assignitems( reportItem.user_metadata_source_id, + reportItem.organization_source_id, reportItem.organization_name, ); } diff --git a/validation-tool-backend/src/users/user.interface.ts b/validation-tool-backend/src/users/user.interface.ts index d35f5ea..b448d6c 100644 --- a/validation-tool-backend/src/users/user.interface.ts +++ b/validation-tool-backend/src/users/user.interface.ts @@ -1,7 +1,5 @@ export interface User { - source_id: number; - source_type: string; - organization_name?: string; + id: number; first_name: string; last_name: string; email: string; diff --git a/validation-tool-backend/src/users/users.service.ts b/validation-tool-backend/src/users/users.service.ts index e01950b..cd911e9 100644 --- a/validation-tool-backend/src/users/users.service.ts +++ b/validation-tool-backend/src/users/users.service.ts @@ -27,7 +27,7 @@ export class UsersService { */ private readonly users = [ { - source_id: 3, + id: 3, source_type: 'user', last_name: 'tester', first_name: 'john', @@ -69,8 +69,8 @@ export class UsersService { .request() .input('Email', VarChar, email) .input('Password', VarChar, password) - .query(`SELECT source_id, source_type, organization_name, first_name, last_name, email - FROM metadata_source WHERE email = @Email + .query(`SELECT id, first_name, last_name, email + FROM susd_user WHERE email = @Email AND password = HASHBYTES('SHA2_256', @Password)`); if (result.recordset && result.recordset.length > 0) { user = result.recordset[0] as User; diff --git a/validation-tool-frontend/src/App.vue b/validation-tool-frontend/src/App.vue index 5913559..762f6e4 100644 --- a/validation-tool-frontend/src/App.vue +++ b/validation-tool-frontend/src/App.vue @@ -1,7 +1,7 @@