From e2b8d1817353c7e7000ae758c9353b9c4afac77e Mon Sep 17 00:00:00 2001 From: Valentin Gauthier Date: Fri, 20 Sep 2024 18:39:36 +0200 Subject: [PATCH 01/16] bugfix + import 3D fixed for gabbro --- pom.xml | 2 +- .../geosiris/webstudio/etp/ETPWorkspace.java | 119 ++++++++++++------ .../servlet/energyml/ObjectRelsTree.java | 98 +++++++++++++++ .../servlet/rest/ETPSurfaceToFile.java | 10 +- .../geosiris/webstudio/utils/ETPUtils.java | 7 +- .../geosiris/webstudio/utils/ObjectTree.java | 12 +- .../webstudio/utils/ResqmlVerification.java | 2 +- .../script/modules/UI/modals/etp.js | 12 +- .../script/modules/UI/tabulation.js | 20 ++- .../script/modules/requests/uiRequest.js | 57 ++++++--- 10 files changed, 263 insertions(+), 76 deletions(-) create mode 100644 src/main/java/com/geosiris/webstudio/servlet/energyml/ObjectRelsTree.java diff --git a/pom.xml b/pom.xml index 0b958d1..565af2d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.geosiris webstudio ${project.groupId}:${project.artifactId} - 1.0.16 + 1.0.17 Geosiris http://www.geosiris.com diff --git a/src/main/java/com/geosiris/webstudio/etp/ETPWorkspace.java b/src/main/java/com/geosiris/webstudio/etp/ETPWorkspace.java index daac8b4..bae6cb5 100644 --- a/src/main/java/com/geosiris/webstudio/etp/ETPWorkspace.java +++ b/src/main/java/com/geosiris/webstudio/etp/ETPWorkspace.java @@ -16,25 +16,35 @@ package com.geosiris.webstudio.etp; import Energistics.Etp.v12.Datatypes.DataArrayTypes.DataArray; +import Energistics.Etp.v12.Datatypes.DataArrayTypes.DataArrayIdentifier; import Energistics.Etp.v12.Datatypes.Object.ContextScopeKind; -import Energistics.Etp.v12.Protocol.DataArray.GetDataArraysResponse; +import Energistics.Etp.v12.Protocol.DataArray.GetDataArrays; import com.geosiris.energyml.exception.ObjectNotFoundNotError; import com.geosiris.energyml.pkg.EPCFile; import com.geosiris.energyml.pkg.EPCPackage; import com.geosiris.energyml.utils.EnergymlWorkspace; import com.geosiris.energyml.utils.ObjectController; import com.geosiris.etp.utils.ETPHelper; -import com.geosiris.etp.utils.ETPHelperREST; import com.geosiris.etp.utils.ETPUri; import com.geosiris.etp.websocket.ETPClient; import com.geosiris.webstudio.servlet.Editor; +import com.google.gson.Gson; import jakarta.xml.bind.JAXBElement; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; +import static com.geosiris.energyml.utils.EPCGenericManager.getObjectTypeForFilePath_fromClassName; import static com.geosiris.energyml.utils.EnergymlWorkspaceHelper.getHdfReference; public class ETPWorkspace implements EnergymlWorkspace { @@ -67,6 +77,7 @@ public ETPWorkspace(String dataspace, ETPClient client) { this.dataspace = dataspace; this.client = client; this.uuidUri_cache = new HashMap<>(); + updateUuidCache(); } public String getDataspace() { @@ -97,16 +108,49 @@ public Object getObjectByUUID(String uuid) { public List readExternalArray(Object energymlArray, Object rootObj, String pathInRoot) throws ObjectNotFoundNotError { String pathInExternal = getHdfReference(energymlArray).get(0); String uri = getUriFromObject(rootObj, dataspace).toString(); - try { + /*try { GetDataArraysResponse resp = ETPHelperREST.getMultipleDataArrays(client, uri, List.of(pathInExternal)); List res = dataArraysToNumbers(resp.getDataArrays().entrySet().stream() - .sorted(Comparator.comparing(a -> a.getKey().toString())) + .sorted(Comparator.comparing(a -> a.getKey().toString())) // .sorted(Comparator.comparingInt(e -> Integer.getInteger(e.getKey().toString()))) .map(Map.Entry::getValue) .collect(Collectors.toList())); // logger.info("@readExternalArray values {} ", res.subList(0,9)); return res; - } catch (Exception _ignore) {_ignore.printStackTrace();} + } catch (Exception _ignore) {_ignore.printStackTrace();}*/ + logger.info("uri " + uri + " pathInExternal " + pathInExternal); + String serverHost = client.getServerUri().getHost(); + if(serverHost.contains("geosiris.com")) { + // Using our own table raw download with http + try { + Map map = new HashMap<>(); + map.put("0", DataArrayIdentifier.newBuilder().setUri(uri).setPathInResource(pathInExternal).build()); + + List res = new ArrayList<>(); + HttpPost send_req = new HttpPost("http://" + client.getServerUri().getAuthority() + (client.getServerUri().getPath() != null ? "/" + client.getServerUri().getPath() : "") + "/data-array/raw/get"); + send_req.addHeader("content-type", "application/json"); + StringEntity params = new StringEntity(GetDataArrays.newBuilder().setDataArrays(map).build().toString()); + send_req.setEntity(params); + HttpClient httpClient = HttpClientBuilder.create().build(); + HttpResponse answer = httpClient.execute(send_req); + Gson gson = new Gson(); + String content = new BufferedReader( + new InputStreamReader(answer.getEntity().getContent(), StandardCharsets.UTF_8)) + .lines() + .collect(Collectors.joining("\n")); + res = gson.fromJson(content, ArrayList.class); + logger.info(String.valueOf(res)); + return res; + } catch (Exception _ignore) { + _ignore.printStackTrace(); + } + }else{ + try { +// List res = ETPHelper.sendGetDataArray_prettier(client, uri, pathInExternal, 50000, true); + List res = ETPHelper.getMultipleDataArrays(client, uri, Collections.singletonList(pathInExternal), 500000).values().iterator().next(); + return res; + } catch (Exception _ignore) {_ignore.printStackTrace();} + } return null; } @@ -140,8 +184,8 @@ public String getObjectUriFromUuid(String uuid){ if(uuidUri_cache.containsKey(uuid)) { return uuidUri_cache.get(uuid).data; }else{ - logger.info("@getObjectUriFromUuid {} {}", uuid); - List uris = ETPHelper.sendGetRessources_pretty(client, new ETPUri(dataspace).toString(), 1, ContextScopeKind.self, 5000); + logger.info("@getObjectUriFromUuid {} dataspace : {}", uuid, dataspace); + List uris = ETPHelper.sendGetRessources_pretty(client, new ETPUri(dataspace).toString(), 1, ContextScopeKind.self, 5000000); for (String uri : uris) { if (uri.contains(uuid)) { uuidUri_cache.put(uuid, new CacheData<>(uri)); @@ -152,6 +196,17 @@ public String getObjectUriFromUuid(String uuid){ return null; } + public void updateUuidCache(){ + logger.info("@updateUuidCache"); + try { + List uris = ETPHelper.sendGetRessources_pretty(client, new ETPUri(dataspace).toString(), 1, ContextScopeKind.self, 5000000); + for (String uri : uris) { + ETPUri etpuri = ETPUri.parse(uri); + uuidUri_cache.put(etpuri.getUuid(), new CacheData<>(uri)); + } + }catch (Exception e){logger.error("{}", e);} + } + public static ETPUri getUriFromObject(Object obj, String dataspace){ EPCPackage epc_pkg = Editor.pkgManager.getMatchingPackage(obj.getClass()); ETPUri uri = new ETPUri(); @@ -159,7 +214,7 @@ public static ETPUri getUriFromObject(Object obj, String dataspace){ uri.setUuid((String) ObjectController.getObjectAttributeValue(obj, "uuid")); uri.setDomain(epc_pkg.getDomain()); uri.setDomainVersion(epc_pkg.getVersionNum().replace(".", "").substring(0,2)); - uri.setObjectType(obj.getClass().getSimpleName()); + uri.setObjectType(getObjectTypeForFilePath_fromClassName(obj.getClass().getName())); uri.setVersion((String) ObjectController.getObjectAttributeValue(obj, "version")); return uri; } @@ -167,38 +222,22 @@ public static ETPUri getUriFromObject(Object obj, String dataspace){ public static List dataArraysToNumbers(List das){ return das.stream() - .map(da -> { - try { - List values = ((List) ObjectController.getObjectAttributeValue(da.getData().getItem(), "values")); - if(values == null){ - // cas of object filled by json from http and deserialized by Gson : - // [Energistics.Etp.v12.Datatypes.ArrayOfInt, {values=[48.0, ...] } ] - // this is translated by Gson as : [String = "Energistics.Etp.v12.Datatypes.ArrayOfInt", com.google.gson.internal.LinkedTreeMap = {'values': [[48.0, ...]]}] - values = (List) ((com.google.gson.internal.LinkedTreeMap) ((List)da.getData().getItem()).get(1)).get("values"); - } -// logger.info("@dataArraysToNumbers values {} ", values.subList(0,9)); - return values; - } catch (Exception ex) { - throw new RuntimeException(ex); + .map(da -> { + try { + List values = ((List) ObjectController.getObjectAttributeValue(da.getData().getItem(), "values")); + if(values == null){ + // cas of object filled by json from http and deserialized by Gson : + // [Energistics.Etp.v12.Datatypes.ArrayOfInt, {values=[48.0, ...] } ] + // this is translated by Gson as : [String = "Energistics.Etp.v12.Datatypes.ArrayOfInt", com.google.gson.internal.LinkedTreeMap = {'values': [[48.0, ...]]}] + values = (List) ((com.google.gson.internal.LinkedTreeMap) ((List)da.getData().getItem()).get(1)).get("values"); } - }) - .flatMap(List::stream).collect(Collectors.toList()); - /* - return das.stream() - .map(da -> { - try { - List values = ((List) ObjectController.getObjectAttributeValue(da.getData().getItem(), "values")); - if(values == null){ - // cas of object filled by json from http and deserialized by Gson : - // [Energistics.Etp.v12.Datatypes.ArrayOfInt, {values=[48.0, ...] } ] - // this is translated by Gson as : [String = "Energistics.Etp.v12.Datatypes.ArrayOfInt", com.google.gson.internal.LinkedTreeMap = {'values': [[48.0, ...]]}] - values = (List) ((com.google.gson.internal.LinkedTreeMap) ((List)da.getData().getItem()).get(1)).get("values"); - } - return values.stream().map(v-> v instanceof String ? Double.parseDouble((String) v) : ((Number)v).doubleValue()).collect(Collectors.toList()); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - }) - .flatMap(List::stream).collect(Collectors.toList());*/ +// logger.info("@dataArraysToNumbers values {} ", values.subList(0,9)); + return values; + } catch (Exception ex) { + throw new RuntimeException(ex); + } + }) + .flatMap(List::stream).collect(Collectors.toList()); } + } diff --git a/src/main/java/com/geosiris/webstudio/servlet/energyml/ObjectRelsTree.java b/src/main/java/com/geosiris/webstudio/servlet/energyml/ObjectRelsTree.java new file mode 100644 index 0000000..e8574b9 --- /dev/null +++ b/src/main/java/com/geosiris/webstudio/servlet/energyml/ObjectRelsTree.java @@ -0,0 +1,98 @@ +/* +Copyright 2019 GEOSIRIS + +Licensed 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.geosiris.webstudio.servlet.energyml; + +import com.geosiris.energyml.utils.ObjectController; +import com.geosiris.webstudio.model.WorkspaceContent; +import com.geosiris.webstudio.utils.ObjectTree; +import com.geosiris.webstudio.utils.SessionUtility; +import com.geosiris.webstudio.utils.Utility; +import energyml.relationships.Relationships; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Servlet implementation class ResqmlObjectTree + */ +@WebServlet("/ObjectRelsTree") +public class ObjectRelsTree extends HttpServlet { + private static final long serialVersionUID = 1L; + public static Logger logger = LogManager.getLogger(ObjectRelsTree.class); + + /** + * @see HttpServlet#HttpServlet() + */ + public ObjectRelsTree() { + super(); + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + if (!SessionUtility.tryConnectServlet(request, response)) { + return; + } + + HttpSession session = request.getSession(false); + + WorkspaceContent wc = SessionUtility.getWorkspaceContent(session); + String objectJSONTree = ""; + + String uuid = request.getParameter("uuid"); + if (uuid != null) { + if (!wc.getParsedRels().containsKey(uuid)) { + wc.getParsedRels().put(uuid, new Relationships()); + } + ObjectTree objTree = ObjectTree.createTree(wc.getParsedRels().get(uuid)); + if (objTree != null) + objectJSONTree = objTree.toJSON(); + else { + logger.error("Null json " + ObjectTree.createTree(wc.getParsedRels().get(uuid)).toJSON()); + } + } + if(objectJSONTree.length() == 0){ + objectJSONTree = "null"; + } + + PrintWriter out = response.getWriter(); + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + out.write(objectJSONTree); + out.flush(); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doGet(request, response); + } + + +} diff --git a/src/main/java/com/geosiris/webstudio/servlet/rest/ETPSurfaceToFile.java b/src/main/java/com/geosiris/webstudio/servlet/rest/ETPSurfaceToFile.java index d674455..d57882c 100644 --- a/src/main/java/com/geosiris/webstudio/servlet/rest/ETPSurfaceToFile.java +++ b/src/main/java/com/geosiris/webstudio/servlet/rest/ETPSurfaceToFile.java @@ -17,6 +17,7 @@ import com.geosiris.etp.utils.ETPUri; import com.geosiris.etp.websocket.ETPClient; +import com.geosiris.webstudio.logs.ServerLogMessage; import com.geosiris.webstudio.model.ETP3DObject; import com.geosiris.webstudio.utils.ETPUtils; import com.geosiris.webstudio.utils.File3DType; @@ -114,10 +115,17 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) List surfaces = new ArrayList<>(); for(ETPUri etpUri: mapUri.values()) { + String err_msg = "Failed to load 3D surface : " + etpUri; try { - surfaces.add(ETPUtils.get3DFileFromETP(etpClient, null, etpUri.toString(), fileFormat)); + ETP3DObject o = ETPUtils.get3DFileFromETP(etpClient, null, etpUri.toString(), fileFormat); + if(o == null){ + SessionUtility.log(request.getSession(), new ServerLogMessage(ServerLogMessage.MessageType.TOAST, err_msg, "Surface loader")); + }else { + surfaces.add(o); + } } catch (Exception e) { logger.error(e.getMessage(), e); + SessionUtility.log(request.getSession(), new ServerLogMessage(ServerLogMessage.MessageType.TOAST, err_msg, "Surface loader")); } } PrintWriter out = response.getWriter(); diff --git a/src/main/java/com/geosiris/webstudio/utils/ETPUtils.java b/src/main/java/com/geosiris/webstudio/utils/ETPUtils.java index 722ca51..741d334 100644 --- a/src/main/java/com/geosiris/webstudio/utils/ETPUtils.java +++ b/src/main/java/com/geosiris/webstudio/utils/ETPUtils.java @@ -48,6 +48,8 @@ import com.geosiris.webstudio.model.ETP3DObject; import com.geosiris.webstudio.servlet.Editor; import com.google.gson.Gson; +import energyml.resqml2_0_1.ObjPointSetRepresentation; +import energyml.resqml2_2.PointSetRepresentation; import jakarta.servlet.http.HttpSession; import jakarta.xml.bind.JAXBException; import org.apache.avro.specific.SpecificRecordBase; @@ -68,6 +70,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import static com.geosiris.energyml.utils.EPCGenericManager.getObjectTypeForFilePath_fromClassName; import static com.geosiris.energyml.utils.EnergymlWorkspaceHelper.getCrsObj; import static com.geosiris.energyml.utils.EnergymlWorkspaceHelper.readArray; import static com.geosiris.energyml.utils.ObjectController.searchAttributeMatchingNameWithPath; @@ -494,7 +497,7 @@ public static ETP3DObject get3DFileFromETP(ETPClient etpClient, HttpSession sess String epsgCode = null; logger.info("URI to load " + uri + " ==> " + obj); - String objClassNameLC = obj.getClass().getSimpleName().toLowerCase(); + String objClassNameLC = obj.getClass().getName(); List meshes = null; try { @@ -815,5 +818,7 @@ public static List readPointRepresentation(Object energymlObject, public static void main(String[] argv){ System.out.println(hsvToRgb(180.0f, 33.0f, 100.0f)); + System.out.println(getObjectTypeForFilePath_fromClassName(ObjPointSetRepresentation.class.getName())); + System.out.println(getObjectTypeForFilePath_fromClassName(PointSetRepresentation.class.getSimpleName())); } } diff --git a/src/main/java/com/geosiris/webstudio/utils/ObjectTree.java b/src/main/java/com/geosiris/webstudio/utils/ObjectTree.java index c45c54a..e6a429a 100644 --- a/src/main/java/com/geosiris/webstudio/utils/ObjectTree.java +++ b/src/main/java/com/geosiris/webstudio/utils/ObjectTree.java @@ -20,6 +20,7 @@ import com.geosiris.webstudio.property.ConfigurationType; import com.geosiris.webstudio.servlet.Editor; import com.google.gson.Gson; +import energyml.relationships.Relationships; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -351,7 +352,8 @@ public String toJSON() { StringBuilder jsonValue = new StringBuilder(); jsonValue.append(" { \"name\" : \"").append(name).append("\",\n"); - jsonValue.append(" \"type\" : \"").append(dataClass.getCanonicalName()).append("\",\n"); + if(dataClass != null) + jsonValue.append(" \"type\" : \"").append(dataClass.getCanonicalName()).append("\",\n"); jsonValue.append(" \"mandatory\" : \"").append(isMandatory).append("\",\n"); if (dataClassTemplatedList != null && dataClassTemplatedList.size() > 0) { @@ -402,7 +404,7 @@ public String toJSON() { // }else { // On met une valeur si ce n'est pas un array et si c'est un type modifiable // directement (comme les proprietes) - if (data != null && !dataClass.getName().toLowerCase().endsWith("array") + if (data != null && dataClass != null && !dataClass.getName().toLowerCase().endsWith("array") && ObjectController.isPropertyClass(data.getClass())) { String dataAsString = data + ""; if (data.getClass().isEnum()) { @@ -416,7 +418,7 @@ public String toJSON() { } dataAsString = Utility.transformStringForJsonCompatibility(dataAsString); jsonValue.append(" \"value\" : ").append(dataAsString).append("\n"); - } else if (data == null && ObjectController.isPrimitiveClass(dataClass)) { + } else if (data == null && dataClass != null && ObjectController.isPrimitiveClass(dataClass)) { jsonValue.append(" \"value\" : \"\"\n"); } else { jsonValue = new StringBuilder(jsonValue.substring(0, jsonValue.lastIndexOf(",")) + " "); @@ -465,4 +467,8 @@ public String toString() { public ObjectTree getParent() { return parent; } + + public static void main(String[] argv){ + System.out.println(createTree(new Relationships()).toJSON()); + } } diff --git a/src/main/java/com/geosiris/webstudio/utils/ResqmlVerification.java b/src/main/java/com/geosiris/webstudio/utils/ResqmlVerification.java index 140fd2c..a541c39 100644 --- a/src/main/java/com/geosiris/webstudio/utils/ResqmlVerification.java +++ b/src/main/java/com/geosiris/webstudio/utils/ResqmlVerification.java @@ -405,7 +405,7 @@ private static List verifyReferencedDOR( || (refObjVersion != null && refObjVersion.compareTo(objVersion) != 0) ) { messages.add(new LogResqmlVerification("DOR reference has wrong information", - "Referenced object Version is '" + refObjTitle + "' and not '" + objVersion + "Referenced object Version is '" + refObjVersion + "' and not '" + objVersion + "' at path : " + dor.getName(), rootUUID, rootTitle, diff --git a/src/main/webapp/ressources/script/modules/UI/modals/etp.js b/src/main/webapp/ressources/script/modules/UI/modals/etp.js index 2656a82..83607be 100644 --- a/src/main/webapp/ressources/script/modules/UI/modals/etp.js +++ b/src/main/webapp/ressources/script/modules/UI/modals/etp.js @@ -263,6 +263,10 @@ export function loadETPObjectList(eltId_objectList, eltId_formRequest){ } ); + var div_but_import = document.createElement("div"); + div_but_import.className = "input-group"; + formImportETPobjects.appendChild(div_but_import); + const formSubmit_import = document.createElement("input"); formSubmit_import.value = "ImportDataObject"; formSubmit_import.type = "button"; @@ -273,7 +277,7 @@ export function loadETPObjectList(eltId_objectList, eltId_formRequest){ function(){resquestValidation(__ID_CONSOLE__, null);}); } formSubmit_import.appendChild(document.createTextNode("import")); - formImportETPobjects.appendChild(formSubmit_import); + div_but_import.appendChild(formSubmit_import); @@ -293,7 +297,7 @@ export function loadETPObjectList(eltId_objectList, eltId_formRequest){ ); } formSubmit_delete.appendChild(document.createTextNode("Delete data object")); - formImportETPobjects.appendChild(formSubmit_delete); + div_but_import.appendChild(formSubmit_delete); const formSubmit_visualize = document.createElement("input"); @@ -304,7 +308,7 @@ export function loadETPObjectList(eltId_objectList, eltId_formRequest){ loadUrisIn3DVue(); } formSubmit_visualize.appendChild(document.createTextNode("Visualize data object")); - formImportETPobjects.appendChild(formSubmit_visualize); + div_but_import.appendChild(formSubmit_visualize); // activity launcher const launch_select_id = "etp_select_activity_type"; @@ -491,7 +495,7 @@ export function updateExportToETPTableContent(relations){ ); f_cols.push(col_check); - ["num", "type", "uuid", "schemaVersion"].forEach( + ["title", "type", "uuid", "schemaVersion"].forEach( (attrib) => { f_cols.push( new JsonTableColumnizer_DotAttrib( diff --git a/src/main/webapp/ressources/script/modules/UI/tabulation.js b/src/main/webapp/ressources/script/modules/UI/tabulation.js index ff98fbe..f1de485 100644 --- a/src/main/webapp/ressources/script/modules/UI/tabulation.js +++ b/src/main/webapp/ressources/script/modules/UI/tabulation.js @@ -25,8 +25,8 @@ export function getActiveOpenedObject(idTabHeader){ var tabHeader = document.getElementById(idTabHeader); var navs = tabHeader.getElementsByClassName("nav-link"); for (var i = navs.length - 1; i >= 0; i--) { - if(navs[i].className.includes(" active")){ - return nav[i].parent; + if(navs[i].classList.contains("active")){ + return navs[i].parentNode; } } return null; @@ -194,13 +194,21 @@ export function closeTabulation(uuid, idTabHeader){//}, idTabcontent){ //refreshHighlightedOpenedObjects(); var foundTab = getTabulation(uuid, idTabHeader); if(foundTab != null){ - if(foundTab.previousSibling != null){ - foundTab.previousSibling.firstChild.click(); - }else if(foundTab.nextSibling != null){ - foundTab.nextSibling.firstChild.click(); + var isCurrentSelectedTab = foundTab == getActiveOpenedObject(idTabHeader); + var tabToSelect = null; + if(isCurrentSelectedTab){ + if(foundTab.previousSibling != null){ + tabToSelect = foundTab.previousSibling.firstChild; + }else if(foundTab.nextSibling != null){ + tabToSelect = foundTab.nextSibling.firstChild; + } } foundTab.remove(); document.getElementById("tabulation_id_"+uuid).remove(); + + if(tabToSelect != null){ + tabToSelect.click(); + } refreshHighlightedOpenedObjects(); return true; diff --git a/src/main/webapp/ressources/script/modules/requests/uiRequest.js b/src/main/webapp/ressources/script/modules/requests/uiRequest.js index dc2f615..e51ff4a 100644 --- a/src/main/webapp/ressources/script/modules/requests/uiRequest.js +++ b/src/main/webapp/ressources/script/modules/requests/uiRequest.js @@ -57,37 +57,41 @@ export function exportAndClose(fileName){ } //Ouvre un onglet dans le panneau de contenur d'objet (le crée si non déjà existant) -export function openResqmlObjectContent( uuid, +export function openResqmlObjectContent( uuid, idTabHeader, idTabContainer, idConsoleElt, - classObjectContent, classObjectProperty){ + classObjectContent, classObjectProperty, endpoint="ResqmlObjectTree"){ + /*ObjectRelsTree*/ + //console.log('openTab ' + uuid); if(beginTask(true)){ - if(!openTabulation(uuid, idTabHeader)){ // Si la tabulation existe on n'en re-crée pas une + if(endpoint=="ObjectRelsTree" || !openTabulation(uuid, idTabHeader)){ // Si la tabulation existe on n'en re-crée pas une var xmlHttp = new XMLHttpRequest(); - getJsonObjectFromServer("ResqmlObjectTree?uuid=" + uuid).then(function(parsedJSON){ + getJsonObjectFromServer(endpoint + "?uuid=" + uuid).then(function(parsedJSON){ + var id_suffix = endpoint == "ObjectRelsTree" ? "-rels" : ""; + + //console.log(parsedJSON); if(parsedJSON != null){ var objectProperty = document.createElement("div"); - objectProperty.id = genObjectPropertyElementId(uuid); + objectProperty.id = genObjectPropertyElementId(uuid) + id_suffix; objectProperty.className = classObjectProperty; // ---------- var resqmlElt = new ResqmlElement(parsedJSON, uuid, objectProperty); var content = resqmlElt.createView(); // ---------- - - content.id = genObjectContentElementId(uuid); + content.id = genObjectContentElementId(uuid) + id_suffix; content.className += " " + classObjectContent; var divObjectContent = document.createElement("div"); divObjectContent.style.height = "100%"; divObjectContent.style.width = "100%"; divObjectContent.style.padding= "0px"; - divObjectContent.id= genObjectContentDivElementId(); + divObjectContent.id= genObjectContentDivElementId() + id_suffix; var butExpandObject = document.createElement("span"); butExpandObject.title = "Expand tree"; butExpandObject.className += " treeExpander fas fa-angle-double-down"; - butExpandObject.id = "but_Expand_" + uuid; + butExpandObject.id = "but_Expand_" + uuid + id_suffix; divObjectContent.appendChild(butExpandObject); butExpandObject.onclick = function(){ @@ -102,7 +106,7 @@ export function openResqmlObjectContent( uuid, var butCollapseObject = document.createElement("span"); butCollapseObject.title = "Collapse tree"; butCollapseObject.className += " treeExpander fas fa-angle-double-up"; - butCollapseObject.id = "but_Collapse_" + uuid; + butCollapseObject.id = "but_Collapse_" + uuid + id_suffix; divObjectContent.appendChild(butCollapseObject); butCollapseObject.onclick = function(){ @@ -121,7 +125,7 @@ export function openResqmlObjectContent( uuid, var butValidateObject = document.createElement("button"); butValidateObject.appendChild(document.createTextNode("Validate")); butValidateObject.className += " btn btn-outline-dark objButtonAction"; - butValidateObject.id = "but_Validate_" + uuid; + butValidateObject.id = "but_Validate_" + uuid + id_suffix; divBtnGrp.appendChild(butValidateObject); butValidateObject.onclick = function(){ @@ -131,7 +135,7 @@ export function openResqmlObjectContent( uuid, var butRefresh = document.createElement("button"); butRefresh.appendChild(document.createTextNode("Refresh")); butRefresh.className += " btn btn-outline-dark objButtonAction"; - butRefresh.id = "but_AutoCorrect_" + uuid; + butRefresh.id = "but_AutoCorrect_" + uuid + id_suffix; divBtnGrp.appendChild(butRefresh); butRefresh.onclick = function(){ @@ -154,7 +158,7 @@ export function openResqmlObjectContent( uuid, butPrint_Json.appendChild(document.createTextNode("Json")); butPrint_Json.title = "Google Gson translation"; butPrint_Json.className += " btn btn-outline-success objButtonAction"; - butPrint_Json.id = "but_Print_Json_" + uuid; + butPrint_Json.id = "but_Print_Json_" + uuid + id_suffix; divBtnGrp.appendChild(butPrint_Json); butPrint_Json.onclick = function(){ @@ -164,7 +168,7 @@ export function openResqmlObjectContent( uuid, var butPrintDownloadJSON = document.createElement("button"); butPrintDownloadJSON.appendChild(document.createTextNode("Download JSON")); butPrintDownloadJSON.className += " btn btn-outline-success objButtonAction"; - butPrintDownloadJSON.id = "but_Download_json_" + uuid; + butPrintDownloadJSON.id = "but_Download_json_" + uuid + id_suffix; divBtnGrp.appendChild(butPrintDownloadJSON); butPrintDownloadJSON.onclick = function(){ @@ -174,7 +178,7 @@ export function openResqmlObjectContent( uuid, /*var butPrintXml = document.createElement("button"); butPrintXml.appendChild(document.createTextNode("Xml")); butPrintXml.className += " btn btn-outline-success objButtonAction"; - butPrintXml.id = "but_Print_xml_" + uuid; + butPrintXml.id = "but_Print_xml_" + uuid + id_suffix; divBtnGrp.appendChild(butPrintXml); butPrintXml.onclick = function(){ @@ -184,7 +188,7 @@ export function openResqmlObjectContent( uuid, var butRawEditXml = document.createElement("button"); butRawEditXml.appendChild(document.createTextNode("Edit raw XML")); butRawEditXml.className += " btn btn-outline-info objButtonAction"; - butRawEditXml.id = "butRawEditXml_" + uuid; + butRawEditXml.id = "butRawEditXml_" + uuid + id_suffix; divBtnGrp.appendChild(butRawEditXml); butRawEditXml.onclick = function(){ @@ -194,7 +198,7 @@ export function openResqmlObjectContent( uuid, var butPrintDownloadXML = document.createElement("button"); butPrintDownloadXML.appendChild(document.createTextNode("Download XML")); butPrintDownloadXML.className += " btn btn-outline-success objButtonAction"; - butPrintDownloadXML.id = "but_Download_xml_" + uuid; + butPrintDownloadXML.id = "but_Download_xml_" + uuid + id_suffix; divBtnGrp.appendChild(butPrintDownloadXML); butPrintDownloadXML.onclick = function(){ @@ -204,7 +208,7 @@ export function openResqmlObjectContent( uuid, var butAutoCorrect = document.createElement("button"); butAutoCorrect.appendChild(document.createTextNode("Auto-correct")); butAutoCorrect.className += " btn btn-outline-info objButtonAction"; - butAutoCorrect.id = "but_AutoCorrect_" + uuid; + butAutoCorrect.id = "but_AutoCorrect_" + uuid + id_suffix; divBtnGrp.appendChild(butAutoCorrect); butAutoCorrect.onclick = function(){ @@ -214,7 +218,7 @@ export function openResqmlObjectContent( uuid, var butClone = document.createElement("button"); butClone.appendChild(document.createTextNode("Clone")); butClone.className += " btn btn-outline-success objButtonAction"; - butClone.id = "but_Clone_" + uuid; + butClone.id = "but_Clone_" + uuid + id_suffix; butClone.title = "Clone this object to create a copy with an other uuid. The copy's title contains the original object uuid."; divBtnGrp.appendChild(butClone); @@ -230,6 +234,21 @@ export function openResqmlObjectContent( uuid, // formObjectModification.appendChild(formValidator); // on le met avant le form pour bypass la valdiation de form divBtnGrp.appendChild(formValidator); + /*if(endpoint=="ResqmlObjectTree"){ + // Root additional rels + var formOpenRels = document.createElement("input"); + formOpenRels.type = "submit"; + formOpenRels.value = "Rels"; + formOpenRels.className += "tabulationSave btn btn-outline-info objButtonAction"; + divBtnGrp.appendChild(formOpenRels); + + formOpenRels.onclick = function(){ + openResqmlObjectContent(uuid, + idTabHeader, idTabContainer, idConsoleElt, + classObjectContent, classObjectProperty, endpoint="ObjectRelsTree") + }; + }*/ + /// AJOUTER * madatory element var mandatoryLabel = document.createElement("span"); From 6c052ee05796f9ee1a7ff5d9e189cad3f292d20c Mon Sep 17 00:00:00 2001 From: Valentin Gauthier Date: Wed, 25 Sep 2024 02:09:20 +0200 Subject: [PATCH 02/16] adding putDataspace + bugfix in log msg filter ui --- .../etp/DataspaceHandler_WebStudio.java | 11 + .../webstudio/servlet/etp/ETPRequest.java | 27 +- .../geosiris/webstudio/utils/ETPUtils.java | 2 +- .../webstudio/utils/SessionUtility.java | 8 + src/main/webapp/jsp/htmlParts/modal_ETP.jsp | 29 + .../script/modules/UI/eventHandler.js | 4 +- .../ressources/script/modules/UI/htmlUtils.js | 7 +- .../webapp/ressources/script/modules/UI/ui.js | 12 +- .../script/modules/energyml/ResqmlElement.js | 3126 +++++++++-------- .../script/modules/etp/etp_connection.js | 8 + .../ressources/script/modules/logs/console.js | 22 +- .../script/modules/requests/requests.js | 4 +- 12 files changed, 1700 insertions(+), 1560 deletions(-) diff --git a/src/main/java/com/geosiris/webstudio/etp/DataspaceHandler_WebStudio.java b/src/main/java/com/geosiris/webstudio/etp/DataspaceHandler_WebStudio.java index 2b50374..afda358 100644 --- a/src/main/java/com/geosiris/webstudio/etp/DataspaceHandler_WebStudio.java +++ b/src/main/java/com/geosiris/webstudio/etp/DataspaceHandler_WebStudio.java @@ -20,6 +20,8 @@ import com.geosiris.etp.communication.ClientInfo; import com.geosiris.etp.communication.Message; import com.geosiris.etp.protocols.handlers.DataspaceHandler; +import com.geosiris.webstudio.utils.SessionUtility; +import jakarta.servlet.http.HttpSession; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -31,6 +33,12 @@ public class DataspaceHandler_WebStudio extends DataspaceHandler{ public static Logger logger = LogManager.getLogger(DataspaceHandler_WebStudio.class); + private HttpSession session; + + public DataspaceHandler_WebStudio(HttpSession session){ + this.session = session; + } + @Override public Collection on_DeleteDataspaces(DeleteDataspaces msg, MessageHeader msgHeader, ClientInfo clientInfo) { logger.info("[DataspaceHandler_WebStudio] received message" + msg); @@ -64,6 +72,9 @@ public Collection on_PutDataspaces(PutDataspaces msg, MessageHeader msg @Override public Collection on_PutDataspacesResponse(PutDataspacesResponse msg, MessageHeader msgHeader, ClientInfo clientInfo) { logger.info("[DataspaceHandler_WebStudio] received message" + msg); + + SessionUtility.logToast(session, "Dataspace created"); + SessionUtility.logAction(session, "updatedataspace"); return new ArrayList<>(); } diff --git a/src/main/java/com/geosiris/webstudio/servlet/etp/ETPRequest.java b/src/main/java/com/geosiris/webstudio/servlet/etp/ETPRequest.java index f926557..4037236 100644 --- a/src/main/java/com/geosiris/webstudio/servlet/etp/ETPRequest.java +++ b/src/main/java/com/geosiris/webstudio/servlet/etp/ETPRequest.java @@ -15,10 +15,9 @@ */ package com.geosiris.webstudio.servlet.etp; -import Energistics.Etp.v12.Datatypes.Object.ActiveStatusKind; -import Energistics.Etp.v12.Datatypes.Object.ContextScopeKind; -import Energistics.Etp.v12.Datatypes.Object.DataObject; -import Energistics.Etp.v12.Datatypes.Object.Resource; +import Energistics.Etp.v12.Datatypes.Object.*; +import Energistics.Etp.v12.Protocol.Dataspace.PutDataspaces; +import Energistics.Etp.v12.Protocol.Dataspace.PutDataspacesResponse; import Energistics.Etp.v12.Protocol.Discovery.GetResources; import Energistics.Etp.v12.Protocol.Discovery.GetResourcesResponse; import Energistics.Etp.v12.Protocol.Store.*; @@ -81,7 +80,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) return; } - PrintWriter out = response.getWriter(); + PrintWriter out = response.getWriter(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); out.write(ETPRequestUtils.getAllBuildableMessages()); @@ -169,6 +168,18 @@ private String manageETPRequest(Map> parameterMap, HttpSess logger.info("null GetResourcesResponse "); } } + } else if (request.toLowerCase().startsWith("putdataspace")) { + String newDataspace = parameterMap.get("newDataspace").get(0); + PutDataspaces pds = PutDataspaces.newBuilder() + .setDataspaces(Map.of("0", Dataspace.newBuilder() + .setUri(new ETPUri(newDataspace).toString()) + .setStoreLastWrite(0) + .setStoreCreated(0) + .setPath(dataspace) + .setCustomData(new HashMap<>()) + .build()) + ).build(); + ETPUtils.sendETPRequest(session, etpClient, pds, ask_aknowledge, ETPUtils.waitingForResponseTime); } else if (request.toLowerCase().startsWith("deletedataobject")) { Map mapUri = new HashMap<>(); for (String uri : parameterMap.get("etp_uri")) { @@ -209,8 +220,8 @@ private String manageETPRequest(Map> parameterMap, HttpSess etpuri.setDataspace(dataspace); } SessionUtility.log(session, new ServerLogMessage(MessageType.LOG, - "ETP request import on " + etpuri + " == " + etpuri.hasDataspace() + " --- " + etpuri.getDataspace(), - SessionUtility.EDITOR_NAME)); + "ETP request import on " + etpuri + " == " + etpuri.hasDataspace() + " --- " + etpuri.getDataspace(), + SessionUtility.EDITOR_NAME)); mapUri.put(mapUri.size()+"", etpuri.toString()); } @@ -369,7 +380,7 @@ private Pair, String> getDataObjectMaptoURI(List
-
- - -
-
+
+ + +
+ + Filter only in attribute : + diff --git a/src/main/webapp/ressources/script/modules/UI/modals/propertiesVue.js b/src/main/webapp/ressources/script/modules/UI/modals/propertiesVue.js index b18c24b..c71a5a4 100644 --- a/src/main/webapp/ressources/script/modules/UI/modals/propertiesVue.js +++ b/src/main/webapp/ressources/script/modules/UI/modals/propertiesVue.js @@ -18,6 +18,7 @@ import {downloadGetURL_Promise, sendDeleteURL_Promise, getJsonObjectFromServer} import {addJsonData} from "../../energyml/JsonElementVue.js" import {randomColor, createDeleteButton} from "../htmlUtils.js" import {beginTask, endTask} from "../ui.js" +import {getAttribute} from "../../common/utils.js" export function refreshPropertyDictVue(){ @@ -94,7 +95,7 @@ export function updateJsonDictUI(uri, containerId, progressBarId, counterId, pri }).catch((e) => {console.log(e); document.getElementById(progressBarId).style.display = "none";}); } -export function filterJsonDictUI(containerId, counterId, filter, caseSensitive, splitPhraseInWords){ +export function filterJsonDictUI(containerId, counterId, filter, caseSensitive, splitPhraseInWords, attributeToSearchIn = null){ if(filter == null) filter = ""; @@ -112,8 +113,16 @@ export function filterJsonDictUI(containerId, counterId, filter, caseSensitive, }else{ for(var i=0; i < containerDiv.length; i++){ var child = containerDiv[i]; + var found = true; - var txtContent = child.textContent; + var txtContent = ""; + + if(attributeToSearchIn != null && attributeToSearchIn.length > 0){ + txtContent = getAttribute(child.getElementsByClassName("jsonTreeDiv")[0]._object, attributeToSearchIn); + }else{ + txtContent = child.textContent; + } + if(!caseSensitive){ txtContent = txtContent.toLowerCase() } diff --git a/src/main/webapp/ressources/script/modules/energyml/JsonElementVue.js b/src/main/webapp/ressources/script/modules/energyml/JsonElementVue.js index 9558149..15f7961 100644 --- a/src/main/webapp/ressources/script/modules/energyml/JsonElementVue.js +++ b/src/main/webapp/ressources/script/modules/energyml/JsonElementVue.js @@ -54,6 +54,9 @@ export function addJsonData(jsObject, jsonEltVue, printListIdx, f_applyOnKey){ eltToPutChildIn.style.paddingLeft = "20px"; eltToPutChildIn.style.borderLeft = "1px dashed black"; eltToPutChildIn.className = 'jsonTreeDiv'; + + eltToPutChildIn._object = jsObject[i]; + var collapser = null; if(spanTitle != null){ collapser = createCollapser(spanTitle, eltToPutChildIn); @@ -92,6 +95,7 @@ export function addJsonData(jsObject, jsonEltVue, printListIdx, f_applyOnKey){ } } }else{ + spanTitle._object = jsObject[i]; if(spanTitle != null){ var boldSpan = document.createElement("b"); boldSpan.appendChild(spanTitle.firstChild); From 51dd992f3f49b52107554bf375995ad98a98e55a Mon Sep 17 00:00:00 2001 From: Valentin Gauthier Date: Wed, 25 Sep 2024 03:33:34 +0200 Subject: [PATCH 04/16] -- --- .../jsp/htmlParts/modal_PropertiesDictVue.jsp | 26 +++++++++---------- .../script/modules/energyml/JsonElementVue.js | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/webapp/jsp/htmlParts/modal_PropertiesDictVue.jsp b/src/main/webapp/jsp/htmlParts/modal_PropertiesDictVue.jsp index ff27ef8..1fe624e 100644 --- a/src/main/webapp/jsp/htmlParts/modal_PropertiesDictVue.jsp +++ b/src/main/webapp/jsp/htmlParts/modal_PropertiesDictVue.jsp @@ -17,24 +17,22 @@ limitations under the License.