From 512348669fb33be8e8044ba27745cee64e43a632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Mon, 5 Feb 2024 08:41:47 +0100 Subject: [PATCH 1/5] Remove empty class SourcesLib and deprecated/unused methods in ResourceLib / Sonarlint improvements (#7692) * Remove empty class SourcesLib and deprecated/unused methods in ResourceLib * Sonalint improvements --- .../main/java/org/fao/geonet/lib/DbLib.java | 10 ++--- .../java/org/fao/geonet/lib/ElementLib.java | 6 +-- .../src/main/java/org/fao/geonet/lib/Lib.java | 21 ++++++---- .../main/java/org/fao/geonet/lib/NetLib.java | 6 +-- .../java/org/fao/geonet/lib/ResourceLib.java | 24 ++--------- .../java/org/fao/geonet/lib/SourcesLib.java | 40 ------------------- .../main/java/org/fao/geonet/lib/TextLib.java | 22 +++++----- 7 files changed, 38 insertions(+), 91 deletions(-) delete mode 100644 core/src/main/java/org/fao/geonet/lib/SourcesLib.java diff --git a/core/src/main/java/org/fao/geonet/lib/DbLib.java b/core/src/main/java/org/fao/geonet/lib/DbLib.java index 1352ee28439..6a85a1e334c 100644 --- a/core/src/main/java/org/fao/geonet/lib/DbLib.java +++ b/core/src/main/java/org/fao/geonet/lib/DbLib.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -67,7 +67,7 @@ public void insertData(ServletContext servletContext, final ServiceContext conte runSQL(context, data); } - static public void runSQL(final ServiceContext context, final List data) { + public static void runSQL(final ServiceContext context, final List data) { TransactionManager.runInTransaction("Apply SQL statements in database", context.getApplicationContext(), TransactionManager.TransactionRequirement.CREATE_ONLY_WHEN_NEEDED, TransactionManager.CommitBehavior.ALWAYS_COMMIT, false, new TransactionTask() { @@ -88,7 +88,7 @@ public void insertData(ServletContext servletContext, Statement statement, Path runSQL(statement, data, true); } - static private void runSQL(EntityManager entityManager, List data, boolean failOnError) throws Exception { + private static void runSQL(EntityManager entityManager, List data, boolean failOnError) throws Exception { StringBuffer sb = new StringBuffer(); boolean inBlock = false; @@ -244,7 +244,7 @@ private List loadSqlDataFile(ServletContext servletContext, ApplicationC Path file = checkFilePath(servletContext, appPath, filePath, filePrefix, DatabaseType.lookup(connection).toString()); // --- load the sql data - return Lib.text.load(servletContext, appPath, file, Constants.ENCODING); + return Lib.text.load(file, Constants.ENCODING); } finally { if (connection != null) { connection.close(); @@ -258,7 +258,7 @@ private List loadSqlDataFile(ServletContext servletContext, Statement st Path file = checkFilePath(servletContext, appPath, filePath, filePrefix, DatabaseType.lookup(statement.getConnection()).toString()); // --- load the sql data - return Lib.text.load(servletContext, appPath, file, Constants.ENCODING); + return Lib.text.load(file, Constants.ENCODING); } } diff --git a/core/src/main/java/org/fao/geonet/lib/ElementLib.java b/core/src/main/java/org/fao/geonet/lib/ElementLib.java index 3da8ced307e..b3089cf5f36 100644 --- a/core/src/main/java/org/fao/geonet/lib/ElementLib.java +++ b/core/src/main/java/org/fao/geonet/lib/ElementLib.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -46,7 +46,7 @@ public class ElementLib { //----------------------------------------------------------------------------- public Set getIds(Element elem) { - HashSet hs = new HashSet(); + HashSet hs = new HashSet<>(); for (Object child : elem.getChildren()) hs.add(((Element) child).getChildText("id")); @@ -57,7 +57,7 @@ public Set getIds(Element elem) { //----------------------------------------------------------------------------- public Element pruneChildren(Element elem, Set ids) { - ArrayList alToPrune = new ArrayList(); + ArrayList alToPrune = new ArrayList<>(); //--- collect elements to prune diff --git a/core/src/main/java/org/fao/geonet/lib/Lib.java b/core/src/main/java/org/fao/geonet/lib/Lib.java index 0f199b03fa0..524976fd2e8 100644 --- a/core/src/main/java/org/fao/geonet/lib/Lib.java +++ b/core/src/main/java/org/fao/geonet/lib/Lib.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -24,11 +24,16 @@ package org.fao.geonet.lib; public class Lib { - public final static ElementLib element = new ElementLib(); - public final static DbLib db = new DbLib(); - public final static ResourceLib resource = new ResourceLib(); - public final static TypeLib type = new TypeLib(); - public final static NetLib net = new NetLib(); - public final static SourcesLib sources = new SourcesLib(); - public final static TextLib text = new TextLib(); + public static final ElementLib element = new ElementLib(); + public static final DbLib db = new DbLib(); + public static final ResourceLib resource = new ResourceLib(); + public static final TypeLib type = new TypeLib(); + public static final NetLib net = new NetLib(); + public static final TextLib text = new TextLib(); + + /** + * Private constructor to avoid instantiate the class. + */ + private Lib() { + } } diff --git a/core/src/main/java/org/fao/geonet/lib/NetLib.java b/core/src/main/java/org/fao/geonet/lib/NetLib.java index 6f1939a9ca8..87d53c5fc13 100644 --- a/core/src/main/java/org/fao/geonet/lib/NetLib.java +++ b/core/src/main/java/org/fao/geonet/lib/NetLib.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -43,7 +43,7 @@ import java.net.Proxy; import java.net.URL; import java.net.URLConnection; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Properties; import java.util.regex.PatternSyntaxException; @@ -229,7 +229,7 @@ public URLConnection setupProxy(ServiceContext context, URL url) throws IOExcept conn = url.openConnection(proxy); if (username.trim().length() != 0) { - String encodedUserPwd = new Base64().encodeAsString((username + ":" + password).getBytes(Charset.forName("UTF-8"))); + String encodedUserPwd = new Base64().encodeAsString((username + ":" + password).getBytes(StandardCharsets.UTF_8)); conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd); } diff --git a/core/src/main/java/org/fao/geonet/lib/ResourceLib.java b/core/src/main/java/org/fao/geonet/lib/ResourceLib.java index a198e7a6cbc..ef997006a8a 100644 --- a/core/src/main/java/org/fao/geonet/lib/ResourceLib.java +++ b/core/src/main/java/org/fao/geonet/lib/ResourceLib.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -34,7 +34,6 @@ import org.fao.geonet.exceptions.OperationNotAllowedEx; import org.fao.geonet.kernel.AccessManager; import org.fao.geonet.kernel.GeonetworkDataDirectory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.security.access.AccessDeniedException; import org.springframework.stereotype.Component; @@ -113,7 +112,7 @@ public void checkPrivilege(ServiceContext context, String id, denyAccess(context); } - public void denyAccess(ServiceContext context) throws Exception { + public void denyAccess(ServiceContext context) throws AccessDeniedException, OperationNotAllowedEx { if (context.getUserSession().isAuthenticated()) { throw new AccessDeniedException("User is not permitted to access this resource"); } else { @@ -134,21 +133,6 @@ public void checkEditPrivilege(ServiceContext context, String id) /** * @return the absolute path of the folder choosen to store all deleted metadata */ - @Deprecated - public Path getRemovedDir(ServiceContext context) { - GeonetContext gc = (GeonetContext) context - .getHandlerContext(Geonet.CONTEXT_NAME); - return gc.getBean(GeonetworkDataDirectory.class).getBackupDir(); - } - - /** - * See {@link #getRemovedDir(Path, String)} - */ - @Deprecated - public Path getRemovedDir(ServiceContext context, String id) { - return getRemovedDir(getRemovedDir(context), id); - } - public Path getRemovedDir(int id) { ApplicationContext appContext = ApplicationContextHolder.get(); GeonetworkDataDirectory dataDirectory = appContext.getBean(GeonetworkDataDirectory.class); @@ -172,10 +156,10 @@ public Path getRemovedDir(Path removedDir, String id) { // --- // ----------------------------------------------------------------------------- - private String pad(int group, int lenght) { + private String pad(int group, int length) { String text = Integer.toString(group); - while (text.length() < lenght) + while (text.length() < length) text = "0" + text; return text; diff --git a/core/src/main/java/org/fao/geonet/lib/SourcesLib.java b/core/src/main/java/org/fao/geonet/lib/SourcesLib.java deleted file mode 100644 index e4fa3739f2b..00000000000 --- a/core/src/main/java/org/fao/geonet/lib/SourcesLib.java +++ /dev/null @@ -1,40 +0,0 @@ -//============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the -//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) -//=== and United Nations Environment Programme (UNEP) -//=== -//=== This program is free software; you can redistribute it and/or modify -//=== it under the terms of the GNU General Public License as published by -//=== the Free Software Foundation; either version 2 of the License, or (at -//=== your option) any later version. -//=== -//=== This program is distributed in the hope that it will be useful, but -//=== WITHOUT ANY WARRANTY; without even the implied warranty of -//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -//=== General Public License for more details. -//=== -//=== You should have received a copy of the GNU General Public License -//=== along with this program; if not, write to the Free Software -//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -//=== -//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, -//=== Rome - Italy. email: geonetwork@osgeo.org -//============================================================================== - -package org.fao.geonet.lib; - -//============================================================================= - -public class SourcesLib { - //--------------------------------------------------------------------------- - //--- - //--- API methods - //--- - //--------------------------------------------------------------------------- - - //--------------------------------------------------------------------------- - -} - -//============================================================================= - diff --git a/core/src/main/java/org/fao/geonet/lib/TextLib.java b/core/src/main/java/org/fao/geonet/lib/TextLib.java index ca78ee34f0c..a3f7e3b6b33 100644 --- a/core/src/main/java/org/fao/geonet/lib/TextLib.java +++ b/core/src/main/java/org/fao/geonet/lib/TextLib.java @@ -1,5 +1,5 @@ //============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the //=== United Nations (FAO-UN), United Nations World Food Programme (WFP) //=== and United Nations Environment Programme (UNEP) //=== @@ -26,11 +26,11 @@ import org.fao.geonet.Util; import org.fao.geonet.utils.IO; -import javax.servlet.ServletContext; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -41,27 +41,25 @@ public class TextLib { private static final Random RANDOM = new Random(); - public List load(ServletContext servletContext, Path appPath, Path file) throws IOException { - return load(servletContext, appPath, file, "ISO-8859-1"); + public List load(Path file) throws IOException { + return load(file, "ISO-8859-1"); } - public List load(ServletContext servletContext, Path appPath, Path file, String encoding) throws IOException { - BufferedReader reader = IO.newBufferedReader(file, Charset.forName(encoding)); - List al = new ArrayList(); - String line = reader.readLine(); - try { + public List load(Path file, String encoding) throws IOException { + try(BufferedReader reader = IO.newBufferedReader(file, Charset.forName(encoding))) { + List al = new ArrayList<>(); + String line = reader.readLine(); + while (line != null) { al.add(line); line = reader.readLine(); } return al; - } finally { - reader.close(); } } public void save(Path file, List lines) throws IOException { - try (BufferedWriter ow = Files.newBufferedWriter(file, Charset.forName("ISO-8859-1"))) { + try (BufferedWriter ow = Files.newBufferedWriter(file, StandardCharsets.ISO_8859_1)) { for (String line : lines) { ow.write(line); ow.newLine(); From 04af77734ef558e38e7e06f701f6f04cbd68556b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:00:30 +0100 Subject: [PATCH 2/5] Bump commons-fileupload from 1.3.3 to 1.5 (#6851) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated-dependencies: - dependency-name: commons-fileupload:commons-fileupload dependency-type: direct:production --- In GN it is only used in SiteApi class in the services module. Other occurrences are introduced by openrdf-utils dependency. --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Juan Luis Rodríguez --- core/pom.xml | 4 ---- pom.xml | 2 +- services/pom.xml | 4 ++++ web/pom.xml | 4 ---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 1b010541e3c..36ee42ae577 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -340,10 +340,6 @@ org.apache.xmlgraphics xmlgraphics-commons - - commons-fileupload - commons-fileupload - commons-collections commons-collections diff --git a/pom.xml b/pom.xml index d6699fae764..61e3bcfedf2 100644 --- a/pom.xml +++ b/pom.xml @@ -525,7 +525,7 @@ commons-fileupload commons-fileupload - 1.3.3 + 1.5 commons-collections diff --git a/services/pom.xml b/services/pom.xml index d95e6fa9990..8d749eaf07f 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -222,6 +222,10 @@ org.apache.commons commons-csv + + commons-fileupload + commons-fileupload + diff --git a/web/pom.xml b/web/pom.xml index c27f820ec45..764ffe4f8b6 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -227,10 +227,6 @@ org.apache.xmlgraphics xmlgraphics-commons - - commons-fileupload - commons-fileupload - commons-collections commons-collections From 7c5e656d90c2edc7034d860262fb706e88517602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Rodri=CC=81guez?= Date: Tue, 6 Feb 2024 13:18:41 +0100 Subject: [PATCH 3/5] Automatic formatting --- .../catalog/components/metadatamanager/EditorService.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js b/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js index 4ff822de1b4..527e6f8b2ae 100644 --- a/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js +++ b/web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js @@ -380,7 +380,9 @@ // and is depending on each schema. If emtpy an empty array is set. var getLayerConfiguration = function () { var configuration = angular.fromJson(getInputValue("layerConfig")) || []; - return Array.isArray(configuration) ? configuration : [configuration.resource]; + return Array.isArray(configuration) + ? configuration + : [configuration.resource]; }; var extent = [], From 9cefa225f229fdcc72ce00c36e7c928282877dad Mon Sep 17 00:00:00 2001 From: Jo Cook Date: Tue, 6 Feb 2024 16:36:13 +0000 Subject: [PATCH 4/5] Addressing docs translation glitch #7687- fixes adding-static-pages and configuring-search-fields (#7696) * Addressing docs translation glitch #7687- fixes adding-static-pages and configuring-search-fields * Addressing docs translation glitch #7687- fixes creating-custom-editor --- .../adding-static-pages.md | 18 +++++++++--------- .../configuring-search-fields.md | 4 ++-- .../editor-ui/creating-custom-editor.md | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/manual/docs/customizing-application/adding-static-pages.md b/docs/manual/docs/customizing-application/adding-static-pages.md index d1c31a506f7..0d0fd982b9a 100644 --- a/docs/manual/docs/customizing-application/adding-static-pages.md +++ b/docs/manual/docs/customizing-application/adding-static-pages.md @@ -8,13 +8,13 @@ This feature allows to store the HTML content for static pages and show the link - Each page can be in 3 states: - - `EN`: visible to administrator. - - `TE`: visible to logged users. - - `IC`: visible to everyone. + - `HIDDEN`: visible to administrator. + - `PRIVATE`: visible to logged users. + - `PUBLIC`: visible to everyone. -- Pages can be added to different page sections. Currently the sections implemented are `OP` (top menu of the main page) and `ER` (footer of the main page). +- Pages can be added to different page sections. Currently the sections implemented are `TOP` (top menu of the main page) and `FOOTER` (footer of the main page). -- Only the administrator can edit the pages and see the pages in `EN` status. +- Only the administrator can edit the pages and see the pages in `HIDDEN` status. - The creation and the management of the content is done via the API. @@ -80,10 +80,10 @@ curl -X DELETE "http://localhost:8080/geonetwork/srv/api/pages/eng/contactus?for The status of the page can be changed with the method PUT `/api/pages/{language}/{pageId}/{status}` where status could assume these values: -- `IC` - Visible to every user -- `LY` - Visible to not logged users -- `TE` - Visible to logged users -- `EN` - Hidden to anyone +- `PUBLIC` - Visible to every user +- `PUBLIC_ONLY` - Visible to not logged users +- `PRIVATE` - Visible to logged users +- `HIDDEN` - Hidden to anyone Other methods in the API are to change/delete a page and to GET the list of the pages or the info of a specific one. diff --git a/docs/manual/docs/customizing-application/configuring-search-fields.md b/docs/manual/docs/customizing-application/configuring-search-fields.md index c03b2184ba8..266e107b046 100644 --- a/docs/manual/docs/customizing-application/configuring-search-fields.md +++ b/docs/manual/docs/customizing-application/configuring-search-fields.md @@ -195,7 +195,7 @@ curl -X POST "localhost:8080/geonetwork/srv/api/search/records/_search" \ To customize how the field is indexed see `web/src/main/webResources/WEB-INF/data/config/index/records.json`. -To return it in the search response, use the `ce` parameter of the query. See . +To return it in the search response, use the `_source` parameter of the query. See . ## Boosting at search time @@ -248,4 +248,4 @@ By default, the search score is defined as (see `web-ui/src/main/resources/catal ## Language analyzer -By default a `rd` analyzer is used. If the catalog content is english, it may make sense to change the analyzer to `sh`. To customize the analyzer see `web/src/main/webResources/WEB-INF/data/config/index/records.json` +By default a `standard` analyzer is used. If the catalog content is english, it may make sense to change the analyzer to `english`. To customize the analyzer see `web/src/main/webResources/WEB-INF/data/config/index/records.json` diff --git a/docs/manual/docs/customizing-application/editor-ui/creating-custom-editor.md b/docs/manual/docs/customizing-application/editor-ui/creating-custom-editor.md index db72ca078f2..c4e16d8965b 100644 --- a/docs/manual/docs/customizing-application/editor-ui/creating-custom-editor.md +++ b/docs/manual/docs/customizing-application/editor-ui/creating-custom-editor.md @@ -59,7 +59,7 @@ The other option to define a more advanced field type is to catch the element us ## Grouping element from the standards {#creating-custom-editor-fieldsWithFieldset} -List of elements to be displayed in a fieldset (i.e. boxed element). Those elements usually contain children elements and define major sections in the standard. For example, in ISO19139, `on` and `on` are major sections and should usually be displayed as a group of `on`. +List of elements to be displayed in a fieldset (i.e. boxed element). Those elements usually contain children elements and define major sections in the standard. For example, in ISO19139, `identification` and `distribution` are major sections and should usually be displayed as a group of `information`. ``` xml @@ -127,7 +127,7 @@ A view has a label and defines a specific rendering of the metadata records. A v ``` -The view could be displayed or not according to the metadata record content or the current user session using the `rd` and `fo` attributes. +The view could be displayed or not according to the metadata record content or the current user session using the `displayIfRecord` and `displayIfServiceInfo` attributes. Attributes: @@ -334,7 +334,7 @@ e.g. only 2 INSPIRE themes: ## Adding a section to a tab {#creating-custom-editor-section} -A section is a group of fields. If a `me` attribute is provided, then it will create an HTML fieldset which is collapsible. If no `me` attribute is provided, then it will just render the inner elements. For example, if you need a tab without a root fieldset, just create the mandatory section with no name and then the inner elements. +A section is a group of fields. If a `name` attribute is provided, then it will create an HTML fieldset which is collapsible. If no `name` attribute is provided, then it will just render the inner elements. For example, if you need a tab without a root fieldset, just create the mandatory section with no name and then the inner elements. Attributes: @@ -433,13 +433,13 @@ displayIfRecord and displayIfServiceInfo could be combined. An AND operator is u ## Adding a field {#creating-custom-editor-field} -To display a simple element use the `th` attribute to point to the element to display: +To display a simple element use the `xpath` attribute to point to the element to display: ``` xml ``` -To override a field label use the `me` attribute and define that new label in `{schema}/loc/{lang}/strings.xml`: +To override a field label use the `name` attribute and define that new label in `{schema}/loc/{lang}/strings.xml`: ``` xml ``` -`el` attribute can be used in template mode or not. Example to remove `on` while only editing `or` or `ce`. `or` or `ce` are mandatory, but as the `el` element points to the `on` ancestor, there is no mandatory flag displayed and the remove control removes the `on` element. +`del` attribute can be used in template mode or not. Example to remove `spatialResolution` while only editing `denominator` or `distance`. `denominator` or `distance` are mandatory, but as the `del` element points to the `spatialResolution` ancestor, there is no mandatory flag displayed and the remove control removes the `spatialResolution` element. ``` xml