Skip to content

Commit

Permalink
[7.67.x-blue] [RHPAM-4445] Unable to update the task description with…
Browse files Browse the repository at this point in the history
… long string(more than 255 chars) (kiegroup#2208)

* [RHPAM-4445] Unable to update the task description with long string(more than 255 chars)

* [RHPAM-4445] Unable to update the task description with long string(more than 255 chars)

Co-authored-by: Abhijit Humbe <abhumbe@abhumbe.pnq.csb>
  • Loading branch information
2 people authored and fjtirado committed Oct 5, 2022
1 parent 2b8e661 commit f428e22
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
Expand Up @@ -63,6 +63,8 @@ public class JPATaskLifeCycleEventListener extends PersistableEventListener impl
private static final Logger logger = LoggerFactory.getLogger(JPATaskLifeCycleEventListener.class);
private List<ArchiveLoggerProvider> archiveLoggerProviders;

private static final int TASK_DESCRIPTION_LENGTH = Integer.parseInt(System.getProperty("org.jbpm.ht.task.description.length", "255"));


public JPATaskLifeCycleEventListener(boolean flag) {
super(null);
Expand Down Expand Up @@ -641,10 +643,10 @@ public void beforeTaskUpdatedEvent(TaskEvent event) {

}

public String getUpdateFieldLog(String fieldName, String previousValue, String value){
return "Updated "+ fieldName
+ " {From: '"+ (previousValue!=null ? previousValue : "" )
+ "' to: '"+ (value!=null ? value : "" ) + "'}" ;
public String getUpdateFieldLog(String fieldName, String previousValue, String value) {
return "Updated " + fieldName
+ " {From: '"+ (previousValue != null ? previousValue : "")
+ "' to: '"+ (value != null ? value : "") + "'}";
}

@Override
Expand All @@ -659,10 +661,15 @@ public void afterTaskUpdatedEvent(TaskEvent event) {
return;
}

if((ti.getDescription() != null && !ti.getDescription().equals(auditTaskImpl.getDescription()))
|| (ti.getDescription() == null && auditTaskImpl.getDescription() != null)){
if ((ti.getDescription() != null && !ti.getDescription().equals(auditTaskImpl.getDescription()))
|| (ti.getDescription() == null && auditTaskImpl.getDescription() != null)) {
String message = getUpdateFieldLog("Description", auditTaskImpl.getDescription(), ti.getDescription());

if (message != null && message.length() > TASK_DESCRIPTION_LENGTH) {
message = message.substring(0, (TASK_DESCRIPTION_LENGTH - 2)) + "'}";
logger.warn("TaskEvent message content was trimmed as it was too long(more than {} characters)", TASK_DESCRIPTION_LENGTH);
}

TaskEventImpl taskEventImpl = new TaskEventImpl(event,
TaskEventType.UPDATED,
message);
Expand Down
Expand Up @@ -375,6 +375,63 @@ public void testDescriptionUpdateFromEmpty() {
true,
"Updated Description {From: '' to: 'new description'}");
}

private void testLongTaskDescription(String oldDescription,
String newDescription,
String expectedDescription,
boolean changeExpected,
String expectedMessage) {
Task task = new TaskFluent()
.setDescription(oldDescription)
.setAdminUser("Administrator")
.getTask();
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();

List<I18NText> descriptions = new ArrayList<I18NText>();
descriptions.add(new I18NTextImpl("", newDescription));
taskService.setDescriptions(taskId, descriptions);

task = taskService.getTaskById(taskId);
Assertions.assertThat(task.getDescription()).isEqualTo(expectedDescription);

List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
Assertions.assertThat(auditTasks).hasSize(1);
Assertions.assertThat(auditTasks.get(0).getDescription()).isEqualTo(expectedDescription);

List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
if (changeExpected) {
Assertions.assertThat(taskEvents).hasSize(2);
Assertions.assertThat(taskEvents.get(1).getMessage()).isEqualTo(expectedMessage);
} else {
Assertions.assertThat(taskEvents).hasSize(1);
}
}



@Test
public void testLongTaskDescriptionUpdateFromEmpty() {
System.setProperty("org.jbpm.ht.task.description.length", "255");

testLongTaskDescription("",
"Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-44459999999999999",
"Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445999999999",
true,
"Updated Description {From: '' to: 'Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.'}");
System.clearProperty("org.jbpm.ht.task.description.length");
}

@Test
public void testLongTaskDescriptionUpdateDifferent() {
System.setProperty("org.jbpm.ht.task.description.length", "255");
testLongTaskDescription("old Description",
"Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-44459999999999999",
"Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445999999999",
true,
"Updated Description {From: 'old Description' to: 'Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira https://issues.redhat.com/browse/RHPAM-4445Long task description to test the jira '}");
System.clearProperty("org.jbpm.ht.task.description.length");
}

private void testNameUpdate(String oldName,
String newName,
Expand Down
Expand Up @@ -38,6 +38,7 @@
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import org.jbpm.services.task.utils.CollectionUtils;
Expand All @@ -48,6 +49,8 @@
import org.kie.internal.task.api.model.Delegation;
import org.kie.internal.task.api.model.InternalTask;
import org.kie.internal.task.api.model.SubTasksStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Entity
@Table(name="Task",
Expand All @@ -65,6 +68,14 @@ public class TaskImpl implements InternalTask {
* WSHT uses a name for the unique identifier, for now we use a generated ID which is also the key, which can be
* mapped to the name or a unique name field added later.
*/

private static final Logger logger = LoggerFactory.getLogger(TaskImpl.class);

@Transient
private static final int TASK_DESCRIPTION_LENGTH = Integer.parseInt(System.getProperty("org.jbpm.ht.task.description.length", "255"));



@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="taskIdSeq")
@Column(name = "id")
Expand Down Expand Up @@ -431,6 +442,10 @@ public String getDescription() {
}

public void setDescription(String description) {
if (description != null && description.length() > TASK_DESCRIPTION_LENGTH) {
description = description.substring(0, TASK_DESCRIPTION_LENGTH);
logger.warn("Task Description content was trimmed as it was too long (more than {} characters)", TASK_DESCRIPTION_LENGTH);
}
this.description = description;
}

Expand Down

0 comments on commit f428e22

Please sign in to comment.