Skip to content

Commit 26843b2

Browse files
kinowmr-c
authored andcommitted
Replacing SpringBoot 2 by SpringBoot 3, handling Hibernate changes as well, fixing tests.
1 parent 18db9e6 commit 26843b2

19 files changed

+193
-204
lines changed

pom.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<parent>
1616
<groupId>org.springframework.boot</groupId>
1717
<artifactId>spring-boot-starter-parent</artifactId>
18-
<version>2.7.18</version>
18+
<version>3.1.4</version>
1919
<relativePath/>
2020
</parent>
2121

@@ -68,12 +68,25 @@
6868
<dependency>
6969
<groupId>org.springframework.data</groupId>
7070
<artifactId>spring-data-commons</artifactId>
71-
<version>2.7.18</version>
7271
</dependency>
7372
<dependency>
74-
<groupId>com.vladmihalcea</groupId>
75-
<artifactId>hibernate-types-55</artifactId>
76-
<version>2.21.1</version>
73+
<groupId>org.springframework.data</groupId>
74+
<artifactId>spring-data-jpa</artifactId>
75+
</dependency>
76+
<dependency>
77+
<groupId>jakarta.persistence</groupId>
78+
<artifactId>jakarta.persistence-api</artifactId>
79+
<version>3.1.0</version>
80+
</dependency>
81+
<dependency>
82+
<groupId>io.hypersistence</groupId>
83+
<artifactId>hypersistence-utils-hibernate-62</artifactId>
84+
<version>3.8.2</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>com.fasterxml.jackson.module</groupId>
88+
<artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId>
89+
<version>2.17.2</version>
7790
</dependency>
7891
<!-- Liquibase; note that Flyway, while probably having more documentation and users,
7992
changed its license model. Similarly to mongo, we prefer an open license that

src/main/java/org/commonwl/view/CwlViewerApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import org.springframework.boot.SpringApplication;
2323
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
2425
import org.springframework.scheduling.annotation.EnableAsync;
2526
import org.springframework.scheduling.annotation.EnableScheduling;
2627
import org.springframework.transaction.annotation.EnableTransactionManagement;
2728

2829
@SpringBootApplication
2930
@EnableAsync
31+
@EnableJpaRepositories
3032
@EnableScheduling
3133
@EnableTransactionManagement
3234
public class CwlViewerApplication {

src/main/java/org/commonwl/view/cwl/CWLValidationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package org.commonwl.view.cwl;
2121

22-
import javax.validation.ValidationException;
22+
import jakarta.validation.ValidationException;
2323

2424
/** Exception thrown when a workflow failed CWLTool validation */
2525
public class CWLValidationException extends ValidationException {

src/main/java/org/commonwl/view/git/GitDetails.java

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.view.git;
2121

22+
import com.fasterxml.jackson.annotation.JsonCreator;
2223
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2324
import com.fasterxml.jackson.databind.JsonNode;
2425
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -34,7 +35,7 @@
3435

3536
/** Represents all the parameters necessary to access a file/directory with Git */
3637
@JsonIgnoreProperties(
37-
value = {"internalUrl"},
38+
value = {"internalUrl", "logger"},
3839
ignoreUnknown = true)
3940
public class GitDetails implements Serializable {
4041

@@ -45,6 +46,7 @@ public class GitDetails implements Serializable {
4546
private String path;
4647
private String packedId;
4748

49+
@JsonCreator
4850
public GitDetails(String repoUrl, String branch, String path) {
4951
this.repoUrl = repoUrl;
5052

@@ -110,16 +112,12 @@ public GitType getType() {
110112
if (domain.startsWith("www.")) {
111113
domain = domain.substring(4);
112114
}
113-
switch (domain) {
114-
case "github.com":
115-
return GitType.GITHUB;
116-
case "gitlab.com":
117-
return GitType.GITLAB;
118-
case "bitbucket.org":
119-
return GitType.BITBUCKET;
120-
default:
121-
return GitType.GENERIC;
122-
}
115+
return switch (domain) {
116+
case "github.com" -> GitType.GITHUB;
117+
case "gitlab.com" -> GitType.GITLAB;
118+
case "bitbucket.org" -> GitType.BITBUCKET;
119+
default -> GitType.GENERIC;
120+
};
123121
} catch (URISyntaxException ex) {
124122
return GitType.GENERIC;
125123
}
@@ -133,27 +131,25 @@ public GitType getType() {
133131
*/
134132
public String getUrl(String branchOverride) {
135133
String packedPart = packedId == null ? "" : "#" + packedId;
136-
switch (getType()) {
137-
case GITHUB:
138-
case GITLAB:
139-
return "https://"
140-
+ normaliseUrl(repoUrl).replace(".git", "")
141-
+ "/blob/"
142-
+ branchOverride
143-
+ "/"
144-
+ path
145-
+ packedPart;
146-
case BITBUCKET:
147-
return "https://"
148-
+ normaliseUrl(repoUrl).replace(".git", "")
149-
+ "/src/"
150-
+ branchOverride
151-
+ "/"
152-
+ path
153-
+ packedPart;
154-
default:
155-
return repoUrl;
156-
}
134+
return switch (getType()) {
135+
case GITHUB, GITLAB ->
136+
"https://"
137+
+ normaliseUrl(repoUrl).replace(".git", "")
138+
+ "/blob/"
139+
+ branchOverride
140+
+ "/"
141+
+ path
142+
+ packedPart;
143+
case BITBUCKET ->
144+
"https://"
145+
+ normaliseUrl(repoUrl).replace(".git", "")
146+
+ "/src/"
147+
+ branchOverride
148+
+ "/"
149+
+ path
150+
+ packedPart;
151+
default -> repoUrl;
152+
};
157153
}
158154

159155
/**
@@ -174,18 +170,17 @@ public String getUrl() {
174170
public String getInternalUrl(String branchOverride) {
175171
String packedPart = packedId == null ? "" : "%23" + packedId;
176172
String pathPart = path.equals("/") ? "" : "/" + path;
177-
switch (getType()) {
178-
case GITHUB:
179-
case GITLAB:
180-
return "/workflows/"
181-
+ normaliseUrl(repoUrl).replace(".git", "")
182-
+ "/blob/"
183-
+ branchOverride
184-
+ pathPart
185-
+ packedPart;
186-
default:
187-
return "/workflows/" + normaliseUrl(repoUrl) + "/" + branchOverride + pathPart + packedPart;
188-
}
173+
return switch (getType()) {
174+
case GITHUB, GITLAB ->
175+
"/workflows/"
176+
+ normaliseUrl(repoUrl).replace(".git", "")
177+
+ "/blob/"
178+
+ branchOverride
179+
+ pathPart
180+
+ packedPart;
181+
default ->
182+
"/workflows/" + normaliseUrl(repoUrl) + "/" + branchOverride + pathPart + packedPart;
183+
};
189184
}
190185

191186
/**
@@ -211,25 +206,23 @@ public String getRawUrl(String branchOverride, String pathOverride) {
211206
if (pathOverride == null) {
212207
pathOverride = path;
213208
}
214-
switch (getType()) {
215-
case GITHUB:
216-
return "https://raw.githubusercontent.com/"
217-
+ normaliseUrl(repoUrl).replace("github.com/", "").replace(".git", "")
218-
+ "/"
219-
+ branchOverride
220-
+ "/"
221-
+ pathOverride;
222-
case GITLAB:
223-
case BITBUCKET:
224-
return "https://"
225-
+ normaliseUrl(repoUrl).replace(".git", "")
226-
+ "/raw/"
227-
+ branchOverride
228-
+ "/"
229-
+ pathOverride;
230-
default:
231-
return repoUrl;
232-
}
209+
return switch (getType()) {
210+
case GITHUB ->
211+
"https://raw.githubusercontent.com/"
212+
+ normaliseUrl(repoUrl).replace("github.com/", "").replace(".git", "")
213+
+ "/"
214+
+ branchOverride
215+
+ "/"
216+
+ pathOverride;
217+
case GITLAB, BITBUCKET ->
218+
"https://"
219+
+ normaliseUrl(repoUrl).replace(".git", "")
220+
+ "/raw/"
221+
+ branchOverride
222+
+ "/"
223+
+ pathOverride;
224+
default -> repoUrl;
225+
};
233226
}
234227

235228
/**

src/main/java/org/commonwl/view/git/GitLicenseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.commonwl.view.git;
22

3-
import javax.validation.ValidationException;
3+
import jakarta.validation.ValidationException;
44

55
public class GitLicenseException extends ValidationException {
66

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package org.commonwl.view.util;
22

3-
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
4-
import javax.persistence.MappedSuperclass;
5-
import org.hibernate.annotations.TypeDef;
6-
import org.hibernate.annotations.TypeDefs;
3+
import jakarta.persistence.MappedSuperclass;
74

8-
@TypeDefs({@TypeDef(name = "json", typeClass = JsonBinaryType.class)})
95
@MappedSuperclass
106
public class BaseEntity {}

src/main/java/org/commonwl/view/workflow/QueuedWorkflow.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import io.hypersistence.utils.hibernate.type.json.JsonType;
6+
import jakarta.persistence.Column;
7+
import jakarta.persistence.Convert;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.GenerationType;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.Table;
513
import java.io.Serializable;
614
import java.util.List;
715
import java.util.Objects;
8-
import javax.persistence.Column;
9-
import javax.persistence.Convert;
10-
import javax.persistence.Entity;
11-
import javax.persistence.GeneratedValue;
12-
import javax.persistence.GenerationType;
13-
import javax.persistence.Id;
14-
import javax.persistence.Table;
1516
import org.commonwl.view.cwl.CWLToolStatus;
1617
import org.commonwl.view.util.BaseEntity;
1718
import org.hibernate.annotations.GenericGenerator;
@@ -22,7 +23,6 @@
2223
@JsonInclude(JsonInclude.Include.NON_EMPTY)
2324
@Entity
2425
@Table(name = "queued_workflow")
25-
@SuppressWarnings("JpaAttributeTypeInspection")
2626
public class QueuedWorkflow extends BaseEntity implements Serializable {
2727

2828
// ID for database
@@ -34,20 +34,20 @@ public class QueuedWorkflow extends BaseEntity implements Serializable {
3434

3535
// Very barebones workflow to build loading thumbnail and overview
3636
@Column(columnDefinition = "jsonb")
37-
@Type(type = "json")
37+
@Type(value = JsonType.class)
3838
@Convert(disableConversion = true)
3939
private Workflow tempRepresentation;
4040

4141
// List of packed workflows for packed workflows
4242
// TODO: Refactor so this is not necessary
4343
@Column(columnDefinition = "jsonb")
44-
@Type(type = "json")
44+
@Type(value = JsonType.class)
4545
@Convert(disableConversion = true)
4646
private List<WorkflowOverview> workflowList;
4747

4848
// Cwltool details
4949
@Column(columnDefinition = "jsonb")
50-
@Type(type = "json")
50+
@Type(value = JsonType.class)
5151
@Convert(disableConversion = true)
5252
private CWLToolStatus cwltoolStatus = CWLToolStatus.RUNNING;
5353

src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.data.jpa.repository.JpaRepository;
66
import org.springframework.data.jpa.repository.Modifying;
77
import org.springframework.data.jpa.repository.Query;
8+
import org.springframework.stereotype.Repository;
89
import org.springframework.transaction.annotation.Transactional;
910

1011
/**
@@ -13,6 +14,7 @@
1314
* <p>Use only queries without objects and JSON here. For other methods use the Impl class to avoid
1415
* issues with serialization.
1516
*/
17+
@Repository
1618
public interface QueuedWorkflowRepository
1719
extends JpaRepository<QueuedWorkflow, String>, QueuedWorkflowRepositoryCustom {
1820

src/main/java/org/commonwl/view/workflow/QueuedWorkflowRepositoryImpl.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.commonwl.view.workflow;
22

3-
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
4-
import javax.persistence.EntityManager;
5-
import javax.persistence.PersistenceContext;
3+
import io.hypersistence.utils.hibernate.type.json.JsonType;
4+
import jakarta.persistence.EntityManager;
5+
import jakarta.persistence.PersistenceContext;
66
import org.commonwl.view.git.GitDetails;
77
import org.hibernate.query.Query;
88

@@ -19,12 +19,19 @@ public class QueuedWorkflowRepositoryImpl implements QueuedWorkflowRepositoryCus
1919

2020
@Override
2121
public QueuedWorkflow findByRetrievedFrom(GitDetails retrievedFrom) {
22+
// N.B. The migration from Spring Boot 2 to 3 got blocked for a while as
23+
// we couldn't figure out a way to get the mapping of types to work.
24+
// We always ended up the error about the invalid operator for the
25+
// jsonb = bytea types. Found this comment from the author of the
26+
// mapping library we use, with what was the fix for our issue (ran
27+
// out of ideas, so started testing everything found online):
28+
// Use `new JsonType(GitDetails.class)`. That finally solved it.
29+
// Ref: https://github.com/common-workflow-language/cwlviewer/pull/568
2230
return (QueuedWorkflow)
2331
entityManager
2432
.createNativeQuery(QUERY_FIND_BY_RETRIEVED_FROM, QueuedWorkflow.class)
2533
.unwrap(Query.class)
26-
.setParameter("retrievedFrom", retrievedFrom, JsonBinaryType.INSTANCE)
27-
.getResultList()
34+
.setParameter("retrievedFrom", retrievedFrom, new JsonType(GitDetails.class))
2835
.stream()
2936
.findFirst()
3037
.orElse(null);
@@ -35,7 +42,7 @@ public void deleteByTempRepresentation_RetrievedFrom(GitDetails retrievedFrom) {
3542
entityManager
3643
.createNativeQuery(QUERY_DELETE_BY_RETRIEVED_FROM, QueuedWorkflow.class)
3744
.unwrap(Query.class)
38-
.setParameter("retrievedFrom", retrievedFrom, JsonBinaryType.INSTANCE)
45+
.setParameter("retrievedFrom", retrievedFrom, new JsonType(GitDetails.class))
3946
.executeUpdate();
4047
}
4148
}

0 commit comments

Comments
 (0)