@@ -804,6 +804,62 @@ class Connection {
804
804
return await pg . describeUserProcess ( ) ;
805
805
}
806
806
807
+ isOgcProcess ( process ) {
808
+ let nodes = Object . values ( process . process_graph ) ;
809
+ return Boolean ( nodes . find ( node => {
810
+ let process = this . processes . get ( node . process_id ) ;
811
+ return Utils . isObject ( process ) && Boolean ( process . ogcapi ) ;
812
+ } ) ) ;
813
+ }
814
+
815
+ async executeOgcProcess ( process , abortController = null ) {
816
+ if ( Utils . size ( process . process_graph ) !== 1 ) {
817
+ throw new Error ( 'Synchronous execution with OGC API - Processes only supports one process at at time.' ) ;
818
+ }
819
+ let requestBody = this . _normalizeUserProcess (
820
+ process ,
821
+ {
822
+ plan : plan ,
823
+ budget : budget
824
+ }
825
+ ) ;
826
+ let response = await this . _post ( '/result' , requestBody , Environment . getResponseType ( ) , abortController ) ;
827
+ let syncResult = {
828
+ data : response . data ,
829
+ costs : null ,
830
+ type : null ,
831
+ logs : [ ]
832
+ } ;
833
+
834
+ if ( typeof response . headers [ 'openeo-costs' ] === 'number' ) {
835
+ syncResult . costs = response . headers [ 'openeo-costs' ] ;
836
+ }
837
+
838
+ if ( typeof response . headers [ 'content-type' ] === 'string' ) {
839
+ syncResult . type = response . headers [ 'content-type' ] ;
840
+ }
841
+
842
+ let links = Array . isArray ( response . headers . link ) ? response . headers . link : [ response . headers . link ] ;
843
+ for ( let link of links ) {
844
+ if ( typeof link !== 'string' ) {
845
+ continue ;
846
+ }
847
+ let logs = link . match ( / ^ < ( [ ^ > ] + ) > ; \s ? r e l = " m o n i t o r " / i) ;
848
+ if ( Array . isArray ( logs ) && logs . length > 1 ) {
849
+ try {
850
+ let logsResponse = await this . _get ( logs [ 1 ] ) ;
851
+ if ( Utils . isObject ( logsResponse . data ) && Array . isArray ( logsResponse . data . logs ) ) {
852
+ syncResult . logs = logsResponse . data . logs ;
853
+ }
854
+ } catch ( error ) {
855
+ console . warn ( error ) ;
856
+ }
857
+ }
858
+ }
859
+
860
+ return syncResult ;
861
+ }
862
+
807
863
/**
808
864
* Executes a process synchronously and returns the result as the response.
809
865
*
@@ -824,6 +880,9 @@ class Connection {
824
880
budget : budget
825
881
}
826
882
) ;
883
+ if ( isOgcProcess ( requestBody . process ) ) {
884
+ return this . executeOgcProcess ( process , abortController ) ;
885
+ }
827
886
let response = await this . _post ( '/result' , requestBody , Environment . getResponseType ( ) , abortController ) ;
828
887
let syncResult = {
829
888
data : response . data ,
0 commit comments