Skip to content

Commit 4c40ad4

Browse files
committed
Merge develop into main
2 parents 3140831 + 79c79f6 commit 4c40ad4

31 files changed

Lines changed: 397 additions & 257 deletions

‎wise-api/pom.xml‎

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.springframework.boot</groupId>
66
<artifactId>spring-boot-starter-parent</artifactId>
7-
<version>3.5.5</version>
7+
<version>4.0.5</version>
88
</parent>
99

1010
<groupId>org.wisemapping</groupId>
@@ -42,7 +42,7 @@
4242
</dependency>
4343
<dependency>
4444
<groupId>org.springframework.boot</groupId>
45-
<artifactId>spring-boot-starter-aop</artifactId>
45+
<artifactId>spring-boot-starter-aspectj</artifactId>
4646
</dependency>
4747
<dependency>
4848
<groupId>org.springframework.boot</groupId>
@@ -105,8 +105,8 @@
105105
</dependency>
106106
<dependency>
107107
<groupId>io.github.resilience4j</groupId>
108-
<artifactId>resilience4j-spring-boot3</artifactId>
109-
<version>2.3.0</version>
108+
<artifactId>resilience4j-spring6</artifactId>
109+
<version>2.4.0</version>
110110
</dependency>
111111
<dependency>
112112
<groupId>com.intellij</groupId>
@@ -117,34 +117,28 @@
117117
<dependency>
118118
<groupId>org.postgresql</groupId>
119119
<artifactId>postgresql</artifactId>
120-
<version>42.7.10</version>
121120
</dependency>
122121
<dependency>
123122
<groupId>jakarta.xml.bind</groupId>
124123
<artifactId>jakarta.xml.bind-api</artifactId>
125-
<version>4.0.5</version>
126124
</dependency>
127125

128126
<dependency>
129127
<groupId>jakarta.mail</groupId>
130128
<artifactId>jakarta.mail-api</artifactId>
131-
<version>2.1.3</version>
132129
</dependency>
133130
<!-- Hibernate Validator -->
134131
<dependency>
135132
<groupId>org.hibernate.validator</groupId>
136133
<artifactId>hibernate-validator</artifactId>
137-
<version>9.1.0.Final</version>
138134
</dependency>
139135
<dependency>
140136
<groupId>com.mysql</groupId>
141137
<artifactId>mysql-connector-j</artifactId>
142-
<version>9.2.0</version>
143138
</dependency>
144139
<dependency>
145140
<groupId>org.eclipse.angus</groupId>
146141
<artifactId>jakarta.mail</artifactId>
147-
<version>2.0.3</version>
148142
</dependency>
149143
<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
150144
<dependency>
@@ -158,14 +152,12 @@
158152
<dependency>
159153
<groupId>com.zaxxer</groupId>
160154
<artifactId>HikariCP</artifactId>
161-
<version>7.0.0</version>
162155
</dependency>
163156

164157
<!-- Only for test purposes -->
165158
<dependency>
166159
<groupId>org.hsqldb</groupId>
167160
<artifactId>hsqldb</artifactId>
168-
<version>2.7.4</version>
169161
<scope>runtime</scope>
170162
</dependency>
171163

@@ -190,7 +182,6 @@
190182
<dependency>
191183
<groupId>org.springframework.security</groupId>
192184
<artifactId>spring-security-test</artifactId>
193-
<version>6.5.7</version>
194185
<scope>test</scope>
195186
</dependency>
196187

@@ -255,31 +246,13 @@
255246
<artifactId>maven-surefire-plugin</artifactId>
256247
<configuration>
257248
<argLine>-XX:+EnableDynamicAgentLoading -Djdk.attach.allowAttachSelf=true -Dnet.bytebuddy.experimental=true -Duser.language=en -Duser.country=US</argLine>
249+
<forkedProcessExitTimeoutInSeconds>120</forkedProcessExitTimeoutInSeconds>
258250
</configuration>
259251
</plugin>
260-
<plugin>
261-
<groupId>org.hibernate.orm.tooling</groupId>
262-
<artifactId>hibernate-enhance-maven-plugin</artifactId>
263-
<version>6.6.26.Final</version>
264-
<executions>
265-
<execution>
266-
<phase>process-classes</phase>
267-
<goals>
268-
<goal>enhance</goal>
269-
</goals>
270-
<configuration>
271-
<enableLazyInitialization>true</enableLazyInitialization>
272-
<enableDirtyTracking>true</enableDirtyTracking>
273-
<enableAssociationManagement>true</enableAssociationManagement>
274-
</configuration>
275-
</execution>
276-
</executions>
277-
</plugin>
278252
<!-- Git Commit ID Plugin to add git information to build -->
279253
<plugin>
280254
<groupId>io.github.git-commit-id</groupId>
281255
<artifactId>git-commit-id-maven-plugin</artifactId>
282-
<version>9.0.1</version>
283256
<executions>
284257
<execution>
285258
<id>get-the-git-infos</id>

‎wise-api/src/main/java/com/wisemapping/config/AppConfig.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@
5757
import static org.springframework.security.config.Customizer.withDefaults;
5858

5959
@SpringBootApplication(scanBasePackages = "com.wisemapping")
60-
@Import({ com.wisemapping.config.common.JPAConfig.class, com.wisemapping.config.common.SecurityConfig.class })
60+
@Import({
61+
com.wisemapping.config.common.JPAConfig.class,
62+
com.wisemapping.config.common.SecurityConfig.class,
63+
com.wisemapping.config.common.Resilience4jConfig.class
64+
})
6165
@EnableScheduling
6266
@EnableAsync
6367
@EnableWebSecurity
@@ -229,7 +233,7 @@ public TaskExecutor taskExecutor() {
229233
executor.setCorePoolSize(1);
230234
executor.setMaxPoolSize(1);
231235
executor.setQueueCapacity(100);
232-
executor.setKeepAliveSeconds(60);
236+
executor.setKeepAliveSeconds(10);
233237
executor.setThreadNamePrefix("AsyncTask-");
234238
executor.setAllowCoreThreadTimeOut(true);
235239
// Use CallerRunsPolicy to prevent task rejection and provide backpressure

‎wise-api/src/main/java/com/wisemapping/config/common/JPAConfig.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.wisemapping.dao.MindmapManagerImpl;
44
import com.wisemapping.model.Account;
55
import com.wisemapping.service.MindmapServiceImpl;
6-
import org.springframework.boot.autoconfigure.domain.EntityScan;
6+
import org.springframework.boot.persistence.autoconfigure.EntityScan;
77
import org.springframework.context.annotation.Configuration;
88
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
99

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.wisemapping.config.common;
2+
3+
import io.github.resilience4j.spring6.fallback.configure.FallbackConfiguration;
4+
import io.github.resilience4j.spring6.ratelimiter.configure.RateLimiterConfiguration;
5+
import io.github.resilience4j.spring6.ratelimiter.configure.RateLimiterConfigurationProperties;
6+
import io.github.resilience4j.spring6.spelresolver.configure.SpelResolverConfiguration;
7+
import org.springframework.boot.context.properties.ConfigurationProperties;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.Import;
11+
12+
@Configuration
13+
@Import({
14+
SpelResolverConfiguration.class,
15+
FallbackConfiguration.class,
16+
RateLimiterConfiguration.class
17+
})
18+
public class Resilience4jConfig {
19+
@Bean
20+
@ConfigurationProperties(prefix = "resilience4j.ratelimiter")
21+
public RateLimiterConfigurationProperties rateLimiterConfigurationProperties() {
22+
return new RateLimiterConfigurationProperties();
23+
}
24+
}

‎wise-api/src/main/java/com/wisemapping/dao/LabelManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.wisemapping.model.MindmapLabel;
2121
import com.wisemapping.model.Account;
2222
import jakarta.persistence.EntityManager;
23+
import jakarta.persistence.PersistenceContext;
2324
import jakarta.persistence.criteria.CriteriaBuilder;
2425
import jakarta.persistence.criteria.CriteriaQuery;
2526
import jakarta.persistence.criteria.Predicate;
@@ -34,7 +35,7 @@
3435
@Repository("labelManager")
3536
public class LabelManagerImpl
3637
implements LabelManager {
37-
@Autowired
38+
@PersistenceContext
3839
private EntityManager entityManager;
3940

4041
@Override

‎wise-api/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java‎

Lines changed: 12 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.wisemapping.model.*;
2121
import jakarta.persistence.EntityManager;
2222
import jakarta.persistence.Query;
23+
import jakarta.persistence.PersistenceContext;
2324
import jakarta.persistence.TypedQuery;
2425
import jakarta.persistence.criteria.CriteriaBuilder;
2526
import jakarta.persistence.criteria.CriteriaQuery;
@@ -43,7 +44,7 @@
4344
public class MindmapManagerImpl
4445
implements MindmapManager {
4546
private static final Logger logger = LoggerFactory.getLogger(MindmapManagerImpl.class);
46-
@Autowired
47+
@PersistenceContext
4748
private EntityManager entityManager;
4849
@Autowired
4950
private jakarta.persistence.EntityManagerFactory entityManagerFactory;
@@ -309,113 +310,19 @@ public void updateMindmap(@NotNull Mindmap mindMap, boolean saveHistory) {
309310
@Transactional(propagation = Propagation.REQUIRES_NEW)
310311
public void updateMindmapSpamInfo(@NotNull com.wisemapping.model.MindmapSpamInfo spamInfo) {
311312
assert spamInfo != null : "Update MindmapSpamInfo: SpamInfo is required!";
312-
// Validate that we have a valid mindmap ID
313313
if (spamInfo.getMindmapId() == null || spamInfo.getMindmapId() < 0) {
314314
throw new IllegalArgumentException("Invalid mindmap ID for spam info: " + spamInfo.getMindmapId());
315315
}
316-
// "Last Win" strategy: Use native SQL to force update regardless of conflicts
317-
// This ensures the latest data always wins, even in high concurrency scenarios
318-
try {
319-
// Use Java Calendar for consistent timestamp handling across all databases
320-
Calendar now = Calendar.getInstance();
321-
// Get database-specific SQL based on database product name
322-
String sql = getUpsertSqlForDatabase();
323-
// Convert SpamStrategyType enum to Character for native SQL
324-
Character spamTypeCode = spamInfo.getSpamTypeCode() != null ? spamInfo.getSpamTypeCode().getCode() : null;
325-
entityManager.createNativeQuery(sql)
326-
.setParameter(1, spamInfo.getMindmapId())
327-
.setParameter(2, spamInfo.isSpamDetected())
328-
.setParameter(3, spamInfo.getSpamDetectionVersion())
329-
.setParameter(4, spamTypeCode) // Convert enum to char
330-
.setParameter(5, spamInfo.getSpamDescription())
331-
.setParameter(6, now) // created_at
332-
.setParameter(7, now) // updated_at
333-
.setParameter(8, now) // updated_at for UPDATE clause
334-
.executeUpdate();
335-
} catch (Exception e) {
336-
// If native SQL fails, log the error and throw a runtime exception
337-
// This ensures we don't fall back to JPA merge which causes optimistic locking
338-
// issues
339-
throw new RuntimeException("Failed to update MindmapSpamInfo for mindmap ID: " +
340-
spamInfo.getMindmapId() + " (native SQL failed)", e);
341-
}
342-
}
343-
344-
/**
345-
* Gets the appropriate UPSERT SQL statement based on the database product.
346-
* Supports MySQL, PostgreSQL, and HSQLDB.
347-
*
348-
* @return Database-specific UPSERT SQL statement
349-
*/
350-
private String getUpsertSqlForDatabase() {
351-
try {
352-
// Get database dialect name
353-
// Use entityManagerFactory which is already autowired, as unwrapping
354-
// entityManager to EMF might fail
355-
String dialectName = entityManagerFactory
356-
.unwrap(org.hibernate.SessionFactory.class)
357-
.getSessionFactoryOptions()
358-
.getServiceRegistry()
359-
.getService(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment.class)
360-
.getDialect()
361-
.getClass()
362-
.getSimpleName();
363-
364-
// Determine SQL based on Hibernate dialect class name
365-
if (dialectName.contains("PostgreSQL")) {
366-
// PostgreSQL uses ON CONFLICT
367-
return """
368-
INSERT INTO MINDMAP_SPAM_INFO (mindmap_id, spam_detected, spam_detection_version, spam_type_code, spam_description, created_at, updated_at)
369-
VALUES (?, ?, ?, ?, ?, ?, ?)
370-
ON CONFLICT (mindmap_id) DO UPDATE SET
371-
spam_detected = EXCLUDED.spam_detected,
372-
spam_detection_version = EXCLUDED.spam_detection_version,
373-
spam_type_code = EXCLUDED.spam_type_code,
374-
spam_description = EXCLUDED.spam_description,
375-
updated_at = ?
376-
""";
377-
} else if (dialectName.contains("HSQL")) {
378-
// HSQLDB uses MERGE
379-
return """
380-
MERGE INTO MINDMAP_SPAM_INFO AS t
381-
USING (VALUES(?, ?, ?, ?, ?, ?, ?)) AS s(mindmap_id, spam_detected, spam_detection_version, spam_type_code, spam_description, created_at, updated_at)
382-
ON t.mindmap_id = s.mindmap_id
383-
WHEN MATCHED THEN UPDATE SET
384-
spam_detected = s.spam_detected,
385-
spam_detection_version = s.spam_detection_version,
386-
spam_type_code = s.spam_type_code,
387-
spam_description = s.spam_description,
388-
updated_at = ?
389-
WHEN NOT MATCHED THEN INSERT (mindmap_id, spam_detected, spam_detection_version, spam_type_code, spam_description, created_at, updated_at)
390-
VALUES (s.mindmap_id, s.spam_detected, s.spam_detection_version, s.spam_type_code, s.spam_description, s.created_at, s.updated_at)
391-
""";
392-
} else {
393-
// MySQL uses ON DUPLICATE KEY UPDATE
394-
return """
395-
INSERT INTO MINDMAP_SPAM_INFO (mindmap_id, spam_detected, spam_detection_version, spam_type_code, spam_description, created_at, updated_at)
396-
VALUES (?, ?, ?, ?, ?, ?, ?)
397-
ON DUPLICATE KEY UPDATE
398-
spam_detected = VALUES(spam_detected),
399-
spam_detection_version = VALUES(spam_detection_version),
400-
spam_type_code = VALUES(spam_type_code),
401-
spam_description = VALUES(spam_description),
402-
updated_at = ?
403-
""";
404-
}
405-
} catch (Exception e) {
406-
// Fallback to MySQL syntax if detection fails
407-
logger.warn("Failed to detect database dialect, using MySQL syntax: {}", e.getMessage());
408-
return """
409-
INSERT INTO MINDMAP_SPAM_INFO (mindmap_id, spam_detected, spam_detection_version, spam_type_code, spam_description, created_at, updated_at)
410-
VALUES (?, ?, ?, ?, ?, ?, ?)
411-
ON DUPLICATE KEY UPDATE
412-
spam_detected = VALUES(spam_detected),
413-
spam_detection_version = VALUES(spam_detection_version),
414-
spam_type_code = VALUES(spam_type_code),
415-
spam_description = VALUES(spam_description),
416-
updated_at = ?
417-
""";
316+
MindmapSpamInfo managed = entityManager.find(MindmapSpamInfo.class, spamInfo.getMindmapId());
317+
if (managed == null) {
318+
managed = new MindmapSpamInfo();
319+
managed.setMindmapId(spamInfo.getMindmapId());
320+
entityManager.persist(managed);
418321
}
322+
managed.setSpamDetected(spamInfo.isSpamDetected());
323+
managed.setSpamDetectionVersion(spamInfo.getSpamDetectionVersion());
324+
managed.setSpamTypeCode(spamInfo.getSpamTypeCode());
325+
managed.setSpamDescription(spamInfo.getSpamDescription());
419326
}
420327

421328
/**
@@ -1117,7 +1024,7 @@ private void saveHistory(@NotNull final Mindmap mindMap) {
11171024
history.setCreationTime(Calendar.getInstance());
11181025
history.setEditor(mindMap.getLastEditor());
11191026
history.setMindmapId(mindMap.getId());
1120-
entityManager.merge(history);
1027+
entityManager.persist(history);
11211028
}
11221029

11231030
/**

‎wise-api/src/main/java/com/wisemapping/dao/UserManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.wisemapping.service.MetricsService;
2626
import jakarta.persistence.EntityManager;
2727
import jakarta.persistence.EntityManagerFactory;
28+
import jakarta.persistence.PersistenceContext;
2829
import jakarta.persistence.TypedQuery;
2930
import jakarta.persistence.criteria.CriteriaBuilder;
3031
import jakarta.persistence.criteria.CriteriaQuery;
@@ -50,7 +51,7 @@ public class UserManagerImpl
5051
implements UserManager {
5152
private static final Logger logger = LoggerFactory.getLogger(UserManagerImpl.class);
5253

53-
@Autowired
54+
@PersistenceContext
5455
private EntityManager entityManager;
5556
@Autowired
5657
private EntityManagerFactory entityManagerFactory;

‎wise-api/src/main/java/com/wisemapping/model/Mindmap.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class Mindmap implements Serializable {
8989
@Column(name = "public")
9090
private boolean isPublic;
9191

92-
@OneToOne(mappedBy = "mindmap", fetch = FetchType.LAZY)
92+
@OneToOne(mappedBy = "mindmap", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
9393
@JsonIgnore
9494
private MindmapSpamInfo spamInfo;
9595

@@ -308,6 +308,9 @@ public MindmapSpamInfo getSpamInfo() {
308308

309309
public void setSpamInfo(MindmapSpamInfo spamInfo) {
310310
this.spamInfo = spamInfo;
311+
if (spamInfo != null && spamInfo.getMindmap() != this) {
312+
spamInfo.setMindmap(this);
313+
}
311314
}
312315

313316
public Calendar getLastModificationTime() {

‎wise-api/src/main/java/com/wisemapping/rest/model/RestLockInfo.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public RestLockInfo() {
4040

4141
}
4242

43+
@com.fasterxml.jackson.annotation.JsonIgnore
4344
public RestLockInfo(@Nullable LockInfo lockInfo, @NotNull Account user) {
4445
this.email = user.getEmail();
4546
}
@@ -53,4 +54,3 @@ public void setEmail(String email) {
5354
this.email = email;
5455
}
5556
}
56-

0 commit comments

Comments
 (0)