Skip to content

Commit

Permalink
Merge pull request #241 from DependencyTrack/create-model-for-workflo…
Browse files Browse the repository at this point in the history
…w-engine

Create model for workflow engine
  • Loading branch information
nscuro authored Jul 20, 2023
2 parents 4b09783 + 9adaf33 commit 1e69392
Show file tree
Hide file tree
Showing 9 changed files with 689 additions and 15 deletions.
123 changes: 123 additions & 0 deletions src/main/java/org/dependencytrack/model/WorkflowState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.dependencytrack.model;

import com.fasterxml.jackson.annotation.JsonInclude;

import javax.jdo.annotations.Column;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

@PersistenceCapable(table= "WORKFLOW_STATE")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Unique(name = "WORKFLOW_STATE_COMPOSITE_IDX", members = {"token", "step"})
public class WorkflowState implements Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.NATIVE)
private long id;

// null allowed because first step will have no parent and will be the first step of recursion
@Persistent
@Column(name = "PARENT_STEP_ID" , allowsNull = "true")
private WorkflowState parent;

@Persistent
@Column(name = "TOKEN", jdbcType = "VARCHAR", length = 36, allowsNull = "false")
@NotNull
private UUID token;

@Persistent
@Column(name = "STARTED_AT", allowsNull = "true")
private Date startedAt;

@Persistent
@Column(name = "UPDATED_AT", allowsNull = "true")
private Date updatedAt;

@Persistent
@Column(name = "STEP", jdbcType = "VARCHAR", length = 64, allowsNull = "false")
@NotNull
@Extension(vendorName = "datanucleus", key = "enum-check-constraint", value = "true")
private WorkflowStep step;

@Persistent
@Column(name = "STATUS", jdbcType = "VARCHAR", length = 64, allowsNull = "false")
@NotNull
@Extension(vendorName = "datanucleus", key = "enum-check-constraint", value = "true")
private WorkflowStatus status;

@Persistent
@Column(name = "FAILURE_REASON", jdbcType = "CLOB", allowsNull = "true")
private String failureReason;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public WorkflowState getParent() {
return parent;
}

public void setParent(WorkflowState parent) {
this.parent = parent;
}

public UUID getToken() {
return token;
}

public void setToken(UUID token) {
this.token = token;
}

public Date getStartedAt() {
return startedAt;
}

public void setStartedAt(Date startedAt) {
this.startedAt = startedAt;
}

public Date getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}

public WorkflowStep getStep() {
return step;
}

public void setStep(WorkflowStep step) {
this.step = step;
}

public WorkflowStatus getStatus() {
return status;
}

public void setStatus(WorkflowStatus status) {
this.status = status;
}

public String getFailureReason() {
return failureReason;
}

public void setFailureReason(String failureReason) {
this.failureReason = failureReason;
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/dependencytrack/model/WorkflowStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.dependencytrack.model;

public enum WorkflowStatus {
PENDING,
TIMED_OUT,
COMPLETED,
FAILED,
CANCELLED,
NOT_APPLICABLE
}
10 changes: 10 additions & 0 deletions src/main/java/org/dependencytrack/model/WorkflowStep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.dependencytrack.model;

public enum WorkflowStep {
BOM_CONSUMPTION,
BOM_PROCESSING,
VULN_ANALYSIS,
REPO_META_ANALYSIS,
POLICY_EVALUATION,
METRICS_UPDATE
}
41 changes: 40 additions & 1 deletion src/main/java/org/dependencytrack/persistence/QueryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
import org.dependencytrack.model.VulnerabilityMetrics;
import org.dependencytrack.model.VulnerabilityScan;
import org.dependencytrack.model.VulnerableSoftware;
import org.dependencytrack.model.WorkflowState;
import org.dependencytrack.model.WorkflowStatus;
import org.dependencytrack.model.WorkflowStep;
import org.dependencytrack.notification.NotificationScope;
import org.dependencytrack.notification.publisher.PublisherClass;
import org.hyades.proto.vulnanalysis.v1.ScanStatus;
Expand Down Expand Up @@ -118,6 +121,7 @@ public class QueryManager extends AlpineQueryManager {
private VexQueryManager vexQueryManager;
private VulnerabilityQueryManager vulnerabilityQueryManager;
private VulnerableSoftwareQueryManager vulnerableSoftwareQueryManager;
private WorkflowStateQueryManager workflowStateQueryManager;

private TagQueryManager tagQueryManager;

Expand Down Expand Up @@ -329,6 +333,13 @@ private NotificationQueryManager getNotificationQueryManager() {
return notificationQueryManager;
}

private WorkflowStateQueryManager getWorkflowStateQueryManager() {
if (workflowStateQueryManager == null) {
workflowStateQueryManager = (request == null) ? new WorkflowStateQueryManager(getPersistenceManager()) : new WorkflowStateQueryManager(getPersistenceManager(), request);
}
return workflowStateQueryManager;
}

/**
* Get the IDs of the {@link Team}s a given {@link Principal} is a member of.
*
Expand Down Expand Up @@ -978,7 +989,7 @@ public ServiceComponent updateServiceComponent(ServiceComponent transientService
}

public void deleteServiceComponents(final Project project) {
getServiceComponentQueryManager().deleteServiceComponents(project);
getServiceComponentQueryManager().deleteServiceComponents(project);
}

public void recursivelyDelete(ServiceComponent service, boolean commitIndex) {
Expand Down Expand Up @@ -1537,4 +1548,32 @@ public Object executeAndClose(final Query<?> query, final Object... parameters)
}
}


public List<WorkflowState> getAllWorkflowStatesForAToken(UUID token) {
return getWorkflowStateQueryManager().getAllWorkflowStatesForAToken(token);
}

public List<WorkflowState> getAllDescendantWorkflowStatesOfParent(WorkflowState parent) {
return getWorkflowStateQueryManager().getAllDescendantWorkflowStatesOfParent(parent);
}

public WorkflowState getWorkflowStateById(long id) {
return getWorkflowStateQueryManager().getWorkflowState(id);
}

public WorkflowState updateWorkflowState(WorkflowState transientWorkflowState) {
return getWorkflowStateQueryManager().updateWorkflowState(transientWorkflowState);
}

public int updateAllDescendantStatesOfParent(WorkflowState parentWorkflowState, WorkflowStatus transientStatus) {
return getWorkflowStateQueryManager().updateAllDescendantStatesOfParent(parentWorkflowState, transientStatus);
}

public WorkflowState getWorkflowStateByTokenAndStep(UUID token, WorkflowStep workflowStep) {
return getWorkflowStateQueryManager().getWorkflowStateByTokenAndStep(token, workflowStep);
}

public void deleteWorkflowState(WorkflowState workflowState) {
getWorkflowStateQueryManager().deleteWorkflowState(workflowState);
}
}
Loading

0 comments on commit 1e69392

Please sign in to comment.