Skip to content

Commit

Permalink
#30510 now you can add wf comments (#30568)
Browse files Browse the repository at this point in the history
Now there is an endpoint to add wf comments
  • Loading branch information
jdotcms authored Nov 12, 2024
1 parent ae3aec7 commit b71b004
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dotcms.rest.api.v1.workflow;

import com.dotcms.rest.ResponseEntityView;

/**
* This class is used to return a WorkflowTimelineItemView object as a response entity.
* @author jsanca
*/
public class ResponseEntityWorkflowCommentView extends ResponseEntityView<WorkflowTimelineItemView> {
public ResponseEntityWorkflowCommentView(final WorkflowTimelineItemView entity) {
super(entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dotcms.rest.api.v1.workflow;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* This class is used to represent a WorkflowCommentForm object.
* @author jsanca
*/
public class WorkflowCommentForm {

private String comment;

@JsonCreator
public WorkflowCommentForm(@JsonProperty("comment") final String comment) {
this.comment = comment;
}

public String getComment() {
return comment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
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;
Expand Down Expand Up @@ -139,6 +140,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 @@ -2641,6 +2643,7 @@ public final Response fireActionByNameMultipart(@Context final HttpServletReques
return ResponseUtil.mapExceptionResponse(e);
}
}

/**
* Fires a workflow action by name, if the contentlet exists could use inode or identifier and optional language.
* @param request {@link HttpServletRequest}
Expand Down Expand Up @@ -3702,7 +3705,6 @@ private void mergeContentletsByDefaultAction(final List<SingleContentQuery> cont
new DotConcurrentFactory.SubmitterConfigBuilder().poolSize(2).maxPoolSize(5).queueCapacity(CONTENTLETS_LIMIT).build());
final CompletionService<Map<String, Object>> completionService = new ExecutorCompletionService<>(dotSubmitter);
final List<Future<Map<String, Object>>> futures = new ArrayList<>();
// todo: add the mock request
final HttpServletRequest statelessRequest = RequestUtil.INSTANCE.createStatelessRequest(request);


Expand Down Expand Up @@ -5677,7 +5679,6 @@ public final ResponseEntityWorkflowHistoryCommentsView getWorkflowTasksHistoryCo
this.contentletAPI.findContentletByIdentifierOrFallback
(contentletIdentifier, mode.showLive, languageId, initDataObject.getUser(), mode.respectAnonPerms);


if (currentContentlet.isPresent()) {

final WorkflowTask currentWorkflowTask = this.workflowAPI.findTaskByContentlet(currentContentlet.get());
Expand All @@ -5698,4 +5699,85 @@ private WorkflowTimelineItemView toWorkflowTimelineItemView(final WorkflowTimeli
wfTimeLine.commentDescription(), wfTimeLine.taskId(), wfTimeLine.type());
}

/**
* Creates a new workflow comment
*
* @param request HttpServletRequest
* @param workflowSchemeForm WorkflowSchemeForm
* @return Response
*/
@POST
@Path("/{contentletId}/comments")
@JSONP
@NoCache
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
@Consumes({MediaType.APPLICATION_JSON})
@Operation(operationId = "postSaveScheme", summary = "Create a workflow comment",
description = "Create a [workflow comment].\n\n " +
"Returns created workflow comment on success.",
tags = {"Workflow"},
responses = {
@ApiResponse(responseCode = "200", description = "Copied workflow comment successfully",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ResponseEntityWorkflowCommentView.class)
)
),
@ApiResponse(responseCode = "400", description = "Bad request"), // invalid param string like `\`
@ApiResponse(responseCode = "401", description = "Invalid User"), // not logged in
@ApiResponse(responseCode = "403", description = "Forbidden"), // no permission
@ApiResponse(responseCode = "500", description = "Internal Server Error")
}
)
public final ResponseEntityWorkflowCommentView saveComment(@Context final HttpServletRequest request,
@Context final HttpServletResponse response,
@PathParam("contentletId") @Parameter(
required = true,
description = "Identifier of contentlet to add comment.",
schema = @Schema(type = "string")
) final String contentletId,
@DefaultValue("-1") @QueryParam("language") @Parameter(
description = "Language version of target content.",
schema = @Schema(type = "string")) final String language,
@RequestBody(
description = "The request body consists of the following three properties:\n\n" +
"| Property | Type | Description |\n" +
"|-|-|-|\n" +
"| `comment` | String | The workflow comment. |\n",
content = @Content(
schema = @Schema(implementation = WorkflowCommentForm.class)
)
) final WorkflowCommentForm workflowCommentForm) throws DotDataException, DotSecurityException {

final InitDataObject initDataObject = new WebResource.InitBuilder(webResource)
.requestAndResponse(request, response)
.rejectWhenNoUser(true)
.requiredBackendUser(true).requiredFrontendUser(false).init();

DotPreconditions.notNull(workflowCommentForm,"Expected Request body was empty.");
Logger.debug(this, ()->"Saving a workflow comment for the contentletId: " + contentletId);

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(contentletId, mode, initDataObject.getUser(),
()->WebAPILocator.getLanguageWebAPI().getLanguage(request).getId()):
this.contentletAPI.findContentletByIdentifierOrFallback
(contentletId, mode.showLive, languageId, initDataObject.getUser(), mode.respectAnonPerms);
if (currentContentlet.isPresent()) {

final WorkflowTask task = this.workflowAPI.findTaskByContentlet(currentContentlet.get());
final WorkflowComment taskComment = new WorkflowComment();
taskComment.setComment(workflowCommentForm.getComment());
taskComment.setCreationDate(new Date());
taskComment.setPostedBy(user.getUserId());
taskComment.setWorkflowtaskId(task.getId());
this.workflowAPI.saveComment(taskComment);
return new ResponseEntityWorkflowCommentView(
toWorkflowTimelineItemView(taskComment));
}

throw new DoesNotExistException("Contentlet with identifier " + contentletId + " does not exist.");
}
} // E:O:F:WorkflowResource.
Loading

0 comments on commit b71b004

Please sign in to comment.