Skip to content

Commit 9d87837

Browse files
kinowmr-c
authored andcommitted
Add liquibase migration, fix remaining repository queries and smaller improvements.
1 parent 603e030 commit 9d87837

13 files changed

+91
-21
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@
7575
<artifactId>hibernate-types-55</artifactId>
7676
<version>2.14.0</version>
7777
</dependency>
78+
<!-- Liquibase; note that Flyway, while probably having more documentation and users,
79+
changed its license model. Similarly to mongo, we prefer an open license that
80+
won't lock users or developers from updating or modifying the code if necessary.
81+
Hence our choice for liquibase. Feel free to suggest alternatives, but keep in
82+
mind the license.
83+
-->
84+
<dependency>
85+
<groupId>org.liquibase</groupId>
86+
<artifactId>liquibase-core</artifactId>
87+
</dependency>
7888
<!-- Postgres -->
7989
<dependency>
8090
<groupId>org.postgresql</groupId>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
8383

8484
@Override
8585
public void addCorsMappings(CorsRegistry registry) {
86-
registry.addMapping("/**").exposedHeaders("Location"); // .setMaxAge(Long.MAX_VALUE)
86+
registry.addMapping("/**").exposedHeaders("Location"); // .setMaxAge(Long.MAX_VALUE)
8787
}
8888
}

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

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

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Modifying;
45
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.transaction.annotation.Transactional;
57

68
import java.util.Date;
79
import java.util.List;
@@ -20,16 +22,18 @@ public interface QueuedWorkflowRepository extends JpaRepository<QueuedWorkflow,
2022
* @param retrievedOn Date of when the queued workflow was retrieved
2123
* @return The number of queued workflows deleted
2224
*/
23-
@Query(value = "DELETE FROM queued_workflow q WHERE q.temp_representation ->> 'retrieved_on' <= ?1", nativeQuery = true)
24-
Long deleteByTempRepresentation_RetrievedOnLessThanEqual(Date retrievedOn);
25+
@Transactional
26+
@Modifying
27+
@Query(value = "DELETE FROM queued_workflow q WHERE q.temp_representation ->> 'retrievedOn' <= ?1", nativeQuery = true)
28+
Integer deleteByTempRepresentation_RetrievedOnLessThanEqual(Date retrievedOn);
2529

2630
/**
2731
* Finds and returns all queued workflows with date retrieved on older or equal to the Date argument passed.
2832
*
2933
* @param retrievedOn Details of where the queued workflow is from
3034
* @return A list of queued workflows
3135
*/
32-
@Query(value = "SELECT q.* FROM queued_workflow q WHERE q.temp_representation ->> 'retrieved_on' <= ?1", nativeQuery = true)
36+
@Query(value = "SELECT q.* FROM queued_workflow q WHERE q.temp_representation ->> 'retrievedOn' <= ?1", nativeQuery = true)
3337
List<QueuedWorkflow> findByTempRepresentation_RetrievedOnLessThanEqual(Date retrievedOn);
3438

3539
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,16 @@
2020
package org.commonwl.view.workflow;
2121

2222
import java.io.File;
23-
import java.io.FileOutputStream;
2423
import java.io.IOException;
2524
import java.nio.file.Path;
2625
import java.io.InputStream;
27-
import java.security.DigestInputStream;
28-
import java.security.MessageDigest;
2926
import java.security.NoSuchAlgorithmException;
3027
import java.util.List;
3128

3229
import javax.servlet.http.HttpServletRequest;
3330
import javax.servlet.http.HttpServletResponse;
3431
import javax.validation.Valid;
3532

36-
import org.apache.commons.codec.binary.Hex;
37-
import org.apache.commons.io.IOUtils;
3833
import org.apache.commons.lang.StringUtils;
3934
import org.commonwl.view.WebConfig;
4035
import org.commonwl.view.cwl.CWLService;
@@ -236,7 +231,7 @@ public Resource getROBundle(@PathVariable("domain") String domain,
236231
@PathVariable("repoName") String repoName,
237232
@PathVariable("branch") String branch,
238233
HttpServletRequest request,
239-
HttpServletResponse response) throws IOException {
234+
HttpServletResponse response) {
240235
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
241236
path = extractPath(path, 7);
242237
GitDetails gitDetails = getGitDetails(domain, owner, repoName, branch, path);
@@ -254,7 +249,7 @@ public Resource getROBundle(@PathVariable("domain") String domain,
254249
@ResponseBody
255250
public Resource getROBundleGeneric(@PathVariable("branch") String branch,
256251
HttpServletRequest request,
257-
HttpServletResponse response) throws IOException {
252+
HttpServletResponse response) {
258253
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
259254
GitDetails gitDetails = getGitDetails(10, path, branch);
260255
File bundleDownload = workflowService.getROBundle(gitDetails);
@@ -584,7 +579,7 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
584579
}
585580

586581
private Resource getGraphFromInputStream(InputStream in, String format)
587-
throws IOException, NoSuchAlgorithmException {
582+
throws IOException {
588583
Workflow workflow = cwlService.parseWorkflowNative(in, null, "workflow"); // first workflow will do
589584
InputStream out = graphVizService.getGraphStream(workflow.getVisualisationDot(), format);
590585
return new InputStreamResource(out);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ public boolean equals(Object o) {
6262
public int hashCode() {
6363
return Objects.hash(fileName, label, doc);
6464
}
65-
}
65+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public Resource getROBundle(@PathVariable("commitid") String commitId,
271271
* The commit ID of the repository
272272
* @param request
273273
* The HttpServletRequest from the controller to extract path
274-
* @param part2
274+
* @param part
275+
* The workflow part
275276
* @throws WorkflowNotFoundException
276277
* If workflow could not be found (404)
277278
* @throws MultipleWorkflowsException

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface WorkflowRepository extends JpaRepository<Workflow, String> {
4848
* @param path The path to the workflow within the repository
4949
* @return The workflow model
5050
*/
51-
@Query(value = "SELECT w.* FROM workflow w WHERE w.lastCommit = ?1 AND w.retrievedFrom ->> 'path' = ?2", nativeQuery = true)
51+
@Query(value = "SELECT w.* FROM workflow w WHERE w.last_commit = ?1 AND w.retrieved_from ->> 'path' = ?2", nativeQuery = true)
5252
List<Workflow> findByCommitAndPath(String commitId, String path);
5353

5454
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.slf4j.LoggerFactory;
4848
import org.springframework.beans.factory.annotation.Autowired;
4949
import org.springframework.beans.factory.annotation.Value;
50-
import org.springframework.core.io.FileSystemResource;
5150
import org.springframework.core.io.PathResource;
5251
import org.springframework.data.domain.Page;
5352
import org.springframework.data.domain.Pageable;
@@ -446,7 +445,7 @@ public Workflow findByCommitAndPath(String commitID, String path, Optional<Strin
446445
* @param gitDetails The Git details of the workflow
447446
* @return A FileSystemResource representing the graph
448447
* @throws WorkflowNotFoundException Error getting the workflow or format
449-
* @throws IOException
448+
* @throws IOException Error reading the workflow files
450449
*/
451450
public PathResource getWorkflowGraph(String format, GitDetails gitDetails)
452451
throws WorkflowNotFoundException, IOException {

src/main/resources/application.properties

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ spring.datasource.password=sa
5050
spring.sql.init.mode=always
5151
spring.sql.init.platform=postgres
5252

53+
spring.jpa.generate-ddl=false
5354
spring.jpa.open-in-view=false
5455
spring.jpa.show-sql=false
5556
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
56-
spring.jpa.hibernate.ddl-auto=none
57+
spring.jpa.hibernate.ddl-auto=validate
5758
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
5859

5960
#=======================
@@ -72,4 +73,10 @@ sparql.endpoint = http://localhost:3030/cwlviewer/
7273
cron.deleteOldQueuedWorkflows = 0 0 * * * ?
7374

7475
# Age limit for queued workflows in hours.
75-
queuedWorkflowAgeLimitHours = 24
76+
queuedWorkflowAgeLimitHours = 24
77+
78+
#=======================
79+
# DB migrations
80+
#=======================
81+
spring.liquibase.enabled=true
82+
spring.liquibase.change-log=classpath:db/changelog/db.changelog.xml
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
6+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
7+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd
8+
http://www.liquibase.org/xml/ns/pro
9+
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd">
10+
<includeAll path="db/changelog/migrations/"/>
11+
</databaseChangeLog>
12+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--liquibase formatted sql
2+
3+
--changeset kinow:create-workflow-table
4+
create table if not exists workflow
5+
(
6+
id varchar(36) not null
7+
primary key,
8+
cwltool_version text,
9+
doc text,
10+
docker_link text,
11+
inputs jsonb,
12+
label text,
13+
last_commit text,
14+
license_link text,
15+
outputs jsonb,
16+
retrieved_from jsonb
17+
constraint unique_workflow_retrieved_from
18+
unique,
19+
retrieved_on timestamp,
20+
ro_bundle_path text,
21+
steps jsonb,
22+
visualisation_dot text
23+
);
24+
--rollback drop table workflow;
25+
26+
--changeset kinow:create-idx_workflow_retrieved_on-index
27+
create index if not exists idx_workflow_retrieved_on
28+
on workflow (retrieved_on);
29+
--rollback drop index idx_workflow_retrieved_on;
30+
31+
--changeset kinow:create-queued_workflow-table
32+
create table if not exists queued_workflow
33+
(
34+
id varchar(36) not null
35+
primary key,
36+
cwltool_status jsonb,
37+
cwltool_version text,
38+
message text,
39+
temp_representation jsonb,
40+
workflow_list jsonb
41+
);
42+
--rollback drop table queued_workflow;

src/main/resources/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
</logger>
5555
-->
5656

57-
</configuration>
57+
</configuration>

src/test/resources/it-application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ spring.jpa.properties.hibernate.format_sql=true
88
logging.level.org.hibernate.type.descriptor.sql=trace
99

1010
logging.level.org.hibernate.SQL=DEBUG
11-
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
11+
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

0 commit comments

Comments
 (0)