[Library | new-theme]: Create common methods to get entity name and entity file name from OpenaireEntities.

1. string-utils.class.ts:
   a. Added method "public static getEntityName(entityType: string, plural: boolean = false): string" to return OpenaireEntities name by entityType.
   b. Added method "public static getEntityFileName(entityType: string): string" to return OpenaireEntities file name by entityType.
2. directLinking.component.ts & dataProvider.component.ts & project.component.ts & resultLanding.component.ts & myOrcidLinks.component.ts & searchResearchResults.component.ts & result-preview.component.ts & search-tab.component.ts: Call StringUtils.getEntityName and StringUtils.getEntityFileName methods instead of checking if/then/else locally.
This commit is contained in:
Konstantina Galouni 2022-06-03 13:01:55 +03:00
parent 9542bd1e32
commit b88c65a343
9 changed files with 67 additions and 129 deletions

View File

@ -9,6 +9,7 @@ import {ClaimResultSearchFormComponent} from "../claim-utils/claimResultSearchFo
import {Subscriber} from "rxjs";
import {properties} from "../../../../environments/environment";
import {OpenaireEntities} from "../../utils/properties/searchFields";
import {StringUtils} from "../../utils/string-utils.class";
@Component({
@ -175,18 +176,6 @@ export class DirectLinkingComponent {
}
private getEntityName (entityType:string, plural:boolean) {
if (entityType == "publication") {
return plural ? OpenaireEntities.PUBLICATIONS : OpenaireEntities.PUBLICATION;
} else if (entityType == "dataset") {
return plural ? OpenaireEntities.DATASETS : OpenaireEntities.DATASET;
} else if (entityType == "software") {
return plural ? OpenaireEntities.SOFTWARE : OpenaireEntities.SOFTWARE_SINGULAR;
} else if (entityType == "other") {
return plural ? OpenaireEntities.OTHER : OpenaireEntities.OTHER_SINGULAR;
} else if (entityType == "result") {
return plural ? OpenaireEntities.RESULTS : OpenaireEntities.RESULT;
} else {
return entityType;
}
return StringUtils.getEntityName(entityType, plural);
}
}

View File

@ -395,7 +395,7 @@ export class DataProviderComponent {
err => {
//console.log(err);
this.aggregationStatusIsInitialized = true;
this.handleError("Error getting "+this.openaireEntities.DATASOURCE+" aggregation status for id: " + this.datasourceId, err);
this.handleError("Error getting "+this.getTypeName()+" aggregation status for id: " + this.datasourceId, err);
}
));
}
@ -728,7 +728,7 @@ export class DataProviderComponent {
}
private handleError(message: string, error) {
console.error(this.openaireEntities.DATASOURCE+" Landing Page: " + message, error);
console.error(this.getTypeName()+" Landing Page: " + message, error);
}
public getResultPreview(result: SearchResult, type: string): ResultPreview {
@ -811,9 +811,6 @@ export class DataProviderComponent {
}
public getTypeName(): string {
if(this.type === "service") {
return this.openaireEntities.SERVICE;
}
return this.openaireEntities.DATASOURCE;
return StringUtils.getEntityName(this.type, false);
}
}

View File

@ -275,21 +275,7 @@ export class ProjectComponent {
}
public getFileNameType(type: string) {
if(type == "publications") {
// return OpenaireEntities.PUBLICATIONS.replace(" ", "-");
return OpenaireEntities.PUBLICATIONS_FILE;
} else if(type == "datasets") {
// return OpenaireEntities.DATASETS.replace(" ", "-");
return OpenaireEntities.DATASETS_FILE;
} else if(type == "software") {
// return OpenaireEntities.SOFTWARE.replace(" ", "-");
return OpenaireEntities.SOFTWARE_FILE;
} else if(type == "other") {
// return OpenaireEntities.OTHER.replace(" ", "-");
return OpenaireEntities.OTHER_FILE;
}
// return OpenaireEntities.RESULTS.replace(" ", "-");
return OpenaireEntities.RESULTS_FILE;
return StringUtils.getEntityFileName(type);
}
public getCsvParams(type: string) {

View File

@ -336,15 +336,7 @@ export class ResultLandingComponent {
public getTypeName(): string {
if (this.type === "dataset") {
return this.openaireEntities.DATASET;
} else if (this.type === "orp" || this.type === "other") {
return this.openaireEntities.OTHER_SINGULAR;
} else if(this.type === "publication") {
return this.openaireEntities.PUBLICATION;
} else if(this.type === "software") {
return this.openaireEntities.SOFTWARE_SINGULAR;
}
return StringUtils.getEntityName(this.type, false);
}
public removeUnknown(array: string[], type: boolean = false): string[] {
@ -521,15 +513,7 @@ export class ResultLandingComponent {
}else if(err.name == "TimeoutError"){
this.errorMessage = 'An error occurred please try again later';
}else{
if (this.type == "publication") {
this.errorMessage = "No "+ this.openaireEntities.PUBLICATION +" found";
} else if (this.type == "software") {
this.errorMessage = 'No ' + this.openaireEntities.SOFTWARE_SINGULAR + ' found';
} else if (this.type == "dataset") {
this.errorMessage += "No "+this.openaireEntities.DATASET+" found";
} else if (this.type == "orp") {
this.errorMessage += "No "+this.openaireEntities.OTHER_SINGULAR+" found";
}
this.errorMessage = "No " + this.getTypeName() + " found";
this.seoService.createLinkForCanonicalURL(this.properties.domain+ properties.baseLink + this.linkToSearchPage);
}
this.showLoading = false;
@ -661,17 +645,7 @@ export class ResultLandingComponent {
}
private handleError(message: string, error) {
if (this.type == "publication") {
console.error(this.openaireEntities.PUBLICATION+" Landing Page: " + message, error);
} else if (this.type == "dataset") {
console.error(this.openaireEntities.DATASET+" Landing Page: " + message, error);
} else if (this.type == "software") {
console.error(this.openaireEntities.SOFTWARE_SINGULAR+" Landing Page: " + message, error);
} else if (this.type == "orp") {
console.error(this.openaireEntities.OTHER_SINGULAR+" Landing Page: " + message, error);
} else {
console.error(this.openaireEntities.RESULT+" Landing Page: " + message, error);
}
console.error(this.getTypeName() + " Landing Page: " + message, error);
}
isRouteAvailable(routeToCheck: string) {

View File

@ -415,16 +415,7 @@ export class MyOrcidLinksComponent {
}
public getEntityName(entityType: string, plural: boolean): string {
if (entityType == "publication") {
return plural ? this.openaireEntities.PUBLICATIONS : this.openaireEntities.PUBLICATION;
} else if (entityType == "dataset") {
return plural ? this.openaireEntities.DATASETS : this.openaireEntities.DATASET;
} else if (entityType == "software") {
return plural ? this.openaireEntities.SOFTWARE : this.openaireEntities.SOFTWARE_SINGULAR;
} else if (entityType == "other") {
return plural ? this.openaireEntities.OTHER : this.openaireEntities.OTHER_SINGULAR;
}
return plural ? this.openaireEntities.RESULTS : this.openaireEntities.RESULT;
return StringUtils.getEntityName(entityType, plural);
}
public pageChanged($event) {

View File

@ -11,6 +11,7 @@ import {NewSearchPageComponent, SearchForm} from "./searchUtils/newSearchPage.co
import {RangeFilter} from "../utils/rangeFilter/rangeFilterHelperClasses.class";
import {properties} from "../../../environments/environment";
import {ContextsService} from "../claims/claim-utils/service/contexts.service";
import {StringUtils} from "../utils/string-utils.class";
@Component({
selector: 'search-research-results',
@ -437,28 +438,10 @@ export class SearchResearchResultsComponent {
}
public getEntityName(entityType: string, plural: boolean, full: boolean): string {
if (entityType == "publication") {
return plural ? this.openaireEntities.PUBLICATIONS : this.openaireEntities.PUBLICATION;
} else if (entityType == "dataset") {
return plural ? this.openaireEntities.DATASETS : this.openaireEntities.DATASET;
} else if (entityType == "software") {
return plural ? this.openaireEntities.SOFTWARE : this.openaireEntities.SOFTWARE_SINGULAR;
} else if (entityType == "other") {
return plural ? this.openaireEntities.OTHER : this.openaireEntities.OTHER_SINGULAR;
}
return plural ? this.openaireEntities.RESULTS : this.openaireEntities.RESULT;
return StringUtils.getEntityName(entityType, plural);
}
public getEntityFileName(entityType: string) {
if(entityType == "publication") {
return this.openaireEntities.PUBLICATIONS_FILE;
} else if (entityType == "dataset") {
return this.openaireEntities.DATASETS_FILE;
} else if (entityType == "software") {
return this.openaireEntities.SOFTWARE_FILE;
} else if (entityType == "other") {
return this.openaireEntities.OTHER_FILE;
}
return this.openaireEntities.RESULTS_FILE;
return StringUtils.getEntityFileName(entityType);
}
}

View File

@ -5,7 +5,7 @@ import {RouterHelper} from "../routerHelper.class";
import {AlertModal} from "../modal/alert";
import {properties} from "../../../../environments/environment";
import {Session} from "../../login/utils/helper.class";
import {Identifier} from "../string-utils.class";
import {Identifier, StringUtils} from "../string-utils.class";
import {OpenaireEntities} from "../properties/searchFields";
@Component({
@ -129,23 +129,7 @@ export class ResultPreviewComponent implements OnInit, OnChanges {
}
public getTypeName(type: string): string {
if (type === "dataset") {
return this.openaireEntities.DATASET;
} else if (type === "other") {
return this.openaireEntities.OTHER_SINGULAR;
} else if (type === "dataprovider") {
return this.openaireEntities.DATASOURCE;
} else if (type === "service") {
return this.openaireEntities.SERVICE;
} else if (type === "publication") {
return this.openaireEntities.PUBLICATION;
} else if (type === "software") {
return this.openaireEntities.SOFTWARE_SINGULAR;
} else if (type === "result") {
return this.openaireEntities.RESULT;
} else {
return type;
}
return StringUtils.getEntityName(type, false);
}
public removeUnknown(array: string[]): string[] {

View File

@ -3,7 +3,7 @@ import {AbstractControl, FormGroup, ValidationErrors, ValidatorFn, Validators} f
import {Stakeholder} from "../monitor/entities/stakeholder";
import {CommunityInfo} from "../connect/community/communityInfo";
import {properties} from "../../../environments/environment";
import {Page} from "./entities/adminTool/page";
import {OpenaireEntities} from "./properties/searchFields";
export class Dates {
public static yearMin = 1800;
@ -444,4 +444,53 @@ export class StringUtils {
return ((yearFrom && yearTo && enabled && (yearFrom.value == "" || yearTo.value == "")) ? { 'rangeRequired': true } : null);
};
}
public static getEntityName(entityType: string, plural: boolean = false): string {
if (entityType == "publication") {
return plural ? OpenaireEntities.PUBLICATIONS : OpenaireEntities.PUBLICATION;
} else if (entityType == "dataset") {
return plural ? OpenaireEntities.DATASETS : OpenaireEntities.DATASET;
} else if (entityType == "software") {
return plural ? OpenaireEntities.SOFTWARE : OpenaireEntities.SOFTWARE_SINGULAR;
} else if (entityType == "other" || entityType == "orp") {
return plural ? OpenaireEntities.OTHER : OpenaireEntities.OTHER_SINGULAR;
} else if (entityType == "result") {
return plural ? OpenaireEntities.RESULTS : OpenaireEntities.RESULT;
} else if (entityType == "project") {
return plural ? OpenaireEntities.PROJECTS : OpenaireEntities.PROJECT;
} else if (entityType == "organization") {
return plural ? OpenaireEntities.ORGANIZATIONS : OpenaireEntities.ORGANIZATION;
} else if (entityType == "dataprovider") {
return plural ? OpenaireEntities.DATASOURCES : OpenaireEntities.DATASOURCE;
} else if (entityType == "service") {
return plural ? OpenaireEntities.SERVICES : OpenaireEntities.SERVICE;
} else if (entityType == "community") {
return plural ? OpenaireEntities.COMMUNITIES : OpenaireEntities.COMMUNITY;
}
return entityType;
}
public static getEntityFileName(entityType: string): string {
if (entityType == "publication" || entityType == "publications") {
return OpenaireEntities.PUBLICATIONS_FILE;
} else if (entityType == "dataset" || entityType == "datasets") {
return OpenaireEntities.DATASETS_FILE;
} else if (entityType == "software") {
return OpenaireEntities.SOFTWARE_FILE;
} else if (entityType == "other" || entityType == "orp") {
return OpenaireEntities.OTHER_FILE;
} else if (entityType == "result" || entityType == "results") {
return OpenaireEntities.RESULTS_FILE;
} else if (entityType == "project" || entityType == "projects") {
return OpenaireEntities.PROJECTS_FILE;
} else if (entityType == "organization" || entityType == "organizations") {
return OpenaireEntities.ORGANIZATIONS_FILE;
} else if (entityType == "dataprovider" || entityType == "dataproviders" || entityType == "datasource" || entityType == "datasources") {
return OpenaireEntities.DATASOURCES_FILE;
} else if (entityType == "service" || entityType == "services") {
return OpenaireEntities.SERVICES_FILE;
}
return entityType.toLowerCase().replace(" ", "-");
}
}

View File

@ -2,6 +2,7 @@ import {Component, Input} from '@angular/core';
import {EnvProperties} from "../../properties/env-properties";
import {ErrorCodes} from "../../properties/errorCodes";
import {OpenaireEntities} from "../../properties/searchFields";
import {StringUtils} from "../../string-utils.class";
@Component({
selector: 'search-tab',
@ -63,22 +64,6 @@ export class SearchTabComponent {
public errorCodes: ErrorCodes = new ErrorCodes();
public getEntityName(entityType: string): string {
if (entityType == "publication") {
return OpenaireEntities.PUBLICATIONS;
} else if (entityType == "dataset") {
return OpenaireEntities.DATASETS;
} else if (entityType == "software") {
return OpenaireEntities.SOFTWARE;
} else if (entityType == "other") {
return OpenaireEntities.OTHER;
} else if (entityType == "result") {
return OpenaireEntities.RESULTS;
} else if (entityType == "project") {
return OpenaireEntities.PROJECTS;
} else if (entityType == "dataprovider") {
return OpenaireEntities.DATASOURCES;
} else if (this.resultType) {
return this.resultType;
}
return StringUtils.getEntityName(entityType, true);
}
}