Skip to content

Commit

Permalink
Java21 (#4450)
Browse files Browse the repository at this point in the history
* Initial commit including POM changes

* Converted ehcache to new format

* Modified .travis.yml

* Jakarta import corrections, EhCache config in app YML

* Fixed file upload and corrected some of the compile errors

* fixed final complilation errors

* Some correction for JSON, EhCache wip

* Expiry order changed

* Added Mail dep and commented out some cache resolver code

* Updated AuditInterceptor

* Fiexed merge with master

* Started java21 and fixed login

* Fixed the null inject and removed dep in travis

* Fixed travis java version

* Use proper protoc

* Relaced proto extensions for optional fields

* Removed some extensions from protos and updated usage

* Created a separate ehcache file for session cache and more proto corrections

* Fixed the cache conf file

* Remove StudyType and fixed study/initiative import

* Changed the proto to keep collected and protocol DTOs

* Fixed travis build and image upload

* Removed the remaining proto extends and updated search client files

* Changed magma version

* Fixed membership addition and DAR history page

* Fixed CacheResource and changed logback version

* Fixed charts, coverage for non-opal taxos and csv download

* Added legacy upgrade and chaged joda time version

* Replaced joda time with LocalDateTime

* Removed the legacy upgrade and removed required membership dto

* Fixed templates for using old fields

* Used 'double' for JSON's proto3 'int64' problem

* Removed DTO unkonwn fields

* Fixed the logs API

* Added a EhCache event logger; changed int64 -> double + ftl fix

* Use the getFileName

* Fixed Pop, DCE cache serialization and creating new contact

* Changed stats type in DTO

---------

Co-authored-by: Ramin Haeri Azad <rhaeri@maelstrom-reseach.org>
  • Loading branch information
kazoompa and Ramin Haeri Azad authored May 2, 2024
1 parent 30c24d2 commit f299f98
Show file tree
Hide file tree
Showing 340 changed files with 3,018 additions and 2,410 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
sudo: required
dist: focal
language: java
jdk:
- openjdk8
- openjdk21
before_install:
- sudo add-apt-repository -y ppa:chris-lea/node.js
- sudo apt-get install -y nodejs devscripts
- nvm install lts/gallium
- node --version
Expand Down
66 changes: 53 additions & 13 deletions mica-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
</properties>

<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>

<dependency>
<groupId>org.obiba.mica</groupId>
<artifactId>mica-spi</artifactId>
Expand All @@ -39,32 +48,32 @@
<artifactId>magma-datasource-excel</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-json</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-ehcache</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jvm</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-servlet</artifactId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jakarta-servlet</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-servlets</artifactId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jakarta-servlets</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.protobuf-java-format</groupId>
Expand Down Expand Up @@ -131,10 +140,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.javamail</groupId>
<artifactId>geronimo-javamail_1.4_mail</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.geronimo.javamail</groupId>-->
<!-- <artifactId>geronimo-javamail_1.4_mail</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
Expand All @@ -151,6 +160,19 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-loader-tools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.ehcache.integrations.shiro</groupId>
<artifactId>shiro-ehcache3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
Expand All @@ -165,6 +187,12 @@
</exclusion>
</exclusions>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- <artifactId>jcl-over-slf4j</artifactId>-->
<!-- </dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
Expand Down Expand Up @@ -242,10 +270,12 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
Expand All @@ -255,6 +285,12 @@
<groupId>eu.flatwhite.shiro</groupId>
<artifactId>shiro-extras</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<classifier>jakarta</classifier>
</dependency>


<dependency>
<groupId>org.obiba.commons</groupId>
Expand All @@ -274,6 +310,10 @@
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
</dependency>
<dependency>
<groupId>org.obiba.commons</groupId>
<artifactId>obiba-password-hasher</artifactId>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import com.google.common.base.Strings;
import com.google.common.eventbus.EventBus;
import jakarta.ws.rs.ForbiddenException;
import org.apache.shiro.SecurityUtils;
import org.joda.time.DateTime;
import org.json.JSONException;
import org.json.JSONObject;
import org.obiba.mica.access.DataAccessCollaboratorRepository;
Expand All @@ -28,7 +28,6 @@

import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import javax.ws.rs.ForbiddenException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -129,8 +128,8 @@ public void acceptCollaborator(@NotNull DataAccessRequest dar, String invitation
if (!found) {
throw new IllegalArgumentException("invitation-wrong-user");
}
DateTime expired = DateTime.parse(jsonKey.getString(CREATED_KEY)).plusDays(dataAccessConfigService.getOrCreateConfig().getCollaboratorInvitationDays());
if (dar.hasAcceptedCollaboratorInvitation(invitation) || expired.isBefore(DateTime.now())) {
LocalDateTime expired = LocalDateTime.parse(jsonKey.getString(CREATED_KEY)).plusDays(dataAccessConfigService.getOrCreateConfig().getCollaboratorInvitationDays());
if (dar.hasAcceptedCollaboratorInvitation(invitation) || expired.isBefore(LocalDateTime.now())) {
throw new IllegalArgumentException("invitation-expired");
}

Expand Down Expand Up @@ -232,7 +231,7 @@ private String makeInvitationKey(@NotNull DataAccessRequest dar, String email) {
jsonKey.put(AUTHOR_KEY, SecurityUtils.getSubject().getPrincipal().toString());
jsonKey.put(REQUEST_KEY, dar.getId());
jsonKey.put(EMAIL_KEY, email);
jsonKey.put(CREATED_KEY, DateTime.now());
jsonKey.put(CREATED_KEY, LocalDateTime.now());
} catch (JSONException e) {
throw new IllegalArgumentException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import jakarta.ws.rs.BadRequestException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.obiba.mica.cache;

import org.ehcache.event.CacheEvent;
import org.ehcache.event.CacheEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EhCacheEventLogger implements CacheEventListener<Object, Object> {

private static final Logger logger = LoggerFactory.getLogger(EhCacheEventLogger.class);

@Override
public void onEvent(CacheEvent cacheEvent) {
logger.info("Cache event = {}, Key = {}, Old value = {}, New value = {}", cacheEvent.getType(),
cacheEvent.getKey(), cacheEvent.getOldValue(), cacheEvent.getNewValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//package org.obiba.mica.cache;
//
//import org.apache.shiro.cache.CacheException;
//import org.ehcache.CacheManager;
//import org.ehcache.config.builders.CacheManagerBuilder;
//import org.ehcache.xml.XmlConfiguration;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.net.MalformedURLException;
//import java.net.URL;
//
//public class MicaEhCacheManagerFactory {
// private static final Logger log = LoggerFactory.getLogger(MicaEhCacheManagerFactory.class);
//
//
// private static final String EHCACHE_CONFIG_FILE = "ehcache.xml";
//
// // Implement a EhCache 3 CacheManager to be used in Spring boot 3 application
//
// public CacheManager create() {
// // How to use Ehcache 3 in Spring boot 3
// // https://www.ehcache.org/documentation/3.8/getting-started.html
//
// // https://www.ehcache.org/documentation/3.8/getting-started.html
//
//
//
// log.info("Creating EhCache Manager");
//// try {
//// XmlConfiguration xmlConfiguration = new XmlConfiguration(new URL(EHCACHE_CONFIG_FILE));
//// CacheManager cacheManager = CacheManagerBuilder.newCacheManager(xmlConfiguration);
//// cacheManager.init();
////
//// return cacheManager;
//// } catch (MalformedURLException e) {
//// throw new CacheException(e);
//// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,12 @@

package org.obiba.mica.config;

import javax.annotation.PreDestroy;
import javax.inject.Inject;

import net.sf.ehcache.Cache;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.cache.CacheManager;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ehcache.InstrumentedEhcache;

@Configuration("cacheConfiguration")
@EnableCaching
@AutoConfigureAfter(value = { MetricsConfiguration.class })
public class CacheConfiguration {

private static final Logger log = LoggerFactory.getLogger(CacheConfiguration.class);

@Inject
private MetricRegistry metricRegistry;

@PreDestroy
public void destroy() {
log.info("Remove Cache Manager metrics");
metricRegistry.getNames().forEach(metricRegistry::remove);
}

@Bean
public EhCacheManagerFactoryBean cacheManagerFactory() {
log.debug("Starting Ehcache");
EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean();
factoryBean.setCacheManagerName("mica");

return factoryBean;
}

@Bean
public CacheManager springCacheManager() {
log.debug("Starting Spring Cache");
net.sf.ehcache.CacheManager cacheManager = cacheManagerFactory().getObject();
EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
ehCacheManager.setCacheManager(cacheManager);
String[] cacheNames = cacheManager.getCacheNames();
for (String cacheName : cacheNames) {
Cache cache = cacheManager.getCache(cacheName);
cacheManager.replaceCacheWithDecoratedCache(cache, InstrumentedEhcache.instrument(metricRegistry, cache));
}
return ehCacheManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void configureReporters(MetricRegistry metricRegistry) {

@Configuration
@ConditionalOnClass(Graphite.class)
public static class GraphiteRegistry implements EnvironmentAware {
public static class GraphiteRegistry implements EnvironmentAware, InitializingBean {

private final Logger log = LoggerFactory.getLogger(GraphiteRegistry.class);

Expand All @@ -99,8 +99,8 @@ public void setEnvironment(Environment environment) {
this.environment = environment;
}

@PostConstruct
private void init() {
@Override
public void afterPropertiesSet() throws Exception {
Boolean graphiteEnabled = environment.getProperty(PROP_GRAPHITE_ENABLED, Boolean.class, false);
if(graphiteEnabled) {
log.info("Initializing Metrics Graphite reporting");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package org.obiba.mica.config;

import javax.validation.Validator;
import jakarta.validation.Validator;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

package org.obiba.mica.core.domain;

import java.io.Serializable;
import java.util.Map;

import javax.annotation.Nullable;

public abstract class AbstractAttributeModelAware implements AttributeAware, ModelAware {
public abstract class AbstractAttributeModelAware implements AttributeAware, ModelAware, Serializable {

private Attributes attributes;

Expand Down
Loading

0 comments on commit f299f98

Please sign in to comment.