Skip to content

Commit

Permalink
JBPM-6894 - User should be able to define case, process, activity lev…
Browse files Browse the repository at this point in the history
…el SLA (#990)
  • Loading branch information
mswiderski authored and cristianonicolai committed Mar 8, 2018
1 parent f8a4491 commit aad4b2b
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 8 deletions.
4 changes: 4 additions & 0 deletions jbpm-wb-common/jbpm-wb-common-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.elemental2</groupId>
<artifactId>elemental2-dom</artifactId>
</dependency>

<!-- Test deps -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2018 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.common.client.util;

import java.util.ArrayList;
import java.util.List;

import elemental2.dom.DomGlobal;
import elemental2.dom.Element;
import org.kie.api.runtime.process.ProcessInstance;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

public class SLAComplianceCell extends AbstractCell<Integer> {

private static final String SLA_STYLE = "label";
private static final String SLA_NA_PRESENT_STYLE = "label-default";
private static final String SLA_PENDING_PRESENT_STYLE = "label-primary";
private static final String SLA_MET_PRESENT_STYLE = "label-success";
private static final String SLA_ABORTED_PRESENT_STYLE = "label-warning";
private static final String SLA_VIOLATED_PRESENT_STYLE = "label-danger";

private List<String> descriptions;

public SLAComplianceCell(final List<String> descriptions) {
this.descriptions = descriptions;
}

@Override
public void render(Context context,
Integer value,
SafeHtmlBuilder sb) {

List<String> tooltipClasses = new ArrayList<>();

tooltipClasses.add(SLA_STYLE);
String description = descriptions.get(0);
switch (value) {
case ProcessInstance.SLA_NA:
description = descriptions.get(1);
tooltipClasses.add(SLA_NA_PRESENT_STYLE);

break;
case ProcessInstance.SLA_PENDING:
description = descriptions.get(2);
tooltipClasses.add(SLA_PENDING_PRESENT_STYLE);
break;
case ProcessInstance.SLA_MET:
description = descriptions.get(3);
tooltipClasses.add(SLA_MET_PRESENT_STYLE);
break;
case ProcessInstance.SLA_ABORTED:
description = descriptions.get(4);
tooltipClasses.add(SLA_ABORTED_PRESENT_STYLE);
break;
case ProcessInstance.SLA_VIOLATED:
description = descriptions.get(5);
tooltipClasses.add(SLA_VIOLATED_PRESENT_STYLE);
break;
default:
description = descriptions.get(0);
tooltipClasses.add(SLA_NA_PRESENT_STYLE);
break;

}

Element span = DomGlobal.document.createElement("span");
span.textContent = description;
tooltipClasses.forEach(c -> span.classList.add(c));
Element content = DomGlobal.document.createElement("span");
content.appendChild(span);
sb.appendHtmlConstant(content.innerHTML);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public final class ProcessInstanceDataSetConstants {
public static final String COLUMN_EXTERNAL_ID = "externalId";
public static final String COLUMN_PROCESS_INSTANCE_DESCRIPTION = "processInstanceDescription";
public static final String COLUMN_LAST_MODIFICATION_DATE = "lastModificationDate";
public static final String COLUMN_SLA_DUE_DATE = "sla_due_date";
public static final String COLUMN_SLA_COMPLIANCE = "slaCompliance";
public static final String COLUMN_ERROR_COUNT = "errorCount";
public static final String PROCESS_INSTANCES_WITH_VARIABLES_INCLUDED_LIST_PREFIX = "DS_ProcessInstancesWithVariablesIncludedGrid";
public static final String PROCESS_INSTANCE_ID = "processInstanceId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class ProcessInstanceSummary extends GenericErrorSummary<Long> {
private Map<String, String> domainData = new HashMap<String, String>();
private List<UserTaskSummary> activeTasks;
private Date lastModificationDate;
private Integer slaCompliance;
private Date slaDueDate;

public ProcessInstanceSummary(Long processInstanceId,
String processId,
Expand All @@ -56,6 +58,8 @@ public ProcessInstanceSummary(Long processInstanceId,
String correlationKey,
Long parentId,
Date lastModificationDate,
Integer slaCompliance,
Date slaDueDate,
Integer errorCount) {
super(errorCount, processInstanceId, processName);
this.id = processInstanceId;
Expand All @@ -73,6 +77,8 @@ public ProcessInstanceSummary(Long processInstanceId,
this.correlationKey = correlationKey;
this.parentId = parentId;
this.lastModificationDate = lastModificationDate;
this.slaCompliance = slaCompliance;
this.slaDueDate = slaDueDate;
}

public ProcessInstanceSummary() {
Expand Down Expand Up @@ -203,6 +209,22 @@ public Date getLastModificationDate() {
public void setLastModificationDate(Date lastModificationDate) {
this.lastModificationDate = lastModificationDate;
}

public Integer getSlaCompliance() {
return slaCompliance;
}

public void setSlaCompliance(Integer slaCompliance) {
this.slaCompliance = slaCompliance;
}

public Date getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(Date slaDueDate) {
this.slaDueDate = slaDueDate;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected void registerDataSetDefinitions() {
"log.correlationKey, " +
"log.externalId, " +
"log.processInstanceDescription, " +
"log.sla_due_date, " +
"log.slaCompliance, " +
"COALESCE(info.lastModificationDate, log.end_date) as lastModificationDate, " +
"(select COUNT(errInfo.id) " +
"from " +
Expand Down Expand Up @@ -90,7 +92,9 @@ protected void registerDataSetDefinitions() {
.label(COLUMN_PROCESS_NAME)
.label(COLUMN_CORRELATION_KEY)
.label(COLUMN_EXTERNAL_ID)
.label(COLUMN_PROCESS_INSTANCE_DESCRIPTION)
.label(COLUMN_PROCESS_INSTANCE_DESCRIPTION)
.date(COLUMN_SLA_DUE_DATE)
.number(COLUMN_SLA_COMPLIANCE)
.date(COLUMN_LAST_MODIFICATION_DATE)
.number(COLUMN_ERROR_COUNT)
.buildDef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ protected ProcessInstanceSummary build(ProcessInstance processInstance) {
processInstance.getCorrelationKey(),
processInstance.getParentId(),
null,
processInstance.getSlaCompliance(),
processInstance.getSlaDueDate(),
0
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public void getProcessInstanceDetailsTest() {
verify(processInstanceSpy).getProcessVersion();
verify(processInstanceSpy).getCorrelationKey();
verify(processInstanceSpy).getParentId();
verify(processInstanceSpy).getSlaCompliance();
verify(processInstanceSpy).getSlaDueDate();
verifyActiveUserTasks(taskSummaryListSpy,
taskSummaryMock);
verifyCurrentActivities(processInstanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.elemental2</groupId>
<artifactId>elemental2-dom</artifactId>
</dependency>

<!-- hack to disable sisu annotation processing (that scans client side types) -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public void callback(final ProcessInstanceSummary process) {
default:
break;
}
view.getStateText().setText(statusStr);

String slaComplianceStr = mapSlaCompliance(process);
view.setSlaComplianceText(slaComplianceStr);

if (process.getActiveTasks() != null && !process.getActiveTasks().isEmpty()) {
SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
Expand All @@ -127,7 +131,7 @@ public void callback(final ProcessInstanceSummary process) {
}
view.getActiveTasksListBox().setHTML(safeHtmlBuilder.toSafeHtml());
}
view.getStateText().setText(statusStr);

}
}).getProcessInstance(serverTemplateId,
new ProcessInstanceKey(serverTemplateId,
Expand All @@ -149,6 +153,30 @@ public void callback(final List<NodeInstanceSummary> details) {
Long.parseLong(processId));
}

protected String mapSlaCompliance(ProcessInstanceSummary process) {
String slaComplianceStr = constants.Unknown();
switch (process.getSlaCompliance()) {
case ProcessInstance.SLA_NA:
slaComplianceStr = constants.SlaNA();
break;
case ProcessInstance.SLA_PENDING:
slaComplianceStr = constants.SlaPending();
break;
case ProcessInstance.SLA_MET:
slaComplianceStr = constants.SlaMet();
break;
case ProcessInstance.SLA_ABORTED:
slaComplianceStr = constants.SlaAborted();
break;
case ProcessInstance.SLA_VIOLATED:
slaComplianceStr = constants.SlaViolated();
break;
default:
break;
}
return slaComplianceStr;
}

public interface ProcessInstanceDetailsView extends IsWidget {

// TODO Review interface to not expose GWT components
Expand All @@ -167,5 +195,7 @@ public interface ProcessInstanceDetailsView extends IsWidget {
HTML getCorrelationKeyText();

HTML getParentProcessInstanceIdText();

void setSlaComplianceText(String value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
<p class="form-control-static" data-field="processVersionText" id="processVersionText"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" for="slaComplianceText" data-field="slaComplianceLabel"></label>

<div class="col-md-8">
<p class="form-control-static" data-field="slaComplianceText" id="slaComplianceText"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" for="correlationKeyText" data-field="correlationKeyLabel"></label>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;

import elemental2.dom.HTMLParagraphElement;

import org.gwtbootstrap3.client.ui.FormLabel;
import org.jboss.errai.ui.shared.api.annotations.DataField;
import org.jboss.errai.ui.shared.api.annotations.Templated;
Expand All @@ -43,6 +46,10 @@ public class ProcessInstanceDetailsViewImpl extends Composite implements
@Inject
@DataField
public HTML processVersionText;

@Inject
@DataField
public HTMLParagraphElement slaComplianceText;

@Inject
@DataField
Expand Down Expand Up @@ -75,6 +82,10 @@ public class ProcessInstanceDetailsViewImpl extends Composite implements
@Inject
@DataField
public FormLabel processVersionLabel;

@Inject
@DataField
public FormLabel slaComplianceLabel;

@Inject
@DataField
Expand Down Expand Up @@ -103,6 +114,7 @@ public void init() {
processDefinitionIdLabel.setText(constants.Process_Definition_Id());
processDeploymentLabel.setText(constants.Deployment_Name());
processVersionLabel.setText(constants.Process_Definition_Version());
slaComplianceLabel.setText(constants.Process_SLA_Compliance());
correlationKeyLabel.setText(constants.Correlation_Key());
stateLabel.setText(constants.Process_Instance_State());
activeTasksListLabel.setText(constants.Active_Tasks());
Expand Down Expand Up @@ -149,4 +161,9 @@ public HTML getParentProcessInstanceIdText() {
public HTML getProcessVersionText() {
return processVersionText;
}

@Override
public void setSlaComplianceText(String value) {
slaComplianceText.textContent = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ protected ProcessInstanceSummary createProcessInstanceSummaryFromDataSet(DataSet
getColumnDateValue(dataSet,
COLUMN_LAST_MODIFICATION_DATE,
i),
getColumnIntValue(dataSet,
COLUMN_SLA_COMPLIANCE,
i),
getColumnDateValue(dataSet,
COLUMN_SLA_DUE_DATE,
i),
getColumnIntValue(dataSet,
COLUMN_ERROR_COUNT,
i)
Expand Down
Loading

0 comments on commit aad4b2b

Please sign in to comment.