2017-12-19 13:53:46 +01:00
|
|
|
import {SearchProjectsService} from '../../services/searchProjects.service';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
2020-05-25 20:58:13 +02:00
|
|
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
2019-06-14 15:06:58 +02:00
|
|
|
import {SearchCustomFilter, SearchUtilsClass} from '../../searchPages/searchUtils/searchUtils.class';
|
2020-05-25 20:58:13 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2018-10-30 12:37:52 +01:00
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
2020-03-16 14:09:46 +01:00
|
|
|
import {SearchResult} from "../entities/searchResult";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
import {OpenaireEntities} from "../properties/searchFields";
|
2020-05-25 20:58:13 +02:00
|
|
|
|
|
|
|
export class FetchProjects {
|
2017-12-19 13:53:46 +01:00
|
|
|
private errorCodes: ErrorCodes;
|
2019-02-19 16:26:59 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2020-05-25 20:58:13 +02:00
|
|
|
|
|
|
|
public results: SearchResult[] = [];
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public filters; // for getResultsForOrganizations
|
2020-05-25 20:58:13 +02:00
|
|
|
public funders: any = []; // for getResultsForOrganizations // this is filled with the initial query - before filtering
|
2020-11-11 15:43:13 +01:00
|
|
|
|
|
|
|
subscriptions = [];
|
2020-05-25 20:58:13 +02:00
|
|
|
public searchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private _searchProjectsService: SearchProjectsService) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.errorCodes = new ErrorCodes();
|
2019-02-19 16:26:59 +01:00
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
2017-12-19 13:53:46 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2020-05-25 20:58:13 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
|
|
|
|
public clearSubscriptions() {
|
|
|
|
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-25 20:58:13 +02:00
|
|
|
public getResultsByKeyword(keyword: string, page: number, size: number, properties: EnvProperties, customFilter: SearchCustomFilter = null) {
|
2017-12-19 13:53:46 +01:00
|
|
|
var parameters = "";
|
2020-05-25 20:58:13 +02:00
|
|
|
if (keyword.length > 0) {
|
2018-10-30 12:37:52 +01:00
|
|
|
parameters = "q=" + StringUtils.URIEncode(keyword);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-25 20:58:13 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2019-06-14 15:06:58 +02:00
|
|
|
var refineParams = null;
|
2020-05-25 20:58:13 +02:00
|
|
|
if (customFilter) {
|
|
|
|
refineParams = (refineParams ? (refineParams + '&') : '') + "&fq=" + StringUtils.URIEncode(customFilter.queryFieldName + " exact " + StringUtils.quote((customFilter.valueId)));
|
2019-06-14 15:06:58 +02:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this._searchProjectsService.searchProjects(parameters, refineParams, page, size, [], properties).subscribe(
|
2020-05-25 20:58:13 +02:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if (this.searchUtils.totalResults == 0) {
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
/*console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
if(err.status == '404') {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}*/
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
this.handleError("Error getting "+OpenaireEntities.PROJECTS+" for keyword: " + keyword, err);
|
2020-05-25 20:58:13 +02:00
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-25 20:58:13 +02:00
|
|
|
|
|
|
|
public getResultsForDataproviders(id: string, page: number, size: number, properties: EnvProperties) {
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2020-11-11 15:43:13 +01:00
|
|
|
|
|
|
|
this.subscriptions.push(this._searchProjectsService.getProjectsforDataProvider(id, page, size, properties).subscribe(
|
2020-05-25 20:58:13 +02:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
this.results = data[1];
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if (this.searchUtils.totalResults == 0) {
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
/*console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
if(err.status == '404') {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}*/
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
this.handleError("Error getting "+OpenaireEntities.PROJECTS+" for "+OpenaireEntities.DATASOURCE+" with id: " + id, err);
|
2020-05-25 20:58:13 +02:00
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2020-05-25 20:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getNumForEntity(entity: string, id: string, properties: EnvProperties) {
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
|
|
|
if (id != "" && entity != "") {
|
2020-11-11 15:43:13 +01:00
|
|
|
|
|
|
|
this.subscriptions.push(this._searchProjectsService.numOfEntityProjects(id, entity, properties).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
2020-05-25 20:58:13 +02:00
|
|
|
this.searchUtils.totalResults = data;
|
|
|
|
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if (this.searchUtils.totalResults == 0) {
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
},
|
|
|
|
err => {
|
2020-05-25 20:58:13 +02:00
|
|
|
/*console.log(err);
|
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
//this.searchUtils.status = errorCodes.ERROR;
|
|
|
|
|
|
|
|
if(err.status == '404') {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
|
|
|
}*/
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
this.handleError("Error getting number of "+OpenaireEntities.PROJECTS+" for " + entity + " with id: " + id, err);
|
2020-05-25 20:58:13 +02:00
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2020-05-25 20:58:13 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-25 20:58:13 +02:00
|
|
|
|
|
|
|
public getResultsForOrganizations(organizationId: string, filterquery: string, page: number, size: number, refineFields: string[], properties: EnvProperties) {
|
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this._searchProjectsService.getProjectsForOrganizations(organizationId, filterquery, page, size, refineFields, properties).subscribe(
|
2020-05-25 20:58:13 +02:00
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0]; // the results can be filtered so this number can be no total results
|
|
|
|
this.results = data[1];
|
|
|
|
if (refineFields && refineFields.length > 0) {
|
|
|
|
this.filters = data[2];
|
|
|
|
filterquery = decodeURIComponent(filterquery);
|
|
|
|
for (var i = 0; i < this.filters.length; i++) {
|
|
|
|
if (filterquery.indexOf(this.filters[i].filterId) !== -1) {
|
|
|
|
//console.log("this.filters[i].filterId:"+this.filters[i].filterId);
|
|
|
|
for (var j = 0; j < this.filters[i].values.length; j++) {
|
|
|
|
//console.log("this.filters[i].values[j].id:"+this.filters[i].values[j].id);
|
|
|
|
if (filterquery.indexOf(this.filters[i].values[j].id) !== -1) {
|
|
|
|
this.filters[i].values[j].selected = true;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-07 10:57:55 +01:00
|
|
|
this.filters[i].countAllValues = this.filters[i].values.length;
|
2020-05-25 20:58:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filterquery == "") {
|
|
|
|
this.searchUtils.totalResultsNoFilters = this.searchUtils.totalResults;
|
|
|
|
this.funders = [];
|
|
|
|
for (var i = 0; i < this.filters.length; i++) {
|
|
|
|
//console.log("this.filters[i].filterId:"+this.filters[i].filterId);
|
|
|
|
if (this.filters[i].filterId == "funder") {
|
|
|
|
this.funders = (this.filters[i].values);
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2024-02-07 10:57:55 +01:00
|
|
|
this.filters[i].countAllValues = this.filters[i].values.length;
|
2020-05-25 20:58:13 +02:00
|
|
|
}
|
|
|
|
//console.log(" this.funders:"+ this.funders);
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-25 20:58:13 +02:00
|
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if (this.searchUtils.totalResults == 0) {
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
this.handleError("Error getting "+OpenaireEntities.PROJECTS+" for "+OpenaireEntities.ORGANIZATION+" with id: " + organizationId, err);
|
2020-05-25 20:58:13 +02:00
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-05-25 20:58:13 +02:00
|
|
|
|
2019-02-19 16:26:59 +01:00
|
|
|
private handleError(message: string, error) {
|
[Monitor Dashboard & Library | new-theme]: Renaming entity types using OpenaireEntities.
Files updated: develop.component.ts, methodology.component.ts, claimEntitiesSelection.component.ts, directLinking.component.ts, linkingGeneric.component.html, linkingGeneric.component.ts, approved.component.ts, searchDataprovidersToDeposit.component.ts, errorPage.component.ts, dataProvider.component.html, dataProvider.component.ts, dataProvider.service.ts, relatedDatasourcesTab.component.ts, project.component.ts, myOrcidLinks.component.ts, searchMyOrcidResults.component.html, searchMyOrcidResults.component.ts, searchAll.component.html, searchAll.component.ts, advancedSearchForm.component.html, advancedSearchForm.component.ts, searchDataProviders.component.ts, searchResearchResults.service.ts, numbers.component.ts, other-portals.component.html, other-portals.component.ts, fetchDataproviders.class.ts, fetchResearchResults.class.ts, searchFields.ts, result-preview.component.ts
2022-05-09 12:13:44 +02:00
|
|
|
console.error("Fetch "+OpenaireEntities.PROJECTS+" (class): " + message, error);
|
2019-02-19 16:26:59 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|