Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Donald Oakes committed Feb 26, 2020
1 parent 9a2df70 commit d3b7366
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public void setActivityInstance(ActivityInstance activityInstance) {
}
}

@Override
public JSONObject toJson() {
return getJson();
}

@Override
public JSONObject getJson() {
JSONObject json = create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import com.centurylink.mdw.constant.OwnerType;
import com.centurylink.mdw.dataaccess.DataAccessException;
import com.centurylink.mdw.dataaccess.DatabaseAccess;
import com.centurylink.mdw.dataaccess.DbAccess;
import com.centurylink.mdw.dataaccess.db.CommonDataAccess;
import com.centurylink.mdw.model.workflow.ProcessInstance;
import com.centurylink.mdw.model.workflow.ProcessList;
import com.centurylink.mdw.model.workflow.WorkStatus;
import com.centurylink.mdw.model.workflow.WorkStatuses;
import com.centurylink.mdw.model.workflow.*;
import com.centurylink.mdw.model.workflow.Process;
import com.centurylink.mdw.util.log.ActivityLog;
import com.centurylink.mdw.util.log.ActivityLogLine;
import com.centurylink.mdw.util.log.StandardLogger;
Expand Down Expand Up @@ -379,4 +378,38 @@ private ActivityLog buildActivityLog(ResultSet rs) throws SQLException {
}
}

/**
* Get activity milestone (with activity instance if started). Does not include implicit milestones (start/stop)
*/
public Milestone getMilestone(Process process, ProcessInstance processInstance, Activity activity) throws DataAccessException {

String sql = "select ACTIVITY_INSTANCE_ID, STATUS_CD, START_DT, END_DT, STATUS_MESSAGE, ACTIVITY_ID, PROCESS_INSTANCE_ID"
+ " from ACTIVITY_INSTANCE where PROCESS_INSTANCE_ID = ? and ACTIVITY_ID = ? order by ACTIVITY_INSTANCE_ID desc";

Milestone milestone = new MilestoneFactory(process).getMilestone(activity);
if (milestone != null) {
milestone.setProcessInstance(processInstance);

try (DbAccess dbAccess = new DbAccess()) {
ResultSet rs = dbAccess.runSelect(sql, processInstance.getId(), activity.getId());
if (rs.next()) {
ActivityInstance activityInstance = new ActivityInstance();
activityInstance.setId(rs.getLong("ACTIVITY_INSTANCE_ID"));
activityInstance.setStatusCode(rs.getInt("STATUS_CD"));
activityInstance.setStartDate(rs.getTimestamp("START_DT"));
activityInstance.setEndDate(rs.getTimestamp("END_DT"));
activityInstance.setMessage(rs.getString("STATUS_MESSAGE"));
activityInstance.setActivityId(rs.getLong("ACTIVITY_ID"));
activityInstance.setProcessInstanceId(rs.getLong("PROCESS_INSTANCE_ID"));
milestone.setActivityInstance(activityInstance);
milestone.setMasterRequestId(processInstance.getMasterRequestId());
}
}
catch (SQLException ex) {
throw new DataAccessException("Error retrieving milestone for pi=" + processInstance.getId() + ", a=" + activity.getId(), ex);
}
}
return milestone;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,7 @@ String invokeServiceProcess(Process process, String masterRequestId, String owne
Linked<Milestone> getMilestones(Long masterProcessInstanceId, boolean future) throws ServiceException;

Linked<ActivityInstance> getActivityHierarchy(ProcessInstance processInstance) throws ServiceException;

List<Milestone> getMilestones(Linked<ProcessInstance> instanceHierarchy) throws ServiceException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -1700,4 +1700,35 @@ private boolean isIgnored(ProcessInstance processInstance) {
return ignores != null &&
ignores.contains(processInstance.getPackageName() + "/" + processInstance.getProcessName() + ".proc");
}

/**
* TODO use WorkflowServices method when available in 6.1.32
* Retrieve milestones for a process instance hierarchy
*/
public List<Milestone> getMilestones(Linked<ProcessInstance> instanceHierarchy)
throws ServiceException {
List<Milestone> milestones = new ArrayList<>();
Process process = ProcessCache.getProcess(instanceHierarchy.get().getProcessId());
if (process != null) {
Linked<Milestone> milestoneDefs = HierarchyCache.getMilestones(process.getId());
for (Linked<Milestone> milestoneDef : milestoneDefs) {
Milestone milestone = milestoneDef.get();
Long processId = milestone.getProcess().getId();
Linked<ProcessInstance> subHierarchy = instanceHierarchy.find(pi -> pi.getProcessId().equals(processId));
if (subHierarchy != null) {
try {
Milestone m = getWorkflowDao().getMilestone(process, subHierarchy.get(), milestone.getActivity());
if (m != null)
milestone = m;
}
catch (DataAccessException ex) {
throw new ServiceException("Failed to load milestone", ex);
}
}
milestones.add(milestone);
}
}
return milestones;
}

}

0 comments on commit d3b7366

Please sign in to comment.