Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update schedule configuration with shedlock and minor updates on workflow query #17

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
Expand All @@ -44,10 +44,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'

# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
version = "0.0.1-SNAPSHOT"
description = "The flexible configurable crm service"

assert System.properties["java.specification.version"] == "17" || "18" || "19" || "20" || "21" || "22"
assert System.properties["java.specification.version"] == "21" || "22" || "23"

allprojects {
group = 'io.flexwork'
Expand All @@ -19,8 +19,8 @@ allprojects {
afterEvaluate {
if (it.plugins.hasPlugin('java') || it.plugins.hasPlugin('java-library')) {
java {
sourceCompatibility=17
targetCompatibility=17
sourceCompatibility=21
targetCompatibility=21
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

jib {
from {
image = "eclipse-temurin:17-jre-focal"
image = "eclipse-temurin:21-jre-focal"
platforms {
platform {
os = "linux"
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ springbootVersion = "3.3.5"
springDependencyManagementVersion="1.1.6"
jhisterVersion = "8.7.1"
j2HtmlVersion = "1.6.0"
shedlockVersion="6.0.1"

[libraries]
jhipster-framework = { module = "tech.jhipster:jhipster-framework", version.ref = "jhisterVersion" }
Expand All @@ -39,6 +40,8 @@ mockito = { module = "org.mockito:mockito-inline", version.ref = "mockitoVersion
mockito-junit = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockitoJunitVersion" }
json-api = { module = "jakarta.json:jakarta.json-api", version.ref = "jsonApiVersion" }
parsson = { module = "org.eclipse.parsson:parsson", version.ref = "parssonVersion" }
shedlock = {module="net.javacrumbs.shedlock:shedlock-spring", version.ref="shedlockVersion"}
shedlock-jdbc-provider = {module="net.javacrumbs.shedlock:shedlock-provider-jdbc-template", version.ref="shedlockVersion"}

[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "springbootVersion" }
Expand All @@ -50,3 +53,4 @@ logback = ["logback-classic"]
junit = ["junit-jupiter-api", "junit-jupiter-engine"]
mockito = ["mockito", "mockito-junit"]
json = ["json-api", "parsson"]
shedlock = ["shedlock", "shedlock-jdbc-provider"]
2 changes: 1 addition & 1 deletion scripts/java_check.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Set the required Java version as a variable
REQUIRED_JAVA_VERSION=17
REQUIRED_JAVA_VERSION=21

# Function to compare two versions
# Function to compare two versions
Expand Down
4 changes: 3 additions & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version = "0.0.1-SNAPSHOT"

description = ""

assert System.properties["java.specification.version"] == "17" || "18" || "19" || "20" || "21" || "22"
assert System.properties["java.specification.version"] == "21" || "22" || "23"

ext {
springProfiles = ""
Expand Down Expand Up @@ -120,6 +120,8 @@ dependencies {
implementation("org.hibernate.validator:hibernate-validator")
implementation(libs.bundles.spring.statemachine)
implementation(libs.liquibase)
implementation(libs.bundles.shedlock)


// testImplementation("com.tngtech.archunit:archunit-junit5-api:${archunitJunit5Version}") {
// exclude group: "org.slf4j", module: "slf4j-api"
Expand Down
2 changes: 0 additions & 2 deletions server/src/main/java/io/flexwork/FlexworkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import tech.jhipster.config.DefaultProfileUtil;

@SpringBootApplication
Expand All @@ -38,7 +37,6 @@
FlexworkProperties.class
})
@EntityScan("io.flexwork")
@EnableScheduling
@Order(1)
public class FlexworkApp implements CommandLineRunner {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.flexwork.config;

import java.util.concurrent.Executor;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
Expand All @@ -20,6 +21,7 @@
@Configuration
@EnableAsync
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
@Profile("!testdev & !testprod")
public class AsyncConfiguration implements AsyncConfigurer {

Expand All @@ -44,7 +46,7 @@ public Executor getAsyncExecutor() {
}

@Bean(name = "auditLogExecutor")
public TaskExecutor auditLogaskExecutor() {
public TaskExecutor auditLogTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(50);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.flexwork.modules.teams.repository;

import io.flexwork.modules.teams.domain.WorkflowState;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -12,4 +13,6 @@ public interface WorkflowStateRepository extends JpaRepository<WorkflowState, Lo
@Query(
"SELECT ws FROM WorkflowState ws WHERE ws.workflow.id = :workflowId AND ws.isInitial = true")
WorkflowState findInitialStateByWorkflowId(@Param("workflowId") Long workflowId);

List<WorkflowState> findByWorkflowId(Long workflowId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.flexwork.modules.teams.service;

import io.flexwork.modules.teams.repository.WorkflowStateRepository;
import io.flexwork.modules.teams.service.dto.WorkflowStateDTO;
import io.flexwork.modules.teams.service.mapper.WorkflowStateMapper;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class WorkflowStateService {

private final WorkflowStateRepository workflowStateRepository;

private final WorkflowStateMapper workflowStateMapper;

public WorkflowStateService(
WorkflowStateRepository workflowStateRepository,
WorkflowStateMapper workflowStateMapper) {
this.workflowStateRepository = workflowStateRepository;
this.workflowStateMapper = workflowStateMapper;
}

public List<WorkflowStateDTO> getStatesByWorkflowId(Long workflowId) {
return workflowStateRepository.findByWorkflowId(workflowId).stream()
.map(workflowStateMapper::toDto)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.flexwork.modules.teams.service.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class WorkflowStateDTO {
private Long id;
private Long workflowId;
private String stateName;
private Boolean isInitial;
private Boolean isFinal;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.flexwork.modules.teams.service.mapper;

import io.flexwork.modules.teams.domain.WorkflowState;
import io.flexwork.modules.teams.service.dto.WorkflowStateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface WorkflowStateMapper {

@Mapping(source = "workflow.id", target = "workflowId")
WorkflowStateDTO toDto(WorkflowState workflowState);

@Mapping(source = "workflowId", target = "workflow.id")
WorkflowState toEntity(WorkflowStateDTO workflowStateDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import io.flexwork.modules.teams.domain.Workflow;
import io.flexwork.modules.teams.service.WorkflowService;
import io.flexwork.modules.teams.service.WorkflowStateService;
import io.flexwork.modules.teams.service.dto.WorkflowDTO;
import io.flexwork.modules.teams.service.dto.WorkflowStateDTO;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -13,8 +15,12 @@ public class WorkflowController {

private final WorkflowService workflowService;

public WorkflowController(WorkflowService workflowService) {
private final WorkflowStateService workflowStateService;

public WorkflowController(
WorkflowService workflowService, WorkflowStateService workflowStateService) {
this.workflowService = workflowService;
this.workflowStateService = workflowStateService;
}

@PostMapping
Expand Down Expand Up @@ -69,4 +75,16 @@ public ResponseEntity<List<WorkflowDTO>> getWorkflowsByTeam(@PathVariable Long t
List<WorkflowDTO> workflows = workflowService.getWorkflowsForTeam(teamId);
return ResponseEntity.ok(workflows);
}

/**
* Retrieve all workflow states for a given workflow ID.
*
* @param workflowId the ID of the workflow
* @return a list of workflow states
*/
@GetMapping("/{workflowId}/states")
public ResponseEntity<List<WorkflowStateDTO>> getWorkflowStates(@PathVariable Long workflowId) {
List<WorkflowStateDTO> states = workflowStateService.getStatesByWorkflowId(workflowId);
return ResponseEntity.ok(states);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
author="flexapp">
<createSequence sequenceName="sequence_generator"
minValue="100" startValue="100" incrementBy="1" />

<!--Table for shedLock, a distributed lock for spring scheduling service -->
<createTable tableName="shedlock">
<column name="name" type="VARCHAR(64)">
<constraints nullable="false" primaryKey="true" />
</column>
<column name="lock_until" type="TIMESTAMP">
<constraints nullable="false" />
</column>
<column name="locked_at" type="TIMESTAMP">
<constraints nullable="false" />
</column>
<column name="locked_by" type="VARCHAR(255)">
<constraints nullable="false" />
</column>
</createTable>

<createTable tableName="fw_user">
<column name="id" type="bigint">
<constraints primaryKey="true" />
Expand Down
Loading