[REMOVE] WorkflowStepController, WorkflowStepEntity, related services, request classes, repository, and specifications
parent
cd71a908f3
commit
ce0258e90d
@ -1,79 +0,0 @@
|
||||
package kr.re.etri.autoflow.controllers;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import kr.re.etri.autoflow.entity.WorkflowStepEntity;
|
||||
import kr.re.etri.autoflow.payload.request.WorkFlowStepRequest;
|
||||
import kr.re.etri.autoflow.service.WorkFlowStepService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "워크플로우 스텝", description = "워크플로우 스텝 API")
|
||||
@RestController
|
||||
@RequestMapping("/api/workflow-steps")
|
||||
@RequiredArgsConstructor
|
||||
public class WorkflowStepController {
|
||||
|
||||
private final WorkFlowStepService workflowStepService;
|
||||
|
||||
@Operation(summary = "모든 워크플로우 스텝 조회")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<WorkflowStepEntity>> getAllWorkflowSteps() {
|
||||
return ResponseEntity.ok(workflowStepService.findAll());
|
||||
}
|
||||
|
||||
@Operation(summary = "워크플로우 스텝 단건 조회")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<WorkflowStepEntity> getWorkflowStep(
|
||||
@Parameter(description = "워크플로우 스텝 ID", example = "1") @PathVariable("id") Long id) {
|
||||
|
||||
return workflowStepService.findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "워크플로우 스텝 검색 및 페이지네이션")
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<Page<WorkflowStepEntity>> searchWorkflowSteps(
|
||||
@ParameterObject @ModelAttribute WorkFlowStepRequest request) {
|
||||
Page<WorkflowStepEntity> page = workflowStepService.search(request);
|
||||
return ResponseEntity.ok(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "워크플로우 스텝 등록")
|
||||
@PostMapping
|
||||
public ResponseEntity<WorkflowStepEntity> createWorkflowStep(@RequestBody WorkflowStepEntity workflowStep) {
|
||||
return ResponseEntity.ok(workflowStepService.save(workflowStep));
|
||||
}
|
||||
|
||||
@Operation(summary = "워크플로우 스텝 수정")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<WorkflowStepEntity> updateWorkflowStep(
|
||||
@Parameter(description = "워크플로우 스텝 ID", example = "1") @PathVariable("id") Long id,
|
||||
@RequestBody WorkflowStepEntity workflowStep) {
|
||||
|
||||
return workflowStepService.findById(id)
|
||||
.map(existing -> {
|
||||
workflowStep.setId(id);
|
||||
return ResponseEntity.ok(workflowStepService.save(workflowStep));
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "워크플로우 스텝 삭제")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteWorkflowStep(
|
||||
@Parameter(description = "워크플로우 스텝 ID", example = "1") @PathVariable("id") Long id) {
|
||||
|
||||
if (workflowStepService.deleteById(id)) {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package kr.re.etri.autoflow.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tb_workflow_steps")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Builder
|
||||
@Schema(description = "워크플로우 스텝 엔티티")
|
||||
public class WorkflowStepEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Schema(description = "워크플로우 스텝 ID", example = "null", defaultValue = "null")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "스텝 이름", example = "데이터 전처리")
|
||||
@Column(nullable = false, length = 100)
|
||||
private String stepName;
|
||||
|
||||
@Schema(description = "스텝 상태", example = "Running")
|
||||
@Column(nullable = false, length = 50)
|
||||
private String status;
|
||||
|
||||
@Schema(description = "생성자 ID", example = "admin")
|
||||
@Column(nullable = false, length = 50)
|
||||
private String regUserId;
|
||||
|
||||
@Schema(description = "생성 일시", example = "2025-09-11T10:00:00")
|
||||
@CreatedDate
|
||||
private LocalDateTime regDt;
|
||||
|
||||
@Schema(description = "버전", example = "1")
|
||||
@Column(nullable = false)
|
||||
private Long version;
|
||||
|
||||
/** Kubeflow에서 가져와야하는 항목 **/
|
||||
|
||||
@Schema(description = "Kubeflow Pipeline ID", example = "b8c5edc5-6feb-4f9a-8c02-0927e8f864bd")
|
||||
@Column(length = 100)
|
||||
private String pipelineId; // Kubeflow Pipeline 식별자
|
||||
|
||||
@Schema(description = "Kubeflow 시작 시각", example = "2025-09-11T10:00:00")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "Kubeflow 종료 시각", example = "2025-09-11T10:30:00")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "Kubeflow 실행 로그 경로", example = "/logs/workflow/step1.log")
|
||||
@Column(length = 500)
|
||||
private String logPath;
|
||||
|
||||
@Schema(description = "프로젝트 아이디", example = "1", defaultValue = "0")
|
||||
@Column(nullable = false)
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "워크플로우 스텝 아이디", example = "1", defaultValue = "0")
|
||||
@Column(nullable = false)
|
||||
private Long workflowStepId;
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package kr.re.etri.autoflow.payload.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WorkFlowStepRequest extends BaseSearchRequest {
|
||||
@Schema(description = "프로젝트 ID", example = "1")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "프로젝트 ID", example = "1")
|
||||
private Long workflowId;
|
||||
}
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
package kr.re.etri.autoflow.repository;
|
||||
|
||||
import kr.re.etri.autoflow.entity.WorkflowEntity;
|
||||
import kr.re.etri.autoflow.entity.WorkflowStepEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface WorkflowStepRepository extends JpaRepository<WorkflowStepEntity, Long>, JpaSpecificationExecutor<WorkflowStepEntity> {
|
||||
Long findVersionById(Long id);
|
||||
}
|
||||
@ -1,88 +0,0 @@
|
||||
package kr.re.etri.autoflow.service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import kr.re.etri.autoflow.entity.WorkflowStepEntity;
|
||||
import kr.re.etri.autoflow.payload.request.WorkFlowStepRequest;
|
||||
import kr.re.etri.autoflow.repository.WorkflowStepRepository;
|
||||
import kr.re.etri.autoflow.specification.WorkflowStepSpecification;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WorkFlowStepService {
|
||||
|
||||
private final WorkflowStepRepository workflowstepRepository;
|
||||
private final WorkflowStepSpecification workflowstepSpecification;
|
||||
|
||||
|
||||
public List<WorkflowStepEntity> findAll() {
|
||||
return workflowstepRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<WorkflowStepEntity> findById(Long id) {
|
||||
return workflowstepRepository.findById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public WorkflowStepEntity save(WorkflowStepEntity workflowstep) {
|
||||
if (workflowstep.getId() == null) {
|
||||
// 신규 생성
|
||||
workflowstep.setVersion(1L);
|
||||
} else {
|
||||
// 업데이트 시 기존 max 버전 + 1
|
||||
// int maxVersion = Math.toIntExact(workflowstepRepository.findVersionById(workflowstep.getId()));
|
||||
// workflowstep.setVersion((long) (maxVersion+1));
|
||||
}
|
||||
return workflowstepRepository.save(workflowstep);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean deleteById(Long id) {
|
||||
if (workflowstepRepository.existsById(id)) {
|
||||
workflowstepRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Page<WorkflowStepEntity> search(WorkFlowStepRequest request) {
|
||||
int pageIndex = request.getPage() > 0 ? request.getPage() - 1 : 0;
|
||||
|
||||
Pageable pageable = PageRequest.of(
|
||||
pageIndex,
|
||||
request.getSize(),
|
||||
Sort.by(Sort.Direction.fromString(request.getSortDirection()), request.getSortField())
|
||||
);
|
||||
|
||||
Specification<WorkflowStepEntity> spec = workflowstepSpecification.searchByConditions(
|
||||
request.getSearchType(),
|
||||
request.getKeyword()
|
||||
);
|
||||
|
||||
// projectId가 있으면 조건 추가 (권장)
|
||||
if (request.getProjectId() != null) {
|
||||
spec = spec.and((root, query, cb) ->
|
||||
cb.equal(root.get("projectId"), request.getProjectId())
|
||||
);
|
||||
}
|
||||
|
||||
// workflowId 있으면 조건 추가 (권장)
|
||||
if (request.getWorkflowId() != null) {
|
||||
spec = spec.and((root, query, cb) ->
|
||||
cb.equal(root.get("workflowId"), request.getWorkflowId())
|
||||
);
|
||||
}
|
||||
|
||||
return workflowstepRepository.findAll(spec, pageable);
|
||||
}
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
package kr.re.etri.autoflow.specification;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.metamodel.Attribute;
|
||||
import jakarta.persistence.metamodel.EntityType;
|
||||
import jakarta.persistence.metamodel.Metamodel;
|
||||
import kr.re.etri.autoflow.entity.WorkflowStepEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WorkflowStepSpecification {
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
private Set<String> stringFields;
|
||||
|
||||
public WorkflowStepSpecification(EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
// 스프링 빈 초기화 후 실행
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
Metamodel metamodel = entityManager.getMetamodel();
|
||||
EntityType<WorkflowStepEntity> entityType = metamodel.entity(WorkflowStepEntity.class);
|
||||
|
||||
// 문자열 타입 필드명만 추출
|
||||
stringFields = entityType.getAttributes().stream()
|
||||
.filter(attr -> attr.getJavaType().equals(String.class))
|
||||
.map(Attribute::getName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
log.info("ProjectEntity string fields: {}", stringFields);
|
||||
}
|
||||
|
||||
public Specification<WorkflowStepEntity> searchByConditions(
|
||||
String searchType, String keyword) {
|
||||
|
||||
return (root, query, cb) -> {
|
||||
Predicate predicate = cb.conjunction();
|
||||
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
if (searchType == null || searchType.isEmpty() ||
|
||||
"전체".equalsIgnoreCase(searchType) || "all".equalsIgnoreCase(searchType)) {
|
||||
Predicate orPredicate = cb.disjunction();
|
||||
for (String field : stringFields) {
|
||||
orPredicate = cb.or(orPredicate,
|
||||
cb.like(cb.lower(root.get(field)), "%" + keyword.toLowerCase() + "%"));
|
||||
}
|
||||
predicate = cb.and(predicate, orPredicate);
|
||||
|
||||
} else if (stringFields.contains(searchType)) {
|
||||
predicate = cb.and(predicate,
|
||||
cb.like(cb.lower(root.get(searchType)), "%" + keyword.toLowerCase() + "%"));
|
||||
}
|
||||
// 날짜 타입 필드 검색 시 무시
|
||||
}
|
||||
|
||||
return predicate;
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue