diff --git a/src/main/java/com/geosiris/energyml/data/Mesh.java b/src/main/java/com/geosiris/energyml/data/Mesh.java index 39c9083..77dc997 100644 --- a/src/main/java/com/geosiris/energyml/data/Mesh.java +++ b/src/main/java/com/geosiris/energyml/data/Mesh.java @@ -17,6 +17,7 @@ import com.geosiris.energyml.exception.NotImplementedException; import com.geosiris.energyml.exception.ObjectNotFoundNotError; +import com.geosiris.energyml.utils.EPCGenericManager; import com.geosiris.energyml.utils.EnergymlWorkspace; import com.geosiris.energyml.utils.EnergymlWorkspaceHelper; import com.geosiris.energyml.utils.ObjectController; @@ -266,6 +267,9 @@ public static List readGrid2dRepresentationHolable(Object energymlO long patchIdx = 0; var patchPathInObjMap = searchAttributeMatchingNameWithPath(energymlObject, "Grid2dPatch"); + if(EPCGenericManager.getObjectQualifiedType(energymlObject).contains("resqml22.")){ + patchPathInObjMap.put("", energymlObject); // Resqml 22 + } for (Map.Entry e : patchPathInObjMap.entrySet()) { String patchPath = e.getKey(); Object patch = e.getValue(); @@ -346,6 +350,9 @@ public static List readGrid2dRepresentationPoints(Object ene long patchIdx = 0; var patchPathInObjMap = searchAttributeMatchingNameWithPath(energymlObject, "Grid2dPatch"); + if(EPCGenericManager.getObjectQualifiedType(energymlObject).contains("resqml22.")){ + patchPathInObjMap.put("", energymlObject); // Resqml 22 + } for (Map.Entry e : patchPathInObjMap.entrySet()) { String patchPath = e.getKey(); Object patch = e.getValue(); @@ -480,4 +487,5 @@ public static List readTriangulatedSetRepresentation(Object energym return meshes; } + } \ No newline at end of file diff --git a/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java b/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java index 9c44b21..183f9c4 100644 --- a/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java +++ b/src/main/java/com/geosiris/energyml/pkg/EpcHdf5FileManager.java @@ -170,7 +170,7 @@ public static List getHdf5PathFromExternalPath( } Object extPartRefObj = epc.getObjectByIdentifier( EPCFile.getIdentifier( - ObjectController.getObjectAttributeValueRgx(extFileProxy, "epcExternalPartReference") + ObjectController.getObjectAttributeValueRgx(extFileProxy, "epcExternalPartReference").get(0) ) ); return getH5PathPossibilities((String) ObjectController.getObjectAttributeValue(extPartRefObj, "Filename"), epc); diff --git a/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java b/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java index c8fe750..7ed6119 100644 --- a/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java +++ b/src/main/java/com/geosiris/energyml/utils/EnergymlWorkspaceHelper.java @@ -80,7 +80,7 @@ public static Object getCrsObj( EnergymlWorkspace workspace ) throws ObjectNotFoundNotError { if (workspace == null) { - System.out.println("@get_crs_obj no Epc file given"); + logger.error("@get_crs_obj no Epc file given"); } else { List crsList = searchAttributeMatchingName(contextObj, "\\.*Crs", Pattern.CASE_INSENSITIVE, "", false, true); if (!crsList.isEmpty()) { @@ -111,10 +111,13 @@ public static Object getCrsObj( } public static List pointAsArray(Object point) { + Object c1 = ObjectController.getObjectAttributeValue(point, "coordinate1"); + Object c2 = ObjectController.getObjectAttributeValue(point, "coordinate2"); + Object c3 = ObjectController.getObjectAttributeValue(point, "coordinate3"); return new ArrayList<>(Arrays.asList( - Double.valueOf(String.valueOf(ObjectController.getObjectAttributeValue(point, "coordinate1"))), - Double.valueOf(String.valueOf(ObjectController.getObjectAttributeValue(point, "coordinate2"))), - Double.valueOf(String.valueOf(ObjectController.getObjectAttributeValue(point, "coordinate3"))) + c1 != null ? Double.valueOf(String.valueOf(c1)) : null, + c2 != null ? Double.valueOf(String.valueOf(c2)) : null, + c3 != null ? Double.valueOf(String.valueOf(c3)) : null )); } @@ -143,7 +146,7 @@ public static boolean isZReversed(Object crs) { } public static List prodNTab(Double val, List tab) { - return tab.stream().map(x -> x * val).collect(Collectors.toList()); + return tab.stream().map(x -> val != null && x != null ? x * val: null).collect(Collectors.toList()); } public static List sumLists(List l1, List l2) { @@ -361,9 +364,9 @@ public static List readGrid2dPatch( EnergymlWorkspace workspace ) throws InvocationTargetException, IllegalAccessException, NotImplementedException { Map pointsPathAndPointsObj = ObjectController.searchAttributeMatchingNameWithPath(patch, "Geometry.Points"); + pointsPathAndPointsObj.putAll(ObjectController.searchAttributeMatchingNameWithPath(patch, "Points")); String pointsPath = pointsPathAndPointsObj.keySet().stream().findFirst().get(); Object pointsObj = pointsPathAndPointsObj.get(pointsPath); - return readArray(pointsObj, grid2d, pathInRoot + pointsPath, workspace); } @@ -376,10 +379,10 @@ public static List>> readPoint3dLatticeArray( List>> result = new ArrayList<>(); try { List origin = pointAsArray(ObjectController.getObjectAttributeValue(energymlArray, "origin")); - List offset = (List) ObjectController.getObjectAttributeValue(energymlArray, "offset"); - if (offset.size() == 2) { - Object slowest = offset.get(0); - Object fastest = offset.get(1); + List offset = ObjectController.getObjectAttributeValueRgx(energymlArray, "offset|dimension"); + if (((List)offset.get(0)).size() == 2) { + Object slowest = ((List)offset.get(0)).get(0); + Object fastest = ((List)offset.get(0)).get(1); List crsSaCount = ((List) searchAttributeInUpperMatchingName(energymlArray, "SlowestAxisCount", rootObj, pathInRoot)).stream() .map(n -> n.intValue()) @@ -387,7 +390,6 @@ public static List>> readPoint3dLatticeArray( List crsFaCount = ((List) searchAttributeInUpperMatchingName(energymlArray, "FastestAxisCount", rootObj, pathInRoot)).stream() .map(n -> n.intValue()) .collect(Collectors.toList()); - Object crs = null; try { crs = getCrsObj(energymlArray, pathInRoot, rootObj, workspace); @@ -397,15 +399,16 @@ public static List>> readPoint3dLatticeArray( boolean zIncreasingDownward = isZReversed(crs); - List slowestVec = pointAsArray(ObjectController.getObjectAttributeValue(slowest, "offset")); + List slowestVec = pointAsArray(ObjectController.getObjectAttributeValueRgx(slowest, "offset|direction").get(0)); + // List slowestSpacing = (List) readArray(ObjectController.getObjectAttributeValue(slowest, "spacing")); List slowestSpacing = (List) readArray(ObjectController.getObjectAttributeValue(zIncreasingDownward ? fastest: slowest, "spacing")); List> slowestTable = new ArrayList<>(); - for (Object spacing : slowestSpacing) { - slowestTable.add(prodNTab(Double.valueOf(String.valueOf(spacing)), slowestVec)); + for (Double spacing : slowestSpacing) { + slowestTable.add(prodNTab(spacing, slowestVec)); } - List fastestVec = pointAsArray(ObjectController.getObjectAttributeValue(fastest, "offset")); + List fastestVec = pointAsArray(ObjectController.getObjectAttributeValueRgx(fastest, "offset|direction").get(0)); // List fastestSpacing = (List) readArray(ObjectController.getObjectAttributeValue(fastest, "spacing")); List fastestSpacing = (List) readArray(ObjectController.getObjectAttributeValue(zIncreasingDownward ? slowest: fastest, "spacing")); List> fastestTable = new ArrayList<>(); @@ -481,6 +484,7 @@ public static List>> readPoint3dLatticeArray( }catch (Exception e){ logger.error(e); } + logger.error(result); return result; } diff --git a/src/main/java/com/geosiris/energyml/utils/ObjectController.java b/src/main/java/com/geosiris/energyml/utils/ObjectController.java index a4f30af..372c3e2 100644 --- a/src/main/java/com/geosiris/energyml/utils/ObjectController.java +++ b/src/main/java/com/geosiris/energyml/utils/ObjectController.java @@ -743,11 +743,11 @@ public static Object getObjectAttributeValue(Object obj, String pathAttribute) { public static List getAttributeAccessMethodRgx(Object obj, String attributeRgx){ List res = new ArrayList<>(); - Pattern pat = Pattern.compile("(get|is)?" + attributeRgx, Pattern.CASE_INSENSITIVE); + Pattern pat = Pattern.compile("(get|is)?(" + attributeRgx +")", Pattern.CASE_INSENSITIVE); for(Method m : obj.getClass().getMethods()){ if (m.getParameterCount() == 0) { Matcher matcher = pat.matcher(m.getName()); - if (matcher.find()) { + if (matcher.matches()) { res.add(m); } } @@ -757,7 +757,7 @@ public static List getAttributeAccessMethodRgx(Object obj, String attrib } public static List getObjectAttributeValueRgx(Object obj, String pathAttribute) { - if(obj == null) return null; + if(obj == null) return new ArrayList<>(); String attribute = pathAttribute; while (attribute.startsWith(".")) { attribute = attribute.substring(1); @@ -806,9 +806,10 @@ public static List getObjectAttributeValueRgx(Object obj, String pathAtt } if (pathAttribute.contains(".")) { - final String nextAttribt = pathAttribute.substring(attribute.length() + 1); + final String nextAttrib = pathAttribute.substring(attribute.length() + 1); List flatten = new ArrayList<>(); - result.stream().map(r -> getObjectAttributeValueRgx(r, nextAttribt)).forEach(l -> flatten.addAll((List) l)); +// return result.stream().map(r -> getObjectAttributeValueRgx(r, nextAttrib)).flatMap(List::stream).collect(Collectors.toList()); + result.stream().map(r -> getObjectAttributeValueRgx(r, nextAttrib)).filter(l -> l != null).forEach(l -> flatten.addAll((List) l)); return flatten; } else { return result; @@ -1261,7 +1262,7 @@ public static Object searchAttributeInUpperMatchingName( return eltList; } - if (obj != rootObj) { + if (!currentPath.isEmpty()){ //(obj != rootObj) { String upperPath = currentPath.substring(0, currentPath.lastIndexOf(".")); if (!upperPath.isEmpty()) { return searchAttributeInUpperMatchingName( @@ -1271,6 +1272,14 @@ public static Object searchAttributeInUpperMatchingName( reFlags, upperPath ); + }else{ + return searchAttributeInUpperMatchingName( + rootObj, + nameRgx, + rootObj, + reFlags, + upperPath + ); } }