Skip to content

Commit

Permalink
feat(contract): delete archived file input values (#3101)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbioteau authored Jul 30, 2024
1 parent d5100ce commit 133cf7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.bonitasoft.engine.core.contract.data;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.*;

Expand Down Expand Up @@ -63,6 +64,11 @@ protected SAContractData(long sourceObjectId, String name, Serializable value, l
private static Serializable clearFileInputContent(Serializable value) {
if (value instanceof FileInputValue inputValue) {
inputValue.setContent(null);
} else if (value instanceof Collection<?>) {
((Collection<?>) value).stream()
.filter(FileInputValue.class::isInstance)
.map(FileInputValue.class::cast)
.forEach(v -> v.setContent(null));
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.bonitasoft.engine.bpm.contract.FileInputValue;
import org.junit.jupiter.api.Test;

Expand All @@ -34,6 +38,23 @@ void clearFileInputContent() {
.isNull();
}

@Test
void clearMultipleFileInputContent() {
var contractData = new SProcessContractData();
contractData.setId(1);
contractData.setName("myFile");
contractData.setValue((Serializable) List.of(
new FileInputValue("theFile", "content".getBytes()),
new FileInputValue("theFile1", "content1".getBytes())));

var archivedContractData = new SAProcessContractData(contractData);

assertThat(archivedContractData.getValue()).isInstanceOf(Collection.class);
assertThat((Collection<?>) archivedContractData.getValue())
.extracting("content")
.containsNull();
}

@Test
void creatingSAProcessContractDataShouldCopyNonArchivedValues() {
long processInstanceId = 555L;
Expand Down

0 comments on commit 133cf7b

Please sign in to comment.