@@ -101,84 +101,83 @@ public static void main(String[] args) {
101101 additionalHeaderField .put ("data-partition-id" , "osdu" ); // Example for OSDU RDDMS
102102 initializationParams .setAdditionalHandshakeHeaderFields (additionalHeaderField );
103103
104- ClientSession clientSession = fetpapi .createClientSession (initializationParams , authorization );
105- clientSession .setCoreProtocolHandlers (new CoreHandlers (clientSession ));
106- clientSession .setDataspaceProtocolHandlers (new DataspaceHandlers (clientSession ));
107- clientSession .setDiscoveryProtocolHandlers (new DiscoveryHandlers (clientSession ));
108- clientSession .setStoreProtocolHandlers (new StoreHandlers (clientSession ));
109- clientSession .setDataArrayProtocolHandlers (new DataArrayHandlers (clientSession ));
110- new Thread (clientSession ::run ).start ();
111- long start = System .currentTimeMillis ();
112- while (clientSession .isEtpSessionClosed () && System .currentTimeMillis () - start < 5000 ) {
113- TimeUnit .MILLISECONDS .sleep (1 );
114- }
115- if (clientSession .isEtpSessionClosed ()) {
116- System .err .println ("The ETP session cound not be establisehd in 5 seconds." );
117- return ;
118- }
119- System .out .println ("Now connected to ETP Server" );
120- // ****** We are now connected to ETP server through clientSession ******
121- // Set the HDF proxy factory in order to use one compliant with ETP
122- repo .setHdfProxyFactory (new FesapiHdfProxyFactory (clientSession ));
123-
124- // ****** Get a dataspace content. This corresponds to getting the content of an EPC file ******
125- // Find an available ETP dataspace
126- DataspaceVector allDataspaces = clientSession .getDataspaces ();
127- Optional <Dataspace > dataspace = allDataspaces .stream ().findAny ();
128- if (dataspace .isEmpty ()) {
129- clientSession .close ();
130- System .err .println ("The ETP server has no dataspace." );
131- return ;
132- }
133- System .out .println ("Working on dataspace " + dataspace .get ().getUri ());
134- // List resources of this ETP dataspace
135- ContextInfo etpContext = new ContextInfo ();
136- etpContext .setUri (dataspace .get ().getUri ());
137- etpContext .setDepth (1 );
138- ResourceVector allResources = clientSession .getResources (etpContext , ContextScopeKind .self );
139- if (allResources .isEmpty ()) {
140- clientSession .close ();
141- System .err .println ("The ETP dataspace has no resource." );
142- return ;
143- }
144- // Get dataobjects from the resources to the DataObjectRepository
145- MapStringString uriMap = new MapStringString ();
146- long index = 0 ;
147- for (Resource resource : allResources ) {
148- uriMap .put (Long .toString (index ++), resource .getUri ());
149- }
150- MapStringDataObject allDataObjects = clientSession .getDataObjects (uriMap );
151- for (DataObject dataObject : allDataObjects .values ()) {
152- repo .addOrReplaceGsoapProxy (dataObject .getData (), fetpapi .getDataObjectType (dataObject .getResource ().getUri ()), fetpapi .getDataspaceUri (dataObject .getResource ().getUri ()));
153- }
154- // ****** We have now in the DataObjectRepository the same content as if we would have deserialized and EPC file looking like the dataspace ******
155-
156- // ****** Use the DataObjectRepository exactly as you are used to do with FESAPI ******
157- if (repo .getIjkGridRepresentationCount () > 0 ) {
158- IjkGridExplicitRepresentation ijkGrid = repo .getIjkGridExplicitRepresentation (0 );
159- ijkGrid .loadSplitInformation ();
160- long originIndex = ijkGrid .getXyzPointIndexFromCellCorner (0 , 0 , 0 , 0 );
161- System .out .println ("The index of the grid origin in XYZ points is : " + originIndex );
162- ijkGrid .unloadSplitInformation ();
163- if (ijkGrid .getValuesPropertyCount () > 0 ) {
164- AbstractValuesProperty prop = ijkGrid .getValuesProperty (0 );
165- SWIGTYPE_p_double propValues = fesapi .new_DoubleArray (prop .getValuesCountOfPatch (0 ));
166- try {
167- prop .getDoubleValuesOfPatch (0 , propValues );
168- System .out .println ("The first cell value of prop " + prop .getTitle () + " is " + fesapi .DoubleArray_getitem (propValues , 0 ));
169- }
170- finally {
171- fesapi .delete_DoubleArray (propValues );
104+ try (ClientSession clientSession = fetpapi .createClientSession (initializationParams , authorization )) {
105+ clientSession .setCoreProtocolHandlers (new CoreHandlers (clientSession ));
106+ clientSession .setDataspaceProtocolHandlers (new DataspaceHandlers (clientSession ));
107+ clientSession .setDiscoveryProtocolHandlers (new DiscoveryHandlers (clientSession ));
108+ clientSession .setStoreProtocolHandlers (new StoreHandlers (clientSession ));
109+ clientSession .setDataArrayProtocolHandlers (new DataArrayHandlers (clientSession ));
110+ new Thread (clientSession ::run ).start ();
111+ long start = System .currentTimeMillis ();
112+ while (clientSession .isEtpSessionClosed () && System .currentTimeMillis () - start < 5000 ) {
113+ TimeUnit .MILLISECONDS .sleep (1 );
114+ }
115+ if (clientSession .isEtpSessionClosed ()) {
116+ System .err .println ("The ETP session cound not be establisehd in 5 seconds." );
117+ return ;
118+ }
119+ System .out .println ("Now connected to ETP Server" );
120+ // ****** We are now connected to ETP server through clientSession ******
121+ // Set the HDF proxy factory in order to use one compliant with ETP
122+ repo .setHdfProxyFactory (new FesapiHdfProxyFactory (clientSession ));
123+
124+ // ****** Get a dataspace content. This corresponds to getting the content of an EPC file ******
125+ // Find an available ETP dataspace
126+ DataspaceVector allDataspaces = clientSession .getDataspaces ();
127+ Optional <Dataspace > dataspace = allDataspaces .stream ().findAny ();
128+ if (dataspace .isEmpty ()) {
129+ clientSession .close ();
130+ System .err .println ("The ETP server has no dataspace." );
131+ return ;
132+ }
133+ System .out .println ("Working on dataspace " + dataspace .get ().getUri ());
134+ // List resources of this ETP dataspace
135+ ContextInfo etpContext = new ContextInfo ();
136+ etpContext .setUri (dataspace .get ().getUri ());
137+ etpContext .setDepth (1 );
138+ ResourceVector allResources = clientSession .getResources (etpContext , ContextScopeKind .self );
139+ if (allResources .isEmpty ()) {
140+ clientSession .close ();
141+ System .err .println ("The ETP dataspace has no resource." );
142+ return ;
143+ }
144+ // Get dataobjects from the resources to the DataObjectRepository
145+ MapStringString uriMap = new MapStringString ();
146+ long index = 0 ;
147+ for (Resource resource : allResources ) {
148+ uriMap .put (Long .toString (index ++), resource .getUri ());
149+ }
150+ MapStringDataObject allDataObjects = clientSession .getDataObjects (uriMap );
151+ for (DataObject dataObject : allDataObjects .values ()) {
152+ repo .addOrReplaceGsoapProxy (dataObject .getData (), fetpapi .getDataObjectType (dataObject .getResource ().getUri ()), fetpapi .getDataspaceUri (dataObject .getResource ().getUri ()));
153+ }
154+ // ****** We have now in the DataObjectRepository the same content as if we would have deserialized and EPC file looking like the dataspace ******
155+
156+ // ****** Use the DataObjectRepository exactly as you are used to do with FESAPI ******
157+ if (repo .getIjkGridExplicitRepresentationCount () > 0 ) {
158+ IjkGridExplicitRepresentation ijkGrid = repo .getIjkGridExplicitRepresentation (0 );
159+ ijkGrid .loadSplitInformation ();
160+ long originIndex = ijkGrid .getXyzPointIndexFromCellCorner (0 , 0 , 0 , 0 );
161+ System .out .println ("The index of the grid origin in XYZ points is : " + originIndex );
162+ ijkGrid .unloadSplitInformation ();
163+ if (ijkGrid .getValuesPropertyCount () > 0 ) {
164+ AbstractValuesProperty prop = ijkGrid .getValuesProperty (0 );
165+ SWIGTYPE_p_double propValues = fesapi .new_DoubleArray (prop .getValuesCountOfPatch (0 ));
166+ try {
167+ prop .getDoubleValuesOfPatch (0 , propValues );
168+ System .out .println ("The first cell value of prop " + prop .getTitle () + " is " + fesapi .DoubleArray_getitem (propValues , 0 ));
169+ }
170+ finally {
171+ fesapi .delete_DoubleArray (propValues );
172+ }
172173 }
173174 }
175+ else {
176+ System .out .println ("This dataspace has no IJK Grid" );
177+ }
178+
179+ System .out .println ("Closing the session thanks to AutoCloseable..." );
174180 }
175- else {
176- System .out .println ("This dataspace has no IJK Grid" );
177- }
178-
179- // Do not forget to close session once you have processed all the dataobject repository.
180- System .out .println ("Closing the session..." );
181- clientSession .close ();
182181 } catch (InterruptedException e ) {
183182 e .printStackTrace ();
184183 }
0 commit comments