Skip to content

Commit

Permalink
#30519 adding history and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Oct 30, 2024
1 parent 56e5870 commit bc64107
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dotcms.rest.api.v1.workflow;

import com.dotcms.rest.ResponseEntityView;
import com.dotmarketing.portlets.workflows.model.WorkflowTimelineItem;

import java.util.List;

/**
* This class is used to return a list of WorkflowTimelineItem objects as a response entity.
*/
public class ResponseEntityWorkflowHistoryCommentsView extends ResponseEntityView<List<WorkflowTimelineItemView>> {

public ResponseEntityWorkflowHistoryCommentsView(final List<WorkflowTimelineItemView> entity) {
super(entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@
import com.dotmarketing.portlets.workflows.model.SystemActionWorkflowActionMapping;
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.portlets.workflows.model.WorkflowActionClass;
import com.dotmarketing.portlets.workflows.model.WorkflowComment;
import com.dotmarketing.portlets.workflows.model.WorkflowScheme;
import com.dotmarketing.portlets.workflows.model.WorkflowStep;
import com.dotmarketing.portlets.workflows.model.WorkflowTask;
import com.dotmarketing.portlets.workflows.model.WorkflowTimelineItem;
import com.dotmarketing.portlets.workflows.util.WorkflowImportExportUtil;
import com.dotmarketing.portlets.workflows.util.WorkflowSchemeImportExportObject;
import com.dotmarketing.util.Config;
Expand Down Expand Up @@ -140,6 +142,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -5596,4 +5599,100 @@ public final ResponseContentletWorkflowStatusView getStatusForContentlet(@Contex
wfStep, wfTask));
}

/**
* Returns the status of a specific piece of Content in the Workflow it is assigned to. In
* summary:
* <ul>
* <li>The Workflow Scheme that the Contentlet is in.</li>
* <li>The Step that the Contentlet is in.</li>
* <li>The User assigned to such a Step.</li>
* </ul>
* Here's an example of how to use this endpoint:
* <pre>
* http://localhost:8080/api/v1/workflow/status/{contentletInode}
* </pre>
*
* @param request The current instance of the {@link HttpServletRequest}.
* @param response The current instance of the {@link HttpServletResponse}.
* @param contentletIdentifier The inode of the Contentlet whose status will be checked.
*
* @return The status information of the Contentlet in the Workflow it is assigned to.
*
* @throws DotDataException The specified Contentlet Inode was not found.
* @throws DotSecurityException The User calling this endpoint does not have required
* permissions to do so.
* @throws InvocationTargetException Failed to transform the {@link WorkflowTask} data for this
* view.
* @throws IllegalAccessException Failed to transform the {@link WorkflowTask} data for this
* view.
*/
@GET
@Path("/tasks/history/comments/{contentletIdentifier}")
@JSONP
@NoCache
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
@Operation(operationId = "getWorkflowTasksHistoryComments", summary = "Find workflow tasks history and comments of content",
description = "Retrieve the workflow tasks comments of a contentlet by its [id]" +
"(https://www.dotcms.com/docs/latest/content-versions#IdentifiersInodes).\n\n" +
"Returns an object containing the associated [workflow history or comments]" +
"https://www2.dotcms.com/docs/latest/workflow-tasks, [workflow task]",
tags = {"Workflow"},
responses = {
@ApiResponse(responseCode = "200", description = "Action(s) returned successfully",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ResponseEntityWorkflowHistoryCommentsView.class)
)
),
@ApiResponse(responseCode = "400", description = "Bad Requesy"),
@ApiResponse(responseCode = "401", description = "Invalid User"),
@ApiResponse(responseCode = "403", description = "Forbidden"),
@ApiResponse(responseCode = "500", description = "Internal Server Error") // includes when inode not found
}
)
public final ResponseEntityView<List<WorkflowTimelineItem>> getWorkflowTasksHistoryComments(@Context final HttpServletRequest request,
@Context final HttpServletResponse response,
@PathParam("contentletIdentifier") @Parameter(
required = true,
description = "Id of content to inspect for workflow tasks.\n\n",
schema = @Schema(type = "string")
) final String contentletIdentifier,
@DefaultValue("-1") @QueryParam("language") @Parameter(
description = "Language version of target content.",
schema = @Schema(type = "string")) final String language
)
throws DotDataException, DotSecurityException, InvocationTargetException, IllegalAccessException {

Logger.debug(this, String.format("Retrieving Workflow tasks for Contentlet with identifier " +
"'%s'", contentletIdentifier));
final InitDataObject initDataObject = new WebResource.InitBuilder(webResource)
.requestAndResponse(request, response)
.rejectWhenNoUser(true)
.requiredBackendUser(true).requiredFrontendUser(false).init();

final User user = initDataObject.getUser();
final long languageId = LanguageUtil.getLanguageId(language);
final PageMode mode = PageMode.get(request);

final Optional<Contentlet> currentContentlet = languageId <= 0?
this.workflowHelper.getContentletByIdentifier(contentletIdentifier, mode, initDataObject.getUser(),
()->WebAPILocator.getLanguageWebAPI().getLanguage(request).getId()):
this.contentletAPI.findContentletByIdentifierOrFallback
(contentletIdentifier, mode.showLive, languageId, initDataObject.getUser(), mode.respectAnonPerms);


if (currentContentlet.isPresent()) {

final WorkflowTask currentWorkflowTask = this.workflowAPI.findTaskByContentlet(currentContentlet.get());
final List<WorkflowTimelineItem> workflowComments = this.workflowAPI.getCommentsAndChangeHistory(currentWorkflowTask);
final List<WorkflowTimelineItemView> workflowTimelineItemViews = workflowComments.stream()
.map(wfTimeLine -> new WorkflowTimelineItemView(wfTimeLine.createdDate(), wfTimeLine.roleId(), this.workflowHelper.getPostedby(wfTimeLine.roleId()),
wfTimeLine.actionId(), wfTimeLine.stepId(), wfTimeLine.commentDescription(), wfTimeLine.taskId(), wfTimeLine.type()))
.collect(Collectors.toList());
return new ResponseEntityView<>(workflowComments);
}

throw new DoesNotExistException("Contentlet with identifier " + contentletIdentifier + " does not exist.");
}


} // E:O:F:WorkflowResource.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.dotcms.rest.api.v1.workflow;

import java.util.Date;

/**
* This class is used to return a list of WorkflowTimelineItem objects as a response entity.
*
* @author jsanca
*/
public class WorkflowTimelineItemView {

private final Date createdDate;
private final String roleId;
private final String postedBy;
private final String actionId;
private final String stepId;
private final String commentDescription;
private final String taskId;
private final String type;

public WorkflowTimelineItemView(Date createdDate, String roleId, String postedBy, String actionId, String stepId, String commentDescription, String taskId, String type) {
this.createdDate = createdDate;
this.roleId = roleId;
this.postedBy = postedBy;
this.actionId = actionId;
this.stepId = stepId;
this.commentDescription = commentDescription;
this.taskId = taskId;
this.type = type;
}

public Date getCreatedDate() {
return createdDate;
}

public String getRoleId() {
return roleId;
}

public String getPostedBy() {
return postedBy;
}

public String getActionId() {
return actionId;
}

public String getStepId() {
return stepId;
}

public String getCommentDescription() {
return commentDescription;
}

public String getTaskId() {
return taskId;
}

public String getType() {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2046,4 +2046,26 @@ public WorkflowTask handleWorkflowTaskData(final WorkflowTask wfTask) {
return wfTask;
}

/**
* Tries to recover the user name based on the role
* @param roleId
* @return String
*/
public String getPostedby(String roleId){

try {

return APILocator.getUserAPI().loadUserById(roleId, APILocator.systemUser(), false).getFullName();
} catch (Exception e) {
try{
return APILocator.getRoleAPI().loadRoleById(roleId).getName();
}
catch(Exception ee){

}
}
return "unknown";
}


} // E:O:F:WorkflowHelper.

0 comments on commit bc64107

Please sign in to comment.