Skip to content

Commit

Permalink
Lib / Update / Spring 5, Hibernate 5, Jetty 9.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Jun 26, 2023
1 parent ff76293 commit a4db92a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
import jeeves.monitor.MonitorManager;
import jeeves.monitor.timer.IndexingRecordMeter;
import jeeves.monitor.timer.IndexingRecordTimer;
import jeeves.monitor.timer.ServiceManagerXslOutputTransformTimer;
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
import jeeves.xlink.Processor;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.api.records.attachments.Store;
import org.fao.geonet.constants.Geonet;
Expand Down Expand Up @@ -74,6 +72,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -146,7 +145,7 @@ public void setMetadataManager(IMetadataManager metadataManager) {

Set<String> waitForIndexing = new HashSet<String>();
Set<String> indexing = new HashSet<String>();
Set<IndexMetadataTask> batchIndex = new ConcurrentHashSet<IndexMetadataTask>();
Set<IndexMetadataTask> batchIndex = ConcurrentHashMap.newKeySet();

@Override
public void forceIndexChanges() throws IOException {
Expand Down
10 changes: 10 additions & 0 deletions domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,40 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jeeves.interfaces.Service;
import jeeves.server.ServiceConfig;
import jeeves.server.context.ServiceContext;

import nonapi.io.github.classgraph.utils.Join;
import org.apache.commons.lang.NotImplementedException;
import org.fao.geonet.Util;
import org.apache.commons.lang.StringUtils;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.api.API;
import org.fao.geonet.api.ApiParams;
import org.fao.geonet.api.ApiUtils;
import org.fao.geonet.api.exception.NotAllowedException;
import org.fao.geonet.api.exception.ResourceNotFoundException;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.domain.AbstractMetadata;
import org.fao.geonet.domain.ReservedOperation;
import org.fao.geonet.domain.InspireAtomFeed;
import org.fao.geonet.domain.InspireAtomFeedEntry;
import org.fao.geonet.exceptions.ResourceNotFoundEx;
import org.fao.geonet.guiapi.search.XsltResponseWriter;
import org.fao.geonet.inspireatom.InspireAtomService;
import org.fao.geonet.inspireatom.harvester.InspireAtomHarvester;
import org.fao.geonet.inspireatom.model.DatasetFeedInfo;
import org.fao.geonet.inspireatom.util.InspireAtomUtil;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.repository.InspireAtomFeedRepository;
import org.fao.geonet.utils.Log;
import org.apache.commons.lang.StringUtils;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.exceptions.MetadataNotFoundEx;
import org.fao.geonet.inspireatom.util.InspireAtomUtil;
import org.fao.geonet.inspireatom.harvester.InspireAtomHarvester;
import org.fao.geonet.domain.InspireAtomFeed;
import org.fao.geonet.domain.InspireAtomFeedEntry;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.lib.Lib;
import org.jdom.Element;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.fao.geonet.exceptions.ResourceNotFoundEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.fao.geonet.api.ApiParams.API_PARAM_RECORD_UUID;
import static org.fao.geonet.inspireatom.util.InspireAtomUtil.retrieveKeywordsFromFileIdentifier;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;

@RequestMapping(value = {
Expand Down Expand Up @@ -203,7 +189,7 @@ record = ApiUtils.canViewRecord(metadataUuid, request);
.addContent(new Element("title").setText(feedTitle))
.addContent(new Element("subtitle").setText(feedSubtitle))
.addContent(new Element("lang").setText(feedLang))
.addContent(new Element("keywords").setText(Join.join(", ", keywords)))
.addContent(new Element("keywords").setText(String.join(", ", keywords)))
.addContent(new Element("authorName").setText(feedAuthorName))
.addContent(new Element("url").setText(feedUrl))
.addContent(datasetsEl);
Expand Down
28 changes: 19 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@
<groupId>org.openrdf</groupId>
<artifactId>sesame</artifactId>
<version>1.2.7</version>
<exclusions>
<!-- Remove CVE-2022-45378 and do not break sesame usage. -->
<exclusion>
<groupId>soap</groupId>
<artifactId>soap</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openrdf</groupId>
Expand Down Expand Up @@ -1093,6 +1100,11 @@
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.9.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
Expand Down Expand Up @@ -1571,7 +1583,7 @@
<kb.url>http://localhost:${kb.port}</kb.url>

<jms.url>tcp://localhost:61616</jms.url>
<activemq.version>5.6.0</activemq.version>
<activemq.version>5.7.0</activemq.version>

<!-- Avoid to create any sessions for crawlers.
Define the list of User-Agent to be considered as bot. -->
Expand All @@ -1587,7 +1599,7 @@
request the list of hosts (but JPA cache db queries). -->
<cors.allowedHosts>*</cors.allowedHosts>

<jetty.version>9.4.48.v20220622</jetty.version>
<jetty.version>9.4.51.v20230217</jetty.version>
<jetty.file>jetty-distribution-${jetty.version}</jetty.file>
<jetty.download>https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/${jetty.version}/${jetty.file}.tar.gz</jetty.download>

Expand All @@ -1598,10 +1610,11 @@
<pg.version>42.3.3</pg.version>

<spring.version>5.3.27</spring.version>
<spring.security.version>5.7.8</spring.security.version>
<spring.jpa.version>2.2.13.RELEASE</spring.jpa.version>
<spring.security.version>5.8.3</spring.security.version>
<spring.jpa.version>2.7.12</spring.jpa.version>
<springboot.version>2.7.0</springboot.version>
<springdoc.version>1.5.9</springdoc.version>
<springdoc.version>1.5.13</springdoc.version>
<hibernate.version>5.6.15.Final</hibernate.version>

<metrics.version>2.2.0</metrics.version>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH'\:'mm'\:'ssZ</maven.build.timestamp.format>
Expand All @@ -1610,10 +1623,8 @@
<wro.version>1.7.9</wro.version>
<wro.debug>true</wro.debug>
<fop.version>2.7</fop.version>
<node.version>v8.11.1</node.version>
<npm.version>5.8.0</npm.version>
<xmlunit.version>2.1.1</xmlunit.version>
<jackson.version>2.10.4</jackson.version>
<jackson.version>2.15.2</jackson.version>
<flying-saucer>9.1.22</flying-saucer>
<camel.version>2.25.1</camel.version>
<log4j2.version>2.17.2</log4j2.version>
Expand All @@ -1623,7 +1634,6 @@
<httpcomponents.version>4.5.14</httpcomponents.version>
<jasypt.version>1.9.3</jasypt.version>
<jupiter.version>5.9.1</jupiter.version>
<hibernate.version>5.6.7.Final</hibernate.version>

<sonar.organization>geonetwork</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down
21 changes: 12 additions & 9 deletions services/src/main/java/org/fao/geonet/api/OpenApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public OpenApiController(ObjectFactory<OpenAPIService> openAPIBuilderObjectFacto
public String openapiJson(HttpServletRequest request, @Value(API_DOCS_URL) String apiDocsUrl)
throws JsonProcessingException {
calculateServerUrl(request, apiDocsUrl);
OpenAPI openAPI = this.getOpenApi();
OpenAPI openAPI = this.getOpenApi(request.getLocale());
return Json.mapper().writeValueAsString(openAPI);
}

Expand All @@ -115,32 +115,33 @@ public String openapiJson(HttpServletRequest request, @Value(API_DOCS_URL) Strin
public String openapiYaml(HttpServletRequest request, @Value(DEFAULT_API_DOCS_URL_YAML) String apiDocsUrl)
throws JsonProcessingException {
calculateServerUrl(request, apiDocsUrl);
OpenAPI openAPI = this.getOpenApi();
OpenAPI openAPI = this.getOpenApi(request.getLocale());
return Yaml.mapper().writeValueAsString(openAPI);
}

@Override
protected void getPaths(Map<String, Object> restControllers) {
protected void getPaths(Map<String, Object> restControllers, Locale locale) {
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
calculatePath(restControllers, map, Optional.empty());
calculatePath(restControllers, map, Optional.empty(), locale);

if (servletContextProvider.isPresent()) {
map = servletContextProvider.get().getMethods();
calculatePath(restControllers, map, servletContextProvider);
calculatePath(restControllers, map, servletContextProvider, locale);
}
if (this.springSecurityOAuth2Provider.isPresent()) {
SecurityOAuth2Provider securityOAuth2Provider = this.springSecurityOAuth2Provider.get();
Map<RequestMappingInfo, HandlerMethod> mapOauth = securityOAuth2Provider.getHandlerMethods();
Map<String, Object> requestMappingMapSec = securityOAuth2Provider.getFrameworkEndpoints();
Class[] additionalRestClasses = requestMappingMapSec.values().stream().map(Object::getClass).toArray(Class[]::new);
AbstractOpenApiResource.addRestControllers(additionalRestClasses);
calculatePath(requestMappingMapSec, mapOauth, Optional.empty());
calculatePath(requestMappingMapSec, mapOauth, Optional.empty(), locale);
}
}

protected void calculatePath(Map<String, Object> restControllers,
Map<RequestMappingInfo, HandlerMethod> map,
Optional<ActuatorProvider> actuatorProvider) {
Optional<ActuatorProvider> actuatorProvider,
Locale locale) {
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) {
RequestMappingInfo requestMappingInfo = entry.getKey();
HandlerMethod handlerMethod = entry.getValue();
Expand All @@ -150,7 +151,8 @@ protected void calculatePath(Map<String, Object> restControllers,
for (String pattern : patterns) {
String operationPath = PathUtils.parsePath(pattern, regexMap)
.replace("/{portal}/api", "");
if (((actuatorProvider.isPresent() && actuatorProvider.get().isRestController(operationPath, handlerMethod.getClass()))
if (((actuatorProvider.isPresent()
&& actuatorProvider.get().isRestController(operationPath, handlerMethod))
|| isRestController(restControllers, handlerMethod, operationPath))
&& isPackageToScan(handlerMethod.getBeanType().getPackage())
&& isPathToMatch(operationPath)) {
Expand All @@ -159,14 +161,15 @@ && isPathToMatch(operationPath)) {
// default allowed requestmethods
if (requestMethods.isEmpty())
requestMethods = this.getDefaultAllowedHttpMethods();
calculatePath(handlerMethod, operationPath, requestMethods);
calculatePath(handlerMethod, operationPath, requestMethods, locale);
// } else {
// System.out.println("API path ignored: " + operationPath);
}
}
}
}


protected boolean isRestController(Map<String, Object> restControllers,
HandlerMethod handlerMethod,
String operationPath) {
Expand Down

0 comments on commit a4db92a

Please sign in to comment.