Skip to content

Commit

Permalink
JBPM-10022 Forms are rendered without Accordion elements when startin…
Browse files Browse the repository at this point in the history
…g a process from Business Central (#1533)
  • Loading branch information
bxf12315 committed Jul 22, 2022
1 parent ebbf150 commit 797382a
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 7 deletions.
Expand Up @@ -17,6 +17,7 @@
package org.jbpm.workbench.forms.display.backend;

import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -29,6 +30,8 @@
import javax.servlet.http.HttpServletResponse;

import org.jbpm.workbench.ks.integration.KieServerIntegration;
import org.kie.internal.process.CorrelationKey;
import org.kie.internal.process.CorrelationProperty;
import org.kie.server.api.marshalling.json.StringContentCaseFile;
import org.kie.server.api.marshalling.json.StringContentMap;
import org.kie.server.client.CaseServicesClient;
Expand Down Expand Up @@ -85,6 +88,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// process and case start operations
String serverTemplateId = req.getParameter("templateid");
String correlationKey = req.getParameter("correlationKey");

String pathInfo = req.getPathInfo();

if (pathInfo == null) {
Expand All @@ -107,8 +112,28 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
String processId = extractValue(processIdPattern, pathInfo);
ProcessServicesClient processServicesClient = getClient(serverTemplateId,
ProcessServicesClient.class);

Long responseBody = processServicesClient.startProcess(containerId, processId, new StringContentMap(body));
Long responseBody = 0L;
if (correlationKey != null && !correlationKey.isEmpty()) {

responseBody = processServicesClient.startProcess(containerId, processId, new CorrelationKey() {
@Override
public String getName() {
return correlationKey;
}

@Override
public List<CorrelationProperty<?>> getProperties() {
return null;
}

@Override
public String toExternalForm() {
return correlationKey;
}
}, new StringContentMap(body));
} else {
responseBody = processServicesClient.startProcess(containerId, processId, new StringContentMap(body));
}

resp.getOutputStream().write(responseBody.toString().getBytes("UTF-8"));
}
Expand Down
@@ -0,0 +1,87 @@
/*
* Copyright 2022 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jbpm.workbench.forms.display.backend;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.stream.Stream;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jbpm.workbench.ks.integration.KieServerIntegration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.server.client.ProcessServicesClient;
import org.kie.server.client.impl.KieServicesClientImpl;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class FormRendererProxyServletTest {

@Mock
KieServerIntegration kieServerIntegration;

@InjectMocks
FormRendererProxyServlet servlet;

@Test
public void testStartProcessWithKieServerFormRenderer() throws IOException, ServletException {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);

String correlationKey = "test-correlationKey";
when(request.getParameter(eq("templateid"))).thenReturn("test-templateid");
when(request.getParameter(eq("correlationKey"))).thenReturn(correlationKey);
when(request.getPathInfo()).thenReturn("/containers/1/processes/2");

BufferedReader reader = mock(BufferedReader.class);
Stream<String> stream = mock(Stream.class);
when(request.getReader()).thenReturn(reader);
when(reader.lines()).thenReturn(stream);
when(stream.collect(any())).thenReturn("{\"name\" : \"value\"}");

KieServicesClientImpl client = mock(KieServicesClientImpl.class);
when(kieServerIntegration.getServerClient(any())).thenReturn(client);
ProcessServicesClient processServicesClient = mock(ProcessServicesClient.class);
when(client.getServicesClient(any())).thenReturn(processServicesClient);

ServletOutputStream servletOutputStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(servletOutputStream);
doNothing().when(servletOutputStream).write(any());

servlet.doPost(request, response);
verify(processServicesClient).startProcess(eq("1"), eq("2"), any(), any());

when(request.getParameter(eq("correlationKey"))).thenReturn(null);

servlet.doPost(request, response);
verify(processServicesClient).startProcess(eq("1"), eq("2"), anyMap());
}
}
Expand Up @@ -28,6 +28,7 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.IsWidget;
import org.gwtbootstrap3.client.ui.TextBox;
import org.jbpm.workbench.forms.client.display.process.AbstractStartProcessFormDisplayer;
import org.jbpm.workbench.forms.client.i18n.Constants;
import org.jbpm.workbench.forms.display.FormDisplayerConfig;
Expand Down Expand Up @@ -56,6 +57,7 @@ public Class<KieServerFormRenderingSettings> getSupportedRenderingSettings() {
protected void initDisplayer() {
startProcessCallback(this);
startCaseCallback(this);
correlationKeyValue(this);
}

@Override
Expand All @@ -71,10 +73,10 @@ public void init(FormDisplayerConfig<ProcessDefinitionKey, KieServerFormRenderin
footerButtons.clear();

container.add(formContainer);

initDisplayer();
correlationKey = new TextBox();

formContainer.add(getFormWidget());
initDisplayer();
initFormWithCorrelationKey();
}

@Override
Expand All @@ -95,7 +97,6 @@ public IsWidget getFormWidget() {
inlineFrame.getElement().getStyle().setLeft(0, Unit.PX);

inlineFrame.setUrl(renderingSettings.getUrl());

FlowPanel div = GWT.create(FlowPanel.class);
div.getElement().getStyle().setPosition(Position.RELATIVE);
div.getElement().getStyle().setOverflow(Overflow.HIDDEN);
Expand Down Expand Up @@ -134,7 +135,11 @@ public void notifyAboutStartCase(String id) {

close();
}


public String getCorrelationKeyValue(){
return correlationKey.getValue();
}

public static native void startProcessCallback(KieServerFormsStartProcessDisplayer dp)/*-{
$wnd.afterProcessStarted = function (processInstanceId) {
dp.@org.jbpm.workbench.forms.client.display.KieServerFormsStartProcessDisplayer::notifyAboutStartProcess(Ljava/lang/String;)(processInstanceId);
Expand All @@ -147,6 +152,12 @@ public static native void startCaseCallback(KieServerFormsStartProcessDisplayer
}
}-*/;

public static native String correlationKeyValue(KieServerFormsStartProcessDisplayer dp)/*-{
$wnd.getCorrelationKey = function () {
return dp.@org.jbpm.workbench.forms.client.display.KieServerFormsStartProcessDisplayer::getCorrelationKeyValue()();
}
}-*/;

@Override
public boolean appendFooter() {
return false;
Expand Down
Expand Up @@ -129,6 +129,10 @@ public void onClick(ClickEvent event) {

initDisplayer();

initFormWithCorrelationKey();
}

protected void initFormWithCorrelationKey() {
final PanelGroup accordion = new PanelGroup();
accordion.setId(DOM.createUniqueId());

Expand Down

0 comments on commit 797382a

Please sign in to comment.