Skip to content

Commit

Permalink
#30629 adding the first step + postmans (#30631)
Browse files Browse the repository at this point in the history
Adding the first step the default initial acitons
  • Loading branch information
jdotcms authored Nov 12, 2024
1 parent 474fab0 commit ac4a771
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.portlets.workflows.model.WorkflowScheme;
import com.dotmarketing.portlets.workflows.model.WorkflowStep;

/**
* View just to encapsulate a scheme and an action for the default workflow actions
Expand All @@ -11,11 +12,13 @@ public class WorkflowDefaultActionView {

private final WorkflowScheme scheme;
private final WorkflowAction action;
private final WorkflowStep firstStep;

public WorkflowDefaultActionView(WorkflowScheme scheme, WorkflowAction action) {
public WorkflowDefaultActionView(final WorkflowScheme scheme, final WorkflowAction action, final WorkflowStep step) {

this.scheme = scheme;
this.action = action;
this.firstStep = step;
}

public WorkflowScheme getScheme() {
Expand All @@ -25,4 +28,8 @@ public WorkflowScheme getScheme() {
public WorkflowAction getAction() {
return action;
}

public WorkflowStep getFirstStep() {
return firstStep;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5211,29 +5211,22 @@ public final Response copyScheme(@Context final HttpServletRequest httpServletRe
@ApiResponse(responseCode = "500", description = "Internal Server Error")
}
)
public final Response findAvailableDefaultActionsByContentType(@Context final HttpServletRequest request,
public final ResponseEntityDefaultWorkflowActionsView findAvailableDefaultActionsByContentType(@Context final HttpServletRequest request,
@Context final HttpServletResponse response,
@PathParam("contentTypeId") @Parameter(
required = true,
description = "Identifier or variable of content type to examine for actions.\n\n" +
"Example ID: `c541abb1-69b3-4bc5-8430-5e09e5239cc8` (Default page content type)\n\n" +
"Example Variable: `htmlpageasset` (Default page content type)",
schema = @Schema(type = "string")
) final String contentTypeId) {
) final String contentTypeId) throws NotFoundInDbException {
final InitDataObject initDataObject = this.webResource.init
(null, request, response, true, null);
try {
Logger.debug(this,
() -> "Getting the available workflow schemes default action for the ContentType: "
+ contentTypeId );
final List<WorkflowDefaultActionView> actions = this.workflowHelper.findAvailableDefaultActionsByContentType(contentTypeId, initDataObject.getUser());
return Response.ok(new ResponseEntityView<>(actions)).build(); // 200
} catch (Exception e) {
Logger.error(this.getClass(),
"Exception on find Available Default Actions exception message: " + e.getMessage(), e);
return ResponseUtil.mapExceptionResponse(e);
}

return new ResponseEntityDefaultWorkflowActionsView(actions);
} // findAvailableDefaultActionsByContentType.

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import com.liferay.portal.language.LanguageUtil;
import com.liferay.portal.model.User;
import com.liferay.util.StringPool;
import io.vavr.control.Try;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.velocity.context.Context;
Expand Down Expand Up @@ -1772,21 +1773,28 @@ public WorkflowAction getAction() {
* @return List<WorkflowDefaultActionView>
*/
@CloseDBIfOpened
public List<WorkflowDefaultActionView> findAvailableDefaultActionsByContentType(final String contentTypeId, final User user) {
public List<WorkflowDefaultActionView> findAvailableDefaultActionsByContentType(final String contentTypeId, final User user) throws NotFoundInDbException {
final ContentTypeAPI contentTypeAPI = APILocator.getContentTypeAPI(user);
final ImmutableList.Builder<WorkflowDefaultActionView> results = new ImmutableList.Builder<>();
final Map<String, WorkflowStep> steps = new HashMap<>();
try {

Logger.debug(this, () -> "Getting the available default workflows actions by content type: " + contentTypeId);
//When no license is available. This should get the system workflow.
final List<WorkflowAction> actions = this.workflowAPI.findAvailableDefaultActionsByContentType(contentTypeAPI.find(contentTypeId), user);
for (final WorkflowAction action : actions){
final WorkflowScheme scheme = this.workflowAPI.findScheme(action.getSchemeId());
final WorkflowDefaultActionView value = new WorkflowDefaultActionView(scheme, action);
steps.computeIfAbsent(scheme.getId(), k -> Try.of(()->this.workflowAPI.findFirstStep(scheme.getId()).orElse(null)).get());
final WorkflowDefaultActionView value = new WorkflowDefaultActionView(scheme, action, steps.get(scheme.getId()));
results.add(value);
}

} catch (DotDataException | DotSecurityException e) {
} catch (NotFoundInDbException e) {
Logger.error(this, e.getMessage());
Logger.debug(this, e.getMessage(), e);
throw e;
}
catch (DotDataException | DotSecurityException e) {

Logger.error(this, e.getMessage());
Logger.debug(this, e.getMessage(), e);
Expand Down Expand Up @@ -1888,9 +1896,11 @@ public List<WorkflowDefaultActionView> findInitialAvailableActionsByContentType(
*/
private List<WorkflowDefaultActionView> buildDefaultActionsViewObj(final List<WorkflowAction> actions) throws DotDataException, DotSecurityException {
final ImmutableList.Builder<WorkflowDefaultActionView> results = new ImmutableList.Builder<>();
final Map<String, WorkflowStep> steps = new HashMap<>();
for (final WorkflowAction action : actions) {
final WorkflowScheme scheme = this.workflowAPI.findScheme(action.getSchemeId());
final WorkflowDefaultActionView value = new WorkflowDefaultActionView(scheme, action);
steps.computeIfAbsent(scheme.getId(), k -> Try.of(()->this.workflowAPI.findFirstStep(scheme.getId()).orElse(null)).get());
final WorkflowDefaultActionView value = new WorkflowDefaultActionView(scheme, action, steps.get(scheme.getId()));
results.add(value);
}
return results.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.dotmarketing.db.LocalTransaction;
import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.workflows.business.DotWorkflowException;
import com.dotmarketing.portlets.workflows.business.WorkflowAPI;
import com.dotmarketing.portlets.workflows.business.WorkflowAPIImpl;
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
Expand All @@ -45,7 +46,6 @@
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -73,9 +73,9 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -614,17 +614,16 @@ public void Find_Available_Actions_Invalid_License() throws Exception {
public void Find_Available_Default_Actions_Invalid_License() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
final ContentType contentType = new ContentTypeDataGen().nextPersisted();// Uses the System Workflow by default
final Response response = nonLicenseWorkflowResource.findAvailableDefaultActionsByContentType(request, new EmptyHttpResponse(), contentType.id());
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
ResponseEntityView ev = ResponseEntityView.class.cast(response.getEntity());
List<WorkflowDefaultActionView> actions = List.class.cast(ev.getEntity());
final ResponseEntityDefaultWorkflowActionsView response = nonLicenseWorkflowResource.findAvailableDefaultActionsByContentType(request, new EmptyHttpResponse(), contentType.id());
assertNotNull(response);
List<WorkflowDefaultActionView> actions = response.getEntity();
for(WorkflowDefaultActionView av:actions){
assertTrue(av.getScheme().isSystem());
}
}

@SuppressWarnings("unchecked")
@Test
@Test(expected = DotWorkflowException.class)
public void Find_Available_Default_Actions_No_Read_Permission_Invalid_License()
throws Exception {

Expand All @@ -637,10 +636,8 @@ public void Find_Available_Default_Actions_No_Read_Permission_Invalid_License()
BaseContentType.CONTENT, editPermission, role.getId());

final HttpServletRequest request = mock(HttpServletRequest.class);
final Response findResponse = nonLicenseWorkflowResource
final ResponseEntityDefaultWorkflowActionsView findResponse = nonLicenseWorkflowResource
.findAvailableDefaultActionsByContentType(request, new EmptyHttpResponse(), contentType.id());
assertEquals(Status.FORBIDDEN.getStatusCode(), findResponse.getStatus());
assertEquals(ACCESS_CONTROL_HEADER_PERMISSION_VIOLATION, findResponse.getHeaderString("access-control"));
} finally {
if(contentType != null){
APILocator.getContentTypeAPI(APILocator.systemUser()).delete(contentType);
Expand Down
Loading

0 comments on commit ac4a771

Please sign in to comment.