Commit e2cb1d76 authored by Aalekh Jain's avatar Aalekh Jain
Browse files

Added `WorkflowSystemMetadataRepository.java`

parent 461b3ec6
package org.opengroup.osdu.workflow.provider.azure.repository;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlQuerySpec;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.workflow.model.WorkflowMetadata;
import org.opengroup.osdu.workflow.provider.azure.config.AzureWorkflowEngineConfig;
import org.opengroup.osdu.workflow.provider.azure.config.CosmosConfig;
import org.opengroup.osdu.workflow.provider.azure.model.WorkflowMetadataDoc;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowSystemMetadataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
@Component
public class WorkflowSystemMetadataRepository extends BaseWorkflowMetadataRepository implements IWorkflowSystemMetadataRepository {
private static final String LOGGER_NAME = WorkflowMetadataRepository.class.getName();
private static final String KEY_DAG_CONTENT = "dagContent";
private static final String KEY_DAG_TYPE = "dagType";
@Autowired
private CosmosConfig cosmosConfig;
@Autowired
private CosmosStore cosmosStore;
@Autowired
private DpsHeaders dpsHeaders;
@Autowired
private JaxRsDpsLog logger;
@Autowired
private AzureWorkflowEngineConfig workflowEngineConfig;
@Override
public WorkflowMetadata getSystemWorkflow(final String workflowName) {
Optional<WorkflowMetadataDoc> workflowSystemMetadataDoc =
cosmosStore.findItem(
cosmosConfig.getSystemdatabase(),
cosmosConfig.getWorkflowMetadataCollection(),
workflowName,
workflowName,
WorkflowMetadataDoc.class
);
if (null == workflowSystemMetadataDoc || !workflowSystemMetadataDoc.isPresent()) {
handleGetWorkflowException(workflowName);
}
return buildWorkflowMetadata(workflowSystemMetadataDoc.get());
}
@Override
public WorkflowMetadata createSystemWorkflow(final WorkflowMetadata workflowMetadata) {
final WorkflowMetadataDoc workflowMetadataDoc = buildWorkflowMetadataDoc(workflowMetadata);
try {
cosmosStore.createItem(
cosmosConfig.getSystemdatabase(),
cosmosConfig.getWorkflowMetadataCollection(),
workflowMetadataDoc.getPartitionKey(),
workflowMetadataDoc
);
} catch (AppException e) {
handleCreateWorkflowException(e, workflowMetadataDoc.getWorkflowName());
}
return buildWorkflowMetadata(workflowMetadataDoc);
}
@Override
public void deleteSystemWorkflow(String workflowName) {
cosmosStore.deleteItem(
cosmosConfig.getSystemdatabase(),
cosmosConfig.getWorkflowMetadataCollection(),
workflowName,
workflowName
);
}
@Override
public List<WorkflowMetadata> getAllSystemWorkflow(String prefix) {
SqlQuerySpec sqlQuerySpec = buildSqlQuerySpecForGetAllWorkflow(prefix);
final List<WorkflowMetadataDoc> workflowSystemMetadataDocs = cosmosStore.queryItems(
cosmosConfig.getSystemdatabase(),
cosmosConfig.getWorkflowMetadataCollection(),
sqlQuerySpec,
new CosmosQueryRequestOptions(),
WorkflowMetadataDoc.class);
return convertWorkflowMetadataDocsToWorkflowMetadataList(workflowSystemMetadataDocs);
}
}
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