Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Dec 10, 2024
1 parent 17708bd commit e9e9e6e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;

@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "fw_team_request")
@Data
Expand Down
29 changes: 16 additions & 13 deletions server/src/main/java/io/flexwork/modules/teams/domain/Workflow.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
package io.flexwork.modules.teams.domain;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import io.flexwork.modules.audit.AbstractAuditingEntity;
import jakarta.persistence.*;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "fw_workflow")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Workflow {
public class Workflow extends AbstractAuditingEntity<Long> {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -71,4 +62,16 @@ public class Workflow {
nullable = false,
columnDefinition = "INT DEFAULT 1000000")
private Integer level3EscalationTimeout;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "parent_workflow_id",
foreignKey = @ForeignKey(name = "fk_workflow_parent_workflow"))
private Workflow parentWorkflow; // Reference to the parent workflow

@Column(name = "cloned_from_global", nullable = false)
private boolean clonedFromGlobal;

@Column(columnDefinition = "TEXT")
private String tags;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@ Optional<Integer> findEscalationTimeoutByLevel(
@EntityGraph(attributePaths = {"states", "transitions", "owner"})
@Query("SELECT w FROM Workflow w WHERE w.id = :workflowId")
Optional<Workflow> findWithDetailsById(@Param("workflowId") Long workflowId);

@Query(
"""
SELECT w
FROM Workflow w
WHERE w.visibility = 'PUBLIC'
AND w.id NOT IN (
SELECT tws.workflow.id
FROM TeamWorkflowSelection tws
WHERE tws.team.id = :teamId
)
""")
List<Workflow> findGlobalWorkflowsNotLinkedToTeam(@Param("teamId") Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,16 @@ public WorkflowDetailedDTO updateWorkflow(

return updatedWorkflow;
}

/**
* List global workflows not linked to the given team.
*
* @param teamId the ID of the team
* @return List of WorkflowDTOs representing the global workflows
*/
public List<WorkflowDTO> listGlobalWorkflowsNotLinkedToTeam(Long teamId) {
return workflowRepository.findGlobalWorkflowsNotLinkedToTeam(teamId).stream()
.map(workflowMapper::toDto)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public class WorkflowDTO {
private Integer level1EscalationTimeout;
private Integer level2EscalationTimeout;
private Integer level3EscalationTimeout;
private Long parentWorkflowId;
private boolean clonedFromGlobal;
private String tags;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public interface WorkflowMapper {

@Mapping(source = "owner.id", target = "ownerId")
@Mapping(source = "parentWorkflow.id", target = "parentWorkflowId")
WorkflowDTO toDto(Workflow workflow);

Workflow toEntity(WorkflowDTO workflowDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public ResponseEntity<List<WorkflowDTO>> getWorkflowsByTeam(@PathVariable Long t
return ResponseEntity.ok(workflows);
}

/**
* Get global workflows not linked to a specific team.
*
* @param teamId the ID of the team
* @return List of WorkflowDTOs representing global workflows not linked to the team
*/
@GetMapping("/teams/{teamId}/global-workflows-not-linked-yet")
public ResponseEntity<List<WorkflowDTO>> getGlobalWorkflowsNotLinkedToTeam(
@RequestParam Long teamId) {
List<WorkflowDTO> workflows = workflowService.listGlobalWorkflowsNotLinkedToTeam(teamId);
return ResponseEntity.ok(workflows);
}

/**
* Endpoint to retrieve all valid target states for a given workflow and current state ID, with
* an option to include the current state itself.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@
defaultValue="1000000">
<constraints nullable="false" />
</column>
<!--To support cloning and referencing global workflows -->
<!--If a workflow is cloned from another workflow, this column stores
the id of the original workflow. -->
<!--If the workflow is created from scratch, the value is NULL. -->
<column name="parent_workflow_id" type="BIGINT">
<constraints nullable="true" />
</column>
<!--To track if a workflow is cloned from a global workflow for better
visibility -->
<column name="cloned_from_global" type="BOOLEAN"
defaultValue="false">
<constraints nullable="false" />
</column>
<!--To support tagging workflows for better categorization and searchability -->
<column name="tags" type="TEXT" />
<column name="created_by" type="bigint" />
<column name="created_at" type="timestamptz" />
<column name="modified_by" type="bigint" />
<column name="modified_at" type="timestamptz" />
</createTable>

<!-- Add foreign key constraint to fw_team for owner_id -->
Expand All @@ -58,6 +77,21 @@
referencedTableName="fw_team" referencedColumnNames="id"
onDelete="CASCADE" constraintName="fk_workflow_owner_team" />

<addForeignKeyConstraint
baseTableName="fw_workflow" baseColumnNames="parent_workflow_id"
referencedTableName="fw_workflow" referencedColumnNames="id"
constraintName="fk_workflow_parent_workflow" />

<addForeignKeyConstraint
baseTableName="fw_workflow" baseColumnNames="created_by"
referencedTableName="fw_user" referencedColumnNames="id"
constraintName="fk_workflow_created_by_user" />

<addForeignKeyConstraint
baseTableName="fw_workflow" baseColumnNames="modified_by"
referencedTableName="fw_user" referencedColumnNames="id"
constraintName="fk_workflow_last_modified_by_user" />

<createTable tableName="fw_team_workflow_selection">
<column name="id" type="BIGINT" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
Expand Down

0 comments on commit e9e9e6e

Please sign in to comment.