Skip to content

Commit

Permalink
Merge pull request #23 from F2I-Consulting/dev
Browse files Browse the repository at this point in the history
v0.3.0.0
  • Loading branch information
philippeVerney authored Sep 16, 2024
2 parents f206630 + 8844b1c commit ff3cac4
Show file tree
Hide file tree
Showing 43 changed files with 6,079 additions and 566 deletions.
212 changes: 132 additions & 80 deletions .github/workflows/github-actions.yml

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
/swig/swigGeneratedJavaWrapper.cpp
/swig/swigGeneratedJavaWrapper.h

## Ignore python swig generated files
/swig/swigGeneratedPythonWrapper.cpp
/swig/swigGeneratedPythonWrapper.h

## Ignore Visual Studio Code files
##
## Get latest from https://github.com/github/gitignore/blob/master/Global/VisualStudioCode.gitignore
Expand Down
75 changes: 44 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.12)
if (WIN32)
cmake_minimum_required(VERSION 3.21)
else ()
cmake_minimum_required(VERSION 3.12)
endif (WIN32)

project(Fetpapi)

Expand All @@ -11,7 +15,7 @@ set (FETPAPI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

# version mechanism
set (Fetpapi_VERSION_MAJOR 0)
set (Fetpapi_VERSION_MINOR 2)
set (Fetpapi_VERSION_MINOR 3)
set (Fetpapi_VERSION_PATCH 0)
set (Fetpapi_VERSION_TWEAK 0)

Expand Down Expand Up @@ -98,7 +102,7 @@ find_package (Threads)
# Boost DEPENDENCY
find_package(Boost 1.70)
if (NOT Boost_FOUND)
# Boost system is required for Beast untill version 1.70 : https://www.boost.org/doc/libs/1_69_0/libs/beast/doc/html/beast/introduction.html
# Boost system is required for Beast until version 1.70 : https://www.boost.org/doc/libs/1_69_0/libs/beast/doc/html/beast/introduction.html
find_package(Boost 1.66 REQUIRED system)
endif()
if (WIN32 AND (Boost_VERSION_MAJOR EQUAL 1) AND (Boost_VERSION_MINOR LESS 74) AND (Boost_VERSION_MINOR GREATER 71))
Expand Down Expand Up @@ -147,6 +151,10 @@ if (WITH_ETP_SSL)
find_package(OpenSSL REQUIRED)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
# OpenSSL::applink is recommended under MSVC : https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::applink)
endif ()
endif ()

if (WITH_FESAPI)
Expand Down Expand Up @@ -182,41 +190,21 @@ endif (WITH_PYTHON_WRAPPING)
# Getting source files
# ============================================================================

file (GLOB FETPAPI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/*.cpp)
file (GLOB FETPAPI_PROTOCOL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/ProtocolHandlers/*.cpp)
file (GLOB FETPAPI_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/*.h)
file (GLOB FETPAPI_PROTOCOL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/ProtocolHandlers/*.h)
file (GLOB FETPAPI_TOOLS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/tools/*.cpp)
file (GLOB FETPAPI_TOOLS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/tools/*.h)
include(${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists.txt)
set (ALL_SOURCES_AND_HEADERS
${ALL_SOURCES_AND_HEADERS}
${FETPAPI_SOURCES}
${FETPAPI_PROTOCOL_SOURCES}
${FETPAPI_HEADERS}
${FETPAPI_PROTOCOL_SOURCES}
${FETPAPI_PROTOCOL_HEADERS}
${FETPAPI_TOOLS_HEADERS}
${FETPAPI_TOOLS_SOURCES}
${FETPAPI_FESAPI_SOURCES}
${FETPAPI_FESAPI_HEADERS}
${FETPAPI_SSL_SOURCES}
${FETPAPI_SSL_HEADERS}
)

if (WITH_ETP_SSL)
file (GLOB FETPAPI_SSL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/ssl/*.cpp)
file (GLOB FETPAPI_SSL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/ssl/*.h)

set (ALL_SOURCES_AND_HEADERS
${ALL_SOURCES_AND_HEADERS}
${FETPAPI_SSL_SOURCES}
${FETPAPI_SSL_HEADERS}
)
endif (WITH_ETP_SSL)

if (WITH_FESAPI)
file (GLOB FETPAPI_FESAPI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/fesapi/*.cpp)
file (GLOB FETPAPI_FESAPI_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/etp/fesapi/*.h)
set (ALL_SOURCES_AND_HEADERS
${ALL_SOURCES_AND_HEADERS}
${FETPAPI_FESAPI_SOURCES}
${FETPAPI_FESAPI_HEADERS}
)
target_include_directories(${PROJECT_NAME} PRIVATE ${FESAPI_INCLUDE_DIR})
endif (WITH_FESAPI)

Expand All @@ -233,7 +221,7 @@ target_include_directories(${PROJECT_NAME} INTERFACE

# organizing sources and headers in the Visual Studio Project
if (WIN32)
source_group ("tools" FILES ${FETPAPI_TOOLS_SOURCES} ${FETPAPI_TOOLS_HEADERS})
source_group ("tools" FILES ${FETPAPI_TOOLS_HEADERS})

set (ETP_PREFIX "etp")
source_group ("${ETP_PREFIX}" FILES ${FETPAPI_SOURCES} ${FETPAPI_HEADERS})
Expand Down Expand Up @@ -339,4 +327,29 @@ if (WITH_FESAPI)
endif (WITH_FESAPI)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetpapiConfig.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Fetpapi")
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Fetpapi")

if (WITH_PYTHON_WRAPPING)
IF (WIN32)
install (
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_CURRENT_LIST_DIR}/python/fetpapi/
)
install(
TARGETS ${PROJECT_NAME}
RUNTIME_DEPENDENCY_SET dep-set
)
cmake_path(GET SSL_EAY_RELEASE PARENT_PATH openSslLibPath)
cmake_path(GET openSslLibPath PARENT_PATH openSslPath)
cmake_path(APPEND openSslPath "bin" OUTPUT_VARIABLE openSslBinPath)
install(
RUNTIME_DEPENDENCY_SET dep-set
PRE_EXCLUDE_REGEXES "api-ms-.*" "ext-ms-.*" "[Ff]esapi[Cc]pp.*\\.dll"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
DIRECTORIES ${openSslBinPath}
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/python/fetpapi/
)
ENDIF (WIN32)
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/python/setup.py bdist_wheel
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python)")
endif (WITH_PYTHON_WRAPPING)
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

# Prepare your build environment
- Create a folder called fesapiEnv.
- Create a folder called fetpapiEnv.
- In this folder create the three following folders
- build
- fetpapi (Git clone this repository into this folder "fetpapi". You should then have a path fesapiEnv/fetpapi/src)
- fetpapi (Git clone this repository into this folder "fetpapi". You should then have a path fetpapiEnv/fetpapi/src)
- dependencies
- The following compilers are known to work (used in CI)
- gcc from version 4.8
Expand All @@ -15,22 +15,19 @@ Download (build and install if necessary) third party libraries:
- (OPTIONALLY) OpenSSL : version 1.1 is known to work.
- (OPTIONALLY) [FESAPI](https://github.com/F2I-Consulting/fesapi/releases) : All versions from version 2.7.0.0 should be ok.

We advise you to install these third party libraries respectively into
- fesapiEnv/dependencies/boost-particularVersion
- fesapiEnv/dependencies/avro-particularVersion
# Configure the build
FETPAPI uses cmake as its build tool. A 3.12 version or later of cmake is required https://cmake.org/download/. We also recommend using cmake-gui (already included in the bin folder of the binary releases of cmake) which provides a graphical user interface on top of cmake. If you want to use cmake in command line, you would find example in [Github Actions file](./.github/workflows/github-actions.yml). Follow the below instructions :

- yourPath/fesapiEnv/fetpapi defines where is the source code folder
- yourPath/fesapiEnv/build/theNameYouWant defines where to build the binaries
- yourPath/fetpapiEnv/fetpapi defines where is the source code folder
- yourPath/fetpapiEnv/build/theNameYouWant defines where to build the binaries
- Click on "Configure" button and select your favorite compiler : it will raise several errors.
- give real path and files to the following cmake variables:
- BOOST
- Boost_INCLUDE_DIR : the directory where you can find the directory named "boost" which contain all BOOST headers
- AVRO (using [our own cmake find module](./cmake/modules/FindAVRO.cmake))
- (ONLY IF NOT AUTOMATICALLY FOUND) AVRO_ROOT : The path to the folder containing include and lib folders of AVRO
- Click again on "Configure" button. You should no more have errors so you can now click on "Generate" button.
- You can now build your solution with your favorite compiler (and linker) using the generated solution in yourPath/fesapiEnv/build/theNameYouWant
- You can now build your solution with your favorite compiler (and linker) using the generated solution in yourPath/fetpapiEnv/build/theNameYouWant
- OPTIONALLY, you can also set the variables WITH_DOTNET_WRAPPING, WITH_PYTHON_WRAPPING to true if you want to also generate wrappers on top of FETPAPI for these two other programming languages. Don't forget to click again on "Configure" button once you changed the value of these two variables.
- You will then have to also provide the path to the SWIG (version 3 as a mininum version) executable http://swig.org/download.html in the SWIG_EXECUTABLE variable (and click again on "Configure" button)
- you will find the wrappers in fetpapi/cs/src (fetpapi/cs also contains a VS2015 project for the wrappers) or fetpapi/python/src
Expand All @@ -44,9 +41,9 @@ FETPAPI uses cmake as its build tool. A 3.12 version or later of cmake is requir
Remark : you can choose where FETPAPI will be installed (using "make install" on Linux or by generating the "INSTALL" project on Visual Studio) by setting the cmake variable called CMAKE_INSTALL_PREFIX
# How to start
As a first way to start, we advise people to look at examples provided with FESAPI. Please give a look at:
- C++ : client ([here](https://github.com/F2I-Consulting/fetpapiClient)) and server ([here](https://github.com/F2I-Consulting/fetpapiServer)) examples.
- C++ : [in example/withFesapi/etpClient.cpp](./example/withFesapi/etpClient.cpp) or [in example/withoutFesapi/etpClient.cpp](./example/withoutFesapi/etpClient.cpp)
- C# : client ([here](https://github.com/F2I-Consulting/fetpapiClient/tree/main/cs)) : FetpapiClient.cs will be generated by cmake configuration when WITH_DOTNET_WRAPPING is ON, the source file is initially located in ([cmake/Program.cs](https://github.com/F2I-Consulting/fetpapiClient/blob/main/cmake/FetpapiClient.cs.in))
- Java (JDK 1.5 and later) : client ([here](https://github.com/F2I-Consulting/fetpapiClient/tree/main/java))
- Java (JDK 1.5 and later) : in java/src/com/f2i_consulting/example/FetpapiClientUsingFesapi.java (FetpapiClientUsingFesapi.java will be generated by cmake configuration when WITH_JAVA_WRAPPING is ON, the source file is initially located [in cmake/FetpapiClientUsingFesapi.java](./cmake/FetpapiClientUsingFesapi.java))
- Python3 (no support for Python2) : in ([python/example/example.py](https://github.com/F2I-Consulting/fetpapiClient/tree/main/python/src/etp_client_example.py)) (please follow instructions in the documentation header of this example python file)

You can also find Doxygen generated documentation [here](https://f2i-consulting.com/fetpapi/doxygen/)
Expand Down
188 changes: 188 additions & 0 deletions cmake/FetpapiClientUsingFesapi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*-----------------------------------------------------------------------
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"; you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-----------------------------------------------------------------------*/
package com.f2i_consulting.fetpapi.client;

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import com.f2i_consulting.fesapi.SWIGTYPE_p_double;
import com.f2i_consulting.fesapi.fesapi;
import com.f2i_consulting.fesapi.common.DataObjectRepository;
import com.f2i_consulting.fesapi.resqml2.AbstractValuesProperty;
import com.f2i_consulting.fesapi.resqml2.IjkGridExplicitRepresentation;
import com.f2i_consulting.fetpapi.DataspaceVector;
import com.f2i_consulting.fetpapi.MapStringDataObject;
import com.f2i_consulting.fetpapi.MapStringString;
import com.f2i_consulting.fetpapi.ResourceVector;
import com.f2i_consulting.fetpapi.fetpapi;
import com.f2i_consulting.fetpapi.Energistics.Etp.v12.Datatypes.Object.ContextInfo;
import com.f2i_consulting.fetpapi.Energistics.Etp.v12.Datatypes.Object.ContextScopeKind;
import com.f2i_consulting.fetpapi.Energistics.Etp.v12.Datatypes.Object.DataObject;
import com.f2i_consulting.fetpapi.Energistics.Etp.v12.Datatypes.Object.Dataspace;
import com.f2i_consulting.fetpapi.Energistics.Etp.v12.Datatypes.Object.Resource;
import com.f2i_consulting.fetpapi.etp.ClientSession;
import com.f2i_consulting.fetpapi.etp.CoreHandlers;
import com.f2i_consulting.fetpapi.etp.DataArrayHandlers;
import com.f2i_consulting.fetpapi.etp.DataspaceHandlers;
import com.f2i_consulting.fetpapi.etp.DiscoveryHandlers;
import com.f2i_consulting.fetpapi.etp.FesapiHdfProxyFactory;
import com.f2i_consulting.fetpapi.etp.InitializationParameters;
import com.f2i_consulting.fetpapi.etp.StoreHandlers;

public class FetpapiClientUsingFesapi {

/**
* Loading the FesapiCpp and Fetpapi native libraries
*/
static {
try {
System.loadLibrary("${FESAPI_ASSEMBLY_NAME}");
}
catch (UnsatisfiedLinkError e) {
System.out.println("UnsatisfiedLinkError : " + e.toString());
}
try {
System.loadLibrary("${ASSEMBLY_NAME}");
}
catch (UnsatisfiedLinkError e) {
System.out.println("UnsatisfiedLinkError : " + e.toString());
}
}

public static void main(String[] args) {
// Read arguments of the command line
String serverUrl = "ws://etp.f2i-consulting.com:9002/";
String authorization = "";

if (args.length < 1) {
System.out.println("Program arguments should be : serverUrl \"<BearerOrBasic> <token>\"");
System.out.println("WARNING : you did not provide a server URL. The URL will be defaulted to ws://etp.f2i-consulting.com:9002/");
}
else {
serverUrl = args[0];
if (args.length < 2) {
System.out.println("Program arguments should be : serverUrl \"Bearer <token>\"");
System.out.println("WARNING : You did not provide any authorizaton after the URL. Please see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization for further details");
}
else {
if (!args[1].startsWith("Basic ") && !args[1].startsWith("Bearer ")) {
System.out.println("WARNING : HTTP authorization \"" + args[3] + "\" field does not start with \"Basic \" nor \"Bearer \" which is unlikely");
}
authorization = args[1];
}
}

// Create a DataObjectRepository in order to store retrieved dataobjects from the ETP server
try (DataObjectRepository repo = new DataObjectRepository()) {
repo.setDefaultStandard(DataObjectRepository.EnergisticsStandard.RESQML2_0_1);
repo.setDefaultStandard(DataObjectRepository.EnergisticsStandard.EML2_0);

// ****** Connect to ETP server through clientSession ******
String instanceUuid = UUID.randomUUID().toString();
InitializationParameters initializationParams = new InitializationParameters(instanceUuid, serverUrl);
MapStringString additionalHeaderField = new MapStringString();
additionalHeaderField.put("data-partition-id", "osdu"); // Example for OSDU RDDMS
initializationParams.setAdditionalHandshakeHeaderFields(additionalHeaderField);

ClientSession clientSession = fetpapi.createClientSession(initializationParams, authorization);
clientSession.setCoreProtocolHandlers(new CoreHandlers(clientSession));
clientSession.setDataspaceProtocolHandlers(new DataspaceHandlers(clientSession));
clientSession.setDiscoveryProtocolHandlers(new DiscoveryHandlers(clientSession));
clientSession.setStoreProtocolHandlers(new StoreHandlers(clientSession));
clientSession.setDataArrayProtocolHandlers(new DataArrayHandlers(clientSession));
new Thread(clientSession::run).start();
long start = System.currentTimeMillis();
while (clientSession.isEtpSessionClosed() && System.currentTimeMillis() - start < 5000) {
TimeUnit.MILLISECONDS.sleep(1);
}
if (clientSession.isEtpSessionClosed()) {
System.err.println("The ETP session cound not be establisehd in 5 seconds.");
return;
}
System.out.println("Now connected to ETP Server");
// ****** We are now connected to ETP server through clientSession ******
// Set the HDF proxy factory in order to use one compliant with ETP
repo.setHdfProxyFactory(new FesapiHdfProxyFactory(clientSession));

// ****** Get a dataspace content. This corresponds to getting the content of an EPC file ******
// Find an available ETP dataspace
DataspaceVector allDataspaces = clientSession.getDataspaces();
Optional<Dataspace> dataspace = allDataspaces.stream().findAny();
if (dataspace.isEmpty()) {
clientSession.close();
System.err.println("The ETP server has no dataspace.");
return;
}
System.out.println("Working on dataspace " + dataspace.get().getUri());
// List resources of this ETP dataspace
ContextInfo etpContext = new ContextInfo();
etpContext.setUri(dataspace.get().getUri());
etpContext.setDepth(1);
ResourceVector allResources = clientSession.getResources(etpContext, ContextScopeKind.self);
if (allResources.isEmpty()) {
clientSession.close();
System.err.println("The ETP dataspace has no resource.");
return;
}
// Get dataobjects from the resources to the DataObjectRepository
MapStringString uriMap = new MapStringString();
long index = 0;
for (Resource resource : allResources) {
uriMap.put(Long.toString(index++), resource.getUri());
}
MapStringDataObject allDataObjects = clientSession.getDataObjects(uriMap);
for (DataObject dataObject : allDataObjects.values()) {
repo.addOrReplaceGsoapProxy(dataObject.getData(), fetpapi.getDataObjectType(dataObject.getResource().getUri()), fetpapi.getDataspaceUri(dataObject.getResource().getUri()));
}
// ****** We have now in the DataObjectRepository the same content as if we would have deserialized and EPC file looking like the dataspace ******

// ****** Use the DataObjectRepository exactly as you are used to do with FESAPI ******
if (repo.getIjkGridRepresentationCount() > 0) {
IjkGridExplicitRepresentation ijkGrid = repo.getIjkGridExplicitRepresentation(0);
ijkGrid.loadSplitInformation();
long originIndex = ijkGrid.getXyzPointIndexFromCellCorner(0, 0, 0, 0);
System.out.println("The index of the grid origin in XYZ points is : " + originIndex);
ijkGrid.unloadSplitInformation();
if (ijkGrid.getValuesPropertyCount() > 0) {
AbstractValuesProperty prop = ijkGrid.getValuesProperty(0);
SWIGTYPE_p_double propValues = fesapi.new_DoubleArray(prop.getValuesCountOfPatch(0));
try {
prop.getDoubleValuesOfPatch(0, propValues);
System.out.println("The first cell value of prop " + prop.getTitle() + " is " + fesapi.DoubleArray_getitem(propValues, 0));
}
finally {
fesapi.delete_DoubleArray(propValues);
}
}
}
else {
System.out.println("This dataspace has no IJK Grid");
}

// Do not forget to close session once you have processed all the dataobject repository.
System.out.println("Closing the session...");
clientSession.close();
} catch (InterruptedException e) {
e.printStackTrace();
}

System.out.println("FINISHED");
}
}
9 changes: 7 additions & 2 deletions cmake/modules/FindAVRO.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ set(_AVRO_SEARCH_NORMAL
unset(_AVRO_x86)
list(APPEND _AVRO_SEARCHES _AVRO_SEARCH_NORMAL)

set(AVRO_NAMES avrocpp avrocpp_s)
set(AVRO_NAMES_DEBUG avrod avrocpp_d avrocpp_s_d)
if(AVRO_USE_STATIC_LIBS)
set(AVRO_NAMES avrocpp_s)
set(AVRO_NAMES_DEBUG avrocpp_s_d)
else()
set(AVRO_NAMES avrocpp)
set(AVRO_NAMES_DEBUG avrod avrocpp_d)
endif()

# Try each search configuration.
foreach(search ${_AVRO_SEARCHES})
Expand Down
Loading

0 comments on commit ff3cac4

Please sign in to comment.