@@ -35,59 +35,61 @@ export class CatalogBrowserService {
3535 @Inject ( CONNECTOR_CATALOG_API ) private catalogApiUrl : string ) {
3636 }
3737
38- getContractOffersFromConnector ( ) : Observable < ContractOffer [ ] > {
38+ getContractOffers ( ) : Observable < ContractOffer [ ] > {
3939 let url = this . catalogApiUrl || this . managementApiUrl ;
40- return this . post < Catalog > ( url + "/v2/catalog/request" ) . pipe (
41- map ( catalog => {
42- const arr : ContractOffer [ ] = [ ] ;
43- let datasets = catalog [ "dcat:dataset" ] ;
44-
40+ return this . post < Catalog [ ] > ( url )
41+ . pipe ( map ( catalogs => catalogs . map ( catalog => {
42+ const arr = Array < ContractOffer > ( ) ;
43+ let datasets = catalog [ "http://www.w3.org/ns/dcat#dataset" ] ;
4544 if ( ! Array . isArray ( datasets ) ) {
4645 datasets = [ datasets ] ;
4746 }
4847
49- datasets . forEach ( dataSet => {
50- const properties : { [ key : string ] : string } = {
48+ for ( let i = 0 ; i < datasets . length ; i ++ ) {
49+ const dataSet : any = datasets [ i ] ;
50+ const properties : { [ key : string ] : string ; } = {
5151 id : dataSet [ "id" ] ,
5252 name : dataSet [ "name" ] ,
5353 version : dataSet [ "version" ] ,
5454 type : dataSet [ "type" ] ,
5555 contentType : dataSet [ "contenttype" ]
56- } ;
57-
56+ }
5857 const assetId = dataSet [ "@id" ] ;
59- const hasPolicy = dataSet [ "odrl:hasPolicy" ] ;
60-
6158
59+ const hasPolicy = dataSet [ "odrl:hasPolicy" ] ;
60+ const policy : PolicyInput = {
61+ "@type" : "set" ,
62+ "@context" : "http://www.w3.org/ns/odrl.jsonld" ,
63+ "uid" : hasPolicy [ "@id" ] ,
64+ "assignee" : hasPolicy [ "assignee" ] ,
65+ "assigner" : hasPolicy [ "assigner" ] ,
66+ "obligation" : hasPolicy [ "odrl:obligations" ] ,
67+ "permission" : hasPolicy [ "odrl:permissions" ] ,
68+ "prohibition" : hasPolicy [ "odrl:prohibitions" ] ,
69+ "target" : hasPolicy [ "odrl:target" ]
70+ } ;
6271
63- hasPolicy . forEach ( ( element : PolicyElement ) => {
64- const policy : PolicyInput = {
65- "@type" : "set" ,
66- "@context" : "http://www.w3.org/ns/odrl.jsonld" ,
67- "uid" : element [ "@id" ] ,
68- "assignee" : element [ "assignee" ] ,
69- "assigner" : element [ "assigner" ] ,
70- "obligation" : element [ "odrl:obligations" ] ,
71- "permission" : element [ "odrl:permissions" ] ,
72- "prohibition" : element [ "odrl:prohibitions" ] ,
73- "target" : element [ "odrl:target" ]
74- } ;
75-
76- const newContractOffer : ContractOffer = {
77- assetId : assetId ,
78- properties : properties ,
79- id : hasPolicy [ "@id" ] ,
80- originator : catalog [ "edc:originator" ] ?? catalog [ "dcat:service" ] [ "endpointUrl" ] ,
81- policy : policy
82- } ;
83-
84- arr . push ( newContractOffer ) ;
85- } ) ;
86- } ) ;
72+ const newContractOffer : ContractOffer = {
73+ assetId : assetId ,
74+ properties : properties ,
75+ "dcat:service" : catalog [ "dcat:service" ] ,
76+ "dcat:dataset" : datasets ,
77+ id : hasPolicy [ "@id" ] ,
78+ originator : catalog [ "originator" ] ,
79+ policy : policy
80+ } ;
8781
82+ arr . push ( newContractOffer )
83+ }
8884 return arr ;
89- } )
90- ) ;
85+ } ) ) , reduce ( ( acc , val ) => {
86+ for ( let i = 0 ; i < val . length ; i ++ ) {
87+ for ( let j = 0 ; j < val [ i ] . length ; j ++ ) {
88+ acc . push ( val [ i ] [ j ] ) ;
89+ }
90+ }
91+ return acc ;
92+ } , new Array < ContractOffer > ( ) ) ) ;
9193 }
9294
9395 initiateTransfer ( transferRequest : TransferProcessInput ) : Observable < string > {
@@ -110,16 +112,8 @@ export class CatalogBrowserService {
110112 params ?: HttpParams | { [ param : string ] : string | number | boolean | ReadonlyArray < string | number | boolean > ; } )
111113 : Observable < T > {
112114 const url = `${ urlPath } ` ;
113- const fetchCatalogData = {
114- "@context" : {
115- "@vocab" : "https://w3id.org/edc/v0.0.1/ns/"
116- } ,
117- "counterPartyAddress" : "http://localhost:19194/protocol" ,
118- "protocol" : "dataspace-protocol-http"
119- } ;
120115 let headers = new HttpHeaders ( { "Content-type" : "application/json" } ) ;
121- //return this.catchError(this.httpClient.post<T>(url, "{\"edc:operandLeft\": \"\",\"edc:operandRight\": \"\",\"edc:operator\": \"\",\"edc:Criterion\":\"\"}", {headers, params}), url, 'POST');
122- return this . catchError ( this . httpClient . post < T > ( url , fetchCatalogData , { headers, params} ) , url , 'POST' ) ;
116+ return this . catchError ( this . httpClient . post < T > ( url , "{\"edc:operandLeft\": \"\",\"edc:operandRight\": \"\",\"edc:operator\": \"\",\"edc:Criterion\":\"\"}" , { headers, params} ) , url , 'POST' ) ;
123117 }
124118
125119 private catchError < T > ( observable : Observable < T > , url : string , method : string ) : Observable < T > {
0 commit comments