diff --git a/mdw-common/src/com/centurylink/mdw/model/workflow/Milestone.java b/mdw-common/src/com/centurylink/mdw/model/workflow/Milestone.java index 8733aaa05f..69fd33d182 100644 --- a/mdw-common/src/com/centurylink/mdw/model/workflow/Milestone.java +++ b/mdw-common/src/com/centurylink/mdw/model/workflow/Milestone.java @@ -115,6 +115,11 @@ public void setActivityInstance(ActivityInstance activityInstance) { } } + @Override + public JSONObject toJson() { + return getJson(); + } + @Override public JSONObject getJson() { JSONObject json = create(); diff --git a/mdw-services/src/com/centurylink/mdw/service/data/WorkflowDataAccess.java b/mdw-services/src/com/centurylink/mdw/service/data/WorkflowDataAccess.java index 2232789e5d..b4fbbf2712 100644 --- a/mdw-services/src/com/centurylink/mdw/service/data/WorkflowDataAccess.java +++ b/mdw-services/src/com/centurylink/mdw/service/data/WorkflowDataAccess.java @@ -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; @@ -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; + } + } \ No newline at end of file diff --git a/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java b/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java index 3fb6d90fef..722e9dda51 100644 --- a/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java +++ b/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java @@ -266,4 +266,7 @@ String invokeServiceProcess(Process process, String masterRequestId, String owne Linked getMilestones(Long masterProcessInstanceId, boolean future) throws ServiceException; Linked getActivityHierarchy(ProcessInstance processInstance) throws ServiceException; + + List getMilestones(Linked instanceHierarchy) throws ServiceException; + } \ No newline at end of file diff --git a/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java b/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java index 4b7fda64a7..3de1ec56e1 100644 --- a/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java +++ b/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java @@ -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 getMilestones(Linked instanceHierarchy) + throws ServiceException { + List milestones = new ArrayList<>(); + Process process = ProcessCache.getProcess(instanceHierarchy.get().getProcessId()); + if (process != null) { + Linked milestoneDefs = HierarchyCache.getMilestones(process.getId()); + for (Linked milestoneDef : milestoneDefs) { + Milestone milestone = milestoneDef.get(); + Long processId = milestone.getProcess().getId(); + Linked 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; + } + }