Commit 7b0e94d6 authored by Aalekh Jain's avatar Aalekh Jain
Browse files

Updated `WorkflowManagerServiceImpl`

Updated manager service impl with create system workflow and delete system workflow methods
parent 49dd4bc4
......@@ -4,8 +4,10 @@ import lombok.RequiredArgsConstructor;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.core.common.exception.BadRequestException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.workflow.exception.WorkflowNotFoundException;
import org.opengroup.osdu.workflow.logging.AuditLogger;
import org.opengroup.osdu.workflow.model.CreateWorkflowRequest;
import org.opengroup.osdu.workflow.model.WorkflowEngineRequest;
......@@ -14,6 +16,8 @@ import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowEngineService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowManagerService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowMetadataRepository;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowRunService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowSystemMetadataRepository;
import org.springframework.stereotype.Service;
@Service
......@@ -26,6 +30,8 @@ public class WorkflowManagerServiceImpl implements IWorkflowManagerService {
private final IWorkflowMetadataRepository workflowMetadataRepository;
private final IWorkflowSystemMetadataRepository workflowSystemMetadataRepository;
private final IWorkflowEngineService workflowEngineService;
private final IWorkflowRunService workflowRunService;
......@@ -34,10 +40,7 @@ public class WorkflowManagerServiceImpl implements IWorkflowManagerService {
@Override
public WorkflowMetadata createWorkflow(final CreateWorkflowRequest request) {
if (!request.getWorkflowName().matches("^[a-zA-Z0-9._-]{1,64}$")) {
throw new BadRequestException("Invalid workflow name provided. Must match pattern ^[a-zA-Z0-9._-]{1,64}$");
}
validateWorkflowName(request.getWorkflowName());
final WorkflowMetadata workflowMetadata = getWorkflowMetadata(request, dpsHeaders.getUserEmail());
final WorkflowMetadata savedMetadata = workflowMetadataRepository.createWorkflow(workflowMetadata);
final WorkflowEngineRequest rq = new WorkflowEngineRequest(workflowMetadata.getWorkflowName());
......@@ -47,9 +50,24 @@ public class WorkflowManagerServiceImpl implements IWorkflowManagerService {
return savedMetadata;
}
@Override
public WorkflowMetadata createSystemWorkflow(final CreateWorkflowRequest request) {
validateWorkflowName(request.getWorkflowName());
final WorkflowMetadata workflowMetadata = getWorkflowMetadata(request, dpsHeaders.getUserEmail());
final WorkflowMetadata savedMetadata = workflowSystemMetadataRepository.createSystemWorkflow(workflowMetadata);
final WorkflowEngineRequest rq = new WorkflowEngineRequest(workflowMetadata.getWorkflowName(), false, true);
workflowEngineService.createWorkflow(rq, request.getRegistrationInstructions());
auditLogger.workflowCreateEvent(Collections.singletonList(savedMetadata.toString()));
return savedMetadata;
}
@Override
public WorkflowMetadata getWorkflowByName(final String workflowName) {
return workflowMetadataRepository.getWorkflow(workflowName);
try {
return workflowMetadataRepository.getWorkflow(workflowName);
} catch (WorkflowNotFoundException e) {
return workflowSystemMetadataRepository.getSystemWorkflow(workflowName);
}
}
@Override
......@@ -62,9 +80,29 @@ public class WorkflowManagerServiceImpl implements IWorkflowManagerService {
auditLogger.workflowDeleteEvent(Collections.singletonList(workflowName));
}
@Override
public void deleteSystemWorkflow(String workflowName) {
final WorkflowMetadata workflowMetadata = workflowSystemMetadataRepository.getSystemWorkflow(workflowName);
WorkflowEngineRequest rq = new WorkflowEngineRequest(workflowName, workflowMetadata.isDeployedThroughWorkflowService(), true);
workflowEngineService.deleteWorkflow(rq);
workflowSystemMetadataRepository.deleteSystemWorkflow(workflowName);
auditLogger.workflowDeleteEvent(Collections.singletonList(workflowName));
}
@Override
public List<WorkflowMetadata> getAllWorkflowForTenant(String prefix) {
return workflowMetadataRepository.getAllWorkflowForTenant(prefix);
List<WorkflowMetadata> workflowMetadataList = workflowMetadataRepository.getAllWorkflowForTenant(prefix);
List<WorkflowMetadata> workflowSystemMetadataList = workflowSystemMetadataRepository.getAllSystemWorkflow(prefix);
workflowMetadataList.addAll(workflowSystemMetadataList);
return workflowMetadataList;
}
private void validateWorkflowName(String workflowName) {
if ((StringUtils.isEmpty(workflowName)) ||
(!workflowName.matches("^[a-zA-Z0-9._-]{1,64}$"))) {
throw new BadRequestException("Invalid workflow name provided. Must match pattern ^[a-zA-Z0-9._-]{1,64}$");
}
}
private WorkflowMetadata getWorkflowMetadata(final CreateWorkflowRequest request,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment