From d51dcca87ce5121c90830df1c9752ecc905790f8 Mon Sep 17 00:00:00 2001 From: Luca Giamminonni Date: Thu, 5 May 2022 17:46:30 +0200 Subject: [PATCH] [CST-5307] Added missing javadocs, removed showClaimItem feature --- .../data/feature-authorization/feature-id.ts | 1 - .../item-pages/person/person.component.ts | 25 +++++++--------- .../profile-claim/profile-claim.service.ts | 29 ++++++++++++------- .../profile-page-researcher-form.component.ts | 6 ++++ .../profile-page/profile-page.component.ts | 3 ++ .../claim-item-selector.component.ts | 5 ++-- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/app/core/data/feature-authorization/feature-id.ts b/src/app/core/data/feature-authorization/feature-id.ts index a2082831e0..59514b65cd 100644 --- a/src/app/core/data/feature-authorization/feature-id.ts +++ b/src/app/core/data/feature-authorization/feature-id.ts @@ -28,6 +28,5 @@ export enum FeatureID { CanCreateVersion = 'canCreateVersion', CanViewUsageStatistics = 'canViewUsageStatistics', CanSendFeedback = 'canSendFeedback', - ShowClaimItem = 'showClaimItem', CanClaimItem = 'canClaimItem', } diff --git a/src/app/entity-groups/research-entities/item-pages/person/person.component.ts b/src/app/entity-groups/research-entities/item-pages/person/person.component.ts index 42eb4ec7e6..33db18681f 100644 --- a/src/app/entity-groups/research-entities/item-pages/person/person.component.ts +++ b/src/app/entity-groups/research-entities/item-pages/person/person.component.ts @@ -40,7 +40,7 @@ export class PersonComponent extends ItemComponent implements OnInit { ngOnInit(): void { super.ngOnInit(); - this.authorizationService.isAuthorized(FeatureID.ShowClaimItem, this.object._links.self.href).pipe( + this.authorizationService.isAuthorized(FeatureID.CanClaimItem, this.object._links.self.href).pipe( take(1) ).subscribe((isAuthorized: boolean) => { this.claimable$.next(isAuthorized); @@ -48,21 +48,10 @@ export class PersonComponent extends ItemComponent implements OnInit { } + /** + * Create a new researcher profile claiming the current item. + */ claim() { - - this.authorizationService.isAuthorized(FeatureID.CanClaimItem, this.object._links.self.href).pipe( - take(1) - ).subscribe((isAuthorized: boolean) => { - if (!isAuthorized) { - this.notificationsService.warning(this.translate.get('researcherprofile.claim.not-authorized')); - } else { - this.createFromExternalSource(); - } - }); - - } - - createFromExternalSource() { this.researcherProfileService.createFromExternalSource(this.object._links.self.href).pipe( getFirstSucceededRemoteData(), mergeMap((rd: RemoteData) => { @@ -81,10 +70,16 @@ export class PersonComponent extends ItemComponent implements OnInit { }); } + /** + * Returns true if the item is claimable, false otherwise. + */ isClaimable(): Observable { return this.claimable$; } + /** + * Returns the metadata values to be used for the page title. + */ getTitleMetadataValues(): MetadataValue[]{ const metadataValues = []; const familyName = this.object?.firstMetadata('person.familyName'); diff --git a/src/app/profile-page/profile-claim/profile-claim.service.ts b/src/app/profile-page/profile-claim/profile-claim.service.ts index 1c86ba29f1..9ee2462778 100644 --- a/src/app/profile-page/profile-claim/profile-claim.service.ts +++ b/src/app/profile-page/profile-claim/profile-claim.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { Observable, of } from 'rxjs'; -import { mergeMap, switchMap, take } from 'rxjs/operators'; +import { mergeMap, take } from 'rxjs/operators'; import { ConfigurationDataService } from '../../core/data/configuration-data.service'; import { PaginatedList } from '../../core/data/paginated-list.model'; import { RemoteData } from '../../core/data/remote-data'; @@ -12,6 +12,9 @@ import { PaginatedSearchOptions } from '../../shared/search/models/paginated-sea import { SearchResult } from '../../shared/search/models/search-result.model'; import { getFirstSucceededRemoteData } from './../../core/shared/operators'; +/** + * Service that handle profiles claim. + */ @Injectable() export class ProfileClaimService { @@ -19,6 +22,11 @@ export class ProfileClaimService { private configurationService: ConfigurationDataService) { } + /** + * Returns true if it is possible to suggest profiles to be claimed to the given eperson. + * + * @param eperson the eperson + */ canClaimProfiles(eperson: EPerson): Observable { const query = this.personQueryData(eperson); @@ -33,6 +41,10 @@ export class ProfileClaimService { } + /** + * Returns profiles that could be associated with the given user. + * @param eperson the user + */ search(eperson: EPerson): Observable>>> { const query = this.personQueryData(eperson); if (!hasValue(query) || query.length === 0) { @@ -41,6 +53,10 @@ export class ProfileClaimService { return this.lookup(query); } + /** + * Search object by the given query. + * @param query the query for the search + */ private lookup(query: string): Observable>>> { if (!hasValue(query)) { return of(null); @@ -55,16 +71,7 @@ export class ProfileClaimService { } private personQueryData(eperson: EPerson): string { - const querySections = []; - this.queryParam(querySections, 'dc.title', eperson.name); - this.queryParam(querySections, 'crisrp.name', eperson.name); - return querySections.join(' OR '); + return 'dc.title:' + eperson.name; } - private queryParam(query: string[], metadata: string, value: string) { - if (!hasValue(value)) {return;} - query.push(metadata + ':' + value); - } - - } diff --git a/src/app/profile-page/profile-page-researcher-form/profile-page-researcher-form.component.ts b/src/app/profile-page/profile-page-researcher-form/profile-page-researcher-form.component.ts index e9d9cb6d05..9bb3028ff4 100644 --- a/src/app/profile-page/profile-page-researcher-form/profile-page-researcher-form.component.ts +++ b/src/app/profile-page/profile-page-researcher-form/profile-page-researcher-form.component.ts @@ -152,6 +152,9 @@ export class ProfilePageResearcherFormComponent implements OnInit { return this.processingCreate$.asObservable(); } + /** + * Create a new profile related to the current user from scratch. + */ createProfileFromScratch() { this.processingCreate$.next(true); this.researcherProfileService.create().pipe( @@ -167,6 +170,9 @@ export class ProfilePageResearcherFormComponent implements OnInit { }); } + /** + * Initializes the researcherProfile and researcherProfileItemId attributes using the profile of the current user. + */ private initResearchProfile(): void { this.researcherProfileService.findById(this.user.id).pipe( take(1), diff --git a/src/app/profile-page/profile-page.component.ts b/src/app/profile-page/profile-page.component.ts index ed032fb9d9..9c22c8c950 100644 --- a/src/app/profile-page/profile-page.component.ts +++ b/src/app/profile-page/profile-page.component.ts @@ -172,6 +172,9 @@ export class ProfilePageComponent implements OnInit { this.updateProfile(); } + /** + * Returns true if the researcher profile feature is enabled, false otherwise. + */ isResearcherProfileEnabled(){ return this.isResearcherProfileEnabled$; } diff --git a/src/app/shared/dso-selector/modal-wrappers/claim-item-selector/claim-item-selector.component.ts b/src/app/shared/dso-selector/modal-wrappers/claim-item-selector/claim-item-selector.component.ts index 5c5ee42037..3744f6d054 100644 --- a/src/app/shared/dso-selector/modal-wrappers/claim-item-selector/claim-item-selector.component.ts +++ b/src/app/shared/dso-selector/modal-wrappers/claim-item-selector/claim-item-selector.component.ts @@ -14,8 +14,9 @@ import { ViewMode } from '../../../../core/shared/view-mode.model'; import { ProfileClaimService } from '../../../../profile-page/profile-claim/profile-claim.service'; import { CollectionElementLinkType } from '../../../object-collection/collection-element-link.type'; - - +/** + * Component + */ @Component({ selector: 'ds-claim-item-selector', templateUrl: './claim-item-selector.component.html'