From 5dfb9e6d51fa910a897d927194db91e6d6784a11 Mon Sep 17 00:00:00 2001 From: valentin-gauthier-geosiris <88202743+valentin-gauthier-geosiris@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:44:45 +0100 Subject: [PATCH] bugfix for closed polylines (#30) bugfix for closed polylines --- .gitignore | 4 ++- .../java/com/geosiris/energyml/data/Mesh.java | 11 ++++-- .../com/geosiris/energyml/pkg/EPCPackage.java | 2 +- .../energyml/pkg/EpcHdf5FileManager.java | 32 ++++++++++++++--- .../utils/EnergymlWorkspaceHelper.java | 35 +++++++++++-------- .../energyml/utils/test/EPCPackageTest.java | 2 +- 6 files changed, 61 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 8b3dcf1..3f7461d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,6 @@ target/* pom-test.xml rc/*log4j2.properties logs -src/test/manip* \ No newline at end of file +src/test/manip* + +src/main/java/sample \ No newline at end of file diff --git a/src/main/java/com/geosiris/energyml/data/Mesh.java b/src/main/java/com/geosiris/energyml/data/Mesh.java index 77dc997..addf7dd 100644 --- a/src/main/java/com/geosiris/energyml/data/Mesh.java +++ b/src/main/java/com/geosiris/energyml/data/Mesh.java @@ -56,7 +56,11 @@ public static String meshNameMapping(String arrayTypeName) { public static List readMeshObject(Object energymlObject, EnergymlWorkspace workspace) throws InvocationTargetException, IllegalAccessException { if (energymlObject instanceof List) { - return (List) energymlObject; + List meshes = new ArrayList<>(); + for(var m: (List) energymlObject){ + meshes.addAll(readMeshObject(m, workspace)); + } + return meshes; } String arrayTypeName = meshNameMapping(energymlObject.getClass().getSimpleName()); @@ -219,13 +223,14 @@ public static List readPolylineRepresentation(Object energymlOb for (Long nbNode : nodeCountsList) { pointIndices.add(IntStream.range((int) idx, (int) idx + nbNode.intValue()) .boxed().map(Long::valueOf).collect(Collectors.toList())); - if (closePoly != null && closePoly.size() > polyIdx && closePoly.get(polyIdx) != null) { + if (closePoly != null && closePoly.size() > polyIdx && closePoly.get(polyIdx) != null && ((boolean)closePoly.get(polyIdx))) { pointIndices.get(pointIndices.size() - 1).add(idx); } idx += nbNode; polyIdx++; } - } catch (IndexOutOfBoundsException ignore) { + } catch (IndexOutOfBoundsException err) { + logger.error(err); } if(isZReversed(crs)){ diff --git a/src/main/java/com/geosiris/energyml/pkg/EPCPackage.java b/src/main/java/com/geosiris/energyml/pkg/EPCPackage.java index 6944122..150ae6a 100644 --- a/src/main/java/com/geosiris/energyml/pkg/EPCPackage.java +++ b/src/main/java/com/geosiris/energyml/pkg/EPCPackage.java @@ -166,7 +166,7 @@ public JAXBElement parseXmlContent(String xmlContent, boolean alternateDevVer logger.debug("Success reading with '" + this.packagePath + "' object class : " + result.getValue().getClass().getName()); } else { - logger.error("error reading with package " + this.packagePath); + logger.error("error reading with package " + this.packagePath); // + " --> " + xmlContent); } long ticEnd = System.currentTimeMillis(); diff --git a/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java b/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java index 183f9c4..aeed66e 100644 --- a/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java +++ b/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java @@ -28,6 +28,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -38,7 +39,7 @@ public class EpcHdf5FileManager implements EnergymlWorkspace { public static Logger logger = LogManager.getLogger(EpcHdf5FileManager.class); - private EPCFile epcFile = null; + private final EPCFile epcFile; private EpcHdf5FileManager(EPCFile epc){ super(); @@ -127,7 +128,8 @@ public static List getHdf5PathFromExternalPath( Object rootObj, EPCFile epc ) { - if (externalPathObj instanceof String) { + logger.debug("{} {}", externalPathObj, pathInRoot); + if (externalPathObj instanceof String && pathInRoot != null) { // externalPathObj is maybe an attribute of an ExternalDataArrayPart, now search upper in the object String upperPath = pathInRoot.substring(0, pathInRoot.lastIndexOf(".")); return getHdf5PathFromExternalPath( @@ -145,6 +147,7 @@ public static List getHdf5PathFromExternalPath( } else { List hdfProxyLst = searchAttributeMatchingName(externalPathObj, "HdfProxy"); List extFileProxyLst = searchAttributeMatchingName(externalPathObj, "ExternalFileProxy"); + List extDataArrayPart = searchAttributeMatchingName(externalPathObj, "ExternalDataArrayPart"); // resqml 2.0.1 if (!hdfProxyLst.isEmpty()) { @@ -175,9 +178,28 @@ public static List getHdf5PathFromExternalPath( ); return getH5PathPossibilities((String) ObjectController.getObjectAttributeValue(extPartRefObj, "Filename"), epc); } + + // resqml 2.2 + if(!extDataArrayPart.isEmpty()){ + logger.debug(extDataArrayPart); + List result = new ArrayList<>(); + for(var edap: extDataArrayPart){ + result.addAll(getHdf5PathFromExternalPath( + edap, + null, + rootObj, + epc + )); + } + return result; + } + + // Nothing found here, try with epc name + String epcPath = epc.getFilePath(); + return List.of(epcPath.substring(0, epcPath.length()-4) + ".h5"); } - return null; + return new ArrayList<>(); } public EPCFile getEpcFile() { @@ -203,13 +225,13 @@ public Object getObjectByUUID(String uuid) { public List readExternalArray(Object energyml_array, Object energymlObject, String pathInHDF) throws ObjectNotFoundNotError { List h5filePaths; try { - h5filePaths = getHdf5PathFromExternalPath(energymlObject, null, energymlObject, this.epcFile); + h5filePaths = getHdf5PathFromExternalPath(energyml_array, null, energymlObject, this.epcFile); }catch (Exception e){ logger.error(e); throw e; } String pathInExternal = getHdfReference(energyml_array).get(0); - + logger.debug(h5filePaths); List resultArray = null; assert h5filePaths != null; for(String hdf5Path: h5filePaths) { diff --git a/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java b/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java index 7ed6119..f426891 100644 --- a/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java +++ b/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java @@ -284,23 +284,30 @@ public static List readPoint3dZValueArray(Object energymlArray, Object rootOb workspace ); Object zvalues = ObjectController.getObjectAttributeValue(energymlArray, "ZValues"); - List zvaluesArray = readArray( - zvalues, - rootObj, - pathInRoot + ".ZValues", - workspace - ); + List zvaluesArray = new ArrayList<>(); - List zvalueFlat = null; - if(zvaluesArray.get(0) instanceof Collection){ - zvalueFlat = ((List>)zvaluesArray).stream().flatMap(List::stream).map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList()); - }else{ - zvalueFlat = zvaluesArray.stream().map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList()); + try { + zvaluesArray = readArray( + zvalues, + rootObj, + pathInRoot + ".ZValues", + workspace + ); + }catch (InvocationTargetException e){ + logger.error("Failed to read Z values for {}", energymlArray); } -// logger.info("supGeomArray : {}", (((List)supGeomArray.get(0)).get(0))); -// logger.info("zvaluesArrayNotFlat"); if(!zvaluesArray.isEmpty()) { + List zvalueFlat = null; + if(zvaluesArray.get(0) instanceof Collection){ + zvalueFlat = ((List>)zvaluesArray).stream().flatMap(List::stream).map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList()); + }else{ + zvalueFlat = zvaluesArray.stream().map(z-> z instanceof String ? Double.parseDouble((String) z) : ((Number)z).doubleValue()).collect(Collectors.toList()); + } + // logger.info("supGeomArray : {}", (((List)supGeomArray.get(0)).get(0))); + // logger.info("zvaluesArrayNotFlat"); + + if(supGeomArray.get(0) instanceof Collection && !(((List)supGeomArray.get(0)).get(0) instanceof Collection)){ // supGeom is List>, a list of points // final int colSize = ((List>)supGeomArray).get(0).size(); @@ -484,7 +491,7 @@ public static List>> readPoint3dLatticeArray( }catch (Exception e){ logger.error(e); } - logger.error(result); + logger.debug(result); return result; } diff --git a/src/test/java/com/geosiris/energyml/utils/test/EPCPackageTest.java b/src/test/java/com/geosiris/energyml/utils/test/EPCPackageTest.java index 4fcaa02..89d26ca 100644 --- a/src/test/java/com/geosiris/energyml/utils/test/EPCPackageTest.java +++ b/src/test/java/com/geosiris/energyml/utils/test/EPCPackageTest.java @@ -21,13 +21,13 @@ import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Test; + public class EPCPackageTest { public static Logger logger = LogManager.getLogger(EPCPackage.class); @Test void testPkgInformation() throws EPCPackageInitializationException { EPCPackage pkg22 = new EPCPackage("energyml.resqml2_2", ""); - assert pkg22.getDomainVersion().compareTo("2.2") == 0; assert pkg22.getVersionNum().compareTo("2.2") == 0; assert pkg22.getPackagePath().compareTo("energyml.resqml2_2") == 0;