@@ -35,59 +35,60 @@ 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 } = {
51- id : dataSet [ "id" ] ,
52- name : dataSet [ "name" ] ,
53- version : dataSet [ "version" ] ,
54- type : dataSet [ "type" ] ,
55- contentType : dataSet [ "contenttype" ]
48+ for ( const dataset of datasets ) {
49+ const properties : { [ key : string ] : string ; } = {
50+ id : dataset [ "id" ] ,
51+ name : dataset [ "name" ] ,
52+ version : dataset [ "version" ] ,
53+ type : dataset [ "type" ] ,
54+ contentType : dataset [ "contenttype" ]
55+ }
56+ const assetId = dataset [ "@id" ] ;
57+
58+ const hasPolicy = dataset [ "odrl:hasPolicy" ] ;
59+ const policy : PolicyInput = {
60+ "@type" : "set" ,
61+ "@context" : "http://www.w3.org/ns/odrl.jsonld" ,
62+ "uid" : hasPolicy [ "@id" ] ,
63+ "assignee" : hasPolicy [ "assignee" ] ,
64+ "assigner" : hasPolicy [ "assigner" ] ,
65+ "obligation" : hasPolicy [ "odrl:obligations" ] ,
66+ "permission" : hasPolicy [ "odrl:permissions" ] ,
67+ "prohibition" : hasPolicy [ "odrl:prohibitions" ] ,
68+ "target" : hasPolicy [ "odrl:target" ]
5669 } ;
5770
58- const assetId = dataSet [ "@id" ] ;
59- const hasPolicy = dataSet [ "odrl:hasPolicy" ] ;
60-
61-
62-
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- } ) ;
71+ const newContractOffer : ContractOffer = {
72+ assetId : assetId ,
73+ properties : properties ,
74+ "dcat:service" : catalog [ "dcat:service" ] ,
75+ "dcat:dataset" : datasets ,
76+ id : hasPolicy [ "@id" ] ,
77+ originator : catalog [ "originator" ] ,
78+ policy : policy
79+ } ;
8780
81+ arr . push ( newContractOffer )
82+ }
8883 return arr ;
89- } )
90- ) ;
84+ } ) ) , reduce ( ( acc , val ) => {
85+ for ( const subArray of val ) {
86+ for ( const item of subArray ) {
87+ acc . push ( item ) ;
88+ }
89+ }
90+ return acc ;
91+ } , new Array < ContractOffer > ( ) ) ) ;
9192 }
9293
9394 initiateTransfer ( transferRequest : TransferProcessInput ) : Observable < string > {
@@ -110,16 +111,8 @@ export class CatalogBrowserService {
110111 params ?: HttpParams | { [ param : string ] : string | number | boolean | ReadonlyArray < string | number | boolean > ; } )
111112 : Observable < T > {
112113 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- } ;
120114 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' ) ;
115+ return this . catchError ( this . httpClient . post < T > ( url , "{\"edc:operandLeft\": \"\",\"edc:operandRight\": \"\",\"edc:operator\": \"\",\"edc:Criterion\":\"\"}" , { headers, params} ) , url , 'POST' ) ;
123116 }
124117
125118 private catchError < T > ( observable : Observable < T > , url : string , method : string ) : Observable < T > {
0 commit comments