@ -17,34 +17,35 @@ import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
import { Option } from "../openaireLibrary/sharedComponents/input/input.component" ;
import { Session } from "../openaireLibrary/login/utils/helper.class" ;
import { HelperFunctions } from "../openaireLibrary/utils/HelperFunctions.class" ;
import { properties } from "../../environments/environment" ;
export class StakeholderUtils {
statuses : Option [ ] = [
{ value : 'PUBLIC' , label : 'Public' } ,
{ value : 'RESTRICTED' , label : 'Restricted' } ,
{ value : 'PRIVATE' , label : 'Private' }
] ;
types : Option [ ] = [
{ value : 'funder' , label : StakeholderEntities.FUNDER } ,
{ value : 'ri' , label : StakeholderEntities.RI } ,
{ value : 'project' , label : StakeholderEntities.PROJECT } ,
{ value : 'organization' , label : StakeholderEntities.ORGANIZATION }
] ;
visibility : Option [ ] = [
{ icon : 'earth' , value : "PUBLIC" , label : 'Public' } ,
{ icon : 'restricted' , value : "RESTRICTED" , label : 'Restricted' } ,
{ icon : 'incognito' , value : "PRIVATE" , label : 'Private' } ,
] ;
visibilityIcon : Map < Visibility , string > = new Map < Visibility , string > ( [
[ "PUBLIC" , 'earth' ] ,
[ "PRIVATE" , 'incognito' ] ,
[ "RESTRICTED" , 'restricted' ]
] ) ;
getTypesByUserRoles ( user , id : string = null ) : Option [ ] {
let types = [ ] ;
for ( let type of this . types ) {
@ -54,27 +55,27 @@ export class StakeholderUtils {
}
return types ;
}
public createFunderFromDefaultProfile ( funder : Stakeholder , defaultTopics : Topic [ ] , isDefault : boolean = false ) : Stakeholder {
funder . topics = HelperFunctions . copy ( defaultTopics ) ;
for ( let topic of funder . topics ) {
topic . defaultId = ! isDefault ?topic._id:null ;
topic . defaultId = ! isDefault ? topic._id : null ;
topic . _id = null ;
for ( let category of topic . categories ) {
category . defaultId = ! isDefault ?category._id:null ;
category . defaultId = ! isDefault ? category._id : null ;
category . _id = null ;
let subTokeep : SubCategory [ ] = [ ] ;
for ( let subCategory of category . subCategories ) {
subCategory . defaultId = ! isDefault ?subCategory._id:null ;
subCategory . defaultId = ! isDefault ? subCategory._id : null ;
subCategory . _id = null ;
subTokeep . push ( subCategory ) ;
for ( let section of subCategory . charts ) {
let chartsTokeep : Indicator [ ] = [ ] ;
section . defaultId = ! isDefault ?section._id:null ;
section . defaultId = ! isDefault ? section._id : null ;
section . stakeholderAlias = funder . alias ;
section . _id = null ;
for ( let indicator of section . indicators ) {
indicator . defaultId = ! isDefault ?indicator._id:null ;
indicator . defaultId = ! isDefault ? indicator._id : null ;
indicator . _id = null ;
chartsTokeep . push ( indicator ) ;
for ( let indicatorPath of indicator . indicatorPaths ) {
@ -94,22 +95,22 @@ export class StakeholderUtils {
section . indicators = chartsTokeep ;
}
for ( let section of subCategory . numbers ) {
section . defaultId = ! isDefault ?section._id:null ;
section . defaultId = ! isDefault ? section._id : null ;
section . stakeholderAlias = funder . alias ;
section . _id = null ;
for ( let indicator of section . indicators ) {
indicator . defaultId = ! isDefault ?indicator._id:null ;
indicator . defaultId = ! isDefault ? indicator._id : null ;
indicator . _id = null ;
}
}
}
category . subCategories = subTokeep ;
}
}
return funder ;
}
aliasValidatorString ( elements : string [ ] ) : ValidatorFn {
return ( control : AbstractControl ) : { [ key : string ] : string } | null = > {
if ( control . value && elements . find ( element = >
@ -120,7 +121,7 @@ export class StakeholderUtils {
return null ;
}
}
aliasValidator ( elements : any [ ] ) : ValidatorFn {
return ( control : AbstractControl ) : { [ key : string ] : string } | null = > {
if ( control . value && elements . find ( element = >
@ -131,7 +132,7 @@ export class StakeholderUtils {
return null ;
}
}
generateAlias ( name : string ) : string {
let alias = name . toLowerCase ( ) ;
while ( alias . includes ( '/' ) || alias . includes ( ' ' ) ) {
@ -144,7 +145,7 @@ export class StakeholderUtils {
}
export class IndicatorUtils {
allChartTypes : Option [ ] = [
{ value : 'pie' , label : 'Pie' } ,
{ value : 'table' , label : 'Table' } ,
@ -160,27 +161,88 @@ export class IndicatorUtils {
{ value : 'medium' , label : 'Medium' } ,
{ value : 'large' , label : 'Large' }
] ;
allSourceTypes : Option [ ] = [
{ value : 'search' , label : 'Search' } ,
{ value : 'statistics' , label : 'Statistics' } ,
{ value : 'stats-tool' , label : 'Statistics tool' }
] ;
formats : Option [ ] = [
{ value : "NUMBER" , label : "Number" } ,
{ value : "PERCENTAGE" , label : "Percentage" }
] ;
sourceTypes : Option [ ] = [
{ value : 'stats-tool' , label : 'Statistics tool' }
] ;
isActive : Option [ ] = [
{ icon : 'brightness_1' , iconClass : '' , value : true , label : 'Active' } ,
{ icon : 'brightness_1' , value : false , label : 'Inactive' } ,
] ;
parametersValidators : Map < string , any > = new Map < string , any > ( [
[ 'start_year' , [ Validators . required , Validators . pattern ( '^\\d+$' ) ] ] ,
[ 'end_year' , [ Validators . required , Validators . pattern ( '^\\d+$' ) ] ]
] ) ;
ignoredParameters = [ 'index_name' , 'index_id' , 'index_shortName' ] ;
statsProfileParameter = 'profile' ;
numberSources : Map < SourceType , string [ ] > = new Map < SourceType , string [ ] > ( ) ;
chartSources : Map < SourceType , string [ ] > = new Map < SourceType , string [ ] > ( ) ;
constructor ( ) {
this . numberSources . set ( 'statistics' , [ properties . statisticsAPIURL ] ) ;
this . numberSources . set ( 'search' , [ properties . searchAPIURLLAst ] ) ;
this . numberSources . set ( 'stats-tool' , [ properties . monitorStatsFrameUrl , "http://marilyn.athenarc.gr:8080/stats-api/" , "http://88.197.53.71:8080/stats-api/" , "https://stats.madgik.di.uoa.gr/stats-api/" , "https://beta.services.openaire.eu/stats-tool/" , "https://services.openaire.eu/stats-tool/" , "https://services.openaire.eu/monitor-stats-tool/" ] ) ;
this . chartSources . set ( 'stats-tool' , [ properties . monitorStatsFrameUrl , "http://marilyn.athenarc.gr:8080/stats-api/" , "http://88.197.53.71:8080/stats-api/" , "https://stats.madgik.di.uoa.gr/stats-api/" , "https://beta.services.openaire.eu/stats-tool/" , "https://services.openaire.eu/stats-tool/" , "https://services.openaire.eu/monitor-stats-tool/" ] ) ;
this . chartSources . set ( 'old' , [ properties . statisticsFrameAPIURL ] ) ;
this . chartSources . set ( 'image' , [ "" ] ) ;
}
getSourceType ( source :string ) : SourceType {
let sourceType : SourceType = 'search' ;
this . numberSources . forEach ( ( values , key ) = > {
if ( key == source ) {
sourceType = key ;
}
} ) ;
return sourceType ;
}
getChartUrl ( source : SourceType , url : string ) : string {
return this . chartSources . get ( source ) [ 0 ] + url ;
}
getNumberUrl ( source : string , url : string ) : string {
return this . numberSources . get ( this . getSourceType ( source ) ) [ 0 ] + url ;
}
getNumberSource ( url : string ) : SourceType {
let source : SourceType = 'search' ;
this . numberSources . forEach ( ( values , key ) = > {
values . forEach ( ( value ) = > {
if ( value !== '' && url . indexOf ( value ) !== - 1 ) {
source = key ;
}
} ) ;
} ) ;
return source ;
}
getChartSource ( url : string ) : SourceType {
let source : SourceType = 'image' ;
this . chartSources . forEach ( ( values , key ) = > {
values . forEach ( ( value ) = > {
if ( value !== '' && url . indexOf ( value ) !== - 1 ) {
source = key ;
}
} ) ;
} ) ;
return source ;
}
getChartTypes ( initialType ) {
let types : Option [ ] = [ ] ;
if ( this . basicChartTypes . indexOf ( initialType ) != - 1 ) {
@ -201,15 +263,7 @@ export class IndicatorUtils {
return this . allChartTypes ;
}
}
ignoredParameters = [ 'index_name' , 'index_id' , 'index_shortName' ] ;
statsProfileParameter = 'profile' ;
parametersValidators : Map < string , any > = new Map < string , any > ( [
[ 'start_year' , [ Validators . required , Validators . pattern ( '^\\d+$' ) ] ] ,
[ 'end_year' , [ Validators . required , Validators . pattern ( '^\\d+$' ) ] ]
] ) ;
public getFullUrl ( stakeholder : Stakeholder , indicatorPath : IndicatorPath , fundingL0 : string = null , startYear : string = null , endYear : string = null ) : string {
let replacedUrl = indicatorPath . chartObject ? indicatorPath.chartObject : indicatorPath.url ;
if ( stakeholder . statsProfile ) {
@ -233,7 +287,7 @@ export class IndicatorUtils {
if ( key == "index_shortName" ) {
replacedValue = stakeholder . index_shortName . toLowerCase ( ) ;
}
replacedUrl = replacedUrl . split ( ChartHelper . prefix + key + ChartHelper . suffix ) . join ( replacedValue )
} ) ;
}
@ -251,7 +305,7 @@ export class IndicatorUtils {
}
if ( startYear && indicatorPath . filters [ "start_year" ] ) {
let newJsonObject = JSON . parse ( replacedUrl ) ;
for ( let queries of this . getQueryObjectName ( newJsonObject ) ? newJsonObject [ this . getDescriptionObjectName ( newJsonObject ) ] [ this . getQueryObjectName ( newJsonObject ) ] : newJsonObject [ this . getDescriptionObjectName ( newJsonObject ) ] ) {
if ( ! queries [ "query" ] [ "filters" ] || queries [ "query" ] [ "filters" ] . length == 0 ) {
queries [ "query" ] [ "filters" ] = [ ] ;
@ -272,7 +326,7 @@ export class IndicatorUtils {
}
replacedUrl = JSON . stringify ( newJsonObject ) ;
}
}
//For numbers (e.g. from stats-api , search service, etc)
if ( indicatorPath . url . indexOf ( ChartHelper . prefix + 'index_id' + ChartHelper . suffix ) != - 1 ) {
@ -286,7 +340,7 @@ export class IndicatorUtils {
}
return ( indicatorPath . chartObject ? indicatorPath . url + encodeURIComponent ( replacedUrl ) : replacedUrl ) ;
}
public getFullUrlWithFilters ( stakeholder : Stakeholder , indicatorPath : IndicatorPath , fundingL0 : string = null , startYear : string = null , endYear : string = null , coFunded : boolean = false ) : string {
indicatorPath . filtersApplied = 0 ;
let replacedUrl = indicatorPath . chartObject ? indicatorPath.chartObject : indicatorPath.url ;
@ -315,7 +369,7 @@ export class IndicatorUtils {
if ( key == "index_shortName" ) {
replacedValue = stakeholder . index_shortName . toLowerCase ( ) ;
}
replacedUrl = replacedUrl . split ( ChartHelper . prefix + key + ChartHelper . suffix ) . join ( replacedValue )
} ) ;
}
@ -347,7 +401,7 @@ export class IndicatorUtils {
indicatorPath . filtersApplied += filterResults . filtersApplied ;
}
}
//For numbers
if ( replacedUrl . indexOf ( ChartHelper . prefix + 'index_id' + ChartHelper . suffix ) != - 1 ) {
replacedUrl = replacedUrl . split ( ChartHelper . prefix + 'index_id' + ChartHelper . suffix ) . join ( encodeURIComponent ( stakeholder . index_id ) )
@ -360,9 +414,9 @@ export class IndicatorUtils {
}
//Check apply enhancements return this.applySchemaEnhancements( ..);
return ( indicatorPath . chartObject ? indicatorPath . url + encodeURIComponent ( replacedUrl ) : replacedUrl ) ;
}
private addFilter ( replacedUrl , filterType : FilterType , filterValue ) {
let newJsonObject = JSON . parse ( replacedUrl ) ;
let filterApplied : boolean = false ;
@ -370,7 +424,7 @@ export class IndicatorUtils {
for ( let queries of this . getQueryObjectName ( newJsonObject ) ? newJsonObject [ this . getDescriptionObjectName ( newJsonObject ) ] [ this . getQueryObjectName ( newJsonObject ) ] : newJsonObject [ this . getDescriptionObjectName ( newJsonObject ) ] ) {
/*Chart with Named Queries*/
if ( queries [ "query" ] [ "name" ] && ! queries [ "query" ] [ "select" ] ) {
if ( queries [ "query" ] [ "name" ] . indexOf ( "monitor." ) == - 1 || ! queries [ "query" ] [ "parameters" ] ) {
continue ;
}
@ -481,7 +535,7 @@ export class IndicatorUtils {
}
return { "url" : JSON . stringify ( newJsonObject ) , "filtersApplied" : ( filterApplied ) ? 1 : 0 } ;
}
isComparingChart ( newJsonObject , filter , ) {
let queriesCount = this . getQueryObjectName ( newJsonObject ) ? newJsonObject [ this . getDescriptionObjectName ( newJsonObject ) ] [ this . getQueryObjectName ( newJsonObject ) ] . length : newJsonObject [ this . getDescriptionObjectName ( newJsonObject ) ] . length ;
let values = [ ] ;
@ -498,7 +552,7 @@ export class IndicatorUtils {
}
return values . length > 1 ;
}
generateIndicatorByForm ( form : any , indicatorPaths : IndicatorPath [ ] , type : IndicatorType , addParameters : boolean = true ) : Indicator {
let indicator : Indicator = new Indicator ( form . name , form . description , form . additionalDescription , type ,
form . width , form . height , form . visibility , indicatorPaths , form . defaultId ) ;
@ -517,7 +571,7 @@ export class IndicatorUtils {
} ) ;
return indicator ;
}
generateIndicatorByNumberUrl ( source : SourceType , url : string , stakeholder : Stakeholder , jsonPath = [ ] , sourceServices : string [ ] = [ ] ) : IndicatorPath {
let indicatorPath = new IndicatorPath ( null , source , url , null , jsonPath ) ;
if ( source === 'stats-tool' ) {
@ -555,7 +609,7 @@ export class IndicatorUtils {
}
return indicatorPath ;
}
generateIndicatorByChartUrl ( source : SourceType , url : string , type : IndicatorPathType = null , stakeholder : Stakeholder ) : IndicatorPath {
let indicatorPath = new IndicatorPath ( type , source , null , null , [ ] ) ;
try {
@ -565,13 +619,13 @@ export class IndicatorUtils {
indicatorPath . chartObject = decodeURIComponent ( url . split ( "json=" ) [ 1 ] ) ;
let chart = JSON . parse ( indicatorPath . chartObject ) ;
if ( indicatorPath . url == "chart?json=" ) {
if ( chart [ "library" ] && ( chart [ "library" ] == "HighCharts" || chart [ "library" ] == "eCharts" || chart [ "library" ] == "HighMaps" ) ) {
indicatorPath . type = this . extractType ( chart , indicatorPath ) ;
} else {
indicatorPath . type = this . defaultChartType ;
}
this . extractTitle ( chart , indicatorPath ) ;
this . extractSubTitle ( chart , indicatorPath ) ;
this . extractXTitle ( chart , indicatorPath ) ;
@ -611,7 +665,7 @@ export class IndicatorUtils {
}
return indicatorPath ;
}
private getQueryObjectName ( obj ) {
if ( ( obj [ this . getDescriptionObjectName ( obj ) ] ) . hasOwnProperty ( "queriesInfo" ) ) {
return "queriesInfo" ;
@ -619,7 +673,7 @@ export class IndicatorUtils {
return "queries" ;
}
}
private getDescriptionObjectName ( obj ) {
if ( obj . hasOwnProperty ( "mapDescription" ) ) {
return "mapDescription" ;
@ -631,7 +685,7 @@ export class IndicatorUtils {
return "series" ;
}
}
private extractType ( obj , indicatorPath : IndicatorPath ) : IndicatorPathType {
let type = ( obj [ this . getDescriptionObjectName ( obj ) ] && obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] [ 0 ] [ "type" ] ) ? obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] [ 0 ] [ "type" ] : "" ;
if ( this . basicChartTypes . indexOf ( type ) == - 1 ) {
@ -642,13 +696,13 @@ export class IndicatorUtils {
}
return type ;
}
private extractStakeHolders ( obj , indicatorPath : IndicatorPath , stakeholder : Stakeholder ) {
this . extractFunder ( obj , indicatorPath , stakeholder ) ;
this . extractRI ( obj , indicatorPath , stakeholder ) ;
this . extractOrganization ( obj , indicatorPath , stakeholder ) ;
}
private extractFunder ( obj , indicatorPath : IndicatorPath , stakeholder : Stakeholder ) {
if ( stakeholder . type != "funder" ) {
return ;
@ -677,7 +731,7 @@ export class IndicatorUtils {
}
}
}
private extractRI ( obj , indicatorPath : IndicatorPath , stakeholder : Stakeholder ) {
if ( stakeholder . type != "ri" ) {
return ;
@ -702,7 +756,7 @@ export class IndicatorUtils {
}
}
}
private extractOrganization ( obj , indicatorPath : IndicatorPath , stakeholder : Stakeholder ) {
// works for publication.project.organization.name
// and publication.organization.name
@ -729,7 +783,7 @@ export class IndicatorUtils {
}
}
}
private extractStartYear ( obj , indicatorPath : IndicatorPath ) {
let start_year ;
for ( let query of obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] ) {
@ -747,7 +801,7 @@ export class IndicatorUtils {
}
}
}
private extractEndYear ( obj , indicatorPath : IndicatorPath ) {
let end_year ;
for ( let query of obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] ) {
@ -765,7 +819,7 @@ export class IndicatorUtils {
}
}
}
private parameterizeDefaultQuery ( obj , indicatorPath : IndicatorPath , stakeholder : Stakeholder ) {
let name = "" ;
for ( let query of this . getQueryObjectName ( obj ) ? obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] : obj [ this . getDescriptionObjectName ( obj ) ] ) {
@ -787,7 +841,7 @@ export class IndicatorUtils {
} else if ( name . split ( '.' ) [ 0 ] == "monitor" && parameters . length > 0 && name . split ( '.' ) [ 1 ] == stakeholder . type ) {
// new parameterized queries
//monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}} --> params [start year, end year, id, result type, fl0]
let index = ( name . split ( '.' ) . slice ( 3 ) . length + 2 == parameters . length ) ? [ 2 ] : ( ( name . split ( '.' ) . slice ( 3 ) . length * 2 + 4 == parameters . length ) ? [ 2 , name . split ( '.' ) . slice ( 3 ) . length + 4 ] : [ 0 ] ) ;
for ( let i of index ) {
if ( name . split ( '.' ) . length > 3 && name . split ( '.' ) [ 3 ] == "id" ) {
@ -805,7 +859,7 @@ export class IndicatorUtils {
}
}
}
private extractDataTitle ( obj , indicatorPath : IndicatorPath ) {
let index = 0 ;
if ( ! obj [ this . getDescriptionObjectName ( obj ) ] || ! obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] ) {
@ -820,7 +874,7 @@ export class IndicatorUtils {
index ++ ;
}
}
private extractTitle ( obj , indicatorPath : IndicatorPath ) {
let title = "" ;
if ( obj [ this . getDescriptionObjectName ( obj ) ] [ "title" ] ) {
@ -832,7 +886,7 @@ export class IndicatorUtils {
}
indicatorPath . parameters [ "title" ] = title ? title : "" ;
}
private extractSubTitle ( obj , indicatorPath : IndicatorPath ) {
let subtitle = "" ;
if ( obj [ this . getDescriptionObjectName ( obj ) ] [ "subtitle" ] ) {
@ -845,7 +899,7 @@ export class IndicatorUtils {
indicatorPath . parameters [ "subtitle" ] = subtitle ? subtitle : "" ;
}
}
private extractXTitle ( obj , indicatorPath : IndicatorPath ) {
let title = "" ;
if ( obj [ this . getDescriptionObjectName ( obj ) ] [ "xAxis" ] && obj [ this . getDescriptionObjectName ( obj ) ] [ "xAxis" ] [ "title" ] ) {
@ -860,7 +914,7 @@ export class IndicatorUtils {
}
indicatorPath . parameters [ "xAxisTitle" ] = title ? title : "" ;
}
private extractYTitle ( obj , indicatorPath : IndicatorPath ) {
let title = "" ;
if ( obj [ this . getDescriptionObjectName ( obj ) ] [ "yAxis" ] && obj [ this . getDescriptionObjectName ( obj ) ] [ "yAxis" ] [ "title" ] ) {
@ -875,17 +929,17 @@ export class IndicatorUtils {
}
indicatorPath . parameters [ "yAxisTitle" ] = title ? title : "" ;
}
private extractOldToolTitle ( obj , indicatorPath : IndicatorPath ) {
let title = "" ;
if ( obj [ "title" ] ) {
title = obj [ "title" ] ;
obj [ "title" ] = ChartHelper . prefix + "title" + ChartHelper . suffix ;
indicatorPath . parameters [ "title" ] = title ;
}
}
private extractOldToolXTitle ( obj , indicatorPath : IndicatorPath ) {
let title = "" ;
if ( obj [ "xaxistitle" ] ) {
@ -894,7 +948,7 @@ export class IndicatorUtils {
indicatorPath . parameters [ "xAxisTitle" ] = title ;
}
}
private extractOldToolYTitle ( obj , indicatorPath : IndicatorPath ) {
let title = "" ;
if ( obj [ "fieldsheaders" ] ) {
@ -907,11 +961,11 @@ export class IndicatorUtils {
indicatorPath . parameters [ "yAxisTitle" ] = title ;
}
}
public checkForSchemaEnhancements ( url : string ) : boolean {
return url != this . applySchemaEnhancements ( url ) ;
}
public applySchemaEnhancements ( url : string ) : string {
let resultEnhancements = [
[ ".project.acronym" , ".project acronym" ] ,
@ -930,7 +984,7 @@ export class IndicatorUtils {
}
}
}
if ( url . split ( 'json=' ) . length > 1 ) {
let obj = JSON . parse ( decodeURIComponent ( url . split ( 'json=' ) [ 1 ] ) ) ;
for ( let query of this . getQueryObjectName ( obj ) ? obj [ this . getDescriptionObjectName ( obj ) ] [ this . getQueryObjectName ( obj ) ] : obj [ this . getDescriptionObjectName ( obj ) ] ) {